Polychoric, polyserial and Pearson correlations
lavCor.RdFit an unrestricted model to compute polychoric, polyserial and/or Pearson correlations.
Usage
lavCor(object, ordered = NULL, group = NULL, missing = "listwise",
ov.names.x = NULL, sampling.weights = NULL,
se = "none", test = "none",
estimator = "two.step", baseline = FALSE, ...,
cor.smooth = FALSE, cor.smooth.tol = 1e-04, output = "cor")Arguments
- object
Either a
data.frame, or an object of classlavaan. If the input is adata.frame, and some variables are declared as ordered factors, lavaan will treat them as ordinal variables.- ordered
Character vector. Only used if
objectis adata.frame. Treat these variables as ordered (ordinal) variables. Importantly, all other variables will be treated as numeric (unless they are declared as ordered in the original data frame.)- group
Only used if
objectis adata.frame. Specify a grouping variable.- missing
If
"listwise", cases with missing values are removed listwise from the data frame. If"direct"or"ml"or"fiml"and the estimator is maximum likelihood, an EM algorithm is used to estimate the unrestricted covariance matrix (and mean vector). If"pairwise", pairwise deletion is used. If"default", the value is set depending on the estimator and the mimic option.- sampling.weights
Only used if
objectis adata.frame. Specify a variable containing sampling weights.- ov.names.x
Only used if
objectis adata.frame. Specify variables that need to be treated as exogenous. Only used if at least one variable is declared as ordered.- se
Only used if
output(see below) contains standard errors. SeelavOptionsfor possible options.- test
Only used if output is
"fit"or"lavaan". SeelavOptionsfor possible options.- estimator
If
"none"or"two.step"or"two.stage", only starting values are computed for the correlations (and thresholds), without any further estimation. If all variables are continuous, the starting values are the sample covariances (converted to correlations ifoutput = "cor"). If at least one variable is ordered, the thresholds are computed using univariate information only. The polychoric and/or polyserial correlations are computed in a second stage, keeping the values of the thresholds constant. If an estimator (other than"two.step"or"two.stage") is specified (for exampleestimator = "PML"), these starting values are further updated by fitting the unrestricted model using the chosen estimator. See thelavaanfunction for alternative estimators.- baseline
Only used if output is
"fit"or"lavaan". IfTRUE, a baseline model is also estimated. Note that thetestargument should also be set to a value other than"none".- ...
Optional parameters that are passed to the
lavaanfunction.- cor.smooth
Logical. Only used if
output = "cor". IfTRUE, ensure the resulting correlation matrix is positive definite. The following simple method is used: an eigenvalue decomposition is computed; then, eigenvalues smaller thancor.smooth.tolare set to be equal tocor.smooth.tol, before the matrix is again reconstructed. Finally, the matrix (which may no longer have unit diagonal elements) is converted to a correlation matrix usingcov2cor.- cor.smooth.tol
Numeric. Smallest eigenvalue used when reconstructing the correlation matrix after an eigenvalue decomposition.
- output
If
"cor", the function returns the correlation matrix only. If"cov", the function returns the covariance matrix (this only makes a difference if at least one variable is numeric). If"th"or"thresholds", only the thresholds are returned. If"sampstat", the output equals the result oflavInspect(fit, "sampstat")where fit is the unrestricted model. If"est"or"pe"or"parameterEstimates", the output equals the result oflavParameterEstimates(fit). Finally, if output is"fit"or"lavaan", the function returns an object of classlavaan.
Details
This function is a wrapper around the lavaan function,
but where the model is defined as the unrestricted model. The
following free parameters are included: all covariances/correlations among
the variables, variances for continuous variables, means for continuous
variables, thresholds for ordered variables, and if exogenous variables
are included (ov.names.x is not empty) while some variables
are ordered, also the regression slopes enter the model.
Value
By default, if output = "cor" or output = "cov", a symmetric
matrix (of class "lavaan.matrix.symmetric", which only affects the
way the matrix is printed). If output = "th", a named vector of
thresholds. If output = "fit" or output = "lavaan",
an object of class lavaan.
References
Olsson, U. (1979). Maximum likelihood estimation of the polychoric correlation coefficient. Psychometrika, 44(4), 443-460.
Olsson, U., Drasgow, F., & Dorans, N. J. (1982). The polyserial correlation coefficient. Psychometrika, 47(3), 337-347.
Examples
# Holzinger and Swineford (1939) example
HS9 <- HolzingerSwineford1939[,c("x1","x2","x3","x4","x5",
"x6","x7","x8","x9")]
# Pearson correlations
lavCor(HS9)
#> x1 x2 x3 x4 x5 x6 x7 x8 x9
#> x1 1.000
#> x2 0.297 1.000
#> x3 0.441 0.340 1.000
#> x4 0.373 0.153 0.159 1.000
#> x5 0.293 0.139 0.077 0.733 1.000
#> x6 0.357 0.193 0.198 0.704 0.720 1.000
#> x7 0.067 -0.076 0.072 0.174 0.102 0.121 1.000
#> x8 0.224 0.092 0.186 0.107 0.139 0.150 0.487 1.000
#> x9 0.390 0.206 0.329 0.208 0.227 0.214 0.341 0.449 1.000
# ordinal version, with three categories
HS9ord <- as.data.frame( lapply(HS9, cut, 3, labels = FALSE) )
# polychoric correlations, two-stage estimation
lavCor(HS9ord, ordered=names(HS9ord))
#> x1 x2 x3 x4 x5 x6 x7 x8 x9
#> x1 1.000
#> x2 0.317 1.000
#> x3 0.508 0.304 1.000
#> x4 0.373 0.273 0.136 1.000
#> x5 0.308 0.226 0.125 0.801 1.000
#> x6 0.319 0.274 0.215 0.683 0.783 1.000
#> x7 0.113 -0.097 0.058 0.169 0.136 0.071 1.000
#> x8 0.147 0.094 0.091 0.112 0.160 0.185 0.552 1.000
#> x9 0.459 0.204 0.286 0.258 0.265 0.255 0.365 0.454 1.000
# thresholds only
lavCor(HS9ord, ordered=names(HS9ord), output = "th")
#> x1|t1 x1|t2 x2|t1 x2|t2 x3|t1 x3|t2 x4|t1 x4|t2 x5|t1 x5|t2 x6|t1
#> -1.363 0.844 -1.556 0.741 -0.353 0.626 -0.797 0.956 -0.820 0.527 0.188
#> x6|t2 x7|t1 x7|t2 x8|t1 x8|t2 x9|t1 x9|t2
#> 1.529 -0.820 1.024 -0.129 1.882 -0.425 1.835
# polychoric correlations, with standard errors
lavCor(HS9ord, ordered=names(HS9ord), se = "standard", output = "est")
#> lhs op rhs est.std se z pvalue ci.lower ci.upper
#> 1 x1 ~~ x1 1.000 0.000 NA NA 1.000 1.000
#> 2 x2 ~~ x2 1.000 0.000 NA NA 1.000 1.000
#> 3 x3 ~~ x3 1.000 0.000 NA NA 1.000 1.000
#> 4 x4 ~~ x4 1.000 0.000 NA NA 1.000 1.000
#> 5 x5 ~~ x5 1.000 0.000 NA NA 1.000 1.000
#> 6 x6 ~~ x6 1.000 0.000 NA NA 1.000 1.000
#> 7 x7 ~~ x7 1.000 0.000 NA NA 1.000 1.000
#> 8 x8 ~~ x8 1.000 0.000 NA NA 1.000 1.000
#> 9 x9 ~~ x9 1.000 0.000 NA NA 1.000 1.000
#> 10 x1 ~~ x2 0.317 0.070 4.534 0.000 0.180 0.455
#> 11 x1 ~~ x3 0.508 0.060 8.484 0.000 0.391 0.625
#> 12 x1 ~~ x4 0.373 0.060 6.181 0.000 0.255 0.491
#> 13 x1 ~~ x5 0.308 0.068 4.549 0.000 0.175 0.441
#> 14 x1 ~~ x6 0.319 0.065 4.893 0.000 0.191 0.447
#> 15 x1 ~~ x7 0.113 0.073 1.543 0.123 -0.031 0.257
#> 16 x1 ~~ x8 0.147 0.077 1.921 0.055 -0.003 0.298
#> 17 x1 ~~ x9 0.459 0.073 6.318 0.000 0.317 0.601
#> 18 x2 ~~ x3 0.304 0.066 4.616 0.000 0.175 0.433
#> 19 x2 ~~ x4 0.273 0.069 3.947 0.000 0.138 0.409
#> 20 x2 ~~ x5 0.226 0.069 3.266 0.001 0.090 0.361
#> 21 x2 ~~ x6 0.274 0.070 3.919 0.000 0.137 0.411
#> 22 x2 ~~ x7 -0.097 0.078 -1.241 0.215 -0.250 0.056
#> 23 x2 ~~ x8 0.094 0.085 1.115 0.265 -0.072 0.261
#> 24 x2 ~~ x9 0.204 0.086 2.385 0.017 0.036 0.372
#> 25 x3 ~~ x4 0.136 0.073 1.876 0.061 -0.006 0.279
#> 26 x3 ~~ x5 0.125 0.070 1.786 0.074 -0.012 0.262
#> 27 x3 ~~ x6 0.215 0.079 2.728 0.006 0.060 0.369
#> 28 x3 ~~ x7 0.058 0.074 0.783 0.434 -0.087 0.202
#> 29 x3 ~~ x8 0.091 0.076 1.201 0.230 -0.057 0.239
#> 30 x3 ~~ x9 0.286 0.072 3.954 0.000 0.144 0.428
#> 31 x4 ~~ x5 0.801 0.032 24.928 0.000 0.738 0.864
#> 32 x4 ~~ x6 0.683 0.050 13.794 0.000 0.586 0.781
#> 33 x4 ~~ x7 0.169 0.082 2.058 0.040 0.008 0.330
#> 34 x4 ~~ x8 0.112 0.076 1.474 0.141 -0.037 0.260
#> 35 x4 ~~ x9 0.258 0.066 3.938 0.000 0.130 0.387
#> 36 x5 ~~ x6 0.783 0.042 18.749 0.000 0.702 0.865
#> 37 x5 ~~ x7 0.136 0.069 1.965 0.049 0.000 0.272
#> 38 x5 ~~ x8 0.160 0.074 2.153 0.031 0.014 0.306
#> 39 x5 ~~ x9 0.265 0.065 4.070 0.000 0.137 0.392
#> 40 x6 ~~ x7 0.071 0.078 0.911 0.362 -0.082 0.223
#> 41 x6 ~~ x8 0.185 0.079 2.349 0.019 0.031 0.339
#> 42 x6 ~~ x9 0.255 0.076 3.379 0.001 0.107 0.404
#> 43 x7 ~~ x8 0.552 0.059 9.370 0.000 0.437 0.668
#> 44 x7 ~~ x9 0.365 0.075 4.892 0.000 0.219 0.512
#> 45 x8 ~~ x9 0.454 0.076 5.945 0.000 0.304 0.604
#> 46 x1 | t1 -1.363 0.103 -13.239 0.000 -1.565 -1.162
#> 47 x1 | t2 0.844 0.083 10.224 0.000 0.682 1.006
#> 48 x2 | t1 -1.556 0.115 -13.508 0.000 -1.782 -1.331
#> 49 x2 | t2 0.741 0.080 9.259 0.000 0.584 0.898
#> 50 x3 | t1 -0.353 0.074 -4.766 0.000 -0.498 -0.208
#> 51 x3 | t2 0.626 0.078 8.047 0.000 0.473 0.778
#> 52 x4 | t1 -0.797 0.081 -9.799 0.000 -0.957 -0.638
#> 53 x4 | t2 0.956 0.086 11.151 0.000 0.788 1.125
#> 54 x5 | t1 -0.820 0.082 -10.012 0.000 -0.981 -0.660
#> 55 x5 | t2 0.527 0.076 6.925 0.000 0.378 0.676
#> 56 x6 | t1 0.188 0.073 2.588 0.010 0.046 0.331
#> 57 x6 | t2 1.529 0.113 13.498 0.000 1.307 1.751
#> 58 x7 | t1 -0.820 0.082 -10.012 0.000 -0.981 -0.660
#> 59 x7 | t2 1.024 0.088 11.641 0.000 0.852 1.197
#> 60 x8 | t1 -0.129 0.073 -1.783 0.075 -0.272 0.013
#> 61 x8 | t2 1.882 0.145 12.989 0.000 1.598 2.166
#> 62 x9 | t1 -0.425 0.075 -5.678 0.000 -0.571 -0.278
#> 63 x9 | t2 1.835 0.140 13.131 0.000 1.561 2.109
#> 64 x1 ~1 0.000 0.000 NA NA 0.000 0.000
#> 65 x2 ~1 0.000 0.000 NA NA 0.000 0.000
#> 66 x3 ~1 0.000 0.000 NA NA 0.000 0.000
#> 67 x4 ~1 0.000 0.000 NA NA 0.000 0.000
#> 68 x5 ~1 0.000 0.000 NA NA 0.000 0.000
#> 69 x6 ~1 0.000 0.000 NA NA 0.000 0.000
#> 70 x7 ~1 0.000 0.000 NA NA 0.000 0.000
#> 71 x8 ~1 0.000 0.000 NA NA 0.000 0.000
#> 72 x9 ~1 0.000 0.000 NA NA 0.000 0.000
#> 73 x1 ~*~ x1 1.000 0.000 NA NA 1.000 1.000
#> 74 x2 ~*~ x2 1.000 0.000 NA NA 1.000 1.000
#> 75 x3 ~*~ x3 1.000 0.000 NA NA 1.000 1.000
#> 76 x4 ~*~ x4 1.000 0.000 NA NA 1.000 1.000
#> 77 x5 ~*~ x5 1.000 0.000 NA NA 1.000 1.000
#> 78 x6 ~*~ x6 1.000 0.000 NA NA 1.000 1.000
#> 79 x7 ~*~ x7 1.000 0.000 NA NA 1.000 1.000
#> 80 x8 ~*~ x8 1.000 0.000 NA NA 1.000 1.000
#> 81 x9 ~*~ x9 1.000 0.000 NA NA 1.000 1.000
# polychoric correlations, full output
fit.un <- lavCor(HS9ord, ordered=names(HS9ord), se = "standard",
output = "fit")
summary(fit.un)
#> lavaan 0.6-21 ended normally after 1 iteration
#>
#> Estimator DWLS
#> Optimization method NLMINB
#> Number of model parameters 54
#>
#> Number of observations 301
#>
#>
#> Parameter Estimates:
#>
#> Parameterization Delta
#> Standard errors Standard
#> Information Expected
#> Information saturated (h1) model Unstructured
#>
#> Covariances:
#> Estimate Std.Err z-value P(>|z|)
#> x1 ~~
#> x2 0.317 0.070 4.534 0.000
#> x3 0.508 0.060 8.484 0.000
#> x4 0.373 0.060 6.181 0.000
#> x5 0.308 0.068 4.549 0.000
#> x6 0.319 0.065 4.893 0.000
#> x7 0.113 0.073 1.543 0.123
#> x8 0.147 0.077 1.921 0.055
#> x9 0.459 0.073 6.318 0.000
#> x2 ~~
#> x3 0.304 0.066 4.616 0.000
#> x4 0.273 0.069 3.947 0.000
#> x5 0.226 0.069 3.266 0.001
#> x6 0.274 0.070 3.919 0.000
#> x7 -0.097 0.078 -1.241 0.215
#> x8 0.094 0.085 1.115 0.265
#> x9 0.204 0.086 2.385 0.017
#> x3 ~~
#> x4 0.136 0.073 1.876 0.061
#> x5 0.125 0.070 1.786 0.074
#> x6 0.215 0.079 2.728 0.006
#> x7 0.058 0.074 0.783 0.434
#> x8 0.091 0.076 1.201 0.230
#> x9 0.286 0.072 3.954 0.000
#> x4 ~~
#> x5 0.801 0.032 24.928 0.000
#> x6 0.683 0.050 13.794 0.000
#> x7 0.169 0.082 2.058 0.040
#> x8 0.112 0.076 1.474 0.141
#> x9 0.258 0.066 3.938 0.000
#> x5 ~~
#> x6 0.783 0.042 18.749 0.000
#> x7 0.136 0.069 1.965 0.049
#> x8 0.160 0.074 2.153 0.031
#> x9 0.265 0.065 4.070 0.000
#> x6 ~~
#> x7 0.071 0.078 0.911 0.362
#> x8 0.185 0.079 2.349 0.019
#> x9 0.255 0.076 3.379 0.001
#> x7 ~~
#> x8 0.552 0.059 9.370 0.000
#> x9 0.365 0.075 4.892 0.000
#> x8 ~~
#> x9 0.454 0.076 5.945 0.000
#>
#> Intercepts:
#> Estimate Std.Err z-value P(>|z|)
#> x1 0.000
#> x2 0.000
#> x3 0.000
#> x4 0.000
#> x5 0.000
#> x6 0.000
#> x7 0.000
#> x8 0.000
#> x9 0.000
#>
#> Thresholds:
#> Estimate Std.Err z-value P(>|z|)
#> x1|t1 -1.363 0.103 -13.239 0.000
#> x1|t2 0.844 0.083 10.224 0.000
#> x2|t1 -1.556 0.115 -13.508 0.000
#> x2|t2 0.741 0.080 9.259 0.000
#> x3|t1 -0.353 0.074 -4.766 0.000
#> x3|t2 0.626 0.078 8.047 0.000
#> x4|t1 -0.797 0.081 -9.799 0.000
#> x4|t2 0.956 0.086 11.151 0.000
#> x5|t1 -0.820 0.082 -10.012 0.000
#> x5|t2 0.527 0.076 6.925 0.000
#> x6|t1 0.188 0.073 2.588 0.010
#> x6|t2 1.529 0.113 13.498 0.000
#> x7|t1 -0.820 0.082 -10.012 0.000
#> x7|t2 1.024 0.088 11.641 0.000
#> x8|t1 -0.129 0.073 -1.783 0.075
#> x8|t2 1.882 0.145 12.989 0.000
#> x9|t1 -0.425 0.075 -5.678 0.000
#> x9|t2 1.835 0.140 13.131 0.000
#>
#> Variances:
#> Estimate Std.Err z-value P(>|z|)
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> x4 1.000
#> x5 1.000
#> x6 1.000
#> x7 1.000
#> x8 1.000
#> x9 1.000
#>
#> Scales y*:
#> Estimate Std.Err z-value P(>|z|)
#> x1 1.000
#> x2 1.000
#> x3 1.000
#> x4 1.000
#> x5 1.000
#> x6 1.000
#> x7 1.000
#> x8 1.000
#> x9 1.000
#>