| lrt {semlrtp} | R Documentation |
Fix a Free Parameter to Zero and Do an LR Test
Description
Fix the designated free parameter to zero and do a likelihood ratio test.
Usage
lrt(
fit,
par_id,
store_fit = FALSE,
group = NULL,
se_keep_bootstrap = FALSE,
LRT_method = "default",
scaled.shifted = TRUE,
fallback_method = "satorra.2000"
)
Arguments
fit |
A |
par_id |
It can be an integer.
or a string. If it is an integer,
it should be the row
number of the free parameter in the
parameter table of |
store_fit |
Logical. If |
group |
If a model syntax
is used in |
se_keep_bootstrap |
Logical.
If |
LRT_method |
String. Passed to
the |
scaled.shifted |
Logical.
Used when the method used in
|
fallback_method |
The default
method of |
Details
It fixes the designated
free parameter in a lavaan output,
refit the model, and do a likelihood
ratio test comparing this model with
the original model.
The model to be fixed is generated
by fix_to_zero().
If the parameter to be fixed is a variance, related covariance(s), if any, will also be fixed to zero.
Users should usually call
lrtp() directly instead of calling
this function. It is exported for
developers.
Value
A lrt-class object, which is a
list with the following elements:
-
lrt: The output oflavaan::lavTestLRT(). If there is an error message or warning, it is set toNA. -
par_id: The row number of the designated free parameter. -
par_label: The label of the designated free parameter, generated bylavaan::lav_partable_labels(). -
fit1: The originallavaanoutput, ifstore_fitisTRUE.NAifstore_fitisFALSE, the default. -
fix_to_zero: The output offit_to_zero(). -
call: The call to this function. -
lrt_status: Integer. If 0, then there is no error nor warning in the likelihood ratio test andlavaan::lavTestLRT()returns a table (data.frame) of the test. If -1, then something is wrong, e.g., an error or warning occurred when doing the likelihood ratio test. -
lrt_msg: If something went wrong when doing the likelihood ratio test, this is the error or warning message when callinglavaan::lavTestLRT(). If no error nor warning, this isNA.
Author(s)
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
See Also
print.lrt() for its
print-method, and lrtp() for the
main function.
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 <- lrt(fit, par_id = 15)
out$lrt
parameterEstimates(fit)[15, ]
parameterEstimates(out$fix_to_zero$fit0)[15, ]
# Can use model syntax for par_id
out <- lrt(fit, par_id = "f1 =~ x3")
out$lrt