It fixes a designated free parameter in a lavaan object to zero and refit the model.
Arguments
- fit
A
lavaan-class object.- par_id
An integer. The row number of the free parameter in the parameter table of
fitto be fixed.- store_fit
Logical. If
TRUE,fitwill be stored in the output. Default isFALSE.- se_keep_bootstrap
Logical. If
TRUEandfitused bootstrapping standard error (withse = "bootstrap"), bootstrapping will also be use in fitting the restricted model. IfFALSE, the default, thensewill be set to"standard"if it is"bootstrap"infit, to speed up the computation.
Value
A fix_to_zero-class object, which
is a list with these elements:
fit0is thelavaanoutput of the refitted object.NAif the fit failed for some reasons. To be considered an acceptable solution, the optimization must converge, the solution passeslavaan's post check, the variance-covariance matrix of estimates successfully computed, and the increase in the model degree of freedom equal to the expected change.fit1is the originallavaanoutput ifstore_fitisTRUE. It isNULLifstore_fitisFALSE, the default.par_idis the row number of the designated free parameter in the parameter table.callis the original call to this function.ptable0is the parameter table with the designated parameter fixed to zero. It can be used for diagnostic purpose if the fit failed.fit0_erroris the error message in refitting the model (ptable0), if any. If no error, it isNA.vcov_okisTRUEif the variance-covariance matrix of the estimates can be computed without error nor warning.FALSEotherwise.vcov_msgis the message generated when usinglavaan::lavInspect()to get the variance-covariance matrix of the parameter estimates of the refitted model. IfTRUE, then no error nor warning. Can be used for diagnostic purposes.converged: Whether refitting the modified model (ptable0) converged.post_check_passed: Whether the solution of the modified model (ptable0) passedlavaan's post check.post_check_msg: If the solution failedlavaan's post check, it stores the warning message. If the solution passes the check, it isNA.fit_not_ok: If the fit failed for some reasons, the fit object, if available, is stored in this element rather than infit0. such that the fit object can be retrieved for diagnostic purposed if necessary.df_diff_one: Whether the difference in model degrees of freedom between the modified model and the original model is one. If a variance is fitted to zero, related covariance(s) is/are also fitted to zero and so the difference in model degrees of freedom can be legitimately greater than one.se_force_standard: Whethersewas forced to be"standard"even if it is"bootstrap"infit. IfFALSE, then eitherseis not"bootstrap"infitor it was not changed in fitting the restricted model.
Details
It modifies the parameter
table of a lavaan-class object and
then fits the model again.
Users should usually call
lrtp() directly instead of calling
this function. It is exported for
developers.
Author
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
Examples
library(lavaan)
data(data_sem16)
mod <-
"
f1 =~ x1 + x2 + x3
f2 =~ x4 + x5 + x6
"
fit <- sem(mod, data_sem16)
# Fix the factor covariance to zero
out <- fix_to_zero(fit, par_id = 15)
summary(out$fit0)
#> lavaan 0.6-19 ended normally after 49 iterations
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 12
#>
#> Number of observations 336
#>
#> Model Test User Model:
#>
#> Test statistic 27.655
#> Degrees of freedom 9
#> P-value (Chi-square) 0.001
#>
#> Parameter Estimates:
#>
#> Standard errors Standard
#> Information Expected
#> Information saturated (h1) model Structured
#>
#> Latent Variables:
#> Estimate Std.Err z-value P(>|z|)
#> f1 =~
#> x1 1.000
#> x2 0.911 0.253 3.604 0.000
#> x3 1.051 0.323 3.257 0.001
#> f2 =~
#> x4 1.000
#> x5 2.538 1.424 1.782 0.075
#> x6 5.526 6.331 0.873 0.383
#>
#> Covariances:
#> Estimate Std.Err z-value P(>|z|)
#> f1 ~~
#> f2 0.000
#>
#> Variances:
#> Estimate Std.Err z-value P(>|z|)
#> .x1 1.010 0.119 8.457 0.000
#> .x2 1.067 0.111 9.573 0.000
#> .x3 0.700 0.114 6.159 0.000
#> .x4 1.198 0.096 12.500 0.000
#> .x5 1.037 0.182 5.705 0.000
#> .x6 0.515 0.775 0.664 0.507
#> f1 0.286 0.110 2.595 0.009
#> f2 0.022 0.031 0.723 0.469
#>
