Skip to contents

Compare the fit of two models using the likelihood ratio test (LRT). est_h0 is the null hypothesis model, and est_h1 the alternative hypothesis model. Importantly, the function assumes that est_h0 does not have more free parameters (i.e., degrees of freedom) than est_h1 (the alternative hypothesis model).

Usage

compare_fit(est_h1, est_h0, ...)

Arguments

est_h1

object of class modsem_da or modsem_pi representing the alternative hypothesis model (with interaction terms).

est_h0

object of class modsem_da or modsem_pi representing the null hypothesis model (without interaction terms).

...

additional arguments passed to the underlying comparison function. E.g., for modsem_pi models, this can be used to pass arguments to lavaan::lavTestLRT. currently only used for modsem_pi models.

Examples

# \dontrun{
m1 <- "
 # Outer Model
 X =~ x1 + x2 + x3
 Y =~ y1 + y2 + y3
 Z =~ z1 + z2 + z3

 # Inner model
 Y ~ X + Z + X:Z
"

# LMS approach
est_h1 <- modsem(m1, oneInt, "lms")
est_h0 <- estimate_h0(est_h1, calc.se=FALSE) # std.errors are not needed
compare_fit(est_h1 = est_h1, est_h0 = est_h0)
#> $D
#> [1] 676.5418
#> 
#> $df
#> [1] 1
#> 
#> $p
#> [1] 3.775457e-149
#> 
#> $diff.loglik
#> [1] 338.2709
#> 

# Double centering approach
est_h1 <- modsem(m1, oneInt, method = "dblcent")
est_h0 <- estimate_h0(est_h1, oneInt)

compare_fit(est_h1 = est_h1, est_h0 = est_h0)
#> 
#> Chi-Squared Difference Test
#> 
#>         Df   AIC   BIC  Chisq Chisq diff   RMSEA Df diff Pr(>Chisq)    
#> est_h1 111 53735 54071 122.92                                          
#> est_h0 112 54393 54724 783.18     660.26 0.57413       1  < 2.2e-16 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

# Constrained approach
est_h1 <- modsem(m1, oneInt, method = "ca")
est_h0 <- estimate_h0(est_h1, oneInt)

compare_fit(est_h1 = est_h1, est_h0 = est_h0)
#> 
#> Chi-Squared Difference Test
#> 
#>        Df   AIC   BIC   Chisq Chisq diff   RMSEA Df diff Pr(>Chisq)    
#> est_h1 56 48747 48937  60.401                                          
#> est_h0 57 49404 49589 720.150     659.75 0.57391       1  < 2.2e-16 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# }