Antonia Spr
Antonia Spr

Reputation: 21

Is it possible to use full information maximum likelihood (FIML) estimation when building a SEM tree with the partykit package and lavaan in R?

I would like to capture heterogeneity in depressive symptom trajectories using the R package partykit. Therefore, I specified a latent growth curve model (LGCM) in lavaan and set up a “mobster” function that can handle SEMs as shown by Achim Zeileis in the post “Structural equation model trees with partykit and lavaan”.

Example of an LGCM tree with partykit and lavaan as given in the mentioned blog post (you can load the required data set from GitHub):

# LGCM in lavaan
growth_curve_model <- '
  inter =~ 1*X1 + 1*X2 + 1*X3 + 1*X4 + 1*X5;
  slope =~ 0*X1 + 1*X2 + 2*X3 + 3*X4 + 4*X5;
  inter ~~ vari*inter; inter ~ meani*1;
  slope ~~ vars*slope; slope ~ means*1;
  inter ~~ cov*slope;
  X1 ~~ residual*X1; X1 ~ 0*1;
  X2 ~~ residual*X2; X2 ~ 0*1;
  X3 ~~ residual*X3; X3 ~ 0*1;
  X4 ~~ residual*X4; X4 ~ 0*1;
  X5 ~~ residual*X5; X5 ~ 0*1;
'

# SEM-adapted "mobster"
lavaan_fit <- function(model) {
  function(y, x = NULL, start = NULL, weights = NULL, offset = NULL, ..., estfun = FALSE, object = FALSE) {
    sem <- lavaan::lavaan(model = model, data = y, start = start)
    list(
      coefficients = stats4::coef(sem),
      objfun = -as.numeric(stats4::logLik(sem)),
      estfun = if(estfun) sandwich::estfun(sem) else NULL,
      object = if(object) sem else NULL
    )
  }
}

# transform data
ex1 <- transform(lgcm,
                 agegroup = factor(agegroup),
                 training = factor(training),
                 noise = factor(noise))
ex1 <- ex1 %>%
  rename(
    X1 = o1,
    X2 = o2,
    X3 = o3,
    X4 = o4,
    X5 = o5
  )

# fit tree
library("partykit")
tr <- mob(X1 + X2 + X3 + X4 + X5 ~ agegroup + training + noise, data = ex1,
          fit = lavaan_fit(growth_curve_model),
          control = mob_control(ytype = "data.frame"))

# plot tree
plot(tr, drop = TRUE, tnex = 2)

Since my dataset contains missing values in the observed variables of the LGCM (i.e., the depressive symptom variables at different time points) and imputation methods for longitudinal data seem quite advanced, I was wondering if FIML could be implemented in the SEM tree instead of lavaan’s default ML estimation with listwise deletion.

I tried myself to adapt the “mobster” function so that FIML is used but this did not work so far:

lavaan_fit <- function(model) {
  function(y, x = NULL, start = NULL, weights = NULL, offset = NULL, ..., estfun = FALSE, object = FALSE) {
    sem <- lavaan::lavaan(model = model, data = y, start = start, missing = "fiml")
    list(
      coefficients = stats4::coef(sem),
      objfun = -as.numeric(stats4::logLik(sem)),
      estfun = if(estfun) sandwich::estfun(sem) else NULL,
      object = if(object) sem else NULL
    )
  }
}

I know the semtree package was designed to help with SEM Trees and that FIML estimation should be possible with that package. However, in contrast to the partykit package, my tree never splits with semtree (even if alpha = 0.95). That is why I am looking for a soultion with partykit.

I would be very happy if someone can help me with my question!

Upvotes: 2

Views: 127

Answers (0)

Related Questions