This returns a matrix aligned with the cor_matrix() function after parceling out the effect of one or more other variables. This function requires complete data; incomplete cases are dropped with a warning.

pcor_matrix(data, given, ...)

Arguments

data

Dataframe. Only numeric variables are included into correlation matrix.

given

A character vector with one or multiple variables in data. It/they will be parceled out from all other variables in data, before the correlation table is calculated.

...

Arguments passed on to cor_matrix

var_names

A named character vector with new variable names or a tibble as provided by get_rename_tribbles() for variables. If NULL, then the variables are not renamed. If names are provided, only the variables included here are retained. This is most helpful when the results are passed to some print function, such as report_cor_table()

conf_level

Confidence level to use for confidence intervals, defaults to .95

bootstrap

When using FIML estimation (with missing = "fiml"), significance tests and confidence intervals can be bootstrapped. If you want to do that, pass the number of desired bootstrap resamples (e.g., 5000) to this parameter, but beware that this can take a while.

seed

Pass an integer to set the seed for bootstrapping and thus make this reproducible

method

method="pearson" is the default value. The alternatives to be passed to cor are "spearman" and "kendall". These last two are much slower, particularly for big data sets.

adjust

What adjustment for multiple tests should be used? ("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"). See p.adjust for details about why to use "holm" rather than "bonferroni").

Examples


# One might want to estimate correlations between health and possible predictors in the ESS
# after parceling out / controling for key demographic attributes:
pcor_matrix(ess_health, given = c("agea", "gndr"), 
   var_names = c("health" = "Health", "weight" = "Weight", "dosprt" = "Sport")) %>% 
   tidy(both_directions = FALSE)
#> Warning: Dropped 276 rows with missing data.
#> # A tibble: 3 × 9
#>   column1 column2 estimate std.error  p.value statistic     n conf.low conf.high
#>   <chr>   <chr>      <dbl>     <dbl>    <dbl>     <dbl> <dbl>    <dbl>     <dbl>
#> 1 Weight  Health    0.144     0.0119 1.22e-33     12.2   6950   0.121     0.167 
#> 2 Sport   Health   -0.175     0.0118 3.58e-49    -14.9   6950  -0.198    -0.153 
#> 3 Sport   Weight   -0.0546    0.0120 5.20e- 6     -4.56  6950  -0.0780   -0.0312