A useful wrapper of polycor to robustly estimate a polychoric correlation matrix by calculating all unique pairwise polychoric correlation coefficients.
polycormat(
data,
c = 0.6,
parallel = FALSE,
num_cores = 1L,
return_polycor = TRUE,
variance = TRUE,
constrained = "ifneeded",
method = NULL,
maxcor = 0.999,
tol_thresholds = 0.01
)If return_polycor = TRUE, returns a list with a polychoric correlation matrix and list of "polycor" objects. If return_polycor = FALSE, then only a correlation matrix is returned.
Data matrix or data.frame of integer-valued responses, individual respondents are in rows and responses to the items in the columns.
Tuning constant that governs robustness; must be in [0, Inf]. Defaults to 0.6.
Logical. Shall parallelization be used? Default is FALSE.
Number of cores to be used, only relevant if parallel = TRUE. Defaults to the number of system cores.
Logical. Shall the individual "polycor" objects for each item pair estimate be returned? Default is TRUE.
Shall an estimated asymptotic covariance matrix be returned? Default is TRUE.
Shall strict monotonicity of thresholds be explicitly enforced by linear constraints? This can be a logical (TRUE or FALSE), or "ifneeded" to first try unconstrained optimization and in case of an error perform constrained optimization. Default is "ifneeded".
Numerical optimization method, see optim() and constrOptim(). Default is to use "L-BFGS-B" in case of unconstrained optimization and "Nelder-Mead" in case of constrained optimization.
Maximum absolute correlation (to ensure numerical stability). Default is 0.999.
Minimum distance between consecutive thresholds (to enforce strict monotonicity); only relevant in case of constrained optimization. Default is 0.01.
## example data
set.seed(123)
data <- matrix(sample(c(1,2,3), size = 3*100, replace = TRUE), nrow = 100)
polycormat(data) # robust
polycormat_mle(data) # non-robust MLE
Run the code above in your browser using DataLab