fix_to_zero {semlrtp} | R Documentation |
It fixes a designated free parameter in a lavaan object to zero and refit the model.
fix_to_zero(fit, par_id, store_fit = FALSE, se_keep_bootstrap = FALSE)
fit |
A |
par_id |
An integer. The row
number of the free parameter in the
parameter table of |
store_fit |
Logical. If |
se_keep_bootstrap |
Logical.
If |
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.
A fix_to_zero
-class object, which
is a list with these elements:
fit0
is the lavaan
output of the
refitted object. NA
if the fit
failed for some reasons. To be
considered an acceptable solution,
the optimization must converge,
the solution passes lavaan
'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.
fit1
is the original lavaan
output if store_fit
is TRUE
. It
is NULL
if store_fit
is FALSE
,
the default.
par_id
is the row number of the
designated free parameter in the
parameter table.
call
is the original call to this
function.
ptable0
is the parameter table
with the designated parameter fixed
to zero. It can be used for diagnostic
purpose if the fit failed.
fit0_error
is the error
message in refitting the model
(ptable0
), if
any. If
no error, it is NA
.
vcov_ok
is TRUE
if the
variance-covariance matrix of the
estimates
can be computed without error nor
warning. FALSE
otherwise.
vcov_msg
is the message generated
when using lavaan::lavInspect()
to
get the variance-covariance matrix
of the parameter estimates of the
refitted model. If TRUE
, 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
) passed
lavaan
's post check.
post_check_msg
: If the solution
failed lavaan
's post check,
it stores the warning message.
If the solution passes the check,
it is NA
.
fit_not_ok
: If the fit failed
for some reasons, the fit object,
if available, is stored in this
element rather than in fit0
. 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
: Whether
se
was forced to be "standard"
even if it is "bootstrap"
in
fit
. If FALSE
, then either
se
is not "bootstrap"
in
fit
or it was not changed in
fitting the restricted model.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
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)