Attachment | Size |
---|---|
dataset for the described code | 323.87 KB |
Hi all,
I'm currently attempting an ordered SEM model with FIML. I'm having an "MxComputeGradientDescent: fitfunction mindfulness.fitfunction is not finite" error. I can't figure out what's wrong. The warning message says something about starting values, but they all seem reasonable. Can anyone find an error?
#### make all variables ordered and create threshold matrix man.vars = r("BDI1", "SPSI52", names(k), T) thresh.vals = matrix(nrow=5, ncol=length(man.vars)) thresh.free = matrix(T, nrow=5, ncol=length(man.vars)) for (i in 1:length(man.vars)){ rng = range(k[,man.vars[i]], na.rm=T) threshholds = (seq(from=rng[1], to=rng[2])) +.5; threshholds = threshholds[which(threshholds <rng[2])] k[,man.vars[i]] = mxFactor(k[,man.vars[i]], levels=rng[1]:rng[length(rng)]) thresh.vals[1:length(threshholds),i] = threshholds } thresh.free[is.na(thresh.vals)]=F #### set up openmx model latent.vars = c("PPO", "NPO", "RPS", "ICS", "AS", "BDI", "DESCRIBING", "OBSERVING", "ACTING", "ACCEPTING") #### specity spsi factor loadings ppo = mxPath(from="PPO", to=c("SPSI7", "SPSI9", "SPSI19", "SPSI28", "SPSI38"), arrows=1, free=T, values=.3) npo = mxPath(from="NPO", to=c("SPSI1", "SPSI2", "SPSI6", "SPSI12", "SPSI13", "SPSI17", "SPSI32", "SPSI36", "SPSI41", "SPSI50"), arrows=1, free=T, values=.3) rps = mxPath(from="RPS", to=c("SPSI11", "SPSI29", "SPSI33", "SPSI44", "SPSI49", "SPSI5", "SPSI20", "SPSI39", "SPSI47", "SPSI48", "SPSI18", "SPSI24", "SPSI40", "SPSI43", "SPSI46", "SPSI25", "SPSI26", "SPSI27", "SPSI35", "SPSI37"), arrows=1, free=T, values=.3) ics = mxPath(from="ICS", to=c("SPSI3", "SPSI4", "SPSI8", "SPSI15", "SPSI21", "SPSI22", "SPSI34", "SPSI45", "SPSI51", "SPSI52"), arrows=1, free=T, values=.3) as = mxPath(from="AS", to=c("SPSI10", "SPSI14", "SPSI16", "SPSI23", "SPSI30", "SPSI31", "SPSI42"), arrows=1, free=T, values=.3) #### specify bdi factor loadings bdi = mxPath(from="BDI", to=c("BDI1", "BDI2", "BDI3", "BDI4", "BDI5", "BDI6", "BDI7", "BDI8", "BDI9", "BDI10", "BDI11", "BDI12", "BDI13", "BDI14", "BDI15", "BDI16", "BDI17", "BDI18","BDI19", "BDI20"), arrows=1, free=T, values=.3) #### specify other variables observing = mxPath(from="OBSERVING", to=c("KIMS1", "KIMS5", "KIMS9", "KIMS13", "KIMS17", "KIMS21", "KIMS25", "KIMS29", "KIMS30", "KIMS33", "KIMS37", "KIMS39"), arrows=1, free=T, values=.3) describing = mxPath(from="DESCRIBING", to=c("KIMS2", "KIMS6", "KIMS10", "KIMS14", "KIMS18", "KIMS22", "KIMS26", "KIMS34"), arrows=1, free=T, values=.3) acting = mxPath(from="ACTING", to=c("KIMS3", "KIMS7", "KIMS11", "KIMS15", "KIMS19", "KIMS23", "KIMS27", "KIMS31", "KIMS35", "KIMS38"), arrows=1, free=T, values=.3) accepting = mxPath(from="ACCEPTING", to=c("KIMS4", "KIMS8", "KIMS12", "KIMS16", "KIMS20", "KIMS24", "KIMS28", "KIMS32", "KIMS36"), arrows=1, free=T, values=.3) #### specify manifest mean and variance (fixed to 0 and 1) mn.ordinal = mxPath(from="one", to=man.vars, arrows=1, free=F, values=0) var.ordinal = mxPath(from=man.vars, arrows=2, free=F, values=1) #### latent variable variance of one and mean of 0 var.latent = mxPath(from= latent.vars, arrows=2, free=F, values=1) mn.latent = mxPath(from="one", to= latent.vars, free=F, values=0) dat = mxData(observed=k, type="raw") ##### set the threshold matrix thresh = mxMatrix(type="Full", nrow=nrow(thresh.vals), ncol=length(man.vars), dimnames=list(c(), man.vars), free=thresh.free, values=thresh.vals, name="thresh") thresh2 = mxExpectationRAM(A="A", S="S", F="F", M="M", thresholds="thresh") mod = mxModel("mindfulness", type="RAM", manifestVars=man.vars, latentVars=latent.vars, ppo, npo, rps, ics, as, bdi, observing, describing, acting, accepting, mn.ordinal, var.ordinal, var.latent, mn.latent, dat, thresh, thresh2) mxTryHard(mxRun(mod))
What package provides the
r()
function in the first line of the syntax?One thing to try (if you haven't already) is switching optimizers, e.g.
mxOption(NULL,"Default optimizer","SLSQP")
switches the default optimizer to SLSQP. The available default optimizers are CSOLNP, SLSQP, and, if you installed OpenMx from the virginia.edu repository, NPSOL.Also, which version of OpenMx are you running? You can see that, as well as the current default optimizer, via
mxVersion()
. If you're running version 2.7, be advised that the most serious known issue with v2.7 is its "over-sensitivity to start values". If that's what the problem is, the release announcement I linked has advice in its second paragraph on how to downgrade to v2.6.9, the most recent stable release. You could also upgrade to a "bleeding-edge" build of OpenMx by compiling the package from source.I notice your syntax includes
mxTryHard()
. You might be able to get your model running if you use non-default values for the various arguments tomxTryHard()
; see the function's documentation.MxComputeGradientDescent: engine SLSQP unknown)
OpenMx version: 2.0.1.4157
R version: R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin10.8.0
I tried updating OpenMx using the link you sent, but got the following error message: "Error: package ‘StanHeaders’ 2.6.0-10 was found, but >= 2.7 is required by ‘OpenMx’" I attempted to install StanHeaders through cran and that didn't seem to fix it.
v2.0.1 is pretty out-of-date, and in fact predates our inclusion of SLSQP, which was added for v2.2.
Hmm. You might need to restart R between updating StanHeaders and trying to install OpenMx.
Wow, so all 101 attempts ended with errors?
I agree with everything Rob has suggested.
Here are a couple of additional carrots for updating OpenMx to 2.7. First, there is a new function called
mxGetExpected()
. You give this function a model and e.g. "covariance" to get the model-implied covariance matrix for your model. This can be very helpful when assessing starting values. Second, there soon will be another new function calledmxAutoStart()
which will provide automatic starting values quickly that are extremely close to the ML estimates.I hadn't realized openmx was on cran now. I was still using that old source('....') code to install it. I guess that's still pointing to an old version. After updating R and OpenMx, I get a new error:
That happens at every iteration: one of the variables has trouble. I'm not sure why they get out of ascending order; I tell it what order to be in and it seems to break those boundaries.
The simplest answer is probably to use
umxThresholdMatrix()
from the 'umx' package, and include the elements of the list it outputs into your MxModel.I'm getting a new error. Here's my input:
And here's my output:
I think you need to use
mxThreshold()
, i.e. include the output ofmxThreshold()
in your MxModel object. See its entry in the documentation.It might help to see an example script of an ordinal RAM-type model: https://github.com/OpenMx/OpenMx/blob/master/inst/models/passing/OrdinalPathTest.R .
i got it. I didn't realize i had to wrap umxThresholdMatrix within mxThreshold
Now I'm good. Thanks!