Error: could not find function "mxThreshold"

Posted on
Picture of user. rabil Joined: 01/14/2010

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?

Replied on Thu, 11/13/2014 - 17:26
Picture of user. tbates Joined: Jul 31, 2009

Do you have OpenMx loaded?

Ah... I think this requires OpenMx 2.0?

Replied on Sat, 11/15/2014 - 11:49
Picture of user. rabil Joined: Jan 14, 2010

In reply to by rabil

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.

Replied on Sat, 11/15/2014 - 11:55
Picture of user. rabil Joined: Jan 14, 2010

In reply to by rabil

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.

Replied on Sat, 11/15/2014 - 13:21
Picture of user. tbates Joined: Jul 31, 2009

In reply to by rabil

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()

Replied on Mon, 11/17/2014 - 09:36
Picture of user. RobK Joined: Apr 19, 2011

In reply to by tbates

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 .

Replied on Mon, 11/17/2014 - 10:22
Picture of user. rabil Joined: Jan 14, 2010

In reply to by RobK

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).

Replied on Tue, 11/18/2014 - 10:54
Picture of user. RobK Joined: Apr 19, 2011

In reply to by rabil

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.

Replied on Mon, 11/17/2014 - 09:28
Picture of user. RobK Joined: Apr 19, 2011

In reply to by rabil

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.