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,
  ...
)

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).

cor

Logical. If TRUE, computes frequentist correlation coefficients (default: TRUE).

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
#> 1     mpg     cyl   1   2 -0.3302412 -0.6170915  0.034083055 -1.851339 28
#> 2     mpg    disp   1   3 -0.3615918 -0.6386623 -0.001520729 -2.052225 28
#> 3     cyl    disp   2   3  0.5077685  0.1805229  0.733801007  3.118837 28
#>             p n_pair n_na
#> 1 0.074695109     32    0
#> 2 0.049602794     32    0
#> 3 0.004177802     32    0
results$table_cor  # View partial correlation matrix
#>      mpg        cyl       disp
#> mpg   NA -0.3302412 -0.3615918
#> cyl   NA         NA  0.5077685
#> disp  NA         NA         NA