(Pairwise, Weighted) Correlations, Covariances and Observation Counts
Computes (pairwise, weighted) Pearsons correlations, covariances and observation counts. Pairwise correlations and covariances can be computed together with observation counts and p-values, and output as 3D array (default) or list of matrices. pwcor
and pwcov
offer an elaborate print method.
Notes: weights::wtd.cors
is imported for weighted pairwise correlations (written in C for speed). For weighted correlations with bootstrap SE's see weights::wtd.cor
(but bootstrap can be slow). Weighted correlations for complex surveys are implemented in jtools::svycor
. An equivalent and faster implementation of pwcor
(without weights) is provided in Hmisc::rcorr
(written in Fortran)
pwcor(X, ..., w = NULL, N = FALSE, P = FALSE, array = TRUE, use = "pairwise.complete.obs") pwcov(X, ..., w = NULL, N = FALSE, P = FALSE, array = TRUE, use = "pairwise.complete.obs") pwNobs(X) ## S3 method for class 'pwcor' print(x, digits = 2L, sig.level = 0.05, show = c("all","lower.tri","upper.tri"), spacing = 1L, ...) ## S3 method for class 'pwcov' print(x, digits = 2L, sig.level = 0.05, show = c("all","lower.tri","upper.tri"), spacing = 1L, ...)
X |
a matrix or data.frame, for |
x |
an object of class 'pwcor' / 'pwcov'. |
w |
numeric. A vector of (frequency) weights. |
N |
logical. |
P |
logical. |
array |
logical. If |
use |
argument passed to |
digits |
integer. The number of digits to round to in print. |
sig.level |
numeric. P-value threshold below which a |
show |
character. The part of the correlation / covariance matrix to display. |
spacing |
integer. Controls the spacing between different reported quantities in the printout of the matrix: 0 - compressed, 1 - single space, 2 - double space. |
... |
other arguments passed to |
a numeric matrix, 3D array or list of matrices with the computed statistics. For pwcor
and pwcov
the object has a class 'pwcor' and 'pwcov', respectively.
mna <- na_insert(mtcars) pwcor(mna) pwcov(mna) pwNobs(mna) pwcor(mna, N = TRUE) pwcor(mna, P = TRUE) pwcor(mna, N = TRUE, P = TRUE) aperm(pwcor(mna, N = TRUE, P = TRUE)) print(pwcor(mna, N = TRUE, P = TRUE), digits = 3, sig.level = 0.01, show = "lower.tri") pwcor(mna, N = TRUE, P = TRUE, array = FALSE) print(pwcor(mna, N = TRUE, P = TRUE, array = FALSE), show = "lower.tri")
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.