# Revision of errors from Thu, 05/24/2012 - 18:03

Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.

### General strategies for locating errors

• traceback() . Running "traceback() immediately after an error occurs will print out the sequence of function calls leading up to the error.

### Elements of @output$status Output codes detail the cause of the error. #### @output$status[[1]]

This status element is returned from the optimizer (NPSOL).
A value of 0 means a successful optimization--no error returned.
A value of 1 means that an optimal solution was found, but that the sequence of iterates did not converge. There are several reasons this can happen, including starting at the correct values. It generally does not indicate a problem. These estimates can generally be considered correct solutions, so this code is labeled (Mx status GREEN).
A value of −1 means that the optimizer found itself stuck in a location where the objective function could not be calculated, and could not find a way out. This most often happens if the starting values make the calculation impossible.
A value of 2 or 3 means that the bounds or constraints, respectively, could not be satisfied.
A value of 4 means that the iteration limit was reached, with no solution found. You can use mxOptions() to set a higher iteration limit, or just run mxRun() using the output –it will restart from the most recent set of estimates, and make another run of the same number of iterations.
A value of 6 means that optimality conditions could not be reached, and the optimizer could find no way to improve the estimate. It often implies either a mistake in the model specification or starting values in an intractable range. The estimates resulting from this run might NOT be optimal estimates, and it would be risky to treat them as solutions without further investigation, so this code is labeled (Mx status RED). Sometimes re-running the model from its solution [firstRun <- mxRun(myModel) followed by secondRun <- mxRun(firstRun)] is sufficient to make code Red disappear.
Any other status codes should be reported.

#### @output\$status[[3]]

The third element of status provides detailed information on why the objective function could not be calculated. Examples are:

#### @output[[3]] [CHARSXP: "Covariance matrix is not positive-definite."]

• Look at your starting values. if you have used starting values 1s, you are building an initial expected covariance that is exactly singular. At the first iteration, OpenMx can't invert the expected covariance matrix, and crashes.
• Solution: Try changing your starting values (say, by making all of the covariances and free regressions .5) and see if it runs.

## Error messages and their meaning

Note, while R coders often use the period character inside variable names, this is not legal in OpenMx, which uses this character to specify the container model for variables.

### "Argument is missing, with no default"

• Variations include:
• Error in single.na(to) : argument is missing, with no default

• Typical cause: A leading or trailing comma in your code makes R think that you wanted to pass in a parameter, but left it empty (hence "missing, with not default")
• Examples:
         to                                  = c(,'x','y','z')

• trailing comma
         mxMatrix("Name", nrow               = 3,ncol=3,free=TRUE, values=.5,)

• Cure: remove the errant comma(s).

### Error in convertVFN(... NAs introduced by coercion

• Whenever you see NAs being introduced by coercion, suspect that you have the wrong type of value for a parameter: For instance, perhaps you are setting a number to string or vice versa... the coercion will fail, leaving an NA, which R warns you about.
• Example:
#You say:

     mxMatrix(type                       = "Full", nrow = 1, ncol = 1, free = FALSE,
values                              = "l1", labels = "aa",
lbound                              = 0, ubound = 2, name = "la"),

• We try and convert the character "l1" to a numeric value, can't, return an NA... hence the error: NAs induced by coercion.

• The error:
     Warning messages:
1: In convertVFN(values, free, labels, lbound, ubound, nrow, ncol) :
NAs introduced by coercion...

• Solution: in this case, set the value to a numeric, (and remember that to equate values, you set the labels to be the same)

Error: The expected means matrix associated with the FIML objective function in model 'univSat4' does not contain dimnames.

### Error: The expected means matrix associated with the FIML objective function in model 'univSat4' does not contain dimnames.

• These errors occur when the mxFIMLObjective has no dimnames for the covariance or means, and cannot find them elsewhere (i.e., in the target algebra).
• Example
     model <- mxModel("univSat4",
mxMatrix(type                       = "Symm", nrow=1, ncol=1, free=T, values=1, name="expCov"),
mxMatrix(type                       = "Full", nrow=1, ncol=1, free=T, values=0, name="expMean"),
mxData(observed                     = testData, type="raw"),
mxFIMLObjective(covariance          = "expCov", means="expMean")  # triggers error
)
fit                                 = mxRun(model)

• Fixes
• Add dimnames to the covariance and means matrices:

             mxMatrix("Symm", 1, 1, T, 1, name = "expCov", dimnames=list(selVars, selVars),
mxMatrix("Full", 1,1, T, 0, name  = "expMean", dimnames=list(selVars, selVars)),

• Add dimnames to the Objective
•              mxFIMLObjective(covariance        = "expCov", means="expMean", dimnames=selVars)


### Expected covariance matrix is non-positive-definite.

Suspect your start values, data, and mapping of model onto data. This model for instance will return an error with default start values

require(OpenMx)
data(demoOneFactor)
DV = "x4"
threePred = c("x1", "x2", "x3")
manifests = names(demoOneFactor)
manifests = c(threePred, DV)
dat = demoOneFactor[,manifests]
fit1 = mxModel("base", type="RAM",
latentVars   = "G",
manifestVars = manifests,
mxPath(from = "G", arrows = 2, free = T),
mxPath(from = manifests, arrows=2), # manifest variances
mxPath(from = manifests, arrows=2, connect="unique.bivariate"),
mxPath(from = manifests, to = "G"),
mxData(cov(dat), type = "cov", numObs = 500)
)
summary(mxRun(fit1, unsafe=T))

Starting the variances at their likely values will run.

fit1 = mxModel("base", type="RAM",
latentVars   = "G",
manifestVars = manifests,
mxPath(from = "G", arrows = 2, free = T),
mxPath(from = manifests, arrows=2, values=diag(cov(dat))), # manifest variances
mxPath(from = manifests, arrows=2, connect="unique.bivariate"),
mxPath(from = manifests, to = "G"),
mxData(cov(dat), type = "cov", numObs = 500)
)
summary(mxRun(fit1, unsafe=T))