Corr: Correlation analysis.

View source: R/bruceR-stats_1_basic.R

CorrR Documentation

Correlation analysis.

Description

Correlation analysis.

Usage

Corr(
  data,
  method = "pearson",
  p.adjust = "none",
  all.as.numeric = TRUE,
  digits = 2,
  file = NULL,
  plot = TRUE,
  plot.r.size = 4,
  plot.colors = NULL,
  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

Number of decimal places of output. Defaults to 2.

file

File name of MS Word (.doc).

plot

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

plot.r.size

Font size of correlation text label. Defaults to 4.

plot.colors

Plot colors (character vector). Defaults to "RdBu" of the Color Brewer Palette.

plot.file

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

plot.width

Width (in "inch") of the saved plot. Defaults to 8.

plot.height

Height (in "inch") of the saved plot. Defaults to 6.

plot.dpi

DPI (dots per inch) of the saved plot. Defaults to 500.

Value

Invisibly return a list with (1) correlation results from psych::corr.test() and (2) a ggplot2 object if plot=TRUE.

See Also

Describe

cor_multilevel

Examples

Corr(airquality)
Corr(airquality, p.adjust="bonferroni",
     plot.colors=c("#b2182b", "white", "#2166ac"))

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


bruceR documentation built on June 22, 2024, 12:26 p.m.