Hi,
I'm wondering if I could get some tips on how to fit a multilevel logistic regression. I can fit a multilevel model with a continuous outcome without any problems. However, once I set up a threshold, I get an error code of 5 or 6. I am trying to fit a three-level model, so I went with the example posted at https://github.com/OpenMx/OpenMx/blob/3cb6593af0754be134e107cf4f42315d8c18db2b/inst/models/passing/xxm-3.R and modified the outcome to be binary. The code is below:
data('Pastes') Pastes\$strength = if_else(Pastes\$strength < 60, 1, 0) Pastes\$strength = mxFactor(Pastes\$strength, levels = c(0, 1)) batch <- mxModel( 'batch', type="RAM", latentVars = c('batch'), mxData(data.frame(batch=unique(Pastes$batch)), 'raw', primaryKey='batch'), mxPath('batch', arrows=2, values=1)) sample <- mxModel( 'sample', type="RAM", batch, latentVars = c('sample'), mxData(as.data.frame(Pastes[!duplicated(Pastes$sample), c('batch','sample')]), 'raw', primaryKey='sample'), mxPath('sample', arrows=2, values=1), mxPath('batch.batch', 'sample', values=1, free=FALSE, joinKey='batch')) strength <- mxModel( 'strength', type='RAM', sample, manifestVars = c('strength'), mxData(Pastes, 'raw'), mxPath('one', 'strength'), mxPath('strength', arrows=2, values=1), mxThreshold('strength', nThresh = 1, values = 1), mxPath('sample.sample', 'strength', free=FALSE, values=1, joinKey="sample")) strength <- mxRun(strength)
I assumed it was because I am estimating the residual for strength, but if I fix the the residual to 1, with
mxPath('strength', arrows=2, values=1, free = F),
I get the model to converge, but the parameters are totally off from the equivalent model with lme4
(fm01 <- glmer(strength ~ 1 + (1 | sample) + (1 | batch), Pastes, family = binomial(link = 'logit')))
In fact, it appears that I get a negative variance for sample.
I get identical results to lme4 when I don't treat strength as a factor.
Any help would be greatly appreciated.