Skip to contents

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 lavaan-class object.

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 fit to be fixed to zero. If it is a string, it must be a valid lavaan model syntax for a parameter, or the label of a labelled parameter.

store_fit

Logical. If TRUE, fit will be stored in the output. Default is FALSE.

group

If a model syntax is used in par_id and the model is a multigroup model, this should be either the group label or the group number of the parameter.

se_keep_bootstrap

Logical. If TRUE and fit used bootstrapping standard error (with se = "bootstrap"), bootstrapping will also be use in fitting the restricted model. If FALSE, the default, then se will be set to "standard" if it is "bootstrap" in fit, to speed up the computation.

LRT_method

String. Passed to the method argument of lavaan::lavTestLRT(). Default is "default", and let lavaan::lavTestLRT() decide the method based on fit.

scaled.shifted

Logical. Used when the method used in lavaan::lavTestLRT() is "satorra.2000". Default is TRUE and a scaled and shifted test statistic is used, the same default of lavaan::lavTestLRT().

fallback_method

The default method of lavaan::lavTestLRT(), "satorra.bentler.2001", may sometimes fail. If failed, this function will call lavaan::lavTestLRT() again using fallback_method. which is "satorra.2000" by default.

Value

A lrt-class object, which is a list with the following elements:

  • lrt: The output of lavaan::lavTestLRT(). If there is an error message or warning, it is set to NA.

  • par_id: The row number of the designated free parameter.

  • par_label: The label of the designated free parameter, generated by lavaan::lav_partable_labels().

  • fit1: The original lavaan output, if store_fit is TRUE. NA if store_fit is FALSE, the default.

  • fix_to_zero: The output of fit_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 and lavaan::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 calling lavaan::lavTestLRT(). If no error nor warning, this is NA.

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.

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
#> 
#> Chi-Squared Difference Test
#> 
#>      Df    AIC    BIC  Chisq Chisq diff   RMSEA Df diff Pr(>Chisq)   
#> fit   8 6024.1 6073.7 17.009                                         
#> fit0  9 6032.8 6078.6 27.655     10.646 0.16943       1   0.001103 **
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
parameterEstimates(fit)[15, ]
#>    lhs op rhs   est    se     z pvalue ci.lower ci.upper
#> 15  f1 ~~  f2 0.057 0.028 2.005  0.045    0.001    0.112
parameterEstimates(out$fix_to_zero$fit0)[15, ]
#>    lhs op rhs est se  z pvalue ci.lower ci.upper
#> 15  f1 ~~  f2   0  0 NA     NA        0        0

# Can use model syntax for par_id

out <- lrt(fit, par_id = "f1 =~ x3")
out$lrt
#> 
#> Chi-Squared Difference Test
#> 
#>      Df    AIC    BIC  Chisq Chisq diff   RMSEA Df diff Pr(>Chisq)    
#> fit   8 6024.1 6073.7 17.009                                          
#> fit0  9 6061.7 6107.5 56.566     39.557 0.33875       1  3.186e-10 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1