Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

mxSave

Save model state to a checkpoint file


Description

The function saves the last state of a model to a checkpoint file.

Usage

mxSave(model, chkpt.directory = ".", chkpt.prefix = "")

Arguments

model

an MxModel object

chkpt.directory

character. Directory where the checkpoint file is located

chkpt.prefix

character. Prefix of the checkpoint file

Details

In general, the arguments ‘chkpt.directory’ and ‘chkpt.prefix’ should be identical to the mxOption: ‘Checkpoint Directory’ and ‘Checkpoint Prefix’ that were specified on the model before execution.

Alternatively, the checkpoint file can be manually loaded as a data.frame in R. Use read.table with the options header=TRUE, sep="\t", stringsAsFactors=FALSE, check.names=FALSE.

Value

Returns a logical indicating the success of writing the checkpoint file to the checkpoint directory.

References

The OpenMx User's guide can be found at http://openmx.ssri.psu.edu/documentation

See Also

Other model state: mxComputeCheckpoint(), mxRestore()

Examples

library(OpenMx)

# Simulate some data

x=rnorm(1000, mean=0, sd=1)
y= 0.5*x + rnorm(1000, mean=0, sd=1)
tmpFrame <- data.frame(x, y)
tmpNames <- names(tmpFrame)

dir <- tempdir()  # safe place to create files
mxOption(key="Checkpoint Directory", value=dir)

# Create a model that includes an expected covariance matrix,
# an expectation function, a fit function, and an observed covariance matrix

data <- mxData(cov(tmpFrame), type="cov", numObs = 1000)
expCov <- mxMatrix(type="Symm", nrow=2, ncol=2, values=c(.2,.1,.2), free=TRUE, name="expCov")
expFunction <- mxExpectationNormal(covariance="expCov", dimnames=tmpNames)
fitFunction <- mxFitFunctionML()
testModel <- mxModel(model="testModel", expCov, data, expFunction, fitFunction)

#Use mxRun to optimize the free parameters in the expected covariance matrix
modelOut <- mxRun(testModel)
modelOut$expCov

# Save the ending state of modelOut in a checkpoint file
mxSave(modelOut)

# Restore the saved model from the checkpoint file
modelSaved <- mxRestore(testModel)
modelSaved$expCov

OpenMx

Extended Structural Equation Modelling

v2.19.5
Apache License (== 2.0)
Authors
Steven M. Boker [aut], Michael C. Neale [aut], Hermine H. Maes [aut], Michael J. Wilde [ctb], Michael Spiegel [aut], Timothy R. Brick [aut], Ryne Estabrook [aut], Timothy C. Bates [aut], Paras Mehta [ctb], Timo von Oertzen [ctb], Ross J. Gore [aut], Michael D. Hunter [aut], Daniel C. Hackett [ctb], Julian Karch [ctb], Andreas M. Brandmaier [ctb], Joshua N. Pritikin [aut, cre], Mahsa Zahery [aut], Robert M. Kirkpatrick [aut], Yang Wang [ctb], Ben Goodrich [ctb], Charles Driver [ctb], Massachusetts Institute of Technology [cph], S. G. Johnson [cph], Association for Computing Machinery [cph], Dieter Kraft [cph], Stefan Wilhelm [cph], Sarah Medland [cph], Carl F. Falk [cph], Matt Keller [cph], Manjunath B G [cph], The Regents of the University of California [cph], Lester Ingber [cph], Wong Shao Voon [cph], Juan Palacios [cph], Jiang Yang [cph], Gael Guennebaud [cph], Jitse Niesen [cph]
Initial release
2021-03-26

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.