Learn R Programming

bruceR (version 0.7.2)

Corr: Correlation analysis (to R Console or MS Word).

Description

Correlation analysis (to R Console or MS Word).

Usage

Corr(
  data,
  method = "pearson",
  p.adjust = "none",
  all.as.numeric = TRUE,
  digits = 2,
  nsmall = digits,
  file = NULL,
  plot = TRUE,
  plot.range = c(-1, 1),
  plot.palette = NULL,
  plot.color.levels = 201,
  plot.file = NULL,
  plot.width = 8,
  plot.height = 6,
  plot.dpi = 500
)

Arguments

data

Data frame.

method

"pearson" (default), "spearman", or "kendall".

p.adjust

Adjustment of p values for multiple tests: "none", "fdr", "holm", "bonferroni", ... For details, see stats::p.adjust().

all.as.numeric

TRUE (default) or FALSE. Transform all variables into numeric (continuous).

digits, nsmall

Number of decimal places of output. Default is 2.

file

File name of MS Word (.doc).

plot

TRUE (default) or FALSE. Plot the correlation matrix.

plot.range

Range of correlation coefficients for plot. Default is c(-1, 1).

plot.palette

Color gradient for plot. Default is c("#B52127", "white", "#2171B5"). You may also set it to, e.g., c("red", "white", "blue").

plot.color.levels

Default is 201.

plot.file

NULL (default, plot in RStudio) or a file name ("xxx.png").

plot.width

Width (in "inch") of the saved plot. Default is 8.

plot.height

Height (in "inch") of the saved plot. Default is 6.

plot.dpi

DPI (dots per inch) of the saved plot. Default is 500.

Value

Invisibly return the correlation results obtained from psych::corr.test().

See Also

Describe

Examples

Run this code
# NOT RUN {
Corr(airquality)
Corr(airquality, p.adjust="bonferroni")

d=as.data.table(psych::bfi)
d[,`:=`(
  gender=as.factor(gender),
  education=as.factor(education),
  E=MEAN(d, "E", 1:5, rev=c(1,2), likert=1:6),
  A=MEAN(d, "A", 1:5, rev=1, likert=1:6),
  C=MEAN(d, "C", 1:5, rev=c(4,5), likert=1:6),
  N=MEAN(d, "N", 1:5, likert=1:6),
  O=MEAN(d, "O", 1:5, rev=c(2,5), likert=1:6)
)]
Corr(d[,.(age, gender, education, E, A, C, N, O)])

# }

Run the code above in your browser using DataLab