Skip to contents

smartcor is maintained in two languages, R and Python, kept at feature parity. Both implementations detect variable types, select the method with the same decision logic, run the same likelihood-ratio screen for latent normality, and return the same estimate, confidence interval, p-value, and rationale. This page maps the R interface to the Python one so you can translate any example on this site.

Install

The package is on PyPI:

pip install pysmartcor

Optional plotting support (matplotlib and seaborn):

pip install 'pysmartcor[viz]'

Required dependencies are NumPy, SciPy, and pandas. The Python package has no dependency on R or on the polycor package: the latent-variable estimators (polychoric, polyserial, tetrachoric) use a vendored, corrected port of the semopy maximum-likelihood routines.

Function-by-function translation

R Python
smart_cor(x, y) smart_cor(x, y)
smart_cormat(data) smart_cormat(data)
smart_cor_df(data) smart_cor_df(data)
compare_methods(x, y) compare_methods(x, y)
test_bivariate_normality(x, y) test_bivariate_normality(x, y)
detect_type(x) detect_type(x)
available_methods(tx, ty) available_methods(tx, ty)
tidy(result) result.tidy()
print(result) print(result)
plot(m) / ggcor_heatmap(m) cor_heatmap(m)
ggcor_method_heatmap(m) method_heatmap(m)
seed = 42 rng = 42

A worked pair, side by side

R:

library(smartcor)
gss = read.csv(system.file("extdata", "gss_2024_casestudy.csv", package = "smartcor"))
res = smart_cor(gss$coninc, gss$sex)
tidy(res)

Python:

from importlib.resources import as_file, files
import pandas as pd
from pysmartcor import smart_cor

with as_file(files("pysmartcor").joinpath("data/gss_2024_casestudy.csv")) as csv:
    gss = pd.read_csv(csv)
res = smart_cor(gss["coninc"], gss["sex"])
res.tidy()

Both calls detect the same types, select point-biserial correlation, and report the same estimate and inference.

What matches and what differs

The method selection, the LR normality test statistic, the analytic confidence intervals, and the p-values agree between the two implementations. Bootstrap and permutation draws use each language’s own random number generator, so seeded resampling results are reproducible within a language but not identical across languages. Latent-variable point estimates can differ in the final decimals on near-boundary problems because R fits rho and thresholds jointly by maximum likelihood via polycor, while Python profiles rho with thresholds fixed at their marginal estimates.