Skip to content

Feature Request: Add support for lavaan objects in equivalence_test() #1176

@andreifoldes

Description

@andreifoldes

Summary

The equivalence_test() function currently does not support lavaan objects (structural equation models), which limits its utility for researchers working with SEM frameworks. This feature request proposes adding lavaan support to enable equivalence testing for SEM parameters.

Minimal Reproducible Example

# Load required packages
library(lavaan)
library(parameters)

# Create simple example data
set.seed(123)
n <- 100
x <- rnorm(n)
y <- 0.3 * x + rnorm(n, 0, 0.8)  # Small effect: β = 0.3
data <- data.frame(x = x, y = y)

# Fit simple lavaan model
model <- 'y ~ x'
fit <- sem(model, data = data)

# Check that lavaan model works
summary(fit)
#> lavaan 0.6-19 ended normally after 1 iteration
#> 
#>   Estimator                                         ML
#>   Optimization method                           NLMINB
#>   Number of model parameters                         2
#> 
#>   Number of observations                           100
#> 
#> Model Test User Model:
#>                                                       
#>   Test statistic                                 0.000
#>   Degrees of freedom                                 0
#> 
#> Parameter Estimates:
#> 
#>   Standard errors                             Standard
#>   Information                                 Expected
#>   Information saturated (h1) model          Structured
#> 
#> Regressions:
#>                    Estimate  Std.Err  z-value  P(>|z|)
#>   y ~                                                 
#>     x                 0.258    0.085    3.048    0.002

# Verify vcov() works for lavaan objects
vcov(fit)
#>        y~x  y~~y
#> y~x  0.007      
#> y~~y 0.000 0.007

# Problem 1: equivalence_test() returns NULL for lavaan objects
result1 <- equivalence_test(fit)
print(result1)
#> NULL

# Problem 2: simulate_model() workaround fails
result2 <- equivalence_test(simulate_model(fit))
#> Error: Can't extract variance-covariance matrix. `get_varcov()` returned
#> following error: no applicable method for 'vcov' applied to an object of
#> class "lavaan"

# What we expect to work (similar to lm objects):
lm_fit <- lm(y ~ x, data = data)
equivalence_test(lm_fit, range = c(-0.1, 0.1))
#> # TOST-test for Practical Equivalence
#> 
#>   ROPE: [-0.10 0.10]
#> 
#> Parameter   |        90% CI |  SGPV | Equivalence |     p
#> ---------------------------------------------------------
#> (Intercept) | [-0.21, 0.05] | 0.603 |   Undecided | 0.421
#> x           | [ 0.12, 0.40] | 0.015 |    Rejected | 0.966

Current Behavior

The equivalence_test() function:

  1. Returns NULL for lavaan objects without any error message
  2. Fails with vcov error when using simulate_model() workaround, despite vcov() working correctly for lavaan objects

Expected Behavior

The equivalence_test() function should:

  1. Accept lavaan objects as input
  2. Extract parameter estimates, standard errors, and other necessary statistics from the lavaan object
  3. Perform equivalence testing (TOST, Bayesian, or CET rules) on the model parameters
  4. Return a properly formatted equivalence test result

Use Case

This feature would be particularly valuable for:

  • Structural Equation Modeling (SEM) researchers testing for practical equivalence
  • Cross-lagged panel models (CLPM/RI-CLPM) where researchers want to test if cross-lagged effects are practically equivalent to zero
  • Confirmatory Factor Analysis (CFA) where loadings or correlations need equivalence testing
  • Mediation analysis where indirect effects need to be tested for practical significance

Example Expected Output

equivalence_test(lavaan_fit, range = c(-0.1, 0.1))

# Expected output:
# Equivalence test for Practical Equivalence
# 
# ROPE: [-0.10 0.10]
# 
# Parameter    | Estimate | SE    | 90% CI        | TOST p | Decision
# ----------------------------------------------------------------
# y ~ x        | 0.045    | 0.032 | [-0.01, 0.10] | 0.023  | Equivalent
# y ~~ y       | 0.234    | 0.045 | [0.16, 0.31]  | 0.891  | Not Equivalent

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement 💥Implemented features can be improved or revised

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions