smartcor detects variable types and selects a suitable
correlation method for each pair. It supports continuous, count, binary,
ordinal, and categorical variables and returns the estimate, inference,
selected method, and rationale.
Once the package is on CRAN, a single call installs it together with
all of its dependencies (including polycor):
install.packages("smartcor")To install the supplied archive instead, use remotes
package.
remotes::install_local("smartcor.zip")The package includes gss_2024_casestudy.csv. This CSV is
frozen for reproducibility. The examples below read the bundled copy and
do not download data.
library(smartcor)
csv = system.file("extdata", "gss_2024_casestudy.csv", package = "smartcor")
gss = read.csv(csv)result = smart_cor(gss$coninc, gss$age, verbose = FALSE)
print(result)
result$estimate
result$method
result$p.value
c(result$ci_lower, result$ci_upper)Set assume_latent_normal to control pairs that can use a
latent-variable method:
smart_cor(gss$degree, gss$happy, assume_latent_normal = "auto")
smart_cor(gss$degree, gss$happy, assume_latent_normal = TRUE)
smart_cor(gss$degree, gss$happy, assume_latent_normal = FALSE)The default, "auto", tests the assumption for each
affected pair. A binary-by-binary table is saturated, so automatic
selection uses phi. Set the argument to TRUE to request
tetrachoric correlation.
columns = c("age", "coninc", "degree", "happy", "sex", "region")
matrix = smart_cormat(
gss[, columns],
assume_latent_normal = FALSE,
verbose = FALSE
)
matrix$correlations
matrix$methods
matrix$types
tidy(matrix)Use smart_cor_df() when a script needs plain data
frames:
plain = smart_cor_df(gss[, columns], assume_latent_normal = FALSE)
plain$correlations
plain$methodscomparison = compare_methods(
gss$degree,
gss$happy,
assume_latent_normal = FALSE,
bootstrap = FALSE,
verbose = FALSE
)
comparison$resultsplot(matrix)
ggcor_heatmap(matrix)
ggcor_method_heatmap(matrix)The package implements Pearson, Spearman, Kendall’s tau, point-biserial, rank-biserial, phi, tetrachoric, Yule’s Q, polychoric, polyserial, Cramer’s V, Theil’s U, Tschuprow’s T, and Goodman-Kruskal’s gamma.
The accompanying paper, smartcor: Intelligent Correlation Method Selection for Mixed Variable Types by M. Harshvardhan and Pritam Ranjan (2026), is available as an arXiv preprint: arXiv:2607.22285 (doi:10.48550/arXiv.2607.22285). The package vignettes cover the same material: method selection, the underlying theory, and inference.
M. Harshvardhan (maintainer) and Pritam Ranjan.
GPL (>= 3)