mxTryHard {OpenMx}R Documentation

Make multiple attempts to run a model

Description

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.

Usage

mxTryHard(model,extraTries=10,greenOK=FALSE,loc=1,scale=0.25,checkHess=TRUE,fit2beat=Inf,paste=TRUE,...)

Arguments

model

The model to be run; object of class MxModel.

extraTries

The number of attempts to run the model in addition to the first. In effect, is the maximum number of attempts mxTryHard() will make, since the function will stop once an acceptable solution is reached. Defaults to 10, in which case a maximum of 11 total attempts will be made.

greenOK

Logical; is a solution with Mx status GREEN (npsolstatus=1) acceptable? Defaults to FALSE.

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

fit2beat

An upper limit to the objective-function value that an acceptable solution may have. Useful if a nested submodel of model has already been fitted, since model, with its additional free parameters, should not yield a fit-function value any greater than that of the submodel.

paste

Logical. If TRUE (default), start values for the returned fitted model are printed to console as a comma-separated string. This is useful if the user wants to copy-paste these values into an R script, say, in an omxSetParameters() statement. If FALSE, the vector of start values is printed as-is. Note that this vector, from omxGetParameters(), has names corresponding to the free parameters; these names are not displayed when paste=TRUE.

...

Additional arguments to be passed to mxRun() (for example, intervals=TRUE). Note that mxTryHard() always internally invokes mxRun() with argument suppressWarnings=TRUE.

Value

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.

See Also

mxRun()

Examples

 
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


[Package OpenMx version 2.0.1-4157 Index]