corr: Correlation matrix

View source: R/models.R

corrR Documentation

Correlation matrix

Description

Computes Pearson, Spearman, or Kendall correlations from variables in a data frame. With data = NULL, the active data set is used.

Usage

corr(
  ...,
  data = NULL,
  method = c("pearson", "spearman", "kendall"),
  missing = c("pairwise", "listwise"),
  sig = FALSE,
  obs = FALSE,
  ci = FALSE,
  star = FALSE,
  level = 0.95,
  digits = 3,
  p_digits = 3,
  show = TRUE,
  console = FALSE
)

Arguments

...

Numeric variables. If omitted, all numeric variables are used.

data

Data frame or NULL for active data.

method

Correlation method.

missing

Pairwise or listwise deletion.

sig

Show a p-value matrix.

obs

Show a matrix of pairwise sample sizes.

ci

Show pairwise confidence intervals where available.

star

Add significance stars to the displayed correlation matrix.

level

Confidence level.

digits, p_digits

Decimal places.

show

Logical; open the formatted result in the Viewer. Default TRUE.

console

Logical; also print the traditional result in the Console. Default FALSE.

Value

An object of class r4vn_stat, returned invisibly. Its sections component contains the formatted correlation matrix and any requested p-value, pairwise sample-size, or confidence-interval tables. Its raw component contains the numeric correlation (correlation), p-value (p.value), and pairwise sample-size (n) matrices plus the selected correlation method; call records the matched function call.

Examples


# Extended usage examples
d <- data.frame(age = c(20, 25, 30, 35, 40, 45),
                bmi = c(20, 22, 24, 23, 26, 28),
                score = c(60, 65, 68, 72, 75, 80))

corr(age, bmi, score, data = d, show = FALSE)
corr(age, bmi, score, data = d, method = "spearman", show = FALSE)
corr(age, bmi, score, data = d, sig = TRUE, obs = TRUE, ci = TRUE, show = FALSE)
corr(age, bmi, score, data = d, star = TRUE, show = FALSE)

R4VN documentation built on Sept. 30, 2026, 5:13 p.m.