mxTryHard {OpenMx} | R Documentation |
Makes multiple attempts to fit an MxModel object with mxRun()
until the optimizer yields an acceptable solution or the maximum number of attempts is reached. Each attempt uses the parameter estimates of the previous attempt as start values, except they are each multiplied by random draws from a uniform distribution. From among its attempts, the function returns the fitted, post-mxRun()
model with the smallest fit-function value, and prints to the console the start values it used for that model.
mxTryHard(model, extraTries = 10, greenOK = FALSE, loc = 1, scale = 0.25, checkHess = TRUE, fit2beat = Inf, paste = TRUE, iterationSummary=FALSE, bestInitsOutput=TRUE, showInits=FALSE, ...)
model |
The model to be run; object of class |
extraTries |
The number of attempts to run the model in addition to the first. In effect, is the maximum number of attempts |
greenOK |
Logical; is a solution with Mx status GREEN (npsolstatus=1) acceptable? Defaults to |
loc, scale |
The location and scale parameters of the uniform (rectangular) distribution from which random values are drawn to disturb start values between attempts. The location parameter is the distribution's median, and the scale parameter is the half-width of the rectangle (that is, the absolute difference between the median and the extrema). Defaults to a uniform distribution on the interval (0.75, 1.25). |
checkHess |
Logical; is a positive-definite Hessian a requirement for an acceptable solution? Defaults to |
fit2beat |
An upper limit to the objective-function value that an acceptable solution may have. Useful if a nested submodel of |
paste |
Logical. If |
iterationSummary |
Logical. If |
bestInitsOutput |
Logical. If |
showInits |
Logical. If |
... |
Additional arguments to be passed to |
Usually, mxTryHard()
returns a post-mxRun()
MxModel
object. Specifically, this will be the fitted model having the smallest fit-function value found by mxTryHard()
during its attempts. The start values used to obtain this fitted model are printed to console.
If every attempt at running model
fails, mxTryHard()
returns an object of class 'try-error', and the start values from the last attempt are printed to console.
mxTryHard()
throws a warning if the returned MxModel
object has a nonzero npsolstatus.
mxRun()
library(OpenMx) data(demoOneFactor) # load the demoOneFactor dataframe manifests <- names(demoOneFactor) # set the manifest to the 5 demo variables latents <- c("G") # define 1 latent variable model <- mxModel(model="One Factor", type="RAM", manifestVars = manifests, latentVars = latents, mxPath(from=latents, to=manifests, labels=paste("b", 1:5, sep="")), mxPath(from=manifests, arrows=2, labels=paste("u", 1:5, sep="")), mxPath(from=latents , arrows=2, free=FALSE, values=1.0), mxData(cov(demoOneFactor), type="cov", numObs=500) ) model <- mxTryHard(model) # Run the model, returning the result into model summary(model) # Show summary of the fitted model