Backward compatibility issue with extracting or inserting certain results of optimization into mxModel objects

2 replies [Last post]
neale's picture
Offline
Joined: 07/31/2009

The attached file runs fine under 1.3 but fails unpleasantly under the current svn trunk (2484).

> LCA2 <- LCAfun(data[4:8], 2, 5, 3)
Error in as.character.default() :
no method for coercing this S4 class to a vector
In addition: Warning messages:
1: In mxFIMLObjective(covariance = "R", means = "M", dimnames = nameList[1], :
Objective functions have been deprecated. Please use mxExpectationNormal() and mxFitFunctionML() instead.
2: In mxFIMLObjective(covariance = "R", means = "M", dimnames = tempVar, :
Objective functions have been deprecated. Please use mxExpectationNormal() and mxFitFunctionML() instead.
3: In is.na(x) : is.na() applied to non-(list or vector) of type 'S4'

The error comes as a result of:

temp$objective <- mxFIMLObjective(covariance = "R", means = "M", 
    dimnames = tempVar, thresholds = paste("ThresholdClass", 
        i, "Item", j, sep = "_"), vector = TRUE)

which can be avoided easily enough with:

    temp <- mxModel(temp,mxFIMLObjective(covariance="R", means="M", dimnames=tempVar, 
	    thresholds=paste("ThresholdClass",i,"Item",j,sep="_"),vector=TRUE))

However, it does mean that we are losing a bit of backward compatibility unless we were to trap old-fashioned access to model objects.

Second, I discovered that weirdly a warning that the objective function is NaN is generated when there are no free parameters but the model is mxRun anyway:

> LCA2 <- LCAfun(data[4:8], 2, 5, 3)
Running LCA_model_2_classes
Running LCA_model_2_classes
Running LCA_model_2_classes
Running LCA_model_2_classes
Running LCA_model_2_classes
Running LCA_model_2_classes
Running LCA_model_2_classes
Running LCA_model_2_classes
NULL
There were 17 warnings (use warnings() to see them)
war
>
> nings
Error: object 'nings' not found
> warnings()
Warning messages:
1: In mxFIMLObjective(covariance = "R", means = "M", dimnames = nameList[1], ... :
Objective functions have been deprecated. Please use mxExpectationNormal() and mxFitFunctionML() instead.

13: The job for model 'LCA_model_2_classes' exited abnormally with the error message: Fit function returned nan at iteration 0.1
14: The job for model 'LCA_model_2_classes' exited abnormally with the error message: Fit function returned nan at iteration 0.1
15: The job for model 'LCA_model_2_classes' exited abnormally with the error message: Fit function returned nan at iteration 0.1
16: The job for model 'LCA_model_2_classes' exited abnormally with the error message: Fit function returned nan at iteration 0.1
17: The job for model 'LCA_model_2_classes' exited abnormally with the error message: Fit function returned nan at iteration 0.1

Although no optimization has occurred, I'd like to see these things anyway. I can (and do) grab them from the objective, per this bit of the code:

 			#  This doesn't work due to bug when all parameters are fixed (returns NA for minimum)
 			#		funList[i] <- ifelse(is.na(lcamodelRun@output$minimum),Inf,modelList[[i]]@output$minimum)
 			funList[i] <- ifelse(is.na(lcamodelRun$mixtureObj@result),Inf,lcamodelRun$mixtureObj@result) 

I hesitate to label this as a bug, but I really don't think it should be issuing warnings and I do think it should be returning a function value. It has been optimized with respect to all the parameters, it just so happens that there aren't any.

AttachmentSize
LCA_Example Separate Items Plan C.R8.8 KB
jpritikin's picture
Offline
Joined: 05/23/2012
fixed in svn head

I committed a fix to improve the error message.

neale's picture
Offline
Joined: 07/31/2009
Much better, thanks

The error now says:

Error: Right-hand side of assignment operator has illegal value MxExpectationNormal and MxFitFunctionML

which at least hints at what the issue is. How wide might be the use case that trigger this error?

Relatedly, to figure out which version of OpenMx someone is using (at the build level) one can do this:

as.numeric(unlist(strsplit(as.character(packageVersion("OpenMx")),"\\.")))[4]

but I wondered if there was anything a bit less cumbersome...