Attachment | Size |
---|---|
![]() | 761.72 KB |
I've been trying to modify this example from OpenMx' repos for testing. For this purpose, I am trying to fit the model using WLS. However, this returns the following error message:
Error in runHelper(model, frontendStart, intervals, silent, suppressWarnings, : MxExpectationRAM: latent exogenous variables are not supported (x -> sw)
Even without any other changes to the code, I get this error. I've fitted models with WLS before without issue, but I fail to identify what may differs that would cause this error. Furthermore, I am trying to understand why I get this error using WLS, but not with ML.
Code sample:
# MPlus: Three-level growth model with a continuous outcome and one covariate on each of the three levels # https://www.statmodel.com/usersguide/chapter9.shtml library(OpenMx) #mxOption(NULL, "Number of Threads", 8L) options(width=120) ex923 <- suppressWarnings(try(read.table("ex9.23.dat"))) # if (is(ex923, "try-error")) ex923 <- read.table("data/ex9.23.dat") colnames(ex923) <- c(paste0('y',1:4), 'x', 'w', 'z', 'level2', 'level3') ex923$level2 <- as.integer(ex923$level2) ex923$level3 <- as.integer(ex923$level3) level3Model <- mxModel( 'level3Model', type='RAM', latentVars=c(paste0('y',1:4), 'ib3', 'sb3', 'z'), mxData(ex923[!duplicated(ex923$level3),], 'raw', primaryKey='level3'), mxPath('ib3', paste0('y',1:4), free=FALSE, values=1), mxPath('sb3', paste0('y',1:4), free=FALSE, values=0:3), mxPath(c('ib3','sb3'), arrows=2, connect="unique.pairs", values=c(1,0,1)), mxPath('one', 'z', free=FALSE, labels="data.z"), mxPath('z', c('ib3','sb3')), mxPath('one', c('ib3','sb3'))) level2Model <- mxModel( 'level2Model', type='RAM', level3Model, latentVars=c(paste0('y',1:4), 'ib2', 'sb2', 'w'), mxData(ex923[!duplicated(ex923$level2),], 'raw', primaryKey='level2'), mxPath('ib2', paste0('y',1:4), free=FALSE, values=1), mxPath('sb2', paste0('y',1:4), free=FALSE, values=0:3), mxPath(c('ib2','sb2'), arrows=2, connect="unique.pairs", values=c(1,0,1)), mxPath('one', 'w', free=FALSE, labels="data.w"), mxPath('w', c('ib2','sb2')), mxPath(paste0('y',1:4), arrows=2), mxPath(paste0('level3Model.y', 1:4), paste0('y',1:4), free=FALSE, values=1, joinKey="level3")) withinModel <- NULL withinModel <- mxModel( 'withinModel', type='RAM', level2Model, manifestVars=c(paste0('y',1:4)), latentVars=c('iw','sw', 'x'), mxData(ex923, 'raw'), mxPath('iw', paste0('y',1:4), free=FALSE, values=1), mxPath('sw', paste0('y',1:4), free=FALSE, values=0:3), mxPath(paste0('y',1:4), arrows=2), mxPath(c('iw','sw'), arrows=2, connect="unique.pairs", values=c(1,0,1)), mxPath('one', 'x', free=FALSE, labels="data.x"), mxPath('x', c('iw','sw')), mxPath(paste0('level2Model.y', 1:4), paste0('y',1:4), free=FALSE, values=1, joinKey="level2"), mxFitFunctionWLS() # Added alternative fit function ) withinModel <- mxRun(withinModel) omxCheckEquals(withinModel$expectation$debug$rampartUsage, c(6000)) omxCheckCloseEnough(logLik(withinModel), -56044.82, 1e-2) # matches Mplus
Although the error is complaining about "latent exogenous variables" the real problem is that OpenMx does not support WLS with multilevel models. WLS is based entirely on the summary statistics which do not exist with the multiple data sets being linked across levels in multilevel models. I'll create an issue on GitHub to catch this and improve the error message, but we have no plans to implement multilevel with WLS in OpenMx.
I have designed and fitted multilevel models in OpenMx in the past. If this is not feasible, I suppose I should not be doing this, but there's no error message of the sort mentioned above.
I do apologize for OpenMx not catching this situation and giving a more reasonable error message. Future versions of OpenMx will.
Is there a particular reason you want to run this model or a similar model with WLS?
dates back to previous posts. ML does not handle ordinal variables in multilevel model, and adding a high number of ordinal variables also makes ML computationally unfeasible. However, it was suggested WLS might work (at least on two-level models), which is why I've been attempting WLS model estimation.
Now, it's the first time I've seen the error message I posted above. Actually, OpenMx does not really produce any error messages when fitting a multilevel model with WLS, which is problematic if this is not possible. Below I've modified the example above to one that will not produce the aforementioned error message. (For the sake of demonstration, I've added an ordinal variable on level 1 and latent interactions on all levels.) It does not produce any estimates or standard errors for upper levels, however, which sort of makes sense now. There really should be a warning/error message prohibiting fitting multilevel models using WLS. As for fitting multilevel models, there's a real need to implement ways to model ordinal/categorical/dichotomous variables in such models.
OpenMx is not the right tool for the job, though. I am not aware of any non-Bayesian general method for fitting multilevel models to such variables. Look into stan.
Agreed.