Learn R Programming

matrixCorr

matrixCorr computes correlation and related association matrices from small to high-dimensional data using simple, consistent functions and sensible defaults. It includes shrinkage and robust options for noisy or p >= n settings, plus convenient print/plot/summary methods. Performance-critical paths are implemented in C++ with BLAS/OpenMP and memory-aware symmetric updates. The API accepts base matrices and data frames and returns standard R objects via a consistent S3 interface.

Contributions from other researchers who want to add new correlation methods are very welcome. A central goal of matrixCorr is to keep efficient correlation and agreement estimation in one package with a common interface and consistent outputs, so methods can be extended, compared, and used without repeated translation across packages.

Supported measures include Pearson, Spearman, Kendall, distance correlation, partial correlation, kernel dependence via the Hilbert-Schmidt independence criterion, directed Chatterjee rank correlation, robust biweight mid-correlation, percentage bend, Winsorized, skipped correlation, and latent categorical/ordinal correlations (tetrachoric, polychoric, polyserial, and biserial), plus repeated-measures correlation; agreement tools cover Cohen’s kappa for nominal ratings, weighted Cohen’s kappa for ordered two-rater agreement, Gwet’s AC1/AC2, multi-rater kappa for nominal panel agreement, Krippendorff’s alpha for panel-level reliability, Bland-Altman (two-method and repeated-measures), the coefficient of individual agreement for replicated and repeated-measures designs, Lin’s concordance correlation coefficient (including MCD-based robust concordance, repeated-measures LMM/REML extensions, and Poisson GLMM count-data CCC), and intraclass correlation for both wide and repeated-measures designs.

Features

AreaFunctions and tools
BackendHigh-performance C++ backend using Rcpp
General correlationspearson_corr(), spearman_rho(), kendall_tau()
Robust correlationsbicor(), pbcor(), wincor(), skipped_corr()
Distance correlationdcor(), bcdcor(), robust_dcor()
Kernel dependencehsic() for raw biased/unbiased HSIC, normalised kCor-style dependence, kernel bandwidth rules, and permutation p-values
Partial correlationpcorr()
Directed dependencexi_corr() for Chatterjee rank correlation, with directed/asymmetric matrices and m-out-of-n bootstrap confidence intervals
Latent categorical/ordinal correlationstetrachoric(), polychoric(), polyserial(), biserial()
Repeated-measures correlationrmcorr()
Shrinkage for $p >> n$shrinkage_corr()
Agreement: two-rater categorical ratingscohen_kappa() and gwet_ac() for nominal AC1/AC2 agreement, weighted_kappa() for ordered categories
Agreement: multi-rater and panel reliabilitymultirater_kappa(), gwet_ac() for panel AC1/AC2 agreement, krippendorff_alpha()
Agreement: Bland-AltmanTwo-method or pairwise wide-input ba(), repeated-measures ba_rm()
Agreement: individual agreementReplicated long-format cia(), repeated-measures cia_rm()
Agreement: probability of agreementprob_agree()
Agreement: concordancePairwise Lin’s CCC ccc(), MCD-based robust CCC robust_ccc(), repeated-measures LMM/REML ccc_rm_reml(), Poisson GLMM count-data CCC ccc_glmm(), non-parametric ccc_rm_ustat()
Agreement: intraclass correlationWide-data icc() with pairwise and overall scope, repeated-measures REML icc_rm_reml()
Interactive viewersMatrix-style Shiny viewers, including the repeated-measures correlation viewer view_rmcorr_shiny()

Installation

# Install from CRAN
install.packages("matrixCorr")

# Development version from GitHub
# install.packages("remotes")
remotes::install_github("Prof-ThiagoOliveira/matrixCorr")

Thread settings (n_threads)

Most computational functions expose an n_threads argument and default to:

getOption("matrixCorr.threads", 1L)

To define a package-wide default once per session:

options(matrixCorr.threads = parallel::detectCores(logical = FALSE))

Quick start

Wide-data correlation workflow

library(matrixCorr)

set.seed(1)
X <- as.data.frame(matrix(rnorm(300 * 6), ncol = 6))
names(X) <- paste0("V", 1:6)

R_pear <- pearson_corr(X, ci = TRUE)
R_bicor <- bicor(X)

print(R_pear, digits = 2)
#> Pearson correlation matrix
#>   method      : pearson
#>   dimensions  : 6 x 6
#>   ci          : yes
#> 
#>       V1    V2    V3    V4    V5    V6
#> V1  1.00  0.02  0.04 -0.02 -0.07  0.01
#> V2  0.02  1.00  0.04  0.03 -0.05  0.13
#> V3  0.04  0.04  1.00 -0.06  0.08 -0.14
#> V4 -0.02  0.03 -0.06  1.00  0.07  0.03
#> V5 -0.07 -0.05  0.08  0.07  1.00  0.04
#> V6  0.01  0.13 -0.14  0.03  0.04  1.00
summary(R_pear)
#> Pearson correlation summary
#>   output      : matrix
#>   dimensions  : 6 x 6
#>   retained_pairs: 15
#>   threshold   : 0.0000
#>   diag        : included
#>   estimate    : -0.1410 to 0.1272
#>   ci          : 95%
#>   ci_method   : fisher_z
#>   ci_width    : 0.222 to 0.226
#>   cross_zero  : 13 pair(s)
#> 
#>  item1 item2 estimate n_complete lwr     upr     fisher_z statistic p_value
#>  V3    V6    -0.1410  300        -0.2502 -0.0282 -0.1419  -2.4459   0.0144 
#>  V2    V6    0.1272   300        0.0142  0.2371  0.1279   2.2047    0.0275 
#>  V3    V5    0.0776   300        -0.0360 0.1892  0.0778   1.3401    0.1802 
#>  V4    V5    0.0724   300        -0.0412 0.1841  0.0725   1.2491    0.2116 
#>  V1    V5    -0.0650  300        -0.1770 0.0486  -0.0651  -1.1222   0.2618 
#>  ...   ...   ...      ...        ...     ...     ...      ...       ...    
#>  V2    V4    0.0335   300        -0.0801 0.1462  0.0335   0.5773    0.5638 
#>  V4    V6    0.0324   300        -0.0811 0.1451  0.0324   0.5584    0.5766 
#>  V1    V2    0.0236   300        -0.0899 0.1365  0.0236   0.4064    0.6845 
#>  V1    V4    -0.0185  300        -0.1315 0.0949  -0.0185  -0.3187   0.7500 
#>  V1    V6    0.0130   300        -0.1004 0.1261  0.0130   0.2243    0.8225 
#> ... 5 more rows not shown (omitted)
#> Use as.data.frame()/tidy()/as.matrix() to inspect the full result.
#> 
#> Strongest pairs by |estimate|
#> 
#>  item1 item2 estimate n_complete lwr     upr     fisher_z statistic p_value
#>  V3    V6    -0.1410  300        -0.2502 -0.0282 -0.1419  -2.4459   0.0144 
#>  V2    V6    0.1272   300        0.0142  0.2371  0.1279   2.2047    0.0275 
#>  V3    V5    0.0776   300        -0.0360 0.1892  0.0778   1.3401    0.1802 
#>  V4    V5    0.0724   300        -0.0412 0.1841  0.0725   1.2491    0.2116 
#>  V1    V5    -0.0650  300        -0.1770 0.0486  -0.0651  -1.1222   0.2618
plot(R_bicor)

The same matrix-style workflow extends to Spearman, Kendall, distance correlation, HSIC/kernel dependence, partial correlation, shrinkage correlation, latent correlation, and the robust estimators pbcor(), wincor(), and skipped_corr().

hsic() computes pairwise kernel dependence matrices with Gaussian, linear, Laplace, and polynomial kernels. It defaults to the package’s normalised kCor-style output; use normalise = FALSE to return raw HSIC estimates, and p_value = TRUE for permutation-based independence tests.

Agreement and repeated-measures workflow

For wide data with discordant outliers, robust_ccc() replaces the classical means, variances, and covariance in Lin’s coefficient with joint, reweighted minimum covariance determinant estimates. Set seed for reproducible FastMCD searches; percentile bootstrap intervals are available with ci = TRUE.

set.seed(42)
reference <- rnorm(40)
method <- reference + rnorm(40, sd = 0.2)
method[1] <- -8
reference[1] <- 9

wide_agreement <- data.frame(reference, method)

fit_ccc <- ccc(wide_agreement)
fit_robust_ccc <- robust_ccc(wide_agreement, seed = 42)

c(
  classical = estimate(fit_ccc)[1, 2],
  robust = estimate(fit_robust_ccc)[1, 2]
)
#>  classical     robust
#> -0.1085298  0.9892595

Use robust_ccc() when an approximately elliptical, unimodal core is a reasonable model and resistance to contamination is required. It is not a distribution-free replacement for ccc(); alpha controls the robustness and efficiency trade-off.

set.seed(6)
S <- 24
Tm <- 4
id <- factor(rep(seq_len(S), each = 2 * Tm))
method <- factor(rep(rep(c("A", "B"), each = Tm), times = S))
time <- rep(rep(seq_len(Tm), times = 2), times = S)

u <- rnorm(S, 0, 0.9)[as.integer(id)]
um <- rnorm(S * 2, 0, 0.25)
um <- um[(as.integer(id) - 1L) * 2L + as.integer(method)]
y <- u + um + (method == "B") * 0.2 + rnorm(length(id), 0, 0.35)

dat_rm <- data.frame(y, id, method, time)

fit_ccc_rm <- ccc_rm_reml(
  dat_rm,
  response = "y",
  subject = "id",
  method = "method",
  time = "time"
)

summary(fit_ccc_rm)
#> 
#> Repeated-measures concordance (REML)
#> 
#> Concordance estimates
#> 
#>  item1 item2 estimate n_subjects n_obs SB     se_ccc
#>  A     B     0.8328   24         192   0.1096 0.0381
#> 
#> Variance components
#> 
#>  sigma2_subject sigma2_subject_method sigma2_subject_time sigma2_error
#>  0.7848         0.0192                0.007               0.1168      
#> 
#> AR(1) diagnostics
#> 
#>  ar1_rho ar1_rho_lag1 ar1_rho_mom ar1_pairs ar1_pval use_ar1 ar1_recommend
#>  -0.1073 -0.1073      -0.1073     144       0.198    FALSE   FALSE

Agreement and reliability methods use the same general inspection pattern, but they target different quantities. The package includes Cohen’s kappa for nominal two-rater ratings, weighted kappa for ordered two-rater ratings, Gwet’s AC1/AC2, multi-rater kappa for nominal panel agreement, Krippendorff’s alpha for panel-level reliability, Bland-Altman analysis, concordance correlation, and intraclass correlation for both wide and repeated-measures designs.

Vignettes

The package documentation is organised as a set of workflow vignettes. The README is intentionally brief; the vignettes are the main user guide.

Start here:

  • vignette("v01-matrixCorr-introduction", package = "matrixCorr") introduces the package structure, common object behaviour, and shared display conventions.
  • vignette("v02-wide-correlation-workflows", package = "matrixCorr") covers Pearson, Spearman, Kendall, distance correlation, and the general wide-data matrix workflow.
  • vignette("v03-robust-and-highdim-correlation", package = "matrixCorr") covers robust estimators, shrinkage, and high-dimensional settings.
  • vignette("v04-latent-and-mixed-scale-correlation", package = "matrixCorr") covers tetrachoric, polychoric, polyserial, and biserial correlation.
  • vignette("v05-agreement-and-icc-wide", package = "matrixCorr") covers Bland-Altman analysis, concordance, and intraclass correlation for wide data.
  • vignette("v06-repeated-measures-workflows", package = "matrixCorr") covers repeated-measures correlation, repeated agreement, and repeated reliability workflows.

If you want a compact overview of the available estimators, start with the introduction vignette and then move to the workflow family that matches your data layout and scientific question.

Contributing

Issues and pull requests are welcome. Please see CONTRIBUTING.md for guidelines and cran-comments.md/DESCRIPTION for package metadata.

License

GPL (>= 3) Thiago de Paula Oliveira

This is a copyleft license: modified versions distributed to others must be distributed under the same GPL terms.

Copy Link

Version

Install

install.packages('matrixCorr')

Monthly Downloads

491

Version

0.12.3

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Thiago de Paula Oliveira

Last Published

September 28th, 2026

Functions in matrixCorr (0.12.3)

abort_bad_arg

Abort with a standardised argument error
biserial

Biserial Correlation Between Continuous and Binary Variables
as.data.frame.corr_edge_list

Edge-list data-frame view
$.summary.corr_result

Summary Accessor for Correlation Summaries
ba_rm

Bland-Altman for repeated measurements
bcdcor

Pairwise Bias-Corrected Squared Distance Correlation
ba

Bland-Altman statistics with confidence intervals
bicor

Biweight mid-correlation (bicor)
abort_internal

Abort for internal errors (should not happen)
build_LDZ

build_LDZ
ccc

Pairwise Lin's concordance correlation coefficient
check_matrix_dims

Check matrix dimensions
ccc_glmm

Poisson GLMM concordance correlation for count agreement
ccc_rm_ustat

Repeated-Measures Lin's Concordance Correlation Coefficient (CCC)
ccc_rm_reml

Concordance Correlation via REML (Linear Mixed-Effects Model)
ccc_lmm_reml_pairwise

ccc_lmm_reml_pairwise
check_inherits

Check object class
check_bool

Check a single logical flag
check_ar1_rho

Check AR(1) correlation parameter
check_prob_scalar

Check probability in unit interval
check_scalar_numeric

Check scalar numeric (with optional bounds)
cia

Coefficient of Individual Agreement
cia_rm

Repeated-Measures Coefficient of Individual Agreement
check_same_length

Check that two vectors have the same length
check_required_cols

Check that a data frame contains required columns
check_scalar_character

Check scalar character (non-empty)
check_scalar_int_pos

Check strictly positive scalar integer
check_scalar_nonneg

Check a non-negative scalar (>= 0)
check_symmetric_matrix

Check matrix symmetry
check_weights

Check weights vector (non-negative, finite, correct length)
compute_ci_from_se

compute_ci_from_se
deprecated-matrixCorr

Deprecated Compatibility Wrappers
dcor

Pairwise Distance Correlation (dCor)
cohen_kappa

Pairwise Cohen's Kappa for Nominal Ratings
estimate

Access MatrixCorr Estimates, Confidence Intervals, and Tidy Results
.mc_abort_condition

Rethrow a caught condition as a cli error
.ba_rep_two_methods

two-method helper
.align_weights_to_levels

Align (optional named) weights to a subset of time levels
estimate_rho

estimate_rho
.vc_message

.vc_message
inform_if_verbose

Inform only when verbose
gwet_ac

Gwet's AC1 and AC2 Agreement Coefficients
icc

Intraclass Correlation for Wide Data
matrixCorr-package

matrixCorr
icc_rm_reml

Repeated-Measures Intraclass Correlation via REML
kendall_tau

Pairwise (or Two-Vector) Kendall's Tau Rank Correlation
hsic

Pairwise Hilbert-Schmidt Independence Criterion
krippendorff_alpha

Krippendorff's Alpha Reliability Coefficient
match_arg

Match argument to allowed values
matrixCorr-internal

Validation and normalisation for correlation
plot.corr_sparse

S3 Plot for Sparse Correlation Results
plot.prob_agree

Plot probability-of-agreement results
pcorr

Partial correlation matrix (sample / ridge / OAS / graphical lasso)
num_or_na

num_or_na
pearson_corr

Pairwise Pearson correlation
plot.corr_matrix

S3 Plot for Dense Correlation Results
plot.corr_edge_list

S3 Plot for Edge-List Correlation Results
multirater_kappa

Multi-Rater Kappa for Nominal Ratings
pbcor

Percentage bend correlation
num_or_na_vec

num_or_na_vec
print.ccc_ci

S3 print for legacy class ccc_ci
print.summary.corr_result

Print Standardized Correlation Summaries
polyserial

Polyserial Correlation Between Continuous and Ordinal Variables
print.summary.latent_corr

Summary Method for Latent Correlation Matrices
print.summary.matrixCorr

Summary Method for Correlation Matrices
print.matrixCorr_ccc_ci

Print method for matrixCorr CCC objects with CIs
print.matrixCorr_ccc

Print method for matrixCorr CCC objects
print.corr_edge_list

Print Edge-List Correlation Results
polychoric

Pairwise Polychoric Correlation
prob_agree

Probability of Agreement for Reliability Curves
robust_dcor

Robust Distance Correlation
spearman_rho

Pairwise Spearman's rank correlation
[[.summary.corr_result

Summary Accessor for Correlation Summaries
rmcorr

Repeated-Measures Correlation (rmcorr)
skipped_corr

Pairwise skipped correlation
shrinkage_corr

Shrinkage Correlation
print.rmcorr_matrix

Methods for rmcorr Matrix Objects
print.rmcorr

Methods for Pairwise rmcorr Objects
robust_ccc

MCD based robust concordance correlation coefficient
run_cpp

run_cpp
summary.corr_edge_list

S3 Summary for Edge-List Correlation Results
view_rmcorr_shiny

Interactive Shiny Viewer for Repeated-Measures Correlation
summary.ccc_rm_reml

Summary Method for ccc_rm_reml Objects
weighted_kappa

Pairwise Weighted Cohen's Kappa for Ordered Ratings
tetrachoric

Pairwise Tetrachoric Correlation
view_corr_shiny

Interactive Shiny viewer for matrixCorr objects
wincor

Pairwise Winsorized correlation
xi_corr

Pairwise Chatterjee Rank Correlation
summary.corr_sparse

S3 Summary for Sparse Correlation Results
summary.corr_matrix

S3 Summary for Dense Correlation Results