Skip to contents

Computes pairwise partial correlations among all variables in a given dataset, controlling for one or more covariates using frequentist methods. The function returns correlation estimates along with confidence intervals. Note: Bayesian methods are not supported in the current version.

Usage

pcor_test_all(
  dat,
  control = NULL,
  triangle = c("upper", "lower", "full"),
  alternative = c("two.sided", "less", "greater"),
  method = c("pearson", "kendall", "spearman"),
  conf.level = 0.95,
  alpha = 0.05,
  detailed = FALSE
)

Arguments

dat

A data frame or matrix containing numeric variables of interest.

control

A data frame, matrix, or numeric vector containing covariates to control for.

triangle

Character. Specifies which part of the correlation matrix to return: "upper", "lower", or "full" (default: "upper").

alternative

Character. Specifies the alternative hypothesis for the frequentist test: "two.sided", "less", or "greater" (default: "two.sided").

method

Character. Specifies the correlation method for the frequentist test: "pearson", "kendall", or "spearman" (default: "pearson").

conf.level

Numeric. The confidence level for confidence intervals (default: 0.95).

alpha

Numeric. Significance level. Defaults to 0.05.

detailed

Logical. Whether to return detailed results (TRUE) or minimal output (FALSE, default).

Value

A list containing:

all

A data frame with all computed correlation statistics.

table_XX

A data frame corresponding to a table named "table_XX", where "XX" is derived from the output variables (e.g., "table_cor", "table_p"). The content of the table depends on the provided inputs.

Examples

results <- pcor_test_all(mtcars[, 1:3], control = mtcars[, 4:5])
results$all  # View detailed results in a tidy format
#>   var_row var_col row col    cor  lower  upper     t df     p sig n_pair
#> 1     mpg     cyl   1   2 -0.330 -0.617  0.034 -1.85 28 0.075  ns     32
#> 2     mpg    disp   1   3 -0.362 -0.639 -0.002 -2.05 28 0.050   *     32
#> 3     cyl    disp   2   3  0.508  0.181  0.734  3.12 28 0.004   *     32
results$table_cor  # View partial correlation matrix
#>      mpg   cyl   disp
#> mpg   NA -0.33 -0.362
#> cyl   NA    NA  0.508
#> disp  NA    NA     NA