Class For Representing A (Fitted) Latent Variable Model
lavaan-class.RdThe lavaan class represents a (fitted) latent variable
model. It contains a description of the model as specified by the user,
a summary of the data, an internal matrix representation, and if the model
was fitted, the fitting results.
Slots
version:The lavaan package version used to create this object
call:The function call as returned by
match.call().timing:The elapsed time (user+system) for various parts of the program as a list, including the total time.
Options:Named list of options that were provided by the user, or filled-in automatically.
ParTable:Named list describing the model parameters. Can be coerced to a data.frame. In the documentation, this is called the `parameter table'.
pta:Named list containing parameter table attributes.
Data:Object of internal class
"Data": information about the data.SampleStats:Object of internal class
"SampleStats": sample statisticsModel:Object of internal class
"Model": the internal (matrix) representation of the modelCache:List of objects that are computed only once and reused many times.
Fit:Object of internal class
"Fit": the results of fitting the model. No longer used.boot:List. Results and information about the bootstrap.
optim:List. Information about the optimization.
loglik:List. Information about the loglikelihood of the model (if maximum likelihood was used).
implied:List. Model implied statistics.
vcov:List. Information about the variance matrix (vcov) of the model parameters.
test:List. Different test statistics.
h1:List. Information about the unrestricted h1 model (if available).
baseline:List. Information about a baseline model (often the independence model) (if available).
internal:List. For internal use only.
external:List. Empty slot to be used by add-on packages.
Methods
- coef
signature(object = "lavaan", type = "free"): Returns the estimates of the parameters in the model as a named numeric vector. Iftype="free", only the free parameters are returned. Iftype="user", all parameters listed in the parameter table are returned, including constrained and fixed parameters.- fitted.values
signature(object = "lavaan"): Returns the implied moments of the model as a list with two elements (per group):covfor the implied covariance matrix, andmeanfor the implied mean vector. If only the covariance matrix was analyzed, the implied mean vector will be zero.- fitted
signature(object = "lavaan"): an alias forfitted.values.- residuals
signature(object = "lavaan", type="raw"): Iftype = "raw", this function returns the raw (= unscaled) difference between the observed and the expected (model-implied) summary statistics. Iftype = "cor", ortype = "cor.bollen", the observed and model implied covariance matrices are first transformed to a correlation matrix (usingcov2cor()), before the residuals are computed. Iftype = "cor.bentler", both the observed and model implied covariance matrices are rescaled by dividing the elements by the square roots of the corresponding variances of the observed covariance matrix. Iftype="normalized", the residuals are divided by the square root of the asymptotic variance of the corresponding summary statistic (the variance estimate depends on the choice for theseargument). Unfortunately, these normalized residuals are not entirely correct, and this option is retained only for historical interest. Iftype="standardized", the residuals are divided by the square root of the asymptotic variance of these residuals. The resulting standardized residuals can be interpreted as z-scores. Iftype="standardized.mplus", the residuals are divided by the square root of the asymptotic variance of these residuals. However, a simplified formula is used (see the Mplus reference below) which often results in negative estimates for the variances, resulting in manyNAvalues for the standardized residuals.- resid
signature(object = "lavaan"): an alias forresiduals- vcov
signature(object = "lavaan", type = "free"): returns the covariance matrix of the estimated parameters. Iftype = "free"(the default), only the free parameters are included. Iftype = "user"(or"joint"), the joint covariance matrix of the free and the user-defined (:=) parameters is returned; the parameter names are the same as those used bycoef().- predict
signature(object = "lavaan"): compute factor scores for all cases that are provided in the data frame. For complete data only.- anova
signature(object = "lavaan"): returns model comparison statistics. This method is just a wrapper around the functionlavTestLRT. If only a single argument (a fitted model) is provided, this model is compared to the unrestricted model. If two or more arguments (fitted models) are provided, the models are compared in a sequential order. Test statistics are based on the likelihood ratio test. For more details and further options, see thelavTestLRTpage.- update
signature(object = "lavaan", model, add, ..., evaluate = TRUE): update a fitted lavaan object and evaluate it (unlessevaluate = FALSE). Note that we use the environment that is stored within the lavaan object, which is not necessarily the parent frame. Theaddargument is analogous to the one described in thelavTestScorepage, and can be used to add parameters to the specified model rather than passing an entirely newmodelargument.- nobs
signature(object = "lavaan"): returns the effective number of observations used when fitting the model. In a multiple group analysis, this is the sum of all observations per group.- logLik
signature(object = "lavaan"): returns the log-likelihood of the fitted model, if maximum likelihood estimation was used. TheAICandBICmethods automatically work vialogLik().- show
signature(object = "lavaan"): Print a short summary of the model fit- summary
signature(object = "lavaan", header = TRUE, fit_measures = FALSE, residuals = FALSE, estimates = TRUE, ci = FALSE, fmi = FALSE, standardized = FALSE, std = standardized, std_nox = FALSE, remove_system_eq = TRUE, remove_eq = TRUE, remove_ineq = TRUE, remove_def = FALSE, remove_nonfree = FALSE, remove_step1 = TRUE, remove_unused = TRUE, plabel = FALSE, cov_std = TRUE, rsquare = FALSE, baseline_model = NULL, h1_model = NULL, fm_args = list(standard.test = "default", scaled.test = "default", rmsea.ci.level = 0.90, rmsea.h0.closefit = 0.05, rmsea.h0.notclosefit = 0.08, robust = TRUE, cat.nonpd = "na"), modindices = FALSE, srmr_close_h0 = NULL, nd = 3L, cutoff = 0.3, dot_cutoff = 0.1): Print a nice summary of the model estimates. Ifheader = TRUE, the header section (including fit measures) is printed. Iffit.measures = TRUE, additional fit measures are added to the header section.fit.measurescan also be a list, which allows one to set options related to the fit measures. SeefitMeasuresfor more details. Ifresiduals = TRUE, a residuals section is added (the largest residuals and the residual summary, printed as bylavResidualswithoutput = "text"); the underlyinglavResiduals(object, output = "list")result is stored as theresidualselement of the summary object.residualscan also be a list of arguments passed on tolavResiduals(for exampleresiduals = list(type = "raw", n.largest = 10)). If bothfit.measures = TRUEandresiduals = TRUEand the residual summary is the SRMR (the default), the SRMR is removed from the fit measures section to avoid printing it twice. Ifestimates = TRUE, print the parameter estimates section. Ifci = TRUE, add confidence intervals to the parameter estimates section. Iffmi = TRUE, add the fmi (fraction of missing information) column, if it is available. Ifstandardized = TRUEor a character vector, the standardized solution is also printed (seelavParameterEstimates). Note that SEs and tests are still based on unstandardized estimates. UsestandardizedSolutionto obtain SEs and test statistics for standardized estimates. Thestd.noxargument is deprecated; thestandardizedargument allows"std.nox"solution to be specifically requested. Thestandardizedargument may also be a character vector of (observed) variable names (for examplec("x1", "x2")); only the parameters involving these variables are then standardized, and the result is shown in aStd.usrcolumn. This generalizes"std.nox", where the exogenousxvariables are the ones left unstandardized. Ifremove_system_eq = TRUE, the system-generated equality constraints (using plabels) are not shown. Ifremove_eq = TRUEorremove_ineq = TRUE, the user-specified (in)equality constraints are not shown. Ifremove_def = TRUE, the user-specified parameter definitions are not shown. Ifremove_nonfree = TRUE, the nonfree parameters are not shown. Ifremove_step1 = TRUE, the parameters of the measurement part are not shown (only used when usingsam().) Ifremove_unused = TRUE, automatically added parameters that are fixed to their default (0 or 1) values are removed. Ifrsquare = TRUE, the R-Square values for the dependent variables in the model are printed. Thefm.argslist allows one to set options related to the fit measures (seefitMeasures).baseline.modelandh1.modelallow one to specify user-defined baseline and/or h1 models for the fit measures. If the model is an exploratory factor analysis (EFA) model, EFA related information is printed automatically. Thecutoffanddot.cutoffarguments control how the factor loadings are displayed: loadings whose absolute value is at or abovecutoffare shown as numbers; loadings whose absolute value falls betweendot.cutoffandcutoffare replaced by a dot; loadings whose absolute value is belowdot.cutoffare left blank. Ifmodindices = TRUEormodindicesis a list, modification indices are printed for all fixed parameters. The argumentnddetermines the number of digits after the decimal point to be printed (currently only in the parameter estimates section.) Historically, nothing was returned, but since 0.6-12, a list is returned of classlavaan.summaryfor which a print function is available.
References
Yves Rosseel (2012). lavaan: An R Package for Structural Equation Modeling. Journal of Statistical Software, 48(2), 1-36. doi:10.18637/jss.v048.i02
Standardized Residuals in Mplus. Document retrieved from URL https://www.statmodel.com/download/StandardizedResiduals.pdf
Examples
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
fit <- cfa(HS.model, data = HolzingerSwineford1939)
summary(fit, standardized = TRUE, fit.measures = TRUE, rsquare = TRUE)
#> lavaan 0.7-1.3097 ended normally after 35 iterations
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 21
#>
#> Number of observations 301
#>
#> Model Test User Model:
#>
#> Test statistic 85.306
#> Degrees of freedom 24
#> P-value (Chi-square) 0.000
#>
#> Model Test Baseline Model:
#>
#> Test statistic 918.852
#> Degrees of freedom 36
#> P-value 0.000
#>
#> User Model versus Baseline Model:
#>
#> Comparative Fit Index (CFI) 0.931
#> Tucker-Lewis Index (TLI) 0.896
#>
#> Loglikelihood and Information Criteria:
#>
#> Loglikelihood user model (H0) -3737.745
#> Loglikelihood unrestricted model (H1) -3695.092
#>
#> Akaike (AIC) 7517.490
#> Bayesian (BIC) 7595.339
#> Sample-size adjusted Bayesian (SABIC) 7528.739
#>
#> Root Mean Square Error of Approximation:
#>
#> RMSEA 0.092
#> 90 Percent confidence interval - lower 0.071
#> 90 Percent confidence interval - upper 0.114
#> P-value H_0: RMSEA <= 0.050 0.001
#> P-value H_0: RMSEA >= 0.080 0.840
#>
#> Standardized Root Mean Square Residual:
#>
#> SRMR 0.065
#>
#> Goodness of Fit Index:
#>
#> Goodness of Fit Index (GFI) 0.959
#> 90 Percent confidence interval - lower 0.939
#> 90 Percent confidence interval - upper 0.976
#>
#> Parameter Estimates:
#>
#> Standard errors Standard
#> Information Expected
#> Information saturated (h1) model Structured
#>
#> Latent Variables:
#> Estimate Std.Err z-value P(>|z|) Std.lv Std.all
#> visual =~
#> x1 1.000 0.900 0.772
#> x2 0.554 0.100 5.554 0.000 0.498 0.424
#> x3 0.729 0.109 6.685 0.000 0.656 0.581
#> textual =~
#> x4 1.000 0.990 0.852
#> x5 1.113 0.065 17.014 0.000 1.102 0.855
#> x6 0.926 0.055 16.703 0.000 0.917 0.838
#> speed =~
#> x7 1.000 0.619 0.570
#> x8 1.180 0.165 7.152 0.000 0.731 0.723
#> x9 1.082 0.151 7.155 0.000 0.670 0.665
#>
#> Covariances:
#> Estimate Std.Err z-value P(>|z|) Std.lv Std.all
#> visual ~~
#> textual 0.408 0.074 5.552 0.000 0.459 0.459
#> speed 0.262 0.056 4.660 0.000 0.471 0.471
#> textual ~~
#> speed 0.173 0.049 3.518 0.000 0.283 0.283
#>
#> Variances:
#> Estimate Std.Err z-value P(>|z|) Std.lv Std.all
#> .x1 0.549 0.114 4.833 0.000 0.549 0.404
#> .x2 1.134 0.102 11.146 0.000 1.134 0.821
#> .x3 0.844 0.091 9.317 0.000 0.844 0.662
#> .x4 0.371 0.048 7.779 0.000 0.371 0.275
#> .x5 0.446 0.058 7.642 0.000 0.446 0.269
#> .x6 0.356 0.043 8.277 0.000 0.356 0.298
#> .x7 0.799 0.081 9.823 0.000 0.799 0.676
#> .x8 0.488 0.074 6.573 0.000 0.488 0.477
#> .x9 0.566 0.071 8.003 0.000 0.566 0.558
#> visual 0.809 0.145 5.564 0.000 1.000 1.000
#> textual 0.979 0.112 8.737 0.000 1.000 1.000
#> speed 0.384 0.086 4.451 0.000 1.000 1.000
#>
#> R-Square:
#> Estimate
#> x1 0.596
#> x2 0.179
#> x3 0.338
#> x4 0.725
#> x5 0.731
#> x6 0.702
#> x7 0.324
#> x8 0.523
#> x9 0.442
#>
fitted(fit)
#> $cov
#> x1 x2 x3 x4 x5 x6 x7 x8 x9
#> x1 1.358
#> x2 0.448 1.382
#> x3 0.590 0.327 1.275
#> x4 0.408 0.226 0.298 1.351
#> x5 0.454 0.252 0.331 1.090 1.660
#> x6 0.378 0.209 0.276 0.907 1.010 1.196
#> x7 0.262 0.145 0.191 0.173 0.193 0.161 1.183
#> x8 0.309 0.171 0.226 0.205 0.228 0.190 0.453 1.022
#> x9 0.284 0.157 0.207 0.188 0.209 0.174 0.415 0.490 1.015
#>
coef(fit)
#> visual=~x2 visual=~x3 textual=~x5 textual=~x6
#> 0.554 0.729 1.113 0.926
#> speed=~x8 speed=~x9 x1~~x1 x2~~x2
#> 1.180 1.082 0.549 1.134
#> x3~~x3 x4~~x4 x5~~x5 x6~~x6
#> 0.844 0.371 0.446 0.356
#> x7~~x7 x8~~x8 x9~~x9 visual~~visual
#> 0.799 0.488 0.566 0.809
#> textual~~textual speed~~speed visual~~textual visual~~speed
#> 0.979 0.384 0.408 0.262
#> textual~~speed
#> 0.173
resid(fit, type = "normalized")
#> $type
#> [1] "normalized"
#>
#> $cov
#> x1 x2 x3 x4 x5 x6 x7 x8 x9
#> x1 0.000
#> x2 -0.493 0.000
#> x3 -0.125 1.539 0.000
#> x4 1.159 -0.214 -1.170 0.000
#> x5 -0.153 -0.459 -2.606 0.070 0.000
#> x6 0.983 0.507 -0.436 -0.130 0.048 0.000
#> x7 -2.423 -3.273 -1.450 0.625 -0.617 -0.240 0.000
#> x8 -0.655 -0.896 -0.200 -1.162 -0.624 -0.375 1.170 0.000
#> x9 2.405 1.249 2.420 0.808 1.126 0.958 -0.625 -0.504 0.000
#>