A thin wrapper around smart_cormat() for pipeline work. It never
prompts, prints nothing, and returns two plain data frames (the estimates
and the method used for each pair) instead of an S3 object.
Usage
smart_cor_df(
data,
cols = NULL,
types = NULL,
assume_latent_normal = "auto",
ordinal_threshold = 10,
ignore_na = TRUE,
conf_level = 0.95,
bootstrap = "auto",
n_boot = 500,
n_perm = 500,
seed = NULL
)Arguments
- data
A data frame or tibble.
- cols
Optional character vector of column names to include. Default: all columns.
- types
Optional named list mapping column names to types (
"continuous","count","binary","ordinal","categorical"). Columns not listed are auto-detected.- assume_latent_normal
"auto"(default) or logical, passed tosmart_cormat().NULLis not useful here because this wrapper never prompts.- ordinal_threshold
Integer passed to
detect_type(). Default:10.- ignore_na
Logical. If
TRUE(default), missing values are handled pairwise. IfFALSE, pairs with missing values come backNA.- conf_level
Numeric between 0 and 1. Confidence level passed through to each
smart_cor()call. Default:0.95.- bootstrap
Character or logical, passed through:
"auto"(default),TRUE, orFALSE.- n_boot
Integer. Bootstrap replications per pair. Default:
500.- n_perm
Integer. Permutation shuffles for Theil's U p-values. Default:
500.- seed
Optional integer seed for the bootstrap and permutation draws; the global RNG state is saved and restored.
Value
A named list with two elements:
correlationsA data frame of correlation estimates (numeric).
methodsA data frame of method codes (character) used for each pair.
Details
By default it uses assume_latent_normal = "auto", so each pair is
screened with test_bivariate_normality() and the method follows the
test (a saturated 2 x 2 pair gets phi).
The two returned data frames share identical row and column names (the
variable names from data). Diagonal entries in correlations are 1;
diagonal entries in methods name the method a self-pair of that type
would get, matching smart_cormat().
Examples
csv = system.file("extdata", "gss_2024_casestudy.csv", package = "smartcor")
gss = read.csv(csv)
# Correlations and methods for four columns in the frozen GSS extract
result = smart_cor_df(
gss[, c("age", "coninc", "degree", "sex")],
assume_latent_normal = FALSE
)
result$correlations
#> age coninc degree sex
#> age 1.000000000 0.01924127 0.02762683 -0.008699344
#> coninc 0.019241267 1.00000000 0.45098152 -0.100768838
#> degree 0.027626830 0.45098152 1.00000000 0.015352069
#> sex -0.008699344 -0.10076884 0.01535207 1.000000000
result$methods
#> age coninc degree sex
#> age pearson pearson spearman point_biserial
#> coninc pearson pearson spearman point_biserial
#> degree spearman spearman kendall rank_biserial
#> sex point_biserial point_biserial rank_biserial phi
# Missing values are handled pairwise by default
example = gss[, c("age", "coninc", "sex")]
example$coninc[1:3] = NA
smart_cor_df(example, assume_latent_normal = FALSE)
#> $correlations
#> age coninc sex
#> age 1.000000000 0.01911907 -0.008699344
#> coninc 0.019119070 1.00000000 -0.100493238
#> sex -0.008699344 -0.10049324 1.000000000
#>
#> $methods
#> age coninc sex
#> age pearson pearson point_biserial
#> coninc pearson pearson point_biserial
#> sex point_biserial point_biserial phi
#>