Automatic Correlation Method Selection Based on Variable Types

Detects variable types (continuous, count, binary, ordinal, categorical) and selects the appropriate correlation method for each pair. Supports Pearson, Spearman, Kendall's tau, point-biserial, rank-biserial, phi, tetrachoric, polychoric, polyserial, Cramer's V, Tschuprow's T, Theil's U, Yule's Q, and Goodman-Kruskal's gamma, each with a confidence interval and p-value. Explains the selection rationale in the output, follows tidy data principles, and works in both interactive and scripted workflows. The methodology is described in Harshvardhan and Ranjan (2026) .


smartcor

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.

Install

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

Load the example data

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)

Correlate one pair

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.

Build a matrix

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$methods

Compare methods

comparison = compare_methods(
  gss$degree,
  gss$happy,
  assume_latent_normal = FALSE,
  bootstrap = FALSE,
  verbose = FALSE
)
comparison$results

Plot a matrix

plot(matrix)
ggcor_heatmap(matrix)
ggcor_method_heatmap(matrix)

Methods

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.

Paper

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.

Authors

M. Harshvardhan (maintainer) and Pritam Ranjan.

License

GPL (>= 3)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("smartcor")

1.0.1 by M. Harshvardhan, 2 months ago


https://harshvardhaniimi.github.io/smartcor/, https://github.com/harshvardhaniimi/smartcor


Report a bug at https://github.com/harshvardhaniimi/smartcor/issues


Browse source code at https://github.com/cran/smartcor


Authors: M. Harshvardhan [aut, cre, cph] , Pritam Ranjan [aut, cph]


Documentation:   PDF Manual  


GPL (>= 3) license


Imports cli, generics, ggplot2, graphics, grDevices, mvtnorm, polycor, rlang, stats, tibble, utils, withr

Suggests knitr, MASS, rmarkdown, testthat


See at CRAN