You are here

Error: could not find function "mxThreshold"

12 posts / 0 new
Last post
rabil's picture
Offline
Joined: 01/14/2010 - 16:47
Error: could not find function "mxThreshold"

I'm running a demo script for a one factor model with ordinal data. I'm using OpenMx 1.4-3532 and R version 3.1.2 (2014-10-31). I get the following error message:

> thresholds <- mxThreshold( vars=c("z1","z2","z3"), nThresh=c(1,1,2),
+ free=TRUE, values=c(-1,0,-.5,1.2) )
Error: could not find function "mxThreshold"

Using "library(help=OpenMx)", "mxThreshold" does not appear. What gives?

tbates's picture
Offline
Joined: 07/31/2009 - 14:25
library(OpenMx) ?

Do you have OpenMx loaded?

Ah... I think this requires OpenMx 2.0?

rabil's picture
Offline
Joined: 01/14/2010 - 16:47
Yes, I have OpenMx loaded

Yes, I have OpenMx loaded (!). The info on mxThreshold seems to go back a few years so I didn't think it was something brand new.

rabil's picture
Offline
Joined: 01/14/2010 - 16:47
I installed the 2.0 beta and

I installed the 2.0 beta and it has the mxThresholds function. Unfortunately, the beta has problems computing confidence intervals. It will compute one interval for a scalar, but if you try to do two confidence intervals it seems to fail:

> oneFactorModel.fit <- mxRun(oneFactorModel,intervals=TRUE)
Running Common Factor Model Path Specification
> summary(oneFactorModel.fit)
Error in if (ci[1] == ci[3] || ci[1] > ci[2] || ci[2] > ci[3]) { :
missing value where TRUE/FALSE needed

I'm running a slightly modified version of the one factor ordinal model where I constrain the ith residual variance to equal 1 - l_i^2 where l1 is the factor loading. (And I've constrained the mean and variance of the common factor to 0 and 1, respectively. I've set the residual variances to free=TRUE. I'm using mxAlgebra and mxConstraint functions.) If I don't ask for confidence intervals, it gives what appears to be the correct estimates. (Using the previoius approach without using the mxThreshold function, I could get what appear to be the correct solutions, but there was always a warning message no matter how many random starting values I tried - all of which produced almost identical estimates. Using mxThreshold there are never any warning or error messages as long as I don't ask for 2 or more confidence intervals.) If I ask just for one scalar confidence interval, it appears to always work. It only fails if I ask for more than one or for a matrix. Unfortunately, I cannot provide the code with the data.

rabil's picture
Offline
Joined: 01/14/2010 - 16:47
I just noticed that this

I just noticed that this popped up in a window after one of the segfaults:

#

The crashed program seems to use third-party or local libraries:

/usr/local/lib/R/site-library/digest/libs/digest.so
/usr/local/lib/R/site-library/OpenMx/libs/OpenMx.so

It is highly recommended to check if the problem persists without those first.

Do you want to continue the report process anyway?

#

The digest package is needed in order to install the beta version of OpenMx.

tbates's picture
Offline
Joined: 07/31/2009 - 14:25
not a good error message

Thanks for that!

summary()

shouldn't be giving people an error like "(ci[1] == ci[3] || ci[1] > ci[2] || ci[2] > ci[3])"

Might be an issue with the code mxThreshold is adding, and summary might need some check code adding in.

If the model is just "trunk/demo/OneFactorOrdinal_MatrixRawRAM.R" with the ith residual variance mxConstrained = 1 - l_i^2 plus scaled common factor, it should be OK to share? I think that would help to post it here.

Also, as this might be fixed in trunk, paste the results of

mxVersion()
RobK's picture
Offline
Joined: 04/19/2011 - 21:00
Confidence limits are NaN

The error message referring to "(ci[1] == ci[3] || ci[1] > ci[2] || ci[2] > ci[3])" is almost certainly occurring because one of the confidence limits is being estimated as NaN (or maybe NA), which in turn (I suspect) is due to a problem with CSOLNP. The error message is thrown by R, not by OpenMx per se. He can still see the CIs with oneFactorModel.fit$output$confidenceIntervals .

rabil's picture
Offline
Joined: 01/14/2010 - 16:47
Thanks. Using NPSOL doesn't

Thanks. Using NPSOL doesn't solve the problem:

> mxOption(NULL,"Default optimizer","NPSOL")
> oneFactorModel.fit.2 <- mxRun(oneFactorModel,intervals=TRUE) # Causes OpenMx 2.0 & R to crash
Running Common Factor Model Path Specification
Warning message:
In model 'Common Factor Model Path Specification' Optimizer returned a non-zero status code 6. The model does not satisfy the first-order optimality conditions to the required accuracy, and no improved point for the merit function could be found during the final linesearch (Mx status RED)
> summary(oneFactorModel.fit.2)
Error in if (ci[1] == ci[3] || ci[1] > ci[2] || ci[2] > ci[3]) { :
missing value where TRUE/FALSE needed
> oneFactorModel.fit$output$confidenceIntervals
NULL

With CSOLNP I do not get the warning message. I do get parameter estimates and a lot of other information, but no confidence intervals now with NPSOL. Using the non-beta OpenMx, the upper limit for the factor loading for the 4th rater is NA (the model code does not use mxThreshold).

RobK's picture
Offline
Joined: 04/19/2011 - 21:00
Does it still crash R with

Does it still crash R with NPSOL? I'm guessing no, but just making sure. Also, you're not seeing CIs because the name of the model you fit with NPSOL is oneFactorModel.fit2, not oneFactorModel.fit. You need to enter oneFactorModel.fit2$output$confidenceIntervals .

The fact that summary() is choking on an NA for one of the confidence limits is pretty annoying, though.

RobK's picture
Offline
Joined: 04/19/2011 - 21:00
The problem with summary() appears to have been fixed

The problem with summary() throwing an error when a CI contains an NA appears to have been repaired with revision 3957, so the problem won't exist in the next release of the package.

Richard, what OS do you run? Would you be able to build OpenMx from source checked out from the repository?

RobK's picture
Offline
Joined: 04/19/2011 - 21:00
Which optimizer?

I second Bates' request for mxVersion() output. I strongly suspect that problems with CIs, and any mysterious crashes, are connected to CSOLNP. If you're currently using CSOLNP, switch to NPSOL with mxOption(NULL,"Default optimizer","NPSOL") before running your model, and try again.

rabil's picture
Offline
Joined: 01/14/2010 - 16:47
I can post the code but I

I can post the code but I cannot provide the data that is used.