Movatterモバイル変換


[0]ホーム

URL:


Encoding:UTF-8
Date:2025-10-17
Title:Extended Structural Equation Modelling
URL:https://openmx.ssri.psu.edu/,https://github.com/OpenMx/OpenMx
BugReports:https://openmx.ssri.psu.edu/forums/
Description:Create structural equation models that can be manipulated programmatically. Models may be specified with matrices or paths (LISREL or RAM) Example models include confirmatory factor, multiple group, mixture distribution, categorical threshold, modern test theory, differential Fit functions include full information maximum likelihood, maximum likelihood, and weighted least squares. equations, state space, and many others.Support and advanced package binaries available athttps://openmx.ssri.psu.edu. The software is described in Neale, Hunter, Pritikin, Zahery, Brick, Kirkpatrick, Estabrook, Bates, Maes, & Boker (2016) <doi:10.1007/s11336-014-9435-8>.
SystemRequirements:GNU make, C++17
ByteCompile:yes
Language:en-US
License:Apache License (== 2.0)
LinkingTo:Rcpp, RcppEigen (≥ 0.3.3.9.4), RcppParallel, StanHeaders(≥ 2.10.0.2), BH (≥ 1.69.0-1), rpf (≥ 0.45), Matrix
Imports:digest, MASS, Matrix (≥ 1.2-16), methods, Rcpp, RcppParallel,parallel, lifecycle
Depends:R (≥ 3.5.0)
Suggests:mvtnorm, numDeriv, roxygen2 (≥ 6.1), rpf (≥ 0.45),snowfall, lme4, covr, testthat, umx, ifaTools, knitr, markdown,rmarkdown, reshape2, ggplot2
VignetteBuilder:knitr
LazyLoad:yes
LazyData:yes
Collate:'0ClassUnion.R' 'cache.R' 'MxBaseNamed.R' 'MxData.R''MxDataWLS.R' 'DefinitionVars.R' 'MxReservedNames.R''MxNamespace.R' 'MxSearchReplace.R' 'MxFlatSearchReplace.R''MxUntitled.R' 'MxAlgebraFunctions.R' 'MxExponential.R''MxMatrix.R' 'DiagMatrix.R' 'FullMatrix.R' 'IdenMatrix.R''LowerMatrix.R' 'SdiagMatrix.R' 'StandMatrix.R' 'SymmMatrix.R''UnitMatrix.R' 'ZeroMatrix.R' 'MxMatrixFunctions.R''MxAlgebra.R' 'MxCycleDetection.R' 'MxDependencies.R''MxAlgebraConvert.R' 'MxSquareBracket.R' 'MxEval.R''MxRename.R' 'MxPath.R' 'MxObjectiveMetaData.R''MxExpectation.R' 'MxExpectationNormal.R' 'MxExpectationRAM.R''MxExpectationLISREL.R' 'MxFitFunction.R''MxFitFunctionAlgebra.R' 'MxFitFunctionML.R''MxFitFunctionMultigroup.R' 'MxFitFunctionRow.R''MxFitFunctionWLS.R' 'MxRAMObjective.R' 'MxLISRELObjective.R''MxFIMLObjective.R' 'MxMLObjective.R' 'MxRowObjective.R''MxAlgebraObjective.R' 'MxBounds.R' 'MxConstraint.R''MxInterval.R' 'MxTypes.R' 'MxCompute.R' 'MxModel.R''MxRAMModel.R' 'MxLISRELModel.R' 'MxModelDisplay.R''MxFlatModel.R' 'MxMultiModel.R' 'MxModelFunctions.R''MxModelParameters.R' 'MxUnitTesting.R' 'MxApply.R' 'MxRun.R''MxRunHelperFunctions.R' 'MxSummary.R' 'MxCompare.R''MxSwift.R' 'MxOptions.R' 'MxThreshold.R' 'OriginalMx.R''MxGraph.R' 'MxGraphviz.R' 'MxDeparse.R' 'MxCommunication.R''MxRestore.R' 'MxVersion.R' 'MxPPML.R' 'MxRAMtoML.R''MxErrorHandling.R' 'MxDetectCores.R' 'MxSaturatedModel.R''omxBrownie.R' 'omxConstrainThresholds.R' 'omxGetNPSOL.R''MxFitFunctionR.R' 'MxRObjective.R''MxExpectationHiddenMarkov.R' 'MxExpectationMixture.R''MxExpectationStateSpace.R' 'MxExpectationBA81.R''MxFitFunctionGREML.R' 'MxExpectationGREML.R' 'MxMI.R''MxFactorScores.R' 'MxRobustSE.R' 'MxAvailableOptimizers.R''MxTryHard.R' 'MxSE.R' 'MxAutoStart.R' 'MxRetro.R''MxPenalty.R' 'MxMMI.R' 'omxReadGRMBin.R' 'MxPredict.R' 'zzz.R'
RdMacros:lifecycle
Biarch:true
Version:2.22.10
RoxygenNote:7.3.2
NeedsCompilation:yes
Packaged:2025-10-17 16:27:10 UTC; rmk
Author: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], Mahsa Zahery [aut], Robert M. Kirkpatrick [aut, cre], Yang Wang [ctb], Ben Goodrich [ctb], Charles Driver [ctb], Jannik H. Orzek [ctb], Don van den Bergh [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]
Maintainer:Robert M. Kirkpatrick <rkirkpatrick2@vcu.edu>
Repository:CRAN
Date/Publication:2025-11-07 16:00:02 UTC

OpenMx: An package for Structural Equation Modeling and Matrix Algebra Optimization

Description

OpenMx is a package for structural equation modeling, matrix algebra optimization and other statistical estimation problems. Try the example below. We try and have useful help files: for instance help(mxRun) to learn more. Also the reference manual

Details

OpenMx solves algebra optimization and statistical estimation problems using matrix algebra. Most users use it for Structural equation modeling.

The core function ismxModel, which makes a model. Models are containers formxData,matrices,mxPathsalgebras,mxBounds,confidence intervals, andmxConstraints.Most models require an expectation (see the list below) to calculate the expectations for the model.Models also need a fit function, several of which are built-in (see below).OpenMx also allows user-defined fit functions for purposes not covered by the built-in functions. (e.g.,mxFitFunctionR ormxFitFunctionAlgebra).

Note, for mxModels oftype="RAM", the expectation and fit-function are set for you automatically.

Running and summarizing a model

Once built, the resulting mxModel can be run (i.e., optimized) usingmxRun. This returns the fitted model.

You can summarize the results of the model usingsummary(yourModel)

Additional overview of model making and getting started

The OpenMx manual is online (see references below). However,mxRun,mxModel,mxMatrixall have working examples that will help get you started as well.

The main OpenMx functions are:mxAlgebra,mxBounds,mxCI,mxConstraint,mxData,mxMatrix,mxModel, andmxPath.

Expectation functions includemxExpectationNormal,mxExpectationRAM,mxExpectationLISREL, andmxExpectationStateSpace;

Fit functions includemxFitFunctionML,mxFitFunctionAlgebra,mxFitFunctionRow andmxFitFunctionR.

Datasets built into OpenMx

OpenMx comes with over a dozen useful datasets built-in. Discover them usingdata(package="OpenMx"), and open them with, for example,data("jointdata", package ="OpenMx", verbose= TRUE)

Please cite the 'OpenMx' package in any publications that make use of it:

Michael C. Neale, Michael D. Hunter, Joshua N. Pritikin, Mahsa Zahery, Timothy R. Brick Robert M.Kirkpatrick, Ryne Estabrook, Timothy C. Bates, Hermine H. Maes, Steven M. Boker. (2016).OpenMx 2.0: Extended structural equation and statistical modeling.Psychometrika,81, 535–549. DOI: 10.1007/s11336-014-9435-8

Steven M. Boker, Michael C. Neale, Hermine H. Maes, Michael J. Wilde, Michael Spiegel, Timothy R. Brick,Jeffrey Spies, Ryne Estabrook, Sarah Kenny, Timothy C. Bates, Paras Mehta, and John Fox. (2011)OpenMx: An Open Source Extended Structural Equation Modeling Framework.Psychometrika, 306-317. DOI:10.1007/s11336-010-9200-6

Steven M. Boker, Michael C. Neale, Hermine H. Maes, Michael J. Wilde, Michael Spiegel, Timothy R. Brick, RyneEstabrook, Timothy C. Bates, Paras Mehta, Timo von Oertzen, Ross J. Gore, Michael D. Hunter, Daniel C.Hackett, Julian Karch, Andreas M. Brandmaier, Joshua N. Pritikin, Mahsa Zahery, Robert M. Kirkpatrick, Yang Wang, and Charles Driver. (2016) OpenMx 2 User Guide. https://openmx.ssri.psu.edu/docs/OpenMx/latest/OpenMxUserGuide.pdf

Author(s)

Maintainer: Robert M. Kirkpatrickrkirkpatrick2@vcu.edu

Authors:

Other contributors:

References

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

See Also

Useful links:

Examples

library(OpenMx)data(demoOneFactor)# ===============================# = Make and run a 1-factor CFA =# ===============================latents  = c("G") # the latent factormanifests = names(demoOneFactor) # manifest variables to be modeled# ====================# = Make the MxModel =# ====================m1 <- mxModel("One Factor", type = "RAM", manifestVars = manifests, latentVars = latents, mxPath(from = latents, to = manifests),mxPath(from = manifests, arrows = 2),mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),mxData(cov(demoOneFactor), type = "cov", numObs = 500))# ===============================# = mxRun it and get a summary! =# ===============================m1 = mxRun(m1)summary(m1)

BaseCompute

Description

This is an internal class and should not be used directly.

See Also

mxComputeEM,mxComputeGradientDescent,mxComputeHessianQuality,mxComputeIterate,mxComputeNewtonRaphson,mxComputeNumericDeriv


Bollen Data on Industrialization and Political Democracy

Description

Data set used in some of OpenMx's examples, for instance WLS. The data were reported in Bollen (1989, p. 428, Table 9.4)This set includes data from 75 developing countries each assessed on four measures of democracy measured twice (1960 and 1965), and three measures of industrialization measured once (1960).

Usage

data("Bollen")

Format

A data frame with 75 observations on the following 11 numeric variables.

y1

Freedom of the press, 1960

y2

Freedom of political opposition, 1960

y3

Fairness of elections, 1960

y4

Effectiveness of elected legislature, 1960

y5

Freedom of the press, 1965

y6

Freedom of political opposition, 1965

y7

Fairness of elections, 1965

y8

Effectiveness of elected legislature, 1965

x1

GNP per capita, 1960

x2

Energy consumption per capita, 1960

x3

Percentage of labor force in industry, 1960

Details

Variables y1-y4 and y5-y8 are typically used as indicators of the latent trait of “political democracy” in 1960 and 1965 respectively. x1-x3 are used as indicators of industrialization (1960).

Source

Thesem package (in turn, via personal communication Bollen to Fox)

References

Bollen, K. A. (1979). Political democracy and the timing of development.American Sociological Review,44, 572-587.

Bollen, K. A. (1980). Issues in the comparative measurement of political democracy.American Sociological Review,45, 370-390.

Bollen, K. A. (1989).Structural equation models. New York: Wiley-Interscience.

Examples

data(Bollen)str(Bollen)plot(y1 ~ y2, data = Bollen)

An S4 base class for discrete marginal distributions

Description

An S4 base class for discrete marginal distributions

See Also

mxMarginalPoisson,mxMarginalNegativeBinomial


Holzinger & Swineford (1939) Ability in 301 children from 2 schools

Description

This classic data set contains of intelligence-test scores from 301 children on 26 tests of cognitive ability.

The tests cover mental speed, memory, mathematical-ability, spatial, and verbal ability as listed below.

The data are also available in the MBESS package.

Usage

data("HS.ability.data")

Format

A data frame comprising 301 observations on 22 variables:

id

student ID number (int)

Gender

Sex (Factor w/ 2 levels “Female” and “Male”)

grade

Grade in school (integer 7 or 8)

agey

Age in years (integer)

agem

Age in months (integer)

school

School attended (Factor w/2 levels “Grant-White” and “Pasteur”)

addition

A speed test of addition (numeric)

code

A speed test (numeric)

counting

A speed test of counting groups of dots (numeric)

straight

A speed test discriminating straight and curved capitals (numeric)

wordr

A memory subtest of word recognition

numberr

A memory subtest of number recognition

figurer

A memory subtest of figure recognition

object

A memory subtest: object-number test

numberf

A memory subtest: number-figure test

figurew

A memory subtest: figure-word test

deduct

A mathematical subtest of deduction

numeric

A mathematical subtest of numerical puzzles

problemr

A mathematical subtest of problem reasoning

series

A mathematical subtest of series completion

arithmet

A mathematical subtest: Woody-McCall mixed fundamentals, form I

visual

A spatial subtest of visual perception

cubes

A spatial subtest

paper

A spatial subtest paper form board

flags

A spatial subtest (also known as lozenges)

paperrev

A spatial subtest additional paper form board test (can substitute for paper)

flagssub

A spatial subtest additional lozenges test (can substitute for flags)

general

A verbal subtest of general information

paragrap

A verbal subtest of paragraph comprehension

sentence

A verbal subtest of sentence completion

wordc

A verbal subtest of word classification

wordm

A verbal subtest of word meaning

Details

The data are from children who differ in grade (seventh- and eighth-grade) and are nested in one of two schools (Pasteur and Grant-White). You will see it in use elsewhere, both in R (lavaan, andMBESS), and in Joreskog (1969) reporting a CFA on the Grant-White school subject subset.

Some tests are alternate or substitute forms, e.g.paperrev (a paper form board test) can substitute forpaper andflagssub for the lozenges testflags.

Source

Holzinger, K., and Swineford, F. (1939).

References

Holzinger, K., and Swineford, F. (1939). A study in factor analysis: The stability of a bifactor solution.Supplementary Educational Monograph, no.48. Chicago: University of Chicago Press.

Joreskog, K. G. (1969). A general approach to confirmatory maximum likelihood factor analysis.Psychometrika,34, 183-202.

Examples

data(HS.ability.data)str(HS.ability.data)levels(HS.ability.data$school)plot(flags ~ flagssub, data = HS.ability.data)

Longitudinal, Overdispersed Count Data

Description

Four-timepoint longitudinal data generated from an arbitrary Monte Carlo simulation, for 1000 simulees. The response variable is a discrete count variable. There are three time-invariant covariates. The data are available in both "wide" and "long" format.

Usage

data("LongitudinalOverdispersedCounts")

Format

The "long" format dataframe,longData, has 4000 rows and the following variables (columns):

  1. id: Factor; simulee ID code.

  2. tiem: Numeric; represents the time metric, wave of assessment.

  3. x1: Numeric; time-invariant covariate.

  4. x2: Numeric; time-invariant covariate.

  5. x3: Numeric; time-invariant covariate.

  6. y: Numeric; the response ("dependent") variable.

The "wide" format dataset,wideData, is a numeric 1000x12 matrix containing the following variables (columns):

  1. id: Simulee ID code.

  2. x1: Time-invariant covariate.

  3. x3: Time-invariant covariate.

  4. x3: Time-invariant covariate.

  5. y0: Response at initial wave of assessment.

  6. y1: Response at first follow-up.

  7. y2: Response at second follow-up.

  8. y3: Response at third follow-up.

  9. t0: Time variable at initial wave of assessment (in this case, 0).

  10. t1: Time variable at first follow-up (in this case, 1).

  11. t2: Time variable at second follow-up (in this case, 2).

  12. t3: Time variable at third follow-up (in this case, 3).

Examples

data(LongitudinalOverdispersedCounts)head(wideData)str(longData)#Let's try ordinary least-squares (OLS) regression:olsmod <- lm(y~tiem+x1+x2+x3, data=longData)#We will see in the diagnostic plots that the residuals are poorly approximated by normality, #and are heteroskedastic.  We also know that the residuals are not independent of one another, #because we have repeated-measures data:plot(olsmod)#In the summary, it looks like all of the regression coefficients are significantly different #from zero, but we know that because the assumptions of OLS regression are violated that #we should not trust its results:summary(olsmod)#Let's try a generalized linear model (GLM).  We'll use the quasi-Poisson quasilikelihood #function to see how well the y variable is approximated by a Poisson distribution #(conditional on time and covariates):glm.mod <- glm(y~tiem+x1+x2+x3, data=longData, family="quasipoisson")#The estimate of the dispersion parameter should be about 1.0 if the data are #conditionally Poisson.  We can see that it is actually greater than 2, #indicating overdispersion:summary(glm.mod)

MxAlgebra Class

Description

MxAlgebra is an S4 class. An MxAlgebra object is anamed entity.New instances of this class can be created using the functionmxAlgebra.

Details

The MxAlgebra class has the following slots:

name - The name of the object
formula - The R expression to be evaluated
result - a matrix with the computation result

The ‘name’ slot is the name of the MxAlgebra object. Use of MxAlgebra objects in themxConstraint function or an objective function requires reference by name.

The ‘formula’ slot is an expression containing the expression to be evaluated. These objects are operated on or related to one another using one or more operations detailed in themxAlgebra help file.

The ‘result’ slot is used to hold the results of computing the expression in the ‘formula’ slot. If the containing model has not been executed, then the ‘result’ slot will hold a 0 x 0 matrix. Otherwise the slot will store the computed value of the algebra using the final estimates of the free parameters.

Slots may be referenced with the $ symbol. See the documentation forClasses and the examples in themxAlgebra document for more information.

References

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

See Also

mxAlgebra,mxMatrix,MxMatrix


MxAlgebraFormula

Description

This is an internal class for the formulas used inmxAlgebra calls.


MxBaseExpectation

Description

The virtual base class for all expectations. Expectations containenough information to generate simulated data. This is an internalclass and should not be used directly.

See Also

mxExpectationNormal,mxExpectationRAM,mxExpectationLISREL,mxExpectationStateSpace,mxExpectationBA81


MxBaseFitFunction

Description

The virtual base class for all fit functions. This is an internal class and should not be used directly.

See Also

mxFitFunctionAlgebra,mxFitFunctionML,mxFitFunctionMultigroup,mxFitFunctionR,mxFitFunctionWLS,mxFitFunctionRow,mxFitFunctionGREML


MxBaseNamed

Description

This is an internal class and should not be used directly. It is thebase class for named entities. Fit functions, expectations, and computescontain this class.


MxBaseObjectiveMetaData

Description

This is an internal class and should not be used directly.It is the virtual base class for all objective functions meta-data


MxBounds Class

Description

MxBounds is an S4 class. New instances of this class canbe created using the functionmxBounds.

Details

The MxBounds class has the following slots:

min - The lower bound
max - The upper bound
parameters - The vector of parameter names

The 'min' and 'max' slots hold scalar numeric values for the lower and upper bounds on the list of parameters, respectively.

Parameters may be any free parameter or parameters from anMxMatrix object. Parameters may be referenced either by name or by referring to their position in the 'spec' matrix of anMxMatrix object. To affect an estimation or optimization, an MxBounds object must be included in anMxModel object with all referencedMxAlgebra andMxMatrix objects.

Slots may be referenced with the $ symbol. See the documentation forClasses and the examples in themxBounds document for more information.

References

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

See Also

mxBounds for the function that creates MxBounds objects.MxMatrix andmxMatrix for free parameter specification. More information about the OpenMx package may be foundhere.


MxCI Class

Description

MxCI is an S4 class. An MxCI object is anamed entity.New instances of this class can be created using the functionmxCI.MxCI objects may be used as arguments in themxModel function.

Details

The MxCI class has the following slots:

reference - The name of the object
lowerdelta - Either a matrix or a data frame
upperdelta - A vector for means, or NA if missing

The reference slot contains a character vector of named free parameters,MxMatrices andMxAlgebras on which confidence intervals are desired. Individual elements ofMxMatrices andMxAlgebras may be listed as well, using the syntax “matrix[row,col]” (seeExtract for more information).

The lowerdelta and upperdelta slots give the changes in likelihoods used to define the confidence interval. The upper bound of the likelihood-based confidence interval is estimated by increasing the parameter estimate, leaving all other parameters free, until the model -2 log likelihood increased by ‘upperdelta’. The lower bound of the confidence interval is estimated by decreasing the parameter estimate, leaving all other parameters free, until the model -2 log likelihood increased by ‘lowerdata’.

Likelihood-based confidence intervals may be specified by including one or more MxCI objects in anMxModel object. Estimation of confidence intervals requires model optimization using themxRun function with the ‘intervals’ argument set to TRUE. The calculation of likelihood-based confidence intervals can be computationally intensive, and may add a significant amount of time to model estimation when many confidence intervals are requested.

References

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

See Also

mxCI for creating MxCI objects. More information about the OpenMx package may be foundhere.


A character, list or NULL

Description

A character, list or NULL


A character or logical

Description

A character or logical


A character or integer

Description

A character or integer


The MxCompare Class

Description

The MxCompare Class

Details

This is an internal class structure. You should not use it directly.UsemxCompare instead.


MxCompute

Description

This is an internal class and should not be used directly.


Class"MxConstraint"

Description

MxConstraint is an S4 class. An MxConstraint objectis anamed entity. New instances of this class canbe created using the functionmxConstraint().

Details

Slots may be referenced with the $ symbol. See the documentation forClasses and the examples in themxConstraint document for more information.

Slots

name:

Character string; the name of the object.

formula:

Object of class"MxAlgebraFormula". TheMxAlgebra-like expression representing the constraint function.

alg1:

Object of class"MxCharOrNumber". For internal use.

alg2:

Object of class"MxCharOrNumber". For internal use.

relation:

Object of class"MxCharOrNumber". For internal use.

jac:

Object of class"MxCharOrNumber". Identifies theMxAlgebra representing the Jacobian for the constraint function.

linear:

Logical. For internal use.

strict:

Logical. Whether to require that all Jacobian entries referencefree parameters.

verbose:

integer. For values greater than zero, enable runtimediagnostics.

Methods

$<-

signature(x = "MxConstraint")

$

signature(x = "MxConstraint")

imxDeparse

signature(object = "MxConstraint")

names

signature(x = "MxConstraint")

print

signature(x = "MxConstraint")

show

signature(object = "MxConstraint")

References

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

See Also

mxConstraint() for the function that creates MxConstraint objects.

Examples

showClass("MxConstraint")

MxData Class

Description

MxData is an S4 class. An MxData object is anamed entity.New instances of this class can be created using the functionmxData.MxData is an S4 class union. An MxData object is eitherNULL or a MxNonNullData object.

Details

The MxNonNullData class has the following slots:

name - The name of the object
observed - Either a matrix or a data frame
vector - A vector for means, or NA if missing
type - Either 'raw', 'cov', or 'cor'
numObs - The number of observations

The 'name' slot is the name of the MxData object.

The ‘observed’ slot is used to contain data, either as a matrix or as a data frame. Use of the data in this slot by other functions depends on the value of the 'type' slot. When 'type' is equal to 'cov' or 'cor', the data input into the 'matrix' slot should be a symmetric matrix or data frame.

The 'vector' slot is used to contain a vector of numeric values, which is used as a vector of means for MxData objects with 'type' equal to 'cov' or 'cor'. This slot may be used in estimation using themxFitFunctionML function.

The 'type' slot may take one of four supported values:

raw

The contents of the ‘observed’ slot are treated as raw data. Missing values are permitted and must be designated as the system missing value. The 'vector' and 'numObs' slots cannot be specified, as the 'vector' argument is not relevant and the 'numObs' argument is automatically populated with the number of rows in the data. Data of this type may use themxFitFunctionML function as its fit function in MxModel objects, which can deal with covariance estimation under full-information maximum likelihood.

cov

The contents of the ‘observed’ slot are treated as a covariance matrix. The 'vector' argument is not required, but may be included for estimations involving means. The 'numObs' slot is required. Data of this type may use fit functions such as themxFitFunctionML, depending on the specified model.

cor

The contents of the ‘observed’ slot are treated as a correlation matrix. The 'vector' argument is not required, but may be included for estimations involving means. The 'numObs' slot is required. Data of this type may use fit functions such as themxFitFunctionML, depending on the specified model.

The 'numObs' slot describes the number of observations in the data. If 'type' equals 'raw', then 'numObs' is automatically populated as the number of rows in the matrix or data frame in the ‘observed’ slot. If 'type' equals 'cov' or 'cor', then this slot must be input using the 'numObs' argument in themxData function when the MxData argument is created.

MxData objects may not be included inMxAlgebra objects or use themxFitFunctionAlgebra function. If these capabilities are desired, data should be appropriately input or transformed using themxMatrix andmxAlgebra functions.

While column names are stored in the ‘observed’ slot of MxData objects, these names are not recognized as variable names inMxPath objects. Variable names must be specified using the 'manifestVars' argument of themxModel function prior to use inMxPath objects.

The mxData function does not currently place restrictions on the size, shape, or symmetry of matrices input into the ‘observed’ argument. While it is possible to specify MxData objects as covariance or correlation matrices that do not have the properties commonly associated with these matrices, failure to correctly specify these matrices will likely lead to problems in model estimation.

References

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

See Also

mxData for creating MxData objects,matrix anddata.frame for objects which may be entered as arguments in the 'matrix' slot. More information about the OpenMx package may be foundhere.


Create static data

Description

Internal static data class.

Details

Not to be used.


MxDirectedGraph

Description

This is an internal class and should not be used directly.It is a class for directed graphs.


MxExpectation

Description

This is an internal class and should not be used directly.


Class "MxExpectationGREML"

Description

MxExpectationGREML is a type of expectation class. It contains the necessary elements for specifying a GREML model. For more information, seemxExpectationGREML().

Objects from the Class

Objects can be created by calls of the formmxExpectationGREML(V, yvars, Xvars, addOnes, blockByPheno, staggerZeroes, dataset.is.yX, casesToDropFromV, REML, yhat).

Slots

V:

Object of class"MxCharOrNumber". Identifies theMxAlgebra orMxMatrix to serve as the 'V' matrix.

yvars:

Character vector. Each string names a column of the raw dataset, to be used as a phenotype.

Xvars:

A list of data column names, specifying the covariates to be used with each phenotype.

addOnes:

Logical; pertains to data-handling at runtime.

blockByPheno:

Logical; pertains to data-handling at runtime.

staggerZeroes:

Logical; pertains to data-handling at runtime.

dataset.is.yX:

Logical; pertains to data-handling at runtime.

y:

Object of class"MxData". Itsobserved slot will contain the phenotype vector, 'y.'

X:

A matrix, to contain the 'X' matrix of covariates.

yXcolnames:

Character vector; used to store the column names of 'y' and 'X.'

casesToDrop:

Integer vector, specifying the rows and columns of the 'V' matrix to be removed at runtime.

b:

A matrix, to contain the vector of regression coefficients calculated at runtime.

bcov:

A matrix, to contain the sampling covariance matrix of the regression coefficients calculated at runtime.

numFixEff:

Integer number of covariates in 'X.'

REML:

Logical. Should restricted maximum-likelihood estimation be used?

yhat:

Object of class"MxCharOrNumber". Identifies theMxAlgebra orMxMatrix to serve as the model-expected phenotypic mean vector.

fitted.values:

A matrix, specifically, the column vector of model-predicted phenotypic means calculated at runtime.

residuals:

A matrix, specifically, the column vector of residuals calculated at runtime.

dims:

Object of class"character".

numStats:

Numeric; number of observed statistics.

dataColumns:

Object of class"numeric".

name:

Object of class"character".

data:

Object of class"MxCharOrNumber".

.runDims:

Object of class"character".

Extends

Class"MxBaseExpectation", directly.Class"MxBaseNamed", by class "MxBaseExpectation", distance 2.Class"MxExpectation", by class "MxBaseExpectation", distance 2.

Methods

No methods defined with class "MxExpectationGREML" in the signature.

References

Kirkpatrick RM, Pritikin JN, Hunter MD, & Neale MC. (2021). Combining structural-equation modeling with genomic-relatedness matrix restricted maximum likelihood in OpenMx. Behavior Genetics 51: 331-342.doi:10.1007/s10519-020-10037-5

The first software implementation of "GREML":
Yang J, Lee SH, Goddard ME, Visscher PM. (2011). GCTA: a tool for genome-wide complex trait analysis. American Journal of Human Genetics 88: 76-82.doi:10.1016/j.ajhg.2010.11.011

One of the first uses of the acronym "GREML":
Benjamin DJ, Cesarini D, van der Loos MJHM, Dawes CT, Koellinger PD, et al. (2012). The genetic architecture of economic and political preferences. Proceedings of the National Academy of Sciences 109: 8026-8031. doi: 10.1073/pnas.1120666109

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

See Also

SeemxExpectationGREML() for creating MxExpectationGREML objects, and for more information generally concerning GREML analyses, including a complete example. More information about the OpenMx package may be foundhere.

Examples

showClass("MxExpectationGREML")

MxFitFunction

Description

This is an internal class and should not be used directly.


Class"MxFitFunctionGREML"

Description

MxFitFunctionGREML is the fitfunction class for GREML analyses.

Objects from the Class

Objects can be created by calls of the formmxFitFunctionGREML(dV).

Slots

dV:

Object of class"MxCharOrNumber". Identifies theMxAlgebra orMxMatrix object(s) to serve as the derivatives of 'V' with respect to free parameters.

dVnames:

Vector of character strings; names of the free parameters corresponding to slotdV. Provides the mapping from elements ofaugGrad and of rows and columns ofaugHess to free parameters.

MLfit:

Object of class"numeric", equal to the maximum-likelihood fitfunction value (as opposed to the restricted maximum-likelihood value).

numObsAdjust:

Object of class"integer".Number of observations adjustment.

aug:

Object of class"MxCharOrNumber". Identifies theMxAlgebra orMxMatrix object used to "augment" the fitfunction value at each function evaluation during optimization.

augGrad:

Object of class"MxCharOrNumber". Identifies theMxAlgebra orMxMatrix object(s) to serve as the first derivatives ofaug with respect to free parameters.

augHess:

Object of class"MxCharOrNumber". Identifies theMxAlgebra orMxMatrix object(s) to serve as the second derivatives ofaug with respect to free parameters.

autoDerivType:

Object of class"character". Dictates whether fitfunction derivatives automatically calculated by OpenMx should be numerical or "semi-analytic."

infoMatType:

Object of class"character". Dictates whether to calculate the average- or expected-information matrix.

dyhat:

Object of class"MxCharOrNumber". Identifies theMxAlgebra orMxMatrix object(s) to serve as the derivatives of 'yhat' with respect to free parameters.

dyhatnames:

Vector of character strings; names of the free parameters corresponding to slotdyhat.

dNames:

Vector of character strings. IfdV and/ordyhat have nonzero length, then populated at runtime by the set of non-redundant free-parameter names appearing indVnames and/ordyhatnames.

.parallelDerivScheme:

Object of class"integer". Dictates how computation of the information matrix will be distributed across multiple threads. This slot is intended for use in testing and debugging by the OpenMx developers, and not to be modified by the end user.

info:

Object of class"list".

dependencies:

Object of class"integer".

expectation:

Object of class"integer".

vector:

Object of class"logical".

rowDiagnostics:

Object of class"logical".

result:

Object of class"matrix".

name:

Object of class"character".

Extends

Class"MxBaseFitFunction", directly.Class"MxBaseNamed", by class "MxBaseFitFunction", distance 2.Class"MxFitFunction", by class "MxBaseFitFunction", distance 2.

Methods

No methods defined with class "MxFitFunctionGREML" in the signature.

References

Kirkpatrick RM, Pritikin JN, Hunter MD, & Neale MC. (2021). Combining structural-equation modeling with genomic-relatedness matrix restricted maximum likelihood in OpenMx. Behavior Genetics 51: 331-342.doi:10.1007/s10519-020-10037-5

The first software implementation of "GREML":
Yang J, Lee SH, Goddard ME, Visscher PM. (2011). GCTA: a tool for genome-wide complex trait analysis. American Journal of Human Genetics 88: 76-82.doi:10.1016/j.ajhg.2010.11.011

One of the first uses of the acronym "GREML":
Benjamin DJ, Cesarini D, van der Loos MJHM, Dawes CT, Koellinger PD, et al. (2012). The genetic architecture of economic and political preferences. Proceedings of the National Academy of Sciences 109: 8026-8031. doi: 10.1073/pnas.1120666109

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

See Also

SeemxFitFunctionGREML() for creating MxFitFunctionGREML objects. SeemxExpectationGREML() for creating MxExpectationGREML objects, and for more information generally concerning GREML analyses, including a complete example. More information about the OpenMx package may be foundhere.

Examples

showClass("MxFitFunctionGREML")

MxFlatModel

Description

This is an internal class and should not be used.


MxInterval

Description

This is an internal class and should not be used directly.

See Also

mxCI


MxLISRELModel

Description

This is an internal class and should not be used directly.


An optional list

Description

An optional list


MxMatrix Class

Description

MxMatrix is a virtual S4 class that comprises the nine types of matrix objects used by OpenMx (seemxMatrix() for details). An MxMatrix object is anamed entity. New instances of this class can be created using the functionmxMatrix(). MxMatrix objects may be used as arguments in other functions from the OpenMx package, includingmxAlgebra(),mxConstraint(), andmxModel().

Objects from the Class

All nine types of object that the class comprises can be created viamxMatrix().

Slots

name:

Character string; the name of the MxMatrix object. Note that this is the object's "Mx name" (so to speak), which identifies it in OpenMx's internal namespace, rather than the symbol identifying it inR's workspace. Use of MxMatrix objects in anmxAlgebra ormxConstraint function requires reference by name.

values:

Numeric matrix of values. If an element is specified as a fixed parameter in the 'free' matrix, then the element in the 'values' matrix is treated as a constant value and cannot be altered or updated by an objective function when included in anmxRun() function. If an element is specified as a free parameter in the 'free' matrix, the element in the 'value' matrix is considered a starting value and can be changed by an objective function when included in anmxRun() function.

labels:

Matrix of character strings which provides the labels of free and fixed parameters. Fixed parameters with identical labels must have identical values. Free parameters with identical labels impose an equality constraint. The same label cannot be applied to a free parameter and a fixed parameter. A free parameter with the label 'NA' implies a unique free parameter, that cannot be constrained to equal any other free parameter.

free:

Logical matrix specifying whether each element is free versus fixed. An element is a free parameter if-and-only-if the corresponding value in the 'free' matrix is 'TRUE'. Free parameters are elements of an MxMatrix object whose values may be changed by a fitfunction when that MxMatrix object is included in anMxModel object and evaluated using themxRun() function.

lbound:

Numeric matrix of lower bounds on free parameters.

ubound:

Numeric matrix of upper bounds on free parameters.

.squareBrackets:

Logical matrix; used internally by OpenMx. Identifies which elements have labels with square brackets in them.

.persist:

Logical; used internally by OpenMx. Governs howmxRun() handles the MxMatrix object when it is inside theMxModel being run.

.condenseSlots:

Logical; used internally by OpenMx. IfFALSE, then the matrices in the 'values', 'labels', 'free', 'lbound', and 'ubound' slots are all of equal dimensions. IfTRUE, then the last four of those slots will "condense" a matrix consisting entirely ofFALSE orNA down to 1x1.

display:

Character string; used internally by OpenMx when parsingMxAlgebras.

dependencies:

Integer; used internally by OpenMx when parsingMxAlgebras.

Methods

$

signature(x = "MxMatrix"): ...

$<-

signature(x = "MxMatrix"): ...

[

signature(x = "MxMatrix"): ...

[<-

signature(x = "MxMatrix"): ...

dim

signature(x = "MxMatrix"): ...

dimnames

signature(x = "MxMatrix"): ...

dimnames<-

signature(x = "MxMatrix"): ...

length

signature(x = "MxMatrix"): ...

names

signature(x = "MxMatrix"): ...

ncol

signature(x = "MxMatrix"): ...

nrow

signature(x = "MxMatrix"): ...

print

signature(x = "MxMatrix"): ...

show

signature(object = "MxMatrix"): ...

Note that some methods are documented separately (see below, under "See Also").

References

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

See Also

mxMatrix() for creating MxMatrix objects. Note that functionsimxCreateMatrix(),imxDeparse(),imxSquareMatrix(),imxSymmetricMatrix(), andimxVerifyMatrix() are separately documented methods for this class. More information about the OpenMx package may be foundhere.

Examples

showClass("MxMatrix")

MxModel Class

Description

MxModel is an S4 class. An MxModel object is anamed entity.

Details

The ‘matrices’ slot contains a list of theMxMatrix objects included in the model. These objects are listed by name. Two objects may not share the same name. If a newMxMatrix is added to an MxModel object with the same name as anMxMatrix object in that model, the added version replaces the previous version. There is no imposed limit on the number ofMxMatrix objects that may be added here.

The ‘algebras’ slot contains a list of theMxAlgebra objects included in the model. These objects are listed by name. Two objects may not share the same name. If a newMxAlgebra is added to an MxModel object with the same name as anMxAlgebra object in that model, the added version replaces the previous version. AllMxMatrix objects referenced in the includedMxAlgebra objects must be included in the ‘matrices’ slot prior to estimation. There is no imposed limit on the number ofMxAlgebra objects that may be added here.

The ‘constraints’ slot contains a list of theMxConstraint objects included in the model. These objects are listed by name. Two objects may not share the same name. If a newMxConstraint is added to an MxModel object with the same name as anMxConstraint object in that model, the added version replaces the previous version. AllMxMatrix objects referenced in the includedMxConstraint objects must be included in the ‘matrices’ slot prior to estimation. There is no imposed limit on the number ofMxConstraint objects that may be added here.

The ‘intervals’ slot contains a list of the confidence intervals requested by includedMxCI objects. These objects are listed by the free parameters,MxMatrices andMxAlgebras referenced in theMxCI objects, not the list ofMxCI objects themselves. If a newMxCI object is added to an MxModel object referencing one or more free parametersMxMatrices orMxAlgebras previously listed in the ‘intervals’ slot, the new confidence interval(s) replace the existing ones. All listed confidence intervals must refer to free parametersMxMatrices orMxAlgebras in the model.

The ‘latentVars’ slot contains a list of latent variable names,which may be referenced byMxPath objects. Thisslot defaults to 'NA', and is only used when themxPath functionis used. In the context of a RAM model, this slot accepts a charactervector of variable names. However, the LISREL model is partitioned intoexogenous and endogenous parts. Both exogenous and endogenous variablescan be specified using a list like,list(endo='a', exo='b').If a character vector is passed to a LISREL model then thosevariables will be assumed endogenous.

The ‘manifestVars’ slot contains a list of latent variable names,which may be referenced byMxPath objects. Thisslot defaults to 'NA', and is only used when themxPath functionis used. In the context of a RAM model, this slot accepts a charactervector of variable names. However, the LISREL model is partitioned intoexogenous and endogenous parts. Both exogenous and endogenous variablescan be specified using a list like,list(endo='a', exo='b').If a character vector is passed to a LISREL model then thosevariables will be assumed endogenous.

The ‘data’ slot contains anMxData object. This slot must be filled prior to execution when a fitfunction referencing data is used. Only oneMxData object may be included per model, but submodels may have their own data in their own ‘data’ slots. If anMxData object is added to an MxModel which already contains anMxData object, the new object replaces the existing one.

The ‘submodels’ slot contains references to all of the MxModel objects included as submodels of this MxModel object. Models held as arguments in other models are considered to be submodels. These objects are listed by name. Two objects may not share the same name. If a new submodel is added to an MxModel object with the same name as an existing submodel, the added version replaces the previous version. When a model containing other models is executed usingmxRun, all included submodels are executed as well. If the submodels are dependent on one another, they are treated as one larger model for purposes of estimation.

The ‘independent’ slot contains a logical value indicating whether or not the model is independent. If a model is independent (independent=TRUE), then the parameters of this model are not shared with any other model. An independent model may be estimated with no dependency on any other model. If a model is not independent (independent=FALSE), then this model shares parameters with one or more other models such that these models must be jointly estimated. These dependent models must be entered as submodels of another MxModel objects, so that they are simultaneously optimized.

The ‘options’ slot contains a list of options for the model. The name of each entry in the list is the option name to be used at runtime. The values in this list are the values of the optimizer options. The standard interface for updating options is through themxOption function.

The ‘output’ slot contains a list of output added to the model by themxRun function. Output includes parameter estimates, optimization information, model fit, and other information. If a model has not been optimized using themxRun function, the 'output' slot will be 'NULL'.

Named entities inMxModel objects may be viewed and referenced by name using the $ symbol. For instance, for an MxModel named "yourModel" containing an MxMatrix named "yourMatrix", the contents of "yourMatrix" can be accessed as yourModel$yourMatrix. Slots (i.e., matrices, algebras, etc.) in an mxMatrix may also be referenced with the $ symbol (e.g., yourModel$matrices or yourModel$algebras). See the documentation forClasses and the examples inmxModel for more information.

Objects from the Class

Objects can be created by calls of the formmxModel().

Slots

name:

Character string. The name of the model object.

matrices:

List of the model'sMxMatrix objects.

algebras:

List of the model'sMxAlgebra objects.

constraints:

List of the model'sMxConstraint objects.

intervals:

List of the model'sMxIntervalobjects, requested viamxCI().

penalties:

List of the model'sMxPenaltyobjects.

latentVars:

"Latent variables;" object of class"MxCharOrList".

manifestVars:

"Manifest variables;" object of class"MxCharOrList".

data:

Object of classMxData.

submodels:

List of MxModel objects.

expectation:

Object of classMxExpectation; dictates the model's specification.

fitfunction:

Object of classMxFitFunction; dictates the cost function to be minimized when fitting the model.

compute:

Object of classMxCompute–the model's compute plan, which contains instructions on what the model is to compute and how to do so.

independent:

Logical; is the model to be run independently from other submodels?

options:

List of model-specific options, set bymxOption().

output:

List of model output produced during a call tomxRun().

.newobjects:

Logical; for internal use.

.resetdata:

Logical; for internal use.

.wasRun:

Logical; for internal use.

.modifiedSinceRun:

Logical; for internal use.

.version:

Object of class"package_version"; for internal use.

Methods

$

signature(x = "MxModel"): Accessor. Accesses slots by slot-name. Also accesses constituentnamed entities, by name.

$<-

signature(x = "MxModel"): Assignment. Generally, this method will not allow the user to make unsafe changes to the MxModel object.

[[

signature(x = "MxModel"): Accessor for constituentnamed entities.

[[<-

signature(x = "MxModel"): Assignment for anamed entity.

names

signature(x = "MxModel"): Returns names of slots andnamed entities.

print

signature(x = "MxModel"): "Print" method.

show

signature(object = "MxModel"): "Show" method.

Note thatimxInitModel(),imxModelBuilder(),imxTypeName(), andimxVerifyModel() are separately documented methods for class "MxModel".

References

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

See Also

mxExpectationRAM,mxExpectationLISREL,mxModel for creating MxModel objects. More information about the OpenMx package may be foundhere.


An optional character

Description

An optional character


A character, integer, or NULL

Description

A character, integer, or NULL


An optional data.frame

Description

An optional data.frame


An optional data.frame or matrix

Description

An optional data.frame or matrix


An optional integer

Description

An optional integer


An optional logical

Description

This is an internal class, the union of NULL and logical.


An optional matrix

Description

An optional matrix


An optional numeric

Description

An optional numeric


MxPenalty

Description

This is an internal class and should not be used directly.


MxRAMGraph

Description

This is an internal class and should not be used directly.It is a class for RAM directed graphs.


MxRAMModel

Description

This is an internal class and should not be used directly.


A package_version or character

Description

A package_version or character


Named Entities

Description

A named entity is an S4 object that can be referenced by name.

Details

Every named entity is guaranteed to have a slot called "name". Within a model, the named entities of that model can be accessed using the $ operator. Access is limited to one nesting depth, such that if 'B' is a submodel of 'A', and 'C' is a matrix of 'B', then 'C' must be accessed using A$B$C.

The following S4 classes are named entities in the OpenMx library:MxAlgebra,MxConstraint,MxMatrix,MxModel,MxData, and MxObjective.

Examples

library(OpenMx)# Create a model, add a matrix to it, and then access the matrix by name.testModel <- mxModel(model="anEmptyModel")testMatrix <- mxMatrix(type="Full", nrow=2, ncol=2, values=c(1,2,3,4), name="yourMatrix")yourModel <- mxModel(testModel, testMatrix, name="noLongerEmpty")yourModel$yourMatrix

Oscillator Data for Latent Differential Equations

Description

Data set used in some of OpenMx's examples, for instance the LDE demo. The data were simulated by Steven M. Boker according to a noisy oscillator model.

Usage

data("Oscillator")

Format

A data frame with 100 observations on the following 1 numeric variable.

x

Noisy oscillator value

Details

The data appear to be sinusoidal with exponential decay on the amplitude. The rows of data are different times. The column is the variable.

Source

Simulated. Pulled fromhttps://openmx.ssri.psu.edu/node/144

References

Boker, S., Neale, M., & Rausch, J. (2004). Latent differential equation modeling with multivariate multi-occasion indicators. InRecent developments on structural equation models van Montfort, K., Oud, H, and Satorra, A. (Eds.). 151-174. Springer, Dordrecht.

Examples

data(Oscillator)plot(Oscillator$x, type='l')

Convert a numeric or character vector into an optimizer status code factor

Description

Below we provide a brief, technical description of each status code followed bya more colloquial, less precise desciption.

Usage

as.statusCode(code)

Arguments

code

a character or numeric vector of optimizer status code

See Also

mxBootstrapsummary.MxModel


Vectorize By Column

Description

This function returns the vectorization of an input matrix in a column by column traversal of the matrix. The output is returned as a column vector.

Usage

cvectorize(x)

Arguments

x

an input matrix.

See Also

rvectorize,vech,vechs

Examples

cvectorize(matrix(1:9, 3, 3))cvectorize(matrix(1:12, 3, 4))

Demonstration data for a one factor model

Description

Data set used in some of OpenMx's examples.

Usage

data("demoOneFactor")

Format

A data frame with 500 observations on the following 5 numeric variables.

x1
x2
x3
x4
x5

Details

Variables x1-x5 are typically used as indicators of the latent trait.

Source

Simulated.

References

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

Examples

data(demoOneFactor)cov(demoOneFactor)cor(demoOneFactor)

Demonstration data for a two factor model

Description

Data set used in some of OpenMx's examples.

Usage

data("demoTwoFactor")

Format

A data frame with 500 observations on the following 10 numeric variables.

x1
x2
x3
x4
x5
y1
y2
y3
y4
y5

Details

Variables x1-x5 are typically used as indicators of one latent trait. Variables y1-y5 are typically used as indicators of another latent trait.

Source

Simulated.

References

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

Examples

data(demoTwoFactor)cov(demoTwoFactor)cor(demoTwoFactor)

Extract Diagonal of a Matrix

Description

Given an input matrix,diag2vec returns a column vector of the elements along the diagonal.

Usage

diag2vec(x)

Arguments

x

an input matrix.

Details

Similar to the functiondiag, except that the input argument is alwaystreated as a matrix (i.e., it doesn't have diag()'s functions of returning an Identity matrix from an nrow specification, nor to return a matrix wrapped around a diagonal if provided with a vector). To get vector2matrix functionality, callvec2diag.

See Also

vec2diag

Examples

diag2vec(matrix(1:9, nrow=3))#      [,1]# [1,]    1# [2,]    5# [3,]    9diag2vec(matrix(1:12, nrow=3, ncol=4))#      [,1]# [1,]    1# [2,]    5# [3,]    9

Example twin extended kinship data: DZ female data

Description

Data for extended twin example ETC88.R

Usage

data("dzfData")

Format

A data frame with 2007 observations on the following 37 variables.

famid

a numeric vector

e1

a numeric vector

e2

a numeric vector

e3

a numeric vector

e4

a numeric vector

e5

a numeric vector

e6

a numeric vector

e7

a numeric vector

e8

a numeric vector

e9

a numeric vector

e10

a numeric vector

e11

a numeric vector

e12

a numeric vector

e13

a numeric vector

e14

a numeric vector

e15

a numeric vector

e16

a numeric vector

e17

a numeric vector

e18

a numeric vector

a1

a numeric vector

a2

a numeric vector

a3

a numeric vector

a4

a numeric vector

a5

a numeric vector

a6

a numeric vector

a7

a numeric vector

a8

a numeric vector

a9

a numeric vector

a10

a numeric vector

a11

a numeric vector

a12

a numeric vector

a13

a numeric vector

a14

a numeric vector

a15

a numeric vector

a16

a numeric vector

a17

a numeric vector

a18

a numeric vector

Examples

data(dzfData)str(dzfData)

Example twin extended kinship data: DZ Male data

Description

Data for extended twin example ETC88.R

Usage

data("dzmData")

Format

A data frame with 1990 observations on the following 37 variables.

famid

a numeric vector

e1

a numeric vector

e2

a numeric vector

e3

a numeric vector

e4

a numeric vector

e5

a numeric vector

e6

a numeric vector

e7

a numeric vector

e8

a numeric vector

e9

a numeric vector

e10

a numeric vector

e11

a numeric vector

e12

a numeric vector

e13

a numeric vector

e14

a numeric vector

e15

a numeric vector

e16

a numeric vector

e17

a numeric vector

e18

a numeric vector

a1

a numeric vector

a2

a numeric vector

a3

a numeric vector

a4

a numeric vector

a5

a numeric vector

a6

a numeric vector

a7

a numeric vector

a8

a numeric vector

a9

a numeric vector

a10

a numeric vector

a11

a numeric vector

a12

a numeric vector

a13

a numeric vector

a14

a numeric vector

a15

a numeric vector

a16

a numeric vector

a17

a numeric vector

a18

a numeric vector

Examples

data(dzmData)str(dzmData)

Example twin extended kinship data: DZ opposite sex twins

Description

Data for extended twin example ETC88.R

Usage

data("dzoData")

Format

A data frame with 3981 observations on the following 37 variables.

famid

a numeric vector

e1

a numeric vector

e2

a numeric vector

e3

a numeric vector

e4

a numeric vector

e5

a numeric vector

e6

a numeric vector

e7

a numeric vector

e8

a numeric vector

e9

a numeric vector

e10

a numeric vector

e11

a numeric vector

e12

a numeric vector

e13

a numeric vector

e14

a numeric vector

e15

a numeric vector

e16

a numeric vector

e17

a numeric vector

e18

a numeric vector

a1

a numeric vector

a2

a numeric vector

a3

a numeric vector

a4

a numeric vector

a5

a numeric vector

a6

a numeric vector

a7

a numeric vector

a8

a numeric vector

a9

a numeric vector

a10

a numeric vector

a11

a numeric vector

a12

a numeric vector

a13

a numeric vector

a14

a numeric vector

a15

a numeric vector

a16

a numeric vector

a17

a numeric vector

a18

a numeric vector

Examples

data(dzoData)str(dzoData)

Eigenvector/Eigenvalue Decomposition

Description

eigenval computes the real parts of the eigenvalues of a square matrix.eigenvec computes the real parts of the eigenvectors of a square matrix.ieigenval computes the imaginary parts of the eigenvalues of a square matrix.ieigenvec computes the imaginary parts of the eigenvectors of a square matrix.eigenval andieigenval return nx1 matrices containing the real or imaginary parts of the eigenvalues, sorted in decreasing order of the modulus of the complex eigenvalue. For eigenvalues without an imaginary part, this is equivalent to sorting in decreasing order of the absolute value of the eigenvalue. (SeeMod for more info.)eigenvec andieigenvec return nxn matrices, where each column corresponds to an eigenvector. These are sorted in decreasing order of the modulus of their associated complex eigenvalue.

Usage

eigenval(x)eigenvec(x)ieigenval(x)ieigenvec(x)

Arguments

x

the square matrix whose eigenvalues/vectors are to be calculated.

Details

Eigenvectors returned byeigenvec andieigenvec are normalized to unit length.

See Also

eigen

Examples

A <- mxMatrix(values = runif(25), nrow = 5, ncol = 5, name = 'A')G <- mxMatrix(values = c(0, -1, 1, -1), nrow=2, ncol=2, name='G')model <- mxModel(A, G, name = 'model')mxEval(eigenvec(A), model)mxEval(eigenvec(G), model)mxEval(eigenval(A), model)mxEval(eigenval(G), model)mxEval(ieigenvec(A), model)mxEval(ieigenvec(G), model)mxEval(ieigenval(A), model)mxEval(ieigenval(G), model)

Bivariate twin data, wide-format from Classic Mx Manual

Description

Data set used in some of OpenMx's examples.

Usage

data("example1")

Format

A data frame with 400 observations on the following variables.

IDNum

Twin pair ID

Zygosity

Zygosity of the twin pair

X1

X variable for twin 1

Y1

Y variable for twin 1

X2

X variable for twin 2

Y2

Y variable for twin 2

Details

Same asexample2 but in wide format instead of tall.

Source

Classic Mx Manual.

References

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

Examples

data(example1)plot(X2 ~ X1, data = example1)

Bivariate twin data, long-format from Classic Mx Manual

Description

Data set used in some of OpenMx's examples.

Usage

data("example2")

Format

A data frame with 800 observations on the following variables.

IDNum

ID number

TwinNum

Twin ID number

Zygosity

Zygosity of the twin

X

X variable for twins 1 and 2

Y

Y variable for twins 1 and 2

Details

Same asexample1 but in tall format instead of wide.

Source

Classic Mx Manual.

References

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

Examples

data(example2)plot(Y ~ X, data = example2)

Matrix exponential

Description

Matrix exponential

Usage

expm(x)

Arguments

x

matrix


Example Factor Analysis Data

Description

Data set used in some of OpenMx's examples.

Usage

data("factorExample1")

Format

A data frame with 500 observations on the following variables.

x1
x2
x3
x4
x5
x6
x7
x8
x9

Details

This appears to be a three factor model, but perhaps with an odd loading structure.

Source

Simulated

References

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

Examples

data(factorExample1)round(cor(factorExample1), 2)factanal(covmat=cov(factorExample1), factors=3, rotation="promax")

Example Factor Analysis Data for Scaling the Model

Description

Data set used in some of OpenMx's examples.

Usage

data("factorScaleExample1")

Format

A data frame with 200 observations on the following variables.

X1
X2
X3
X4
X5
X6
X7
X8
X9
X10
X11
X12

Details

This appears to be a three factor model with factor 1 loading on X1-X4, factor 2 on X5-X8, and factor 3 on X9-X12.

Source

Simulated

References

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

Examples

data(factorScaleExample1)round(cor(factorScaleExample1), 2)

Example Factor Analysis Data for Scaling the Model

Description

Data set used in some of OpenMx's examples.

Usage

data("factorScaleExample2")

Format

A data frame with 200 observations on the following variables.

X1
X2
X3
X4
X5
X6
X7
X8
X9
X10
X11
X12

Details

Three-factor data with factor 1 loading on X1-X4, factor 2 on X5-X8, and factor 3 on X9-X12. It differs fromfactorScaleExample1 in the scaling of the variables.

Source

Simulated

References

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

Examples

data(factorScaleExample2)round(cor(factorScaleExample2), 2)data(factorScaleExample2)plot(sapply(factorScaleExample1, var), type='l', ylim=c(0, 6), lwd=3)lines(1:12, sapply(factorScaleExample2, var), col='blue', lwd=3)

Add dependencies

Description

If there is an expectation, then the fitfunction should alwaysdepend on it. Hence, subclasses that implement this method mustignore the passed-in dependencies and use "dependencies <-callNextMethod()" instead.

Usage

## S4 method for signature 'MxBaseFitFunction'genericFitDependencies(.Object, flatModel, dependencies)

Arguments

.Object

fit function object

flatModel

flat model that lives with .Object

dependencies

accumulated dependency relationships


Add a dependency

Description

The dependency tracking system ensures that algebra andfitfunctions are not recomputed if their inputs have not changed.Dependency information is computed prior to handing the model offto the optimizer to reduce overhead during optimization.

Usage

imxAddDependency(source, sink, dependencies)

Arguments

source

a character vector of the names of the computation sources (inputs)

sink

the name of the computation sink (output)

dependencies

the dependency graph

Details

Each free parameter keeps track of all the objects that store thatfree parameter and the transitive closure of all algebras and fitfunctions that depend on that free parameter. Similarly, eachdefinition variable keeps track of all the objects that store thatfree parameter and the transitive closure of all the algebras andfit functions that depend on that free parameter. At eachiteration of the optimization, when the free parameter values areupdated, all of the dependencies of that free parameter are markedas dirty (seeomxFitFunction.repopulateFun). After analgebra or fit function is computed,omxMarkClean() iscalled to to indicate that the algebra or fit function is updated.Similarly, when definition variables are populated in FIML, all ofthe dependencies of the definition variables are marked as dirty.Particularly for FIML, the fact that non-definition-variabledependencies remain clean is a big performance gain.


imxAutoOptionValue

Description

Convert "Auto" placeholders in global mxOptions to actual default values.

Usage

imxAutoOptionValue(optionName, optionList = options()$mxOption)

Arguments

optionName

Character string naming themxOption for which a numeric or integer value is wanted.

optionList

List of options; defaults to list of globalmxOptions.imxAutoOptionValue

Details

This is an internal function exported for documentation purposes.Its primary purpose is to convert the on-load value of "Auto"tovalid values formxOptions ‘Gradient step size’,‘Gradient iterations’, and‘Function precision’–respectively, 1.0e-7, 1L, and 1e-14.


imxCheckMatrices

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxCheckMatrices(model)

Arguments

model

model


imxCheckVariables

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxCheckVariables(flatModel, namespace)

Arguments

flatModel

flatModel

namespace

namespace


Condense/de-condense slots of an MxMatrix

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxConDecMatrixSlots(object)

Arguments

object

of class MxMatrix


imxConstraintRelations

Description

A string vector of valid constraint binary relations.

Usage

imxConstraintRelations

Format

An object of classcharacter of length 3.


imxConvertIdentifier

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxConvertIdentifier(identifiers, modelname, namespace, strict = FALSE)

Arguments

identifiers

identifiers

modelname

modelname

namespace

namespace

strict

strict


imxConvertLabel

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxConvertLabel(label, modelname, dataname, namespace)

Arguments

label

label

modelname

modelname

dataname

dataname

namespace

namespace


imxConvertSubstitution

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxConvertSubstitution(substitution, modelname, namespace)

Arguments

substitution

substitution

modelname

modelname

namespace

namespace


Create a matrix

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxCreateMatrix(  .Object,  labels,  values,  free,  lbound,  ubound,  nrow,  ncol,  byrow,  name,  condenseSlots,  joinKey,  joinModel)

Arguments

.Object

the matrix

labels

labels

values

values

free

free

lbound

lbound

ubound

ubound

nrow

nrow

ncol

ncol

byrow

byrow

name

name

condenseSlots

condenseSlots

joinKey

joinKey

joinModel

joinModel


Valid types of data that can be contained by MxData

Description

Valid types of data that can be contained by MxData

Usage

imxDataTypes

Format

An object of classcharacter of length 4.


imxDefaultGetSlotDisplayNames

Description

Returns a list of display-friendly object slot namesThis is an internal function exported for those people who knowwhat they are doing.

Usage

imxDefaultGetSlotDisplayNames(x, pattern = ".*")

Arguments

x

The object from which to get slot names

pattern

Initial pattern to match (default of '.*' matches any)


Deparse for MxObjects

Description

Deparse for MxObjects

Usage

imxDeparse(object, indent = "   ")

Arguments

object

object

indent

indent


Are submodels dependence?

Description

Are submodels dependence?

Usage

imxDependentModels(model)

Arguments

model

model


imxDetermineDefaultOptimizer

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxDetermineDefaultOptimizer()

Details

Returns a character, the default optimizer


A C implementation of dmvnorm

Description

This API is visible to permit testing. Please do not use.

Usage

imxDmvnorm(loc, mean, sigma)

Arguments

loc

loc

mean

mean

sigma

sigma


imxEvalByName

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxEvalByName(name, model, compute = FALSE, show = FALSE)

Arguments

name

name

model

model

compute

compute

show

show


imxExtractMethod

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxExtractMethod(model, index)

Arguments

model

model

index

index


imxExtractNames

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxExtractNames(lst)

Arguments

lst

lst


imxExtractReferences

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxExtractReferences(lst)

Arguments

lst

lst


imxExtractSlot

Description

Checks for and extracts a slot from the objectThis is an internal function exported for those people who knowwhat they are doing.

Usage

imxExtractSlot(x, name)

Arguments

x

The object

name

the name of the slot


Remove hierarchical structure from model

Description

Remove hierarchical structure from model

Usage

imxFlattenModel(model, namespace, unsafe = FALSE)

Arguments

model

model

namespace

namespace

unsafe

whether to skip sanity checks


Freeze model

Description

Remove free parameters and fit function from model.

Usage

imxFreezeModel(model)

Arguments

model

model


imxGenSwift

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxGenSwift(tc, sites, sfile)

Arguments

tc

tc

sites

sites

sfile

sfile


imxGenerateLabels

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxGenerateLabels(model)

Arguments

model

model


imxGenerateNamespace

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxGenerateNamespace(model)

Arguments

model

model


imxGenericModelBuilder

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxGenericModelBuilder(  model,  lst,  name,  manifestVars,  latentVars,  productVars,  submodels,  remove,  independent)

Arguments

model

model

lst

lst

name

name

manifestVars

manifestVars

latentVars

latentVars

productVars

productVars

submodels

submodels

remove

remove

independent

independent


Resize an MxMatrix while preserving entries

Description

Resize an MxMatrix while preserving entries

Usage

imxGentleResize(matrix, dimnames)

Arguments

matrix

the MxMatrix to resize

dimnames

desired dimnames for the new matrix

Value

a resized MxMatrix

Examples

m1 <- mxMatrix(values=1:9, nrow=3, ncol=3,               dimnames=list(paste0('r',1:3), paste0('c',1:3)))imxGentleResize(m1, dimnames=list(paste0('r',c(1,3,5)),                                  paste0('c',c(2,4,6))))

imxGetNumThreads

Description

This is an internal function exported for those people who knowwhat they are doing.

This function hard codes responses to a set of environments, like detecting snowfall,or running on a cluster where "OMP_NUM_THREADS" is set or otherwise returning 1 or 2 coresto avoid consuming all the resources on CRAN's test machines during release cycles.

This makes itnot suitable for getting the number of available threads.

To get the number of cores available locally you wantomxDetectCoresor perhaps thedetectCores function in the parallel package.

Usage

imxGetNumThreads()

imxGetSlotDisplayNames

Description

Returns a list of display-friendly object slot namesThis is an internal function exported for those people who knowwhat they are doing.

Usage

imxGetSlotDisplayNames(  object,  pattern = ".*",  slotList = slotNames(object),  showDots = FALSE,  showEmpty = FALSE)

Arguments

object

The object from which to get slot names

pattern

Initial pattern to match (default of '.*' matches any)

slotList

List of slots for which toget display names (default = slotNames(object), i.e., all)

showDots

Include slots whose names start with '.' (default FALSE)

showEmpty

Include slots with length-zero contents (default FALSE)


imxHasAlgebraOnPath

Description

This is an internal function exported for those people who knowwhat they are doing. This function checks if a model (or any of itssubmodels) either (1) has labels on MxPaths that reference one or moreMxAlgebras, or (2) defines any of the RAM matrices as MxAlgebras.

Usage

imxHasAlgebraOnPath(model, submodels = TRUE, strict = FALSE)

Arguments

model

an MxModel object

submodels

logical; recursion over child models?

strict

logical; raise error if 'model' contains no paths?


imxHasConstraint

Description

This is an internal function exported for those people who knowwhat they are doing. This function checks if a model (or itssubmodels) has at least one MxConstraint.

Usage

imxHasConstraint(model)

Arguments

model

model


imxHasDefinitionVariable

Description

This is an internal function exported for those people who knowwhat they are doing. This function checks if a model (or itssubmodels) has at least one definition variable.

Usage

imxHasDefinitionVariable(model)

Arguments

model

model


imxHasNPSOL

Description

imxHasNPSOL

Usage

imxHasNPSOL()

Value

Returns TRUE if the NPSOL proprietary optimizer is compiled andlinked with OpenMx. Otherwise FALSE.


imxHasOpenMP

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxHasOpenMP()

imxHasPenalty

Description

This is an internal function exported for those people who knowwhat they are doing. This function checks if a model (or itssubmodels) has any penalties.

Usage

imxHasPenalty(model)

Arguments

model

model


imxHasThresholds

Description

This is an internal function exported for those people who knowwhat they are doing. This function checks if a model (or itssubmodels) has any thresholds.

Usage

imxHasThresholds(model, submodels = TRUE)

Arguments

model

model

submodels

logical; recursion over child models?


imxHasWLS

Description

This is an internal function exported for those people who knowwhat they are doing. This function checks if a model uses afitfunction with WLS units.

Usage

imxHasWLS(model)

Arguments

model

model


imxIdentifier

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxIdentifier(namespace, name)

Arguments

namespace

namespace

name

name


Are submodels independent?

Description

Are submodels independent?

Usage

imxIndependentModels(model)

Arguments

model

model


imxInitModel

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxInitModel(model)

Arguments

model

model


imxIsDefinitionVariable

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxIsDefinitionVariable(name)

Arguments

name

name


imxIsMultilevel

Description

This is an internal function exported for those people who knowwhat they are doing. If you don't know what you're doing, but want to,here's a brief description of the function. You give this function an MxModel. Itreturns TRUE if the model is multilevel and FALSE otherwise.

Usage

imxIsMultilevel(model)

Arguments

model

model


imxIsPath

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxIsPath(value)

Arguments

value

value


imxIsStateSpace

Description

This is an internal function exported for those people who knowwhat they are doing. If you don't know what you're doing, but want to,here's a brief description of the function. You give this function an MxModel. Itreturns TRUE if the model is a state space model and FALSE otherwise.

Usage

imxIsStateSpace(model)

Arguments

model

model


imxLocateFunction

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxLocateFunction(function_name)

Arguments

function_name

function_name


imxLocateIndex

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxLocateIndex(model, name, referant)

Arguments

model

model

name

name

referant

referant


imxLocateLabel

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxLocateLabel(label, model, parameter)

Arguments

label

label

model

model

parameter

parameter


Test thread-safe output code

Description

This is the code that the backend uses to write diagnosticinformation to standard error. This function should not be calledfrom R. We make it available only for testing.

Usage

imxLog(str)

Arguments

str

the character string to output


imxLookupSymbolTable

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxLookupSymbolTable(name)

Arguments

name

name


imxModelBuilder

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxModelBuilder(  model,  lst,  name,  manifestVars,  latentVars,  productVars,  submodels,  remove,  independent)

Arguments

model

model

lst

lst

name

name

manifestVars

manifestVars

latentVars

latentVars

productVars

productVars

submodels

submodels

remove

remove

independent

independent

Details

TODO: It probably makes sense to split this into separatemethods. For example, modelAddVariables and modelRemoveVariablescould be their own methods. This would reduce some cut&pasteduplication.


imxModelTypes

Description

A list of supported model types

Usage

imxModelTypes

Format

An object of classlist of length 3.


imxMpiWrap

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxMpiWrap(fun)

Arguments

fun

fun


Run an classic mx script

Description

For this to work, classic mx must be installed, and callable from the command line.

Usage

imxOriginalMx(mx.filename, output.directory)

Arguments

mx.filename

Name of file containing the mx script.

output.directory

Where to write mxo output from the script

Value

processed matrix output.

Examples

## Not run: output = imxOriginalMx(mx.filename = "power1.mx", "~/Desktop")## End(Not run)

imxPPML

Description

Potentially enable the PPML optimization for the given model.

Usage

imxPPML(model, flag = TRUE)

Arguments

model

the MxModel to evaluate

flag

whether to potentially enable PPML


imxPPML.Test.Battery

Description

PPML can be applied to a number of special cases. This function will test the given model forall of these special cases.

Usage

imxPPML.Test.Battery(  model,  verbose = FALSE,  testMissingness = TRUE,  testPermutations = TRUE,  testEstimates = TRUE,  testFakeLatents = TRUE,  tolerances = c(0.001, 0.001, 0.001))

Arguments

model

the model to test

verbose

whether to print diagnostics

testMissingness

try with missingness

testPermutations

try with permutations

testEstimates

examine estimates

testFakeLatents

try with fake latents

tolerances

a vector of tolerances

Details

Requirements for model passed to this function:- Path-specified- Means vector must be present- Covariance data (with data means vector)- (Recommended) All error variances should be specified on thediagonal of the S matrix, and not as a latent with a loading onlyon to that manifest

Function will test across all permutations of:- Covariance vs Raw data- Means vector present vs Means vector absent- Path versus Matrix specification- All orders of permutations of latents with manifests


imxPPML.Test.Test

Description

Test that PPML solutions match non-PPML solutions.

Usage

imxPPML.Test.Test(  model,  checkLL = TRUE,  checkByName = FALSE,  tolerance = 0.5,  testEstimates = TRUE)

Arguments

model

the MxModel to evaluate

checkLL

whether to check log likelihood

checkByName

check values using their names

tolerance

closeness tolerance for check

testEstimates

whether to test for the same parameter estimates

Details

This is an internal function used for comparing PPML and non-PPML solutions.Generally, non-developers will not use this function.


imxPenaltyTypes

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxPenaltyTypes

Format

An object of classcharacter of length 3.

Details

Types of regularization penalties.


imxPreprocessModel

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxPreprocessModel(model)

Arguments

model

model


imxReplaceMethod

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxReplaceMethod(x, name, value)

Arguments

x

the thing

name

name

value

value


Replace parts of a model

Description

Replace parts of a model

Usage

imxReplaceModels(model, replacements)

Arguments

model

model

replacements

replacements


imxReplaceSlot

Description

Checks for and replaces a slot from the objectThis is an internal function exported for those people who knowwhat they are doing.

Usage

imxReplaceSlot(x, name, value, check = TRUE)

Arguments

x

object

name

the name of the slot

value

replacement value

check

Check replacement value for validity (default TRUE)


Report backend progress

Description

Prints a show status string to the console without emitting anewline.

Usage

imxReportProgress(info, eraseLen)

Arguments

info

the character string to print

eraseLen

the number of characters to erase

Examples

library(OpenMx)previousLen <<- 0easyReportProcess <- function(msg) {imxReportProgress(msg, previousLen)previousLen <<- nchar(msg)}demo <- function() {easyReportProcess("abc123")Sys.sleep(1)easyReportProcess("this is much longer")Sys.sleep(1)easyReportProcess("this is short")Sys.sleep(1)easyReportProcess("almost done")Sys.sleep(1)easyReportProcess("")cat("DONE!", fill=TRUE)}demo()

imxReservedNames

Description

Vector of reserved names

Usage

imxReservedNames

Format

An object of classcharacter of length 7.


imxReverseIdentifier

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxReverseIdentifier(model, name)

Arguments

model

model

name

name


imxRobustSE

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxRobustSE(model, details = FALSE, dependencyModels = character(0))

Arguments

model

An OpenMx model object that has been run.

details

Logical. whether to return the full parametercovariance matrix.

dependencyModels

Passed toimxRowGradients().

Details

This function computes robust standard errors via a sandwich estimator.The "bread" of the sandwich is the numerically computed inverse Hessianof the likelihood function. This is what is typically used for standarderrors throughout OpenMx. The "meat" of the sandwich is proportional to the covariance matrix of the numerically computed row derivatives of the likelihood function (i.e. row gradients).

Whendetails=FALSE, only the standard errors are returned.

Whendetails=TRUE,a list with five named elements is returned. ElementSE is the vector of standard errors that is also returned whendetails=FALSE.Elementcov is the full robust covariance matrix of the parameter estimates; the square root of the diagonal ofcov gives the standard errors. Elementbread is the aforementioned "bread"–the naive (non-robust) covariance matrix of the parameter estimates. Elementmeat is the aforementioned "meat," proportionalto the covariance matrix of the row gradients. ElementTIC is the model's Takeuchi Information Criterion, which is a generalization of AIC calculated from the "bread," the "meat," and the loglikelihood at the maximum-likelihood solution.

This function does not work correctly with multigroup models in which the groups themselves contain subgroups. This function also does not correctly handlemultilevel data.


imxRowGradients

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxRowGradients(model, robustSE = FALSE, dependencyModels = character(0))

Arguments

model

An OpenMx model object that has been run

robustSE

Logical; are the row gradients being requested to calculate robust standard errors?

dependencyModels

Vector of character strings naming submodels that do not contain data, but contain objects to which data-containing models make reference.

Details

This function computes the gradient for each row of data.The returned object is a matrix with the same number of rows as the data,and the same number of columns as there are free parameters.


imxSameType

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxSameType(a, b)

Arguments

a

a

b

b


imxSeparatorChar

Description

The character between the model name and the named entity insidethe model.

Usage

imxSeparatorChar

Format

An object of classcharacter of length 1.


imxSfClient

Description

As of snowfall 1.84, the snowfall supervisor processstores an internal state information in a variablenamed ".sfOption" that is located in the "snowfall" namespace.The snowfall client processes store internal stateinformation in a variable named ".sfOption" that is locatedin the global namespace.

Usage

imxSfClient()

Details

As long as the previous statement is true, then the currentprocess is a snowfall client if-and-only-if exists(".sfOption").


imxSimpleRAMPredicate

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxSimpleRAMPredicate(model)

Arguments

model

model


Sparse symmetric matrix invert

Description

This API is visible to permit testing. Please do not use.

Usage

imxSparseInvert(mat)

Arguments

mat

the matrix to invert


imxSquareMatrix

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxSquareMatrix(.Object)

Arguments

.Object

.Object


imxStanMathMajor

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxStanMathMajor()

imxSymmetricMatrix

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxSymmetricMatrix(.Object)

Arguments

.Object

.Object


imxTypeName

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxTypeName(model)

Arguments

model

model


imxUntitledName

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxUntitledName()

Details

Returns a character, the name of the next untitled entity


imxUntitledNumber

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxUntitledNumber()

Details

Increments the untitled number counter and returns its value


imxUntitledNumberReset

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxUntitledNumberReset()

Details

Resets theimxUntitledNumber counter


imxUpdateModelValues

Description

Deprecated. This function does not handle parameters with equalityconstraints. Do not use.

Usage

imxUpdateModelValues(model, flatModel, values)

Arguments

model

model

flatModel

flat model

values

values to update


imxVariableTypes

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxVariableTypes

Format

An object of classcharacter of length 2.

Details

The acceptable variable types


imxVerifyMatrix

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxVerifyMatrix(.Object)

Arguments

.Object

.Object


imxVerifyModel

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxVerifyModel(model)

Arguments

model

model


imxVerifyName

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxVerifyName(name, stackNumber)

Arguments

name

name

stackNumber

stackNumber


imxVerifyReference

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

imxVerifyReference(reference, stackNumber)

Arguments

reference

reference

stackNumber

stackNumber


Calculate Chi Square for a WLS Model

Description

This is an internal function used to calculate the Chi Square distributed fit statistic for weighted least squares models.

Usage

imxWlsChiSquare(model, J=NA)

Arguments

model

An MxModel object with acov (WLS) data

J

Optional pre-computed Jacobian matrix

Details

The Chi Square fit statistic for models fit with maximum likelihood depends on the difference in model fit in minus two log likelihood units between the saturated model and the more restricted model under investigation. For models fit with weighted least squares a different expression is required. IfJ is the first derivative (Jacobian) of the mapping from the free parameters to the unique elements of the expected covariance, means, and threholds,J_c is the orthogonal complement ofJ,W is the inverse of the full weight matrix, ande is the difference between the sample-estimated and model-implied covariance, means, and thresholds, then the Chi Square fit statistic is

\chi^2 = e' J_c (J'_c W J_c)^-1 J'_c e

withe' indicating the transpose ofe. This Equation 2.20a from Browne (1984) where he showed that this statistic is chi-square distributed with the conventional degrees of freedom.

Mean and variance adjusted Chi Square statistics are also computed following Asparouhov and Muthen (2006).

Value

A named list with components

Chi

numeric value of the Chi Square fit statistic.

ChiDoF

degrees of freedom for the Chi Square fit statistic.

ChiM

numeric value of the mean adjusted Chi Square fit statistic

ChiMV

numeric value of the mean and variance adjusted Chi Square fit statistic

mAdjust

numeric value of the mean adjustment

mvAdjust

numeric value of the mean and variance adjustment

dstar

adjusted degrees of freedom for the mean and variance adjusted Chi Square fit statistic

References

M. W. Browne. (1984). Asymptotically Distribution-Free Methods for the Analysis of Covariance Structures.British Journal of Mathematical and Statistical Psychology,37, 62-83.

T. Asparouhov and B. O. Muthen. (2006). Robust Chi Square Difference Testing with Mean and Variance Adjusted Test Statistics.Mplus Web Notes: No. 10.


Calculate Standard Errors for a WLS Model

Description

This is an internal function used to calculate standard errors for weighted least squares models.

Usage

imxWlsStandardErrors(model)

Arguments

model

An MxModel object with acov (WLS) data

Details

The standard errors for models fit with maximum likelihood are related to the second derivative (Hessian) of the likelihood function with respect to the free parameters. For models fit with weighted least squares a different expression is required. IfJ is the first derivative (Jacobian) of the mapping from the free parameters to the unique elements of the expected covariance, means, and thresholds,V is the weight matrix used,W is the inverse of the full weight matrix, andU= V J (J' V J)^{-1}, then the asymptotic covariance matrix of the free parameters is

Acov(\theta) = U' W U

withU' indicating the transpose ofU.

Value

A named list with components

SE

The standard errors of the free parameters

Cov

The full covariance matrix of the free parameters. The square root of the diagonal elements of Cov equals SE.

Jac

The Jacobian computed to obtain the standard errors.

References

M. W. Browne. (1984). Asymptotically Distribution-Free Methods for the Analysis of Covariance Structures.British Journal of Mathematical and Statistical Psychology,37, 62-83.

F. Yang-Wallentin, K. G. Jöreskog, & H. Luo. (2010). Confirmatory Factor Analysis of Ordinal Variables with Misspecified Models.Structural Equation Modeling,17, 392-423.


Joint Ordinal and continuous variables to be modeled together

Description

Data set used in some of OpenMx's examples.

Usage

data("jointdata")

Format

A data frame with 250 observations on the following variables.

z1

Continuous variable

z2

Ordinal variable with 2 levels (0, 1)

z3

Continuous variable

z4

Ordinal variable with 4 levels (0, 1, 2, 3)

z5

Ordinal variable with 3 levels (0, 1, 3)

Details

Data generated to test the joint ML algorithm thoroughly.

Source

Simulated.

References

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

Examples

data(jointdata)head(jointdata)

Example data for multiple regression among latent variables

Description

Data set used in some of OpenMx's examples.

Usage

data("latentMultipleRegExample1")

Format

A data frame with 200 observations on the following variables.

X1

Factor 1 indicator

X2

Factor 1 indicator

X3

Factor 1 indicator

X4

Factor 1 indicator

X5

Factor 2 indicator

X6

Factor 2 indicator

X7

Factor 2 indicator

X8

Factor 2 indicator

X9

Factor 3 indicator

X10

Factor 3 indicator

X11

Factor 3 indicator

X12

Factor 3 indicator

Details

Factor 1 strongly predicts factor 3. Factor 2 weakly predicts factor 3.

Source

Simulated.

References

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

Examples

data(latentMultipleRegExample1)round(cor(latentMultipleRegExample1), 2)

Example data for multiple regression among latent variables

Description

Data set used in some of OpenMx's examples.

Usage

data("latentMultipleRegExample2")

Format

A data frame with 200 observations on the following variables.

X1

Factor 1 indicator

X2

Factor 1 indicator

X3

Factor 1 indicator

X4

Factor 1 indicator

X5

Factor 2 indicator

X6

Factor 2 indicator

X7

Factor 2 indicator

X8

Factor 2 indicator

X9

Factor 3 indicator

X10

Factor 3 indicator

X11

Factor 3 indicator

X12

Factor 3 indicator

Details

Factor 1 strongly predicts factor 3. Factor 2 weakly predicts factor 3. Very similar tolatentMultipleRegExample1.

Source

Simulated.

References

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

Examples

data(latentMultipleRegExample2)round(cor(latentMultipleRegExample2), 2)

Respondent-soldiers on four dichotomous items

Description

Data set used in some of OpenMx's examples.

Usage

data("lazarsfeld")

Format

A data frame with 1000 observations on four dichotomous items.

armyrun

In general how do you feel the Army is run?

favatt

Do you think when you are discharged you will [have] a favorable attitude toward the Army?

squaredeal

In general do you feel you yourself have gotten a square deal from the Army?

welfare

Do you feel that the Army is trying its best to look out for the welfare of enlisted men?

frequency

Frequency of response pattern.

Details

A straightforward descriptive analysis of these data shows that negative responses are more numerous except on item 1; and that there is a positive association between each pair of items. A soldier who responds positively to any one item is more likely to respond positively to a second item. Lazarsfeld's analysis is based on the assumption that each soldier can be thought of as belong to one of two latent classes. The probability of positive response to an item is different in one group than in the other. Most importantly, he is willing to assume that for an individual respondent the responses to items are statistically independent.

Source

Lazarsfeld, Paul F. (1950b) "Some Latent Structures", Chapter 11 in Stouffer (1950).

References

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

See Also

http://www.people.vcu.edu/~nhenry/LSA50.htm

Examples

data(lazarsfeld)

Matrix logarithm

Description

Matrix logarithm

Usage

logm(x, tol = .Machine$double.eps)

Arguments

x

matrix

tol

tolerance


Data for multiple regression

Description

Data set used in some of OpenMx's examples.

Usage

data("multiData1")

Format

A data frame with 500 observations on the following variables.

x1
x2
x3
x4
y

Details

x1-x4 are predictor variables, and y is the outcome.

Source

Simulated.

References

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

Examples

data(multiData1)summary(lm(y ~ ., data=multiData1))#results can be replicated in OpenMx.

Create MxAlgebra Object

Description

This function creates a newMxAlgebra. The common use is to compute a value in a model: for instance astandardized value of a parameter, or a parameter which is a function of other values. It is also used inmodels with anmxFitFunctionAlgebra objective function.

note: Unless needed in the model objective, algebras are only computed twice: once at thebeginning and once at the end of running a model, so adding them doesn't often add a lot of overhead.

Usage

mxAlgebra(expression, name = NA, dimnames = NA, ..., fixed = FALSE,          joinKey=as.character(NA), joinModel=as.character(NA),verbose=0L, initial=matrix(as.numeric(NA),1,1),        recompute=c('always','onDemand'))

Arguments

expression

An R expression of OpenMx-supported matrix operators and matrix functions.

name

An optional character string indicating the name of the object.

dimnames

list. The dimnames attribute for the algebra: a listof length 2 giving the row and column names respectively. An emptylist is treated as NULL, and a list of length one as row names. Thelist can be named, and the list names will be used as names for thedimensions.

...

Not used. Forces other arguments to be specified by name.

fixed

Deprecated. Use the ‘recompute’ argument instead.

joinKey

The name of the column in current model's raw data thatis used as a foreign key to match against the primary key inthe joinModel's raw data.

joinModel

The name of the model that this matrix joins against.

verbose

For values greater than zero, enable runtimediagnostics.

initial

a matrix. Whenrecompute='onDemand',you must provide this initial algebra result.

recompute

If ‘onDemand’, this algebra will not be recomputedautomatically when things it depends on change.mxComputeOncecan be used to force it to recompute.

Details

The mxAlgebra function is used to create algebraic expressions that operate on one or moreMxMatrix objects. To evaluate anMxAlgebra object,it must be placed in anMxModel object, along with all referencedMxMatrixobjects and themxFitFunctionAlgebra function.ThemxFitFunctionAlgebra function must reference by name theMxAlgebra object to be evaluated.

Note: f the result for anMxAlgebra depends upon one or more "definition variables" (seemxMatrix()),then the value returned after the call tomxRun() will be computed using the values of those definitionvariables in the first (i.e., first before any automated sorting is done) row of the raw dataset.

The following operators and functions are supported in mxAlgebra:

Operators

solve()

Inversion

t()

Transposition

^

Elementwise powering

%^%

Kronecker powering

+

Addition

-

Subtraction

%*%

Matrix Multiplication

*

Elementwise product

/

Elementwise division

%x%

Kronecker product

%&%

Quadratic product: pre- and post-multiply B by A and its transpose t(A), i.e: A%&% B == A%*% B%*% t(A)

Functions

cov2cor

Convert covariance matrix to correlation matrix

chol

Cholesky Decomposition

cbind

Horizontal adhesion

rbind

Vertical adhesion

colSums

Matrix column sums as a column vector

rowSums

Matrix row sums as a column vector

det

Determinant

tr

Trace

sum

Sum

mean

Arithmetic mean

prod

Product

max

Maximum

min

Min

abs

Absolute value

sin

Sine

sinh

Hyperbolic sine

asin

Arcsine

asinh

Inverse hyperbolic sine

cos

Cosine

cosh

Hyperbolic cosine

acos

Arccosine

acosh

Inverse hyperbolic cosine

tan

Tangent

tanh

Hyperbolic tangent

atan

Arctangent

atanh

Inverse hyperbolic tangent

exp

Exponent

log

Natural Logarithm

mxRobustLog

Robust natural logarithm

sqrt

Square root

p2z

Standard-normal quantile

logp2z

Standard-normal quantile from log probabilities

lgamma

Log-gamma function

lgamma1p

Compute log(gamma(x+1)) accurately for small x

eigenval

Eigenvalues of a square matrix. Usage: eigenval(x); eigenvec(x); ieigenval(x); ieigenvec(x)

rvectorize

Vectorize by row

cvectorize

Vectorize by column

vech

Half-vectorization

vechs

Strict half-vectorization

vech2full

Inverse half-vectorization

vechs2full

Inverse strict half-vectorization

vec2diag

Create matrix from a diagonal vector (similar todiag)

diag2vec

Extract diagonal from matrix (similar todiag)

expm

Matrix Exponential

logm

Matrix Logarithm

omxExponential

Matrix Exponential

omxMnor

Multivariate Normal Integration

omxAllInt

All cells Multivariate Normal Integration

omxNot

Perform unary negation on a matrix

omxAnd

Perform binary and on two matrices

omxOr

Perform binary or on two matrices

omxGreaterThan

Perform binary greater on two matrices

omxLessThan

Perform binary less than on two matrices

omxApproxEquals

Perform binary equals to (within a specified epsilon) on two matrices

omxSelectRows

Filter rows from a matrix

omxSelectCols

Filter columns from a matrix

omxSelectRowsAndCols

Filter rows and columns from a matrix

mxEvaluateOnGrid

Evaluatean algebra on an abscissa grid and collect column results

mpinv

Moore-Penrose Inverse

Ifsolve is used on an uninvertible square matrix in R, viamxEval(), it will fail with an error will; ifsolve is used on an uninvertible square matrix duringruntime, it will fail silently.

mxRobustLog is the same aslog except that it returns -745instead of -Inf for an argument of 0. The value -745 is less thanlog(4.94066e-324), a good approximation of negative infinity because thelog of any number represented as a double will be of smaller absolutemagnitude.

There are also several multi-argument functions usable in MxAlgebras, which apply themselves elementwise to the matrix provided as their first argument. These functions have slightly different usage from theirR counterparts. Their result is always a matrix with the same dimensions as that provided for their first argument. Values must be provided for ALL arguments of these functions, in order. Provide zeroes as logical values ofFALSE, and non-zero numerical values as logical values ofTRUE. For most of these functions, OpenMx cycles over values of arguments other than the first, by column (i.e., in column-major order), to the length of the first argument. Notable exceptions are thelog,log.p, andlower.tail arguments to probability-distribution-related functions, for which only the [1,1] element is used. It is recommended that all arguments after the first be either (1) scalars, or (2) matrices with the same dimensions as the first argument.

Function Arguments Notes
besselI &besselKx,nu,expon.scaled Note that OpenMxdoes cycle over the elements ofexpon.scaled.
besselJ &besselYx,nu
dbetax,shape1,shape2,ncp,log The algorithm for the non-central beta distribution is used for non-negative values ofncp. Negativencp values are ignored, and the algorithm for the central beta distribution is used.
pbetaq,shape1,shape2,ncp,lower.tail,log.p Values ofncp are handled as withdbeta().
dbinomx,size,prob,log
pbinomq,size,prob,lower.tail,log.p
dcauchyx,location,scale,log
pcauchyq,location,scale,lower.tail,log.p
dchisqx,df,ncp,log The algorithm for the non-central chi-square distribution is used for non-negative values ofncp. Negativencp values are ignored, and the algorithm for the central chi-square distribution is used.
pchisqq,df,ncp,lower.tail,log.p Values ofncp are handled as withdchisq().
omxDnbinomx,size,prob,mu,log Exactly one of argumentssize,prob, andmu should be negative, and therefore ignored. Otherwise,mu is ignored, possibly with a warning, and the values ofsize andprob are used, irrespective of whether they are in the parameter space. If onlyprob is negative, the algorithm for the alternativesize-mu parameterization is used. Ifsize is negative, a value forsize is calculated asmu*prob/(1-prob), and the algorithm for thesize-prob parameterization is used (note that this approach is ill-advised whenprob is very close to 0 or 1).
omxPnbinomq,size,prob,mu,lower.tail,log.p Arguments are handled as withomxDnbinom().
dpoisx,lambda,log
ppoisq,lambda,lower.tail,log.p

Value

Returns a newMxAlgebra object.

References

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

See Also

MxAlgebra for the S4 class created by mxAlgebra.mxFitFunctionAlgebra for an objective function which takes an MxAlgebra or MxMatrix object as the function to be minimized.MxMatrix andmxMatrix for objects which may be entered in theexpression argument and the function that creates them. More information about the OpenMx package may be foundhere.

Examples

A <- mxMatrix("Full", nrow = 3, ncol = 3, values=2, name = "A")# Simple example: algebra B simply evaluates to the matrix AB <- mxAlgebra(A, name = "B")# Compute A + BC <- mxAlgebra(A + B, name = "C")# Compute sin(C)D <- mxAlgebra(sin(C), name = "D")# Make a model and evaluate the mxAlgebra object 'D'A <- mxMatrix("Full", nrow = 3, ncol = 3, values=2, name = "A")model <- mxModel(model="AlgebraExample", A, B, C, D )fit   <- mxRun(model)mxEval(D, fit)# Numbers in mxAlgebras are upgraded to 1x1 matrices# Example of Kronecker powering (%^%) and multiplication (%*%)A  <- mxMatrix(type="Full", nrow=3, ncol=3, value=c(1:9), name="A")m1 <- mxModel(model="kron", A, mxAlgebra(A %^% 2, name="KroneckerPower"))mxRun(m1)$KroneckerPower# Running kron# mxAlgebra 'KroneckerPower'# $formula:  A %^% 2# $result:#      [,1] [,2] [,3]# [1,]    1   16   49# [2,]    4   25   64# [3,]    9   36   81

Create MxAlgebra object from a string

Description

Create MxAlgebra object from a string

Usage

mxAlgebraFromString(algString, name = NA, dimnames = NA, ...)

Arguments

algString

the character string to convert into an R expression

name

An optional character string indicating the name of the object.

dimnames

list. The dimnames attribute for the algebra: a list of length 2 giving the row and column names respectively. An empty list is treated as NULL, and a list of length one as row names. The list can be named, and the list names will be used as names for the dimensions.

...

Forwarded verbatim tomxAlgebra

See Also

mxAlgebra

Examples

A <- mxMatrix(values = runif(25), nrow = 5, ncol = 5, name = 'A')B <- mxMatrix(values = runif(25), nrow = 5, ncol = 5, name = 'B')model <- mxModel(A, B, name = 'model',  mxAlgebraFromString("A * (B + A)", name = 'test'))model <- mxRun(model)model[['test']]$resultA$values * (B$values + A$values)

DEPRECATED: Create MxAlgebraObjective Object

Description

WARNING: Objective functions have been deprecated as of OpenMx 2.0.

Please use MxFitFunctionAlgebra() instead. As a temporary workaround, MxAlgebraObjective returns a list containing a NULL MxExpectation object and an MxFitFunctionAlgebra object.

All occurrences of

mxAlgebraObjective(algebra, numObs = NA, numStats = NA)

Should be changed to

mxFitFunctionAlgebra(algebra, numObs = NA, numStats = NA)

Arguments

algebra

A character string indicating the name of anMxAlgebra orMxMatrix object to use for optimization.

numObs

(optional) An adjustment to the total number of observations in the model.

numStats

(optional) An adjustment to the total number of observed statistics in the model.

Details

NOTE: THIS DESCRIPTION IS DEPRECATED. Please change to usingmxFitFunctionAlgebra as shown in the example below.

Fit functions are functions for which free parameter values are chosen such that the value of the objective function is minimized. While the other fit functions in OpenMx require an expectation function for the model, themxAlgebraObjective function uses the referencedMxAlgebra orMxMatrix object as the function to be minimized.

If a model's primary objective function is amxAlgebraObjective objective function, then the referenced algebra in the objective function must return a 1 x 1 matrix (when using OpenMx's default optimizer). There is no restriction on the dimensions of an objective function that is not the primary, or ‘topmost’, objective function.

To evaluate an algebra objective function, place the following objects in aMxModel object: aMxAlgebraObjective,MxAlgebra andMxMatrix entities referenced by theMxAlgebraObjective, and optionalMxBounds andMxConstraint entities. This model may then be evaluated using themxRun function. The results of the optimization may be obtained using themxEval function on the name of theMxAlgebra, after the model has been run.

Value

Returns a list containing a NULL MxExpectation object and an MxFitFunctionAlgebra object. MxFitFunctionAlgebra objects should be included with models with referencedMxAlgebra andMxMatrix objects.

References

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

See Also

mxAlgebra to create an algebra suitable as a reference function to be minimized. More information about the OpenMx package may be foundhere.

Examples

# Create and fit a very simple model that adds two numbers using mxFitFunctionAlgebralibrary(OpenMx)# Create a matrix 'A' with no free parametersA <- mxMatrix('Full', nrow = 1, ncol = 1, values = 1, name = 'A')# Create an algebra 'B', which defines the expression A + AB <- mxAlgebra(A + A, name = 'B')# Define the objective function for algebra 'B'objective <- mxFitFunctionAlgebra('B')# Place the algebra, its associated matrix and # its objective function in a modeltmpModel <- mxModel(model="Addition", A, B, objective)# Evalulate the algebratmpModelOut <- mxRun(tmpModel)# View the resultstmpModelOut$output$minimum

Automatically set starting values for an MxModel

Description

Automatically set starting values for an MxModel

Usage

mxAutoStart(model, type = c("ULS", "DWLS"))

Arguments

model

The MxModel for which starting values are desired

type

The type of starting values to obtain, currently unweighted or diagonally weighted least squares, ULS or DWLS

Details

This function automatically picks very good starting values for many models (RAM, LISREL, Normal), including multiple group versions of these.It works for models with algebras. Models of continuous, ordinal, and joint ordinal-continuous variables are also acceptable.It works for models with covariance or raw data.However, it does not currently work for models with definition variables, state space models, item factor analysis models, or multilevel models; it only works well for GREML models under certain circumstances (see further below).

The method used to obtain new starting values is quite simple. The user's model is changed to an unweighted least squares (ULS) model. The ULS model is estimated and its final point estimates are returned as the new starting values. Optionally, diagonally weighted least squares (DWLS) can be used instead with thetype argument.

Please note that ULS is sensitive to the scales of your variables. For example, if you have variables with means of 20 and variances of 0.001, then ULS will "weight" the means 20,000 times more than the variances and might result in zero variance estimates. Likewise if one variable has a variance of 20 and another has a variance of 0.001, the same problem may arise. To avoid this, make sure your variables are scaled accordingly. You could also usetype='DWLS' to have the function use diagonally weighted least squares to obtain starting values. Of course, using diagonally weighted least squares will take much much longer and will usually not provide better starting values than unweighted least squares.

Also note that ifmodel contains aGREML expectation, argumenttype is ignored, and the function always uses a form of ULS. The function can be very helpful for finding good starting values for GREML MxModels that use an "implicit" (i.e., "specified in terms of covariates viamxExpectationGREML() argumentXvars") model for the phenotypic mean. In contrast, the function is not generally recommended for GREML MxModels that use an "explicit" (i.e., "specified in terms of an MxMatrix or MxAlgebra via argumentyhat") model for the phenotypic mean, and indeed, it can be downright counterproductive in such cases.

Value

an MxModel with new free parameter values

Examples

# Use the frontpage model with negative variances to show better# starting valueslibrary(OpenMx)data(demoOneFactor)latents  = c("G") # the latent factormanifests = names(demoOneFactor) # manifest variables to be modeledm1 <- mxModel("One Factor", type = "RAM",manifestVars = manifests, latentVars = latents,mxPath(from = latents, to = manifests),mxPath(from = manifests, arrows = 2, values=-.2),mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),mxPath(from = "one", to = manifests),mxData(demoOneFactor, type = "raw"))# Starting values imply negative variances!mxGetExpected(m1, 'covariance')# Use mxAutoStart to get much better starting valuesm1s <- mxAutoStart(m1)mxGetExpected(m1s, 'covariance')

mxAvailableOptimizers

Description

List the Optimizers available in this version, e.g. "SLSQP" "CSOLNP"

Usage

mxAvailableOptimizers()

Details

note for advanced users: Special-purpose optimizers like Newton-Raphson or EM are not included in this list.

Value

- list of valid Optimizer names

See Also

-mxOption(model, "Default optimizer")

Examples

mxAvailableOptimizers()

Repeatedly estimate model using resampling with replacement

Description

Bootstrapping is used to quantify the variability of parameter estimates.A new sample is drawn from the model data (uniformly sampling theoriginal data with replacement). The model is re-fitted to this newsample. This process is repeated many times. This yields a series of estimatesfrom these replications which can be used to assess the variability of the parameters.

note:mxBootstrap only bootstraps free model parameters:

To bootstrap algebras, seemxBootstrapEval

To report bootstrapped standardized paths in RAM models,mxBootstrap the model,and then run throughmxBootstrapStdizeRAMpaths

Usage

mxBootstrap(model, replications=200, ...,                        data=NULL, plan=NULL, verbose=0L,                        parallel=TRUE, only=as.integer(NA),OK=mxOption(model, "Status OK"), checkHess=FALSE, unsafe=FALSE)

Arguments

model

The MxModel to be run.

replications

The number of resampling replications. Ifavailable, replications from prior mxBootstrap invocations will be reused.

...

Not used. Forces remaining arguments to be specified by name.

data

A character vector of data or model names

plan

Deprecated

verbose

For levels greater than 0, enables runtime diagnostics

parallel

Whether to process the replications in parallel (not yet implemented!)

only

When provided, only the given replication from a priorrun ofmxBootstrap will be performed. See details.

OK

The set of status code that are considered successful

checkHess

Whether to approximate the Hessian in each replication

unsafe

A boolean indicating whether to ignore errors.

Details

By default, all datasets in the given model are resampledindependently. If resampling is desired from only some ofthe datasets then the models containing them can be listed in the‘data’ parameter.

Thefrequency column in themxData object is usedrepresent a resampled dataset. When resampling, the original rowproportions, as given by the originalfrequency column, arerespected.

When the model has a default compute plan and ‘checkHess’ iskept at FALSE then the Hessian will not be approximated or checked.On the other hand, ‘checkHess’ is TRUE then the Hessian will beapproximated by finite differences. This procedure is of some valuebecause it can be informative to check whether the Hessian is positivedefinite (seemxComputeHessianQuality). However,approximating the Hessian is often costly in terms of CPU time. Forbootstrapping, the parameter estimates derived from the resampled dataare typically of primary interest.

On occasion, replications will fail. Sometimes it can be helpful toexactly reproduce a failed replication to attempt to pinpoint thecause of failure. The ‘only’ option facilitates this kind ofinvestigation. In normal operation, mxBootstrap uses the regular Rrandom number generator to generate a seed for each replication. Thisseed is used to seed an internal pseudorandom number generator(currently the Mersenne Twister algorithm). Theseper-replication seeds are stored as part of the bootstrap output. When‘only’ is specified, the associated stored seed is used to seed theinternal random number generator so that identical weights can beregenerated.

mxBootstrap does not currently offer special support for nested,multilevel, or other dependent data structures.mxBootstrapassumes rows of data are independent. Multilevel models and state spacemodels violate the independence assumption employed bymxBootstrap.By default theunsafe argument prevents multilevel and state spacemodels from usingmxBootstrap; however, settingunsafe=TRUEallows multilevel and state space models to use bootstrapping under the –perhaps foolish – assumption that the user is sufficiently knowledgeable tointerpret the results.

Value

The given model is returned withthe compute plan modified to consist ofmxComputeBootstrap. Results of the bootstrap replications arestored inside the compute plan.mxSummary can be used toobtain per-parameter quantiles and standard errors.

See Also

mxBootstrapEval,mxComputeBootstrap,mxSummary,mxBootstrapStdizeRAMpaths,as.statusCode

Examples

library(OpenMx)data(multiData1)manifests <- c("x1", "x2", "y")biRegModelRaw <- mxModel(  "Regression of y on x1 and x2",  type="RAM",  manifestVars=manifests,  mxPath(from=c("x1","x2"), to="y",          arrows=1,          free=TRUE, values=.2, labels=c("b1", "b2")),  mxPath(from=manifests,          arrows=2,          free=TRUE, values=.8,          labels=c("VarX1", "VarX2", "VarE")),  mxPath(from="x1", to="x2",         arrows=2,          free=TRUE, values=.2,          labels=c("CovX1X2")),  mxPath(from="one", to=manifests,          arrows=1, free=TRUE, values=.1,          labels=c("MeanX1", "MeanX2", "MeanY")),  mxData(observed=multiData1, type="raw"))biRegModelRawOut <- mxRun(biRegModelRaw)boot <- mxBootstrap(biRegModelRawOut, 10)   # start with 10summary(boot)# Looks good, now do the restboot <- mxBootstrap(boot)summary(boot)# examine replication 3boot3 <- mxBootstrap(boot, only=3)print(coef(boot3))print(boot$compute$output$raw[3,names(coef(boot3))])

Evaluate Values in a bootstrapped MxModel

Description

This function can be used to evaluate an arbitrary R expression that includes named entities from aMxModel object, or labels from aMxMatrix object.

Usage

mxBootstrapEval(expression, model, defvar.row = 1, ..., bq=c(.25,.75), method=c('bcbci','quantile'))mxBootstrapEvalByName(name, model, defvar.row = 1, ..., bq=c(.25,.75), method=c('bcbci','quantile'))omxBootstrapEval(expression, model, defvar.row = 1L, ...)omxBootstrapEvalCov(expression, model, defvar.row = 1L, ...)omxBootstrapEvalByName(name, model, defvar.row=1L, ...)

Arguments

expression

An arbitrary R expression.

name

The character name of an object to evaluate.

model

The model in which to evaluate the expression.

defvar.row

The row to use for definition variables when compute=TRUE (defaults to 1). When compute=FALSE, values for definition variables are always taken from the first (i.e., first before any automated sorting is done) row of the raw data.

...

Not used. Forces remaining arguments to be specified by name.

bq

numeric. A vector of bootstrap quantiles at which to summarize the bootstrap replication.

method

character. One of ‘quantile’ or ‘bcbci’.

Details

The argument ‘expression’ is an arbitrary R expression. Any named entities that are used within the R expression are translated into their current value from the model. Any labels from the matrices within the model are translated into their current value from the model. Finally the expression is evaluated and the result is returned. To enable debugging, the ‘show’ argument has been provided. The most common mistake when using this function is to include named entities in the model that are identical to R function names. For example, if a model contains a named entity named ‘c’, then the following mxEval call will return an error:mxEval(c(A, B, C), model).

ThemxEvalByName function is a wrapper aroundmxEval that takes a character instead of an R expression.

nb: ‘bcbci’ stands for ‘bias-corrected bootstrap confidence interval’

The default behavior is to use the ‘bcbci’method, due to its superior theoretical properties.

Value

omxBootstrapEval andomxBootstrapEvalByName return the raw matrix ofcvectorize'd results.omxBootstrapEvalCov returns thecovariance matrix of thecvectorize'd results.mxBootstrapEval andmxBootstrapEvalByName returnthecvectorize'd results summarized bymethod at quantilesbq.

References

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

See Also

mxAlgebra to create algebraic expressions inside your model andmxModel for the model object mxEval looks inside whenevaluating.mxBootstrap to create bootstrap data.

Examples

library(OpenMx)# make a unit-weighted 10-row data set of values 1 thru 10myData = mxData(data.frame(weight=1.0, value=1:10), "raw", weight = "weight")sum(1:10)# Model sums data$value (sum(1:10)= 55), subtracts "A", squares the result, # and tries to minimize this (achieved by setting A=55)testModel = mxModel(model = "testModel1", myData,mxMatrix(name  = "A", "Full", nrow = 1, ncol = 1, values = 1, free=TRUE),# nb: filteredDataRow is an auto-generated matrix of# non-missing data from the present row.# This is placed into the "rowResults" matrix (also auto-generated)mxAlgebra(name = "rowAlg", data.weight * filteredDataRow),# Algebra to turn the rowResults into a single numbermxAlgebra(name = "reduceAlg", (sum(rowResults) - A)^2),mxFitFunctionRow(rowAlgebra    = "rowAlg",reduceAlgebra = "reduceAlg",dimnames      = "value")# no need for an MxExpectation object when using mxFitFunctionRow)testModel = mxRun(testModel) # A is estimated at 55, with SE= 1testBoot = mxBootstrap(testModel)summary(testBoot) # A is estimated at 55, with SE= 0# Let's compute A^2 (55^2 = 3025)mxBootstrapEval(A^2, testBoot)#      SE 25.0% 75.0%# [1,]  0  3025  3025

Bootstrap distribution of standardized RAM path coefficients

Description

Uses the distribution of a bootstrapped RAM model's raw parameters to create a bootstrapped estimate of its standardized path coefficients.

note: Model must have already been run throughmxBootstrap.

Usage

mxBootstrapStdizeRAMpaths(model, bq= c(.25, .75), method= c('bcbci','quantile'), returnRaw= FALSE)

Arguments

model

An MxModel that usesRAM expectation and has already been run throughmxBootstrap.

bq

vector of 2 bootstrap quantiles corresponding to the lower and upper limits of the desired confidence interval.

method

One of 'bcbci' or 'quantile'.

returnRaw

Whether or not to return the raw bootstrapping results (Defaults toFALSE: returning a dataframe summarizing the results).

Details

mxBootstrapStdizeRAMpaths appliesmxStandardizeRAMpaths to each bootstrap replication, thus creating a distribution of standardized estimates for each nonzero path coefficient.

The defaultbq (bootstrap quantiles) of c(.25, .75) correspond to a 50% CI. This default is chosen as many morebootstraps are required to accurately estimate more extreme quantiles. For a 95% CI, usebq=c(.025,.0975).

nb: ‘bcbci’ stands for ‘bias-corrected bootstrap confidence interval’ To learn more about bcbci and quantile methods, see Efron (1982)and Efron and Tibshirani (1994).

note 1: It is possible (though unlikely) that the number of nonzero paths (elements of theA andS RAM matrices) may vary among bootstrap replications. This precludes a simple summary of the standardized paths' bootstrapping results. In this rare case, ifreturnRaw=TRUE, a raw list of bootstrapping results is returned, with a warning. Otherwise an error is thrown.

note 2:mxBootstrapStdizeRAMpaths ignores sub-models. To standardize bootstrapped sub-models, run it on the sub-models directly.

Value

IfreturnRaw=FALSE (default), it returns a dataframe containing, among other things, the standardized path coefficients as estimated from the real data, their bootstrap SEs, and the lower and upper limits of a bootstrap confidence interval. IfreturnRaw=TRUE, typically, a matrix containing the raw bootstrap results is returned; this matrix has one column per non-zero path coefficient, and one row for each successfully converged bootstrap replication or, if the number of paths varies between bootstraps, a raw list of results is returned.

References

Efron B. (1982).The Jackknife, the Bootstrap, and Other Resampling Plans. Philadelphia: Society for Industrial and Applied Mathematics.

Efron B, Tibshirani RJ. (1994).An Introduction to the Bootstrap. Boca Raton: Chapman & Hall/CRC.

See Also

mxBootstrap(),mxStandardizeRAMpaths(),mxBootstrapEval,mxSummary

Examples

require(OpenMx)data(myFADataRaw)manifests = c("x1","x2","x3","x4","x5","x6")# Build and run 1-factor raw-data CFAm1 = mxModel("CFA", type="RAM", manifestVars=manifests, latentVars="F1",# Factor loadingsmxPath("F1", to = manifests, values=1),# Means and variances of F1 and manifestsmxPath(from="F1", arrows=2, free=FALSE, values=1), # fix var  F1 @1mxPath("one", to= "F1", free= FALSE, values = 0),  # fix mean F1 @0# Freely-estimate means and residual variances of manifestsmxPath(from = manifests, arrows=2, free=TRUE, values=1),mxPath("one", to= manifests, values = 1),mxData(myFADataRaw, type="raw"))m1 = mxRun(m1)set.seed(170505) # Desirable for reproducibility# ==========================# = 1. Bootstrap the model =# ==========================m1_booted = mxBootstrap(m1)# =================================================# = 2. Estimate and accumulate a distribution of  =# =    standardized values from each bootstrap.   =# =================================================tmp = mxBootstrapStdizeRAMpaths(m1_booted)#          name label matrix row col Std.Value    Boot.SE     25.0%     75.0%# 1  CFA.A[1,7]    NA      A  x1  F1 0.8049842 0.01583737 0.7899938 0.8124311# 2  CFA.A[2,7]    NA      A  x2  F1 0.7935255 0.01373320 0.7865666 0.8045558# 3  CFA.A[3,7]    NA      A  x3  F1 0.7772050 0.01629684 0.7698374 0.7907878# 4  CFA.A[4,7]    NA      A  x4  F1 0.8248493 0.01315534 0.8150299 0.8351416# 5  CFA.A[5,7]    NA      A  x5  F1 0.7995083 0.01479210 0.7869158 0.8057788# 6  CFA.A[6,7]    NA      A  x6  F1 0.8126734 0.01527586 0.8012809 0.8218805# 7  CFA.S[1,1]    NA      S  x1  x1 0.3520004 0.02546392 0.3399556 0.3759097# 8  CFA.S[2,2]    NA      S  x2  x2 0.3703173 0.02171159 0.3526899 0.3813130# 9  CFA.S[3,3]    NA      S  x3  x3 0.3959524 0.02529583 0.3746547 0.4073505# 10 CFA.S[4,4]    NA      S  x4  x4 0.3196237 0.02163979 0.3025384 0.3357263# 11 CFA.S[5,5]    NA      S  x5  x5 0.3607865 0.02364008 0.3507206 0.3807635# 12 CFA.S[6,6]    NA      S  x6  x6 0.3395619 0.02476480 0.3245124 0.3579489# 13 CFA.S[7,7]    NA      S  F1  F1 1.0000000 0.00000000 1.0000000 1.0000000# 14 CFA.M[1,1]    NA      M   1  x1 2.9950397 0.08745209 2.9368758 3.0430917# 15 CFA.M[1,2]    NA      M   1  x2 2.9775235 0.07719970 2.9109289 3.0197492# 16 CFA.M[1,3]    NA      M   1  x3 3.0133665 0.08645522 2.9598062 3.0779683# 17 CFA.M[1,4]    NA      M   1  x4 3.0505604 0.08210810 2.9952130 3.1103674# 18 CFA.M[1,5]    NA      M   1  x5 2.9776983 0.07973619 2.9362410 3.0311999# 19 CFA.M[1,6]    NA      M   1  x6 2.9830050 0.07632118 2.9360469 3.0416504

Create MxBounds Object

Description

This function creates a newMxBounds object.

Usage

mxBounds(parameters, min = NA, max = NA)

Arguments

parameters

A character vector indicating the names of the parameters on which to apply bounds.

min

A numeric value for the lower bound. NA means use default value.

max

A numeric value for the upper bound. NA means use default value.

Details

Creates a set of boundaries or limits for a parameter or set of parameters. Parameters may be any free parameter or parameters from anMxMatrix object. Parameters may be referenced either by name or by referring to their position in the 'spec' matrix of anMxMatrix object.

Minima and maxima may be specified as scalar numeric values.

Value

Returns a newMxBounds object. If used as an argument in anMxModel object, the parameters referenced in the 'parameters' argument must also be included prior to optimization.

References

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

See Also

MxBounds for the S4 class created by mxBounds.MxMatrix andmxMatrix for free parameter specification. More information about the OpenMx package may be foundhere.

Examples

#Create lower and upper bounds for parameters 'A' and 'B'bounds <- mxBounds(c('A', 'B'), 3, 5)#Create a lower bound of zero for a set of variance parametersvarianceBounds <- mxBounds(c('Var1', 'Var2', 'Var3'), 0)

Create mxCI Object

Description

This function creates a newMxCI object, which allows estimation of likelihood-based confidence intervals in a model(note: to estimate SEs around arbitrary objects, seemxSE)

Usage

mxCI(reference, interval = 0.95, type=c("both", "lower", "upper"), ..., boundAdj=TRUE)

Arguments

reference

A character vector of free parameters, mxMatrices, mxMatrix elements and mxAlgebras on which confidence intervals are to be estimated, listed by name.

interval

A scalar numeric value indicating the confidence interval to be estimated. Must be between 0 and 1. Defaults to 0.95.

type

A character string indicating whether the upper, lower or both confidence limits are returned. Defaults to "both".

...

Not used. Forces remaining arguments to be specified byname.

boundAdj

Whether to correct the likelihood-based confidenceintervals for a lower or upper bound.

Details

The mxCI function createsMxCI objects, which can be used as arguments inMxModel objects. When models containingMxCI objects are optimized usingmxRun with the ‘intervals’ argument set to TRUE, likelihood-based confidence intervals are returned. The likelihood-based confidence intervals calculated byMxCI objects are symmetric with respect to the change in likelihood in either direction, and are not necessarily symmetric around the parameter estimate. Estimation of confidence intervals requires both that anMxCI object be included in the model and that the ‘intervals’ argument of themxRun function is set to TRUE. When estimated, confidence intervals can be accessed in the model output at$output$confidenceIntervals or by usingsummary on a fittedMxModel object.

In all cases, a two-sided hypothesis test is assumed.Therefore, the upper bound willexclude 2.5% (for interval=0.95) even though only one bound isrequested. To obtain a one-sided CI for a one-sided hypothesis test,interval=0.90 will obtain a 95% confidence interval.

When a confidence interval is requested for a free parameter (not analgebra) constrained by a lower bound or an upper bound (but not both)andboundAdj=TRUE then the Wu & Neale (2012) correction is used.This improves the accuracy of the confidence interval when the parameteris estimated close to the bound. For example, this correction will beactivated when a variance with a lower bound of10^{-6} and noupper bound that is estimated close to the bound. The sample size, ormore precisely effective sample size for that particular parameter, willdetermine how close the variance needs to be to the bound at10^{-6} to activate the correction.

The likelihood-based confidence intervals returned usingMxCI are obtained by increasing or decreasing the value of each parameter until the -2 log likelihood of the model increases by an amount corresponding to the requested interval. The confidence limit specified by the ‘interval’ argument is transformed into a corresponding difference in the model -2 log likelihood based on the likelihood ratio test. Thus, a requested confidence interval for a parameter will first determine the corresponding quantile from the chi-squared distribution with one degree of freedom (a value of 3.841459 when a 95 percent confidence interval is requested). That quantile will be populated into either the ‘lowerdelta’ slot, the ‘upperdelta’ slot, or both in the outputMxCI object.

Estimation of likelihood-based confidence intervals begins after optimization has been completed, with each parameter moved in the direction(s) specified in the ‘type’ argument until the specified increase in -2 log likelihood is reached. All other free parameters are left free for this stage of optimization. This process repeats until all confidence intervals have been calculated. The calculation of likelihood-based confidence intervals can be computationally intensive, and may add a significant amount of time to model estimation when many confidence intervals are requested.

Multiple parameters,MxMatrices andMxAlgebras may be listed in the ‘reference’ argument. Individual elements ofMxMatrices andMxAlgebras may be listed as well, using the syntax “matrix[row,col]” (seeExtract for more information). Only scalar numeric values for the ‘interval’ argument are supported. Users requesting different confidence ranges for different parameters must use separatemxCI statements.MxModel objects can hold multipleMxCI objects, but only one confidence interval may be requested per named-entity.

Confidence interval estimation may result in model non-convergence at the confidence limit. Separate optimizer messages may be passed for each confidence limit. This has no impact on the parameter estimates themselves, but may indicate a problem with the referenced confidence limit. Model non-convergence for a particular confidence limit may indicate parameter interdependence or the influence of a parameter boundary.

These error messages and their meanings are listed in the help formxSummary

The validity of a confidence limit can be checked by running a model with the appropriate parameter fixed at the confidence limit in question. If the confidence limit is valid, the -2 log likelihoods of these two models should differ by the specified chi-squared criterion (as set using the ‘lowerdelta’ or ‘upperdelta’ slots in theMxCI object (you can choose which of these to set via the type parameter of mxCI).

Value

Returns a newMxCI object. If used as an argument in anMxModel object, the parameters,MxMatrices andMxAlgebras listed in the 'reference' argument must also be included prior to optimization.

References

The OpenMx User's guide can be found athttps://openmx.ssri.psu.edu/documentation/. Additional support for mxCI() can be found on the OpenMx wiki at http://openmx.ssri.psu.edu/wiki.

Neale, M. C. & Miller M. B. (1997). The use of likelihood basedconfidence intervals in genetic models.Behavior Genetics,27(2), 113-120.

Pek, J. & Wu, H. (2015). Profile likelihood-based confidence intervalsand regions for structural equation models.Psychometrika,80(4), 1123-1145.

Wu, H. & Neale, M. C. (2012). Adjusted confidence intervals for abounded parameter.Behavior genetics, 42(6), 886-898.

See Also

mxSE for computing SEs around arbitrary objects.mxComputeConfidenceInterval is the internal compute plan that implements the algorithm.MxMatrix andmxMatrix for free parameter specification.MxCI for the S4 class created by mxCI.More information about the OpenMx package may be foundhere.

Examples

library(OpenMx)# generate datacovariance <- matrix(c(1.0, 0.5, 0.5, 1.0),     nrow=2,     dimnames=list(c("a", "b"), c("a", "b")))    data <- mxData(covariance, "cov", numObs=100)# create an expected covariance matrixexpect <- mxMatrix("Symm", 2, 2,    free=TRUE,    values=c(1, .5, 1),    labels=c("var1", "cov12", "var2"),    name="expectedCov")# request 95 percent confidence intervals   ci <- mxCI(c("var1", "cov12", "var2"))# specify the modelmodel <- mxModel(model="Confidence Interval Example",    data, expect, ci,    mxExpectationNormal("expectedCov", dimnames=c("a", "b")),    mxFitFunctionML())# run the model results <- mxRun(model, intervals=TRUE)# view confidence intervalsprint(summary(results)$CI)# view all resultssummary(results)# remove a specific mxCI from a modelmodel <- mxModel(model, remove=TRUE, model$intervals[['cov12']])model$intervals# remove all mxCI from a modelmodel <- mxModel(model, remove=TRUE, model$intervals)model$intervals

Check that a model is locally identified

Description

Use the dimension of the null space of the Jacobian to determine whether or not a model is identified local to its current parameter values.The output is a list of the the identification status, the Jacobian, and which parameters are not identified. May give inaccurate results withGREML expectations (see "Details" below).

Usage

mxCheckIdentification(model, details=TRUE, nrows=2, exhaustive=FALSE, silent=FALSE)

Arguments

model

A MxModel object or list of MxModel objects.

details

logical.

nrows

numeric. The maximum number of unique definition variable rows used to evaluate identification.

exhaustive

logical. Whether to use all of nrows (TRUE), or tostop evaluating new rows once the model is identified (FALSE).

silent

logical. Whether or not to print helpful-but-longmessages. silent=TRUE does not print messages.

Details

The mxCheckIdentification function is used to check that a model is identified. That is, the function will tell you if the model has a unique solution in parameter space. The function is most useful when applied to either (a) a model that has been run and had some NA standard errors, or (b) a model that has not been run but has reasonable starting values. In the former situation, mxCheckIdentification is used as a diagnostic after a problem was indicated. In the latter situation, mxCheckIdentification is used as a sanity check.

The method uses the Jacobian of the model expected means and the unique elements of the expected covariance matrix with respect to the free parameters. It is the first derivative of the mapping between the free parameters and the sufficient statistics for the Normal distribution. The method does not depend on data, but does depend on the current values of the free parameters. Thus, it only provides local identification, not global identification.You might get different answers about model identification depending on the free parameter values. Because the method does not depend on data, the model still could be empirically unidentified due to missing data.

The Jacobian is evaluated numerically and generally takes a few seconds, but much less than a minute.

Model identification should be accurate for models with linear ornonlinear equality and inequality constraints. When there areconstraints, mxCheckIdentification uses the Jacobian of the summarystatistics with respect to the free parameters and the Jacobian of thesummary statistics with respect to the constraints. The combinedextended Jacobian must have rank equal to the number of free parametersfor the model to be identified. So, a model can be identified withconstraints that is not identified without constraints.

Model identification should also be accurate for multiple group modelsand models with definition variables. In the case of multiple groups,the Jacobian is computed for each group and they are concatenated:summary statistics for each group go down the rows of the Jacobian; thesingle set of free parameters go across the columns of the Jacobian. Inthe case of definition variables, a new set of summary statistics iscomputed for each unique set of definition variable values; thuscreating a kind of pseudo-multiple group model for each set of uniquedefinition variable values.

For models using definition variables, the additional arguments 'nrows'and 'exhaustive' provide instruction for how to search foridentification. In principle, full model identification for models withdefinition variables requires evaluating the Jacobian of the mappingbetween the free parameters and the summary statisticsfor everyunique combination of definition variable values. This evaluationcan take a long time. However, in practice, the vast majority of modelsare identified after evaluating one or two definition variable rows.The current defaults attempt to capitalize on this practical situation.By default 'mxCheckIdentification' will evaluate up to 2 unique definitionvariable rows, but will stop once the model is identified. To keepevaluating unique definition variable values until the model isidentified or you run out of rows, setnrows=Inf. To evaluateall unique definition variable values, setnrows=Inf andexhaustive=TRUE.

When TRUE, the 'details' argument provides the names of the non-identified parameters. Otherwise, only the status and Jacobian are returned.

For most models with aGREML expectation, the function will run slowly, and use ofdetail=TRUE is therefore not recommended. Additionally, for GREMLMxModels that use an "implicit" (i.e., "specified in terms of covariates viamxExpectationGREML() argumentXvars") model for the phenotypic mean, there are forms of unidentification that the function cannot (yet) detect, and it therefore may give false-positive reports of local identification.

Value

A named list with components

status

logical. TRUE if the model is locally identified; otherwise FALSE.

jacobian

matrix. The numerically evaluated Jacobian.

non_identified_parameters

vector. The free parameter names that are not identified

References

Bekker, P.A., Merckens, A., Wansbeek, T.J. (1994). Identification, Equivalent Models and Computer Algebra. Academic Press: Orlando, FL.

Bollen, K. A. & Bauldry, S. (2010). Model Identification and Computer Algebra. Sociological Methods & Research, 39, p. 127-156.

See Also

mxModel

Examples

require(OpenMx)data(demoOneFactor)manifests <- names(demoOneFactor)latents <- "G1"model2 <- mxModel(model="One Factor", type="RAM",      manifestVars = manifests,      latentVars = latents,      mxPath(from = latents[1], to=manifests[1:5]),      mxPath(from = manifests, arrows = 2, lbound=1e-6),      mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),      mxData(cov(demoOneFactor), type = "cov", numObs=500))fit2 <- mxRun(model2)id2 <- mxCheckIdentification(fit2)id2$status# The model is locally identified# Build a model from the solution of the previous one#  but now the factor variance is also freemodel2n <- mxModel(fit2, name="Non Identified Two Factor",      mxPath(from=latents[1], arrows=2, free=TRUE, values=1))mid2 <- mxCheckIdentification(model2n)mid2$non_identified_parameters# The factor loadings and factor variance#  are not identified.

Likelihood ratio test

Description

Compare the fit of one or more models to that of a reference (base) model or set of reference models.

Usage

mxCompare(base, comparison, ..., all = FALSE,  boot=FALSE, replications=400, previousRun=NULL, checkHess=FALSE)mxCompareMatrix(models,    diag=c('minus2LL','ep','df','AIC'),    stat=c('p', 'diffLL','diffdf'), ...,  boot=FALSE, replications=400, previousRun=NULL, checkHess=FALSE, wholeTable=FALSE)

Arguments

base

A MxModel object or list of MxModel objects.

comparison

A MxModel object or list of MxModel objects.

models

A MxModel object or list of MxModel objects.

diag

statistic used for diagonal entries

stat

statistic used for off-diagonal entries

...

Not used.

all

Boolean. Whether to compare all base models with all comparison models. Defaults to FALSE.

boot

Whether to use the bootstrap distribution to compute the p-value.

replications

How many replications to use to approximate the bootstrap distribution.

previousRun

Results to re-use from a previous bootstrap.

checkHess

Whether to approximate the Hessian in each replication

wholeTable

Return the whole table instead of a matrix shaped summary

Details

mxCompare is used to compare the fit of one or moremxModels to one or more comparison models.mxCompareMatrix compares all the models provided against each other.

Model comparisons are made by subtracting the fit statistics for the comparison model from the fit statistics for the base model. Raw fit statistics of each ‘base’ model are also listed in the output table.

The fit statistics compared depend on the kinds of models compared. Models fit with maximum likelihood are compared based on their minus two log likelihood values. Under certain regularity conditions, the difference in minus two log likelihood values from nested models is chi-squared distributed and forms a likelihood ratio test statistic. Models fit with weighted least squares are compared based on their Satorra-Bentler (2001) scaled difference chi-squared test statistics. Under full weighted least squares, the Satorra-Bentler chi-squared value is equal to the difference in the model chi-squared values; however, for unweighted and diagonally weighted least squares, the two are no longer equal. Satorra and Bentler (2001) showed that that their test statistic behaved well under a variety of conditions, including small sample sizes. By contrast the much simpler difference in the chi-squared statistics only behaved well under large sample sizes (e.g., greater than or equal to 300 rows of data).

Specific to weighted least squares, researchers sometimes use mean-adjusted chi-squared statistics and mean-and-variance scaled chi-squared statistics. Some programs call these WLSM and WLSMV statistics. In some cases, it is fine to evaluate the total fit of a model using adjusted and scaled chi-squared statistics. However, never, ever, ever, ..., ever take differences in mean-adjusted chi-squared statistics, and use them for nested model comparisons. Similarly, never, ever, ever, ..., ever, ever take differences in mean-and-variance scaled chi-squared statistics, and use them for nested model comparisons. The differences in these adjusted and scaled chi-squared statistics are not chi-squared distributed and do not form a valid basis for model comparison. So, just don't do it.

Although not always checked bymxCompare, you should never compare models with different data sets or that use different variables from the same data set.mxCompare might not stop you from doing this, so be thoughtful when comparing models. Make sure your models are nested and use the same data. Weighted least squares models are one case of comparing different data sets that requires particular care.When comparing WLS models, make sure you are using the same exogenous covariates for all compared models. Because WLS is a multi-stage estimation approach, exogenous covariates residualize and change the data fitted in WLS. Consequently, WLS models with different exogenous covariates actually have different data. By contrast, maximum likelihood models with different exogenous covariates still use the same data and are valid to compare.

ThemxCompare function makes an effort to only make valid comparisons.If a comparison is made where thecomparison model has ahigher minus 2 log likelihood (-2LL) than thebase model, then thedifference in their -2LLs will be negative. P-values for likelihoodratio tests will not be reported when either the -2LL or degrees offreedom for the comparison are negative. To ensure that the differences between models are positive and yield p-values for likelihood ratiotests, models listed in the ‘base’ argument mustbe more saturated (i.e., more estimated parameters and fewer degrees offreedom) than models listed in the ‘comparison’ argument. FormxCompareMatrix only the comparisons that make sense will be included.

When multiple models are included in both the ‘base’ and ‘comparison’ arguments, then comparisons are made between the two lists of models based on the value of the ‘all’ argument. If ‘all’ is set to FALSE (default), then the first model in the ‘base’ list is compared to the first model in the ‘comparison’ list, second with second, and so on. If there are an unequal number of ‘base’ and ‘comparison’ models, then the shorter list of models is repeated to match the length of the longer list. For example, comparing base models ‘B1’ and ‘B2’ with comparison models ‘C1’, ‘C2’ and ‘C3’ will yield three comparisons: ‘B1’ with ‘C1’, ‘B2’ with ‘C2’, and ‘B1’ with ‘C3’. Each of those comparisons are prefaced by a comparison between the base model and a missing comparison model to present the fit of the base model.

If ‘all’ is set to TRUE, all possible comparisons between base and comparison models are made, and one entry is made for each base model. All comparisons involving the first model in ‘base’ are made first, followed by all comparisons with the second ‘base’ model, and so on. When there are multiple models in either the ‘base’ or ‘comparison’ arguments but not both, then the ‘all’ argument does not affect the set of comparisons made.

The following columns appear in the output for maximum likelihood comparisons:

base

Name of the base model.

comparison

Name of the comparison model. Is <NA> for the first

ep

Estimated parameters of the comparison model.

minus2LL

Minus 2*log-likelihood of the comparison model. If the comparison model is <NA>, then the minus 2*log-likelihood of the base model is given.

df

Degrees in freedom of the comparison model. If the comparison model is <NA>, then the degrees of freedom of the base model is given.

AIC

Akaike's Information Criterion for the comparison model. If the comparison model is <NA>, then the AIC of the base model is given.

diffLL

Difference in minus 2*log-likelihoods of the base and comparison models. Will be positive when base model -2LL is higher than comparison model -2LL.

diffdf

Difference in degrees of freedoms of the base and comparison models. Will be positive when base model DF is lower than comparison model DF (base model estimated parameters is higher than comparison model estimated parameters)

p

P-value for likelihood ratio test based on diffLL and diffdf values.

Weighted least squares reports a similar set of columns with four substitutions:

chisq

Replaces theminus2LL column. This is the comparison model's chi-squared statistic from Browne (1984, Equation 2.20a), accounting for some misspecification of the weight matrix.

AIC

Although this has the same name as that in maximum likelihood, it is really a pseudo-AIC using the comparison model chi-squared and the number of estimated parameters. It is the chi-squared value plus two times the number of free parameters.

SBchisq

Replaces thediffLL column. This is the Satorra-Bentler (2001, p. 511) scaled difference chi-squared statisic between the base model and the comparison model. If your models use full weighted least squares, then this will be the same as the difference between the individual model chi-squared statistics. However, for unweighted and diagonally weighted least square, theSB chisq will not be equal to the difference between the component model chi-squared statistics.

p

p-value for the Satorra-Bentler chi-squared statistic.

In addition to the particular columns for maximum likelihood and weighted least squares, there are three general columns that are not printed but are accessible via the$ and[ extractors.

fit

The individual model fit value:m2ll for maximum likelihood models,chisq for WLS models.

fitUnits

The units of the fit function:"-2LL" for ML models,"r'Wr" for WLS models.

diffFit

The difference in fit values between the base and comparison models:diffLL for ML models,SBchisq for WLS models.

mxCompare will give a p-value for any comparison in whichboth ‘diffLL’ and ‘diffdf’ are non-negative. However, thisp-value is based on the assumptions of the likelihood ratio test,specifically that the two models being compared are nested. Thelikelihood ratio test and associated p-values are not valid when thecomparison model is not nested in the referenced base model. For a moreaccurate p-value, the empirical bootstrap distribution can be computed(‘boot=TRUE’). However, ‘replications’ must be set highenough for an accurate approximation. The Monte Carlo SE of a proportionfor B replications is\sqrt(p*(1-p)/B), but this will be zero if pis zero, which is nonsense. Note that a parametric-bootstrap p-value ofzero must be interpreted asp < 1/B, which, depending onBand the desired Type I error rate, may not be "statistically significant."

When ‘boot=TRUE’, the model has a default compute plan, and‘checkHess’ is kept at FALSE then the Hessian will not beapproximated or checked. On the other hand, ‘checkHess’ is TRUEthen the Hessian will be approximated by finite differences. Thisprocedure is of some value because it can be informative to checkwhether the Hessian is positive definite (seemxComputeHessianQuality). However, approximating theHessian is often costly in terms of CPU time. For bootstrapping, theparameter estimates derived from the resampled data are typically ofprimary interest.

note: The mxCompare function does not directly accept a digits argument, and dependson the value of the 'digits' option. To set the minimum number of significant digitsprinted, use options('digits' = N) (see example).

Value

Returns a newMxCompare object. If you want something more like a table of results, useas.data.frame() on the returnedMxCompare object.

See Also

mxPowerSearch;mxModel;options (use options('mxOptions') to see all the OpenMx-specific options)

Examples

data(demoOneFactor)manifests <- names(demoOneFactor)latents <- "G1"model1 <- mxModel(model="One Factor", type="RAM",      manifestVars = manifests,      latentVars = latents,      mxPath(from = latents, to=manifests),      mxPath(from = manifests, arrows = 2),      mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),      mxData(cov(demoOneFactor), type = "cov", numObs = 500))fit1 <- mxRun(model1)latents <- c("G1", "G2")model2 <- mxModel(model="One factor Rasch equated", type="RAM",      manifestVars = manifests,      latentVars = latents,      mxPath(from = latents[1], to=manifests[1:5], labels='raschEquated'),      mxPath(from = manifests, arrows = 2),      mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),      mxData(cov(demoOneFactor), type = "cov", numObs=500))fit2 <- mxRun(model2)mxCompare(fit1, fit2) # Rasch equated is significantly worse# Vary precision (rounding) of the table oldPrecision = as.numeric(options('digits')) options('digits' = 1)mxCompare(fit1, fit2)options('digits' = oldPrecision)

Repeatedly estimate model using resampling with replacement

Description

This is a low-level compute plan object to performresampling with replacement.

Usage

mxComputeBootstrap(data, plan, replications=200, ...,                        verbose=0L, parallel=TRUE, freeSet=NA_character_,OK=c("OK", "OK/green"), only=NA_integer_)

Arguments

data

A vector of dataset or model names.

plan

The compute plan used to optimize the model for each dataset.

replications

The number of resampling replications. Ifavailable, replications from prior mxBootstrap invocations will be reused.

...

Not used. Forces remaining arguments to be specified by name.

verbose

For levels greater than 0, enables runtime diagnostics

parallel

Whether to process the replications in parallel

freeSet

names of matrices containing free variables

OK

The set of status code that are considered successful

only

When provided, only the given replication from a priorrun ofmxBootstrap will be performed. See details.

Details

The ‘only’ option facilitates investigation of a singlereplication attempt.

Value

Output is stored in the compute object'soutputslot. Specifically,model$compute$output$raw contains a dataframe with parameters in columns and replications in rows. In additionto parameters, theseed,fit, andstatusCodeof the replication is also included.

When ‘only’ is set to a particular replications, the weightvectors (one per dataset) are also returned in the compute object'soutput slot.model$compute$output$weight is a charactervector (by dataset name) of numeric vectors (the weights). Theseweights can be used to recreate a model identical to the model usedin the given replication.

See Also

mxBootstrap,as.statusCode


Log parameters and state to disk or memory

Description

Captures the current state of the backend. Whenpath is set, thestate is written to disk in a single row. WhentoReturn is set,the state is recorded in memory and returned aftermxRun.

Usage

mxComputeCheckpoint(  what = NULL,  ...,  path = NULL,  append = FALSE,  header = TRUE,  toReturn = FALSE,  parameters = TRUE,  loopIndices = TRUE,  fit = TRUE,  counters = TRUE,  status = TRUE,  standardErrors = FALSE,  gradient = FALSE,  vcov = FALSE,  vcovFilter = c(),  sampleSize = FALSE,  vcovWLS = FALSE,  useVcovFilter = FALSE)

Arguments

what

a character vector of algebra names to include in each checkpoint

...

Not used. Forces remaining arguments to be specified by name

path

a character vector of where to write the checkpoint file

append

if FALSE, truncates the checkpoint file upon open. If TRUE, existing data is preserved and checkpoints are appended.

header

whether to write the header that describes the content of each column

toReturn

logical. Whether to store the checkpoint in memory and return it after the model is run

parameters

logical. Whether to include the parameter vector

loopIndices

logical. Whether to include the loop indices

fit

logical. Whether to include the fit value

counters

logical. Whether to include counters (number of evaluations and iterations)

status

logical. Whether to include the status code

standardErrors

logical. Whether to include the standard errors

gradient

logical. Whether to include the gradients

vcov

logical. Whether to include the vcov in half-vectorized order

vcovFilter

character vector. Vector of parameters indicatingwhich parameter covariances to include. Only the variance isincluded for those parameters not mentioned.

sampleSize

logical. Whether to include the sample size of the mxData.[Experimental]

vcovWLS

logical. Whether to include the vcov from WLS residualizing regressions in half-vectorized order

useVcovFilter

logical. Whether to use the vcovFilter (TRUE) or include all entries (FALSE)

See Also

mxComputeLoadData,mxComputeLoadMatrix,mxComputeLoadContext,mxComputeLoop

Other model state:mxRestore(),mxSave()

Examples

library(OpenMx)m1 <- mxModel(  "poly22", # Eqn 22 from Tsallis & Stariolo (1996)  mxMatrix(type='Full', values=runif(4, min=-1e6, max=1e6),           ncol=1, nrow=4, free=TRUE, name='x'),  mxAlgebra(sum((x*x-8)^2) + 5*sum(x) + 57.3276, name="fit"),  mxFitFunctionAlgebra('fit'))plan <- mxComputeLoop(list(  mxComputeSetOriginalStarts(),    mxComputeSimAnnealing(method="tsallis1996",                          control=list(tempEnd=1)),    mxComputeCheckpoint(path = "result.log")),  i=1:4)m1 <- mxRun(mxModel(m1, plan)) # see the file 'result.log'

Find likelihood-based confidence intervals

Description

There are various equivalent ways to pose the optimizationproblems required to estimate confidence intervals. Most accuratesolutions are achieved when the problem is posed using non-linearconstraints. However, the available optimizers (CSOLNP, SLSQP, and NPSOL) often have difficulty with non-linearconstraints.

Usage

mxComputeConfidenceInterval(  plan,  ...,  freeSet = NA_character_,  verbose = 0L,  engine = NULL,  fitfunction = "fitfunction",  tolerance = NA_real_,  constraintType = "none")

Arguments

plan

compute plan to optimize the model

...

Not used. Forces remaining arguments to be specified by name.

freeSet

names of matrices containing free variables

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

engine

[Deprecated]

fitfunction

the name of the deviance function

tolerance

[Deprecated]

constraintType

one of c('ineq', 'none')

References

Neale, M. C. & Miller M. B. (1997). The use of likelihood basedconfidence intervals in genetic models.Behavior Genetics,27(2), 113-120.

Pek, J. & Wu, H. (2015). Profile likelihood-based confidence intervals and regions for structural equation models.Psychometrika, 80(4), 1123-1145.

Wu, H. & Neale, M. C. (2012). Adjusted confidence intervals for abounded parameter.Behavior genetics, 42(6), 886-898.


Default compute plan

Description

This is an empty placeholder for the default compute plan.To create an actual plan, useomxDefaultComputePlan.

Usage

mxComputeDefault(freeSet = NA_character_)

Arguments

freeSet

names of matrices containing free variables


Fit a model using DLR's (1977) Expectation-Maximization (EM) algorithm

Description

The EM algorithm constitutes the following steps: Start with aninitial parameter vector. Predict the missing data to form acompleted data model. Optimize the completed data model to obtaina new parameter vector. Repeat these steps until convergencecriteria are met.

Usage

mxComputeEM(  expectation = NULL,  predict = NA_character_,  mstep,  observedFit = "fitfunction",  ...,  maxIter = 500L,  tolerance = 1e-09,  verbose = 0L,  freeSet = NA_character_,  accel = "varadhan2008",  information = NA_character_,  infoArgs = list(),  estep = NULL)

Arguments

expectation

a vector of expectation names[Deprecated]

predict

what to predict from the observed data[Deprecated]

mstep

a compute plan to optimize the completed data model

observedFit

the name of the observed data fit function (defaults to "fitfunction")

...

Not used. Forces remaining arguments to be specified by name.

maxIter

maximum number of iterations

tolerance

optimization is considered converged when the maximum relative change in fit is less than tolerance

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

freeSet

names of matrices containing free variables

accel

name of acceleration method ("varadhan2008" or "ramsay1975")

information

name of information matrix approximation method

infoArgs

arguments to control the information matrix method

estep

a compute plan to perform the expectation step

Details

The arguments to this function have evolved. The old stylemxComputeEM(e,p,mstep=m) is equivalent to the new stylemxComputeEM(estep=mxComputeOnce(e,p), mstep=m). This changeallows the API to more closely match the literature on the E-Mmethod. You might usemxAlgebra(..., recompute='onDemand') tocontain the results of the E-step and then cause this algebra tobe recomputed usingmxComputeOnce.

This compute plan does not work with any and all expectations. Itrequires a special kind of expectation that can predict itsmissing data to create a completed data model.

The EM algorithm does not produce a parameter covariance matrixfor standard errors. The Oakes (1999) direct method and S-EM, animplementation of Meng & Rubin (1991), are included.

Ramsay (1975) was recommended in Bock, Gibbons, & Muraki (1988).

References

Bock, R. D., Gibbons, R., & Muraki, E. (1988). Full-informationitem factor analysis.Applied Psychological Measurement,6(4), 431-444.

Dempster, A. P., Laird, N. M., & Rubin, D. B. (1977). Maximum likelihood fromincomplete data via the EM algorithm.Journal of the Royal Statistical Society.Series B (Methodological), 1-38.

Meng, X.-L. & Rubin, D. B. (1991). Using EM to obtain asymptotic variance-covariancematrices: The SEM algorithm.Journal of the American Statistical Association,86 (416), 899-909.

Oakes, D. (1999). Direct calculation of the information matrix viathe EM algorithm.Journal of the Royal Statistical Society:Series B (Statistical Methodology), 61(2), 479-482.

Ramsay, J. O. (1975). Solving implicit equations in psychometric data analysis.Psychometrika, 40 (3), 337-360.

Varadhan, R. & Roland, C. (2008). Simple and globally convergentmethods for accelerating the convergence of any EMalgorithm.Scandinavian Journal of Statistics, 35, 335-353.

See Also

MxAlgebra,mxComputeOnce

Examples

library(OpenMx)set.seed(190127)N <- 200x <- matrix(c(rnorm(N/2,0,1),              rnorm(N/2,3,1)),ncol=1,dimnames=list(NULL,"x"))data4mx <- mxData(observed=x,type="raw")class1 <- mxModel("Class1",mxMatrix(type="Full",nrow=1,ncol=1,free=TRUE,values=0,name="Mu"),mxMatrix(type="Full",nrow=1,ncol=1,free=TRUE,values=4,name="Sigma"),mxExpectationNormal(covariance="Sigma",means="Mu",dimnames="x"),mxFitFunctionML(vector=TRUE))class2 <- mxRename(class1, "Class2")mm <- mxModel("Mixture", data4mx, class1, class2,mxAlgebra((1-Posteriors) * Class1.fitfunction, name="PL1"),mxAlgebra(Posteriors * Class2.fitfunction, name="PL2"),mxAlgebra(PL1 + PL2, name="PL"),mxAlgebra(PL2 / PL,  recompute='onDemand',          initial=matrix(runif(N,.4,.6), nrow=N, ncol = 1), name="Posteriors"),mxAlgebra(-2*sum(log(PL)), name="FF"),mxFitFunctionAlgebra(algebra="FF"),mxComputeEM(  estep=mxComputeOnce("Mixture.Posteriors"),  mstep=mxComputeGradientDescent(fitfunction="Mixture.fitfunction")))mm <- mxOption(mm, "Max minutes", 1/20)  # remove this line to find optimummmfit <- mxRun(mm)summary(mmfit)

Generate data

Description

Generate data specified by the model expectations.

Usage

mxComputeGenerateData(expectation = "expectation")

Arguments

expectation

a character vector of expectations to generate data for


Optimize parameters using a gradient descent optimizer

Description

This optimizer does not require analytic derivatives of the fitfunction. The fully open-source CRAN version of OpenMx offers 2 choices,CSOLNP and SLSQP (from the NLOPT collection). The OpenMx Team's version ofOpenMx offers the choice of three optimizers: CSOLNP, SLSQP, and NPSOL.

Usage

mxComputeGradientDescent(  freeSet = NA_character_,  ...,  engine = NULL,  fitfunction = "fitfunction",  verbose = 0L,  tolerance = NA_real_,  useGradient = deprecated(),  warmStart = NULL,  nudgeZeroStarts = mxOption(NULL, "Nudge zero starts"),  maxMajorIter = NULL,  gradientAlgo = deprecated(),  gradientIterations = deprecated(),  gradientStepSize = deprecated())

Arguments

freeSet

names of matrices containing free parameters.

...

Not used. Forces remaining arguments to be specified by name.

engine

specific 'CSOLNP', 'SLSQP', or 'NPSOL'

fitfunction

name of the fitfunction (defaults to 'fitfunction')

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

tolerance

how close to the optimum is close enough (also known as the optimality tolerance)

useGradient

[Soft-deprecated]

warmStart

a Cholesky factored Hessian to use as the NPSOL Hessian starting value (preconditioner)

nudgeZeroStarts

whether to nudge any zero starting values prior to optimization (default TRUE)

maxMajorIter

maximum number of major iterations

gradientAlgo

[Soft-deprecated]

gradientIterations

[Soft-deprecated]

gradientStepSize

[Soft-deprecated]

Details

All three optimizers can use analytic gradients, and only NPSOLuseswarmStart. To customize more options, seemxOption.

References

Luenberger, D. G. & Ye, Y. (2008).Linear and nonlinear programming. Springer.

Examples

data(demoOneFactor)factorModel <- mxModel(name ="One Factor",  mxMatrix(type="Full", nrow=5, ncol=1, free=FALSE, values=0.2, name="A"),    mxMatrix(type="Symm", nrow=1, ncol=1, free=FALSE, values=1, name="L"),    mxMatrix(type="Diag", nrow=5, ncol=5, free=TRUE, values=1, name="U"),    mxAlgebra(expression=A %*% L %*% t(A) + U, name="R"),  mxExpectationNormal(covariance="R", dimnames=names(demoOneFactor)),  mxFitFunctionML(),    mxData(observed=cov(demoOneFactor), type="cov", numObs=500),     mxComputeSequence(steps=list(     mxComputeGradientDescent(),     mxComputeNumericDeriv(),     mxComputeStandardError(),     mxComputeHessianQuality()    )))factorModelFit <- mxRun(factorModel)factorModelFit$output$conditionNumber # 29.5

Compute the quality of the Hessian

Description

Tests whether the Hessian is positive definite(model$output$infoDefinite) and, if so, computes the approximate conditionnumber (model$output$conditionNumber). See Luenberger & Ye (2008)Second Order Test (p. 190) and Condition Number (p. 239).

Usage

mxComputeHessianQuality(freeSet = NA_character_, ..., verbose = 0L)

Arguments

freeSet

names of matrices containing free variables

...

Not used. Forces remaining arguments to be specified by name.

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

Details

The condition number is approximated by\mathrm{norm}(H) *\mathrm{norm}(H^{-1}) where H is theHessian. The norm is either the 1- or infinity-norm (both obtainthe same result due to symmetry).

References

Luenberger, D. G. & Ye, Y. (2008). Linear and nonlinear programming. Springer.


Repeatedly invoke a series of compute objects until change is less than tolerance

Description

One step (typically the last) must compute the fit or maxAbsChange.

Usage

mxComputeIterate(  steps,  ...,  maxIter = 500L,  tolerance = 1e-09,  verbose = 0L,  freeSet = NA_character_,  maxDuration = as.numeric(NA))

Arguments

steps

a list of compute objects

...

Not used. Forces remaining arguments to be specified by name.

maxIter

the maximum number of iterations

tolerance

iterates until maximum relative change is less than tolerance

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

freeSet

Names of matrices containing free variables.

maxDuration

the maximum amount of time (in seconds) to iterate


Numerically estimate the Jacobian with respect to free parameters

Description

When algebra names are given, all algebras must belong to the samemodel.

When expectations are given, the Jacobian is taken with respectto the manifest model.The manifest model excludes any latent variables or processes. ForRAM and LISREL models, the manifest model contains only themanifest variables with free means, covariance, and thresholds.Ordinal manifest variables are standardized.

Usage

mxComputeJacobian(freeSet=NA_character_, ..., of = "expectation", defvar.row=as.integer(NA), data='data')

Arguments

freeSet

names of matrices containing free variables

...

Not used. Forces remaining arguments to be specified by name.

of

a character vector of expectations or algebra names

defvar.row

A row index. Which row to load for definition variables.

data

From which data to load definition variables.

See Also

omxManifestModelByParameterJacobian,mxGetExpected


Load contextual data to supplement checkpoint

Description

[Experimental]

Usage

mxComputeLoadContext(  method = c("csv"),  path = c(),  column,  ...,  sep = " ",  verbose = 0L,  header = TRUE,  col.names = NULL)

Arguments

method

name of the conduit used to load the columns.

path

the path to the file containing the data

column

a character vector. The column names to log.

...

Not used. Forces remaining arguments to be specified by name.

sep

the field separator character. Values on each line of the file are separated by this character.

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

header

logical. Whether the first row contains column headers.

col.names

character vector. Column names

Details

Currently, this only supports comma separated value format and norow names. Ifheader=TRUE andcol.names areprovided, thecol.names take precedence. Ifheader=FALSE and nocol.names are provided thenthe column names consist of the file name and column offset.

AnoriginalDataIsIndexOne option is not offered. You'll need toadd an extra line at the start on your file if you wish to makeuse oforiginalDataIsIndexOne inmxComputeLoad*.

See Also

mxComputeCheckpoint,mxComputeLoadData,mxComputeLoadMatrix


Load columns into an MxData object

Description

[Experimental]

Usage

mxComputeLoadData(  dest,  column,  method = c("csv", "data.frame"),  ...,  path = c(),  originalDataIsIndexOne = FALSE,  byrow = TRUE,  row.names = c(),  col.names = c(),  skip.rows = 0,  skip.cols = 0,  verbose = 0L,  cacheSize = 100L,  checkpointMetadata = TRUE,  na.strings = c("NA"),  observed = NULL,  rowFilter = c())

Arguments

dest

the name of the model where the columns will be loaded

column

a character vector. The column names to replace.

method

name of the conduit used to load the columns.

...

Not used. Forces remaining arguments to be specified by name.

path

the path to the file containing the data

originalDataIsIndexOne

logical. Whether to use the initial data for index 1

byrow

logical. Whether the data columns are stored in rows.

row.names

optional integer. Column containing the row names.

col.names

optional integer. Row containing the column names.

skip.rows

integer. Number of rows to skip before reading data.

skip.cols

integer. Number of columns to skip before reading data.

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

cacheSize

integer. How many columns to cache perscan through the data. Only used when byrow=FALSE.

checkpointMetadata

logical. Whether to add per record metadata to the checkpoint

na.strings

character vector. A vector of strings that denote a missing value.

observed

data frame. The reservoir of data formethod='data.frame'.

rowFilter

logical vector. Whether to skip the source row.

Details

The purpose of this compute step is to help quickly perform manysimilar analyses. For example, if we are given a sample of peoplewith a few million SNPs (single-nucleotide polymorphism) perperson then we could fit a separate model for each SNP by iteratingover the SNP data.

The column names given in thecolumn parameter must alreadyexist in the model's MxData object. Pre-existing data is assumed to bea placeholder and is not used unlessoriginalDataIsIndexOne is set to TRUE.

Formethod='csv', the highest performance arrangement isbyrow=TRUE because entire columns are stored in singlechunks (rows) on the disk and can be easily loaded. Forbyrow=FALSE, the data requires transposition. To load asingle column of observed data, it is necessary to read throughthe whole file. This can be slow for large files. To amortize thecost of transposition,cacheSize columns are loaded onevery pass through the file.

AftermxRun returns, thedest mxData object willcontain the most recently loaded data. Hence, any single analysisof a series can be reproduced by issuingmxComputeLoadDatawith the single index associated with a particular dataset,replacing the compute plan with something likeomxDefaultComputePlan, and then passing the model backthroughmxRun. This can be a helpful approach wheninvestigating unexpected results.

See Also

mxComputeLoadMatrix,mxComputeCheckpoint,mxRun,omxDefaultComputePlan


Load data from CSV files directly into the backend

Description

THIS INTERFACE IS EXPERIMENTAL AND SUBJECT TO CHANGE.

For method='csv', the file must be formatted in a specific way.The number of columns must match the number of entries availablein the mxMatrix. Matrix types (e.g., symmetric or diagonal) arerespected (seemxMatrix). For example, aFull 2x2matrix will require 4 entries, but a diagonal matrix of the same sizewill only require 2 entries.CSV data must be stored space separated and without row or columnnames.The destinationmxMatrix can have free parameters, but cannothave square bracket populated entries.

IforiginalDataIsIndexOne is TRUE then thiscompute step does nothing when the loop index is 1.The purpose oforiginalDataIsIndexOne is topermit usage of the dataset that was initiallyincluded with the model.

Usage

mxComputeLoadMatrix(dest, method=c('csv','data.frame'), ..., path=NULL, originalDataIsIndexOne=FALSE, row.names=FALSE, col.names=FALSE, observed=NULL)

Arguments

dest

a character vector of matrix names

method

name of the conduit used to load the data.

...

Not used. Forces remaining arguments to be specified by name.

path

a character vector of paths

originalDataIsIndexOne

logical. Whether to use the initial datafor index 1

row.names

logical. Whether row names are present

col.names

logical. Whether column names are present

observed

data frame. The reservoir of data formethod='data.frame'

See Also

mxComputeLoadData,mxComputeCheckpoint

Examples

library(OpenMx)dir <-tempdir()  # safe place to create filesCov <- rWishart(4, 20, toeplitz(c(2,1)/20))write.table(t(apply(Cov, 3, vech)),            file=file.path(dir, "cov.csv"),            col.names=FALSE, row.names=FALSE)Mean <- matrix(rnorm(8),4,2)write.table(Mean, file=file.path(dir, "mean.csv"),            col.names=FALSE, row.names=FALSE)m1 <- mxModel(  "test1",  mxMatrix("Full", 1,2, values=0,       name="mean"),  mxMatrix("Symm", 2,2, values=diag(2), name="cov"),  mxMatrix("Full", 1,2, values=-1,      name="lbound"),  mxMatrix("Full", 1,2, values=1,       name="ubound"),  mxAlgebra(omxMnor(cov,mean,lbound,ubound), name="area"),  mxFitFunctionAlgebra("area"),  mxComputeLoop(list(    mxComputeLoadMatrix(c('mean', 'cov'),                        path=file.path(dir, c('mean.csv', 'cov.csv'))),    mxComputeOnce('fitfunction', 'fit'),    mxComputeCheckpoint(path=file.path(dir, "loadMatrix.csv"))  ), i=1:4))m1 <- mxRun(m1)

Repeatedly invoke a series of compute objects

Description

Wheni is given then these values are iteratedover instead of the sequence 1 to the number ofiterations.

Usage

mxComputeLoop(  steps,  ...,  i = NULL,  maxIter = as.integer(NA),  freeSet = NA_character_,  maxDuration = as.numeric(NA),  verbose = 0L,  startFrom = 1L)

Arguments

steps

a list of compute objects

...

Not used. Forces remaining arguments to be specifiedby name.

i

the values to iterate over

maxIter

the maximum number of iterations

freeSet

Names of matrices containing free variables.

maxDuration

the maximum amount of time (in seconds) toiterate

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

startFrom

Wheni=NULL, permits starting from an index greater than 1.


Optimize parameters using a variation of the Nelder-Mead algorithm.

Description

OpenMx includes a flexible, options-rich implementation of the Nelder-Mead algorithm.

Usage

mxComputeNelderMead(freeSet=NA_character_, fitfunction="fitfunction", verbose=0L, nudgeZeroStarts=mxOption(NULL,"Nudge zero starts"), maxIter=NULL,...,alpha=1, betao=0.5, betai=0.5, gamma=2, sigma=0.5, bignum=1e35, iniSimplexType=c("regular","right","smartRight","random"),iniSimplexEdge=1, iniSimplexMat=NULL, greedyMinimize=FALSE, altContraction=FALSE, degenLimit=0, stagnCtrl=c(-1L,-1L),validationRestart=TRUE,xTolProx=1e-8, fTolProx=1e-8,doPseudoHessian=TRUE,ineqConstraintMthd=c("soft","eqMthd"), eqConstraintMthd=c("GDsearch","soft","backtrack","l1p"),backtrackCtrl=c(0.5,5),centerIniSimplex=FALSE)

Arguments

freeSet

Character-string names ofMxMatrices containing free parameters.

fitfunction

Character-string name of the fitfunction; defaults to 'fitfunction'.

verbose

Integer level of reporting printed to terminal atruntime; defaults to 0.

nudgeZeroStarts

Should free parameters with start values of zero be "nudged" to 0.1 atruntime? Defaults to the current global value ofmxOption "Nudge zero starts". May be a logical value, or one of character strings "Yes" or "No".

maxIter

Integer maximum number of iterations. Value ofNULL is accepted, in which case the value used atruntime will be 10 times the number of iterations specified by the effective value ofmxOption "Major iterations".

...

Not used. Forces remaining arguments to be specified by name.

alpha

Numeric reflection coefficient. Must be positive. Defaults to 1.0.

betao,betai

Numeric outside- and inside-contraction coefficients, respectively. Both must be within unit interval (0,1). Both default to 0.5.

gamma

Numeric expansion coefficient. If positive, must be greater thanalpha. If non-positive, expansion transformations will not be carried out. Defaults to 2.0.

sigma

Numeric shrink coefficient. Cannot exceed 1.0. If non-positive, shrink transformations will not be carried out, and failed contractions will instead be followed by a simplex restart. Defaults to 0.5.

bignum

Numeric value with which the fitfunction value is to be replaced if the fit is non-finite or is evaluated at infeasible parameter values. Defaults to 1e35.

iniSimplexType

Character string naming the method by which to construct the initial simplex from the free-parameter start values. Defaults to "regular".

iniSimplexEdge

Numeric edge-length of the initial simplex. Defaults to 1.0.

iniSimplexMat

Optional numeric matrix providing the vertices of the initial simplex. The matrix must have as many columns as there are free parameters in theMxModel. The matrix's number of rows must be no less than the number of free parameters minus the number of degrees-of-freedom gained from equalityMxConstraints, if any. If a non-NULL value is provided, argumentiniSimplexEdge is ignored, and argumentiniSimplexType is only used in the case of a restart.

greedyMinimize

Logical; should the optimizer use "greedy minimization?" Defaults toFALSE. See below for details.

altContraction

Logical; should the optimizer use an "alternate contraction" transformation? Defaults toFALSE. See below for details.

degenLimit

Numeric "degeneracy limit;" defaults to 0. If positive, the simplex will be restarted if the measure of the angle between any two of its edges is within 0 or pi by less thandegenLimit.

stagnCtrl

"Stagnation control;" integer vector of length 2; defaults toc(-1L,-1L). See below for details.

validationRestart

Logical; defaults to TRUE.

xTolProx

Numeric "domain-convergence" criterion; defaults to 1e-8. See below for details.

fTolProx

Numeric "range-convergence" criterion; defaults to 1e-8. See below for details.

doPseudoHessian

Logical; defaults toTRUE.

ineqConstraintMthd

"Inequality constraint method;" character string. Defaults to "soft".

eqConstraintMthd

"Equality constraint method;" character string. Defaults to "GDsearch".

backtrackCtrl

Numeric vector of length two. See below for details.

centerIniSimplex

Logical. IfFALSE (default), the MxModel's start values are used as the "first" vertex of the initial simplex. IfTRUE, the initial simplex is re-centered so that the MxModel's start values are its eucentroid. However, ifiniSimplexMat is non-NULL or ifiniSimplexType="smartRight", a value ofTRUE is treated asFALSE.

Details

The state of a Nelder-Mead optimization problem is represented by a simplex (polytope) ofn+1 vertices in the space of the free parameters, wheren is the number of free parameters minus the number of degrees-of-freedom gained from equalityMxConstraints. An iteration of the algorithm first sorts then+1 vertices by their corresponding fitfunction values (i.e., the values of the fitfunction when evaluated at each vertex), in ascending order (i.e., from "best" fit to "worst" fit). Then, the "subcentroid," which is the centroid of the "best"n vertices, is calculated. Then, the algorithm attempts to improve upon the worst fit by transforming the simplex; seeSinger & Nelder (2009) for details.

ArgumentiniSimplexType dictates how the initial simplex will be constructed from the start values if argumentiniSimplexMat isNULL, and how the simplex will be re-initialized in the case of a restart. In all four cases, the vector of start values constitutes the "starting vertex" of the initial simplex. IfiniSimplexType="regular", the initial simplex is merely a regular simplex with edge length equal toiniSimplexEdge. A"right" simplex is constructed by incrementing each free parameter byiniSimplexEdge from its starting value; thus, all the edges that intersect at the starting vertex do so at right angles. A"smartRight" simplex is constructed similarly, except that each free parameter is both incrementedand decremented byiniSimplexEdge, and of those two points the one with the smaller fitfunction value is retained as a vertex. A"random" simplex is constructed by randomly perturbing the start values, in a manner similar to the default formxTryHard(), to generate the coordinates of the other vertices. The user is advised that bounds on the free parameters may keep the initial simplex from having the requested regularity or edge-length, and thatiniSimplexType is at best asuggestion in the presence of equalityMxConstraints.

Note that if argumentiniSimplexMat has nonzero length, the actual start values of the MxModel's free parameters are not used as a vertex of the initial simplex (unless one of the rows ofiniSimplexMat happens to contain those start values).

If the simplex is restarted, a new simplex is constructed per argumentiniSimplexType, with edge length equal to the distance between the current best and second-best vertices, and with the current best vertex used as the "first" vertex.

IfgreedyMinimize=FALSE, "greedy expansion" (Singer & Singer, 2004) is used: if the expansion point and reflection point both have smaller fitfunction values than the best vertex, the expansion point is accepted. IfgreedyMinimize=TRUE, "greedy minimization" (Singer & Singer, 2004) is used: if the expansion point and the reflection point both have smaller fitfunction values than the best vertex, the better of the two new points is accepted.

If argumentaltContraction=TRUE, the "modified contraction step" of Gill et al. (1982, Chapter 4) is used, and the candidate point is contracted toward the best vertex instead of toward the subcentroid.

If positive, the first element of argumentstagnCtrl sets a threshold for the number of successive iterations in which the best vertex of the simplex does not change, after which the algorithm is said to be "stagnant" (in a sense similar to that of Kelley, 1999). To attempt to remedy the stagnation, the simplex is restarted. If positive, the second element of argumentstagnCtrl sets threshold for the number of restarts conducted, beyond which stagnation no longer triggers a restart. The rationale for the second element is that the best vertex may not change for many iterations when the optimizer is close to convergence, under which circumstances restarting would be counterproductive, and in any event would require additional fitfunction evaluations.

If argumentvalidationRestart=TRUE, then when the optimizer has successfully converged, it will restart the simplex and attempt to improve upon the tentative solution it already found. This validation restart (Gill et al., 1982, Chapter 4) always re-initializes the simplex as a regular simplex, centered on the best vertex of the tentative solution, with edge-length equal to the distance between the best and worst vertices of the tentative solution. Optimization proceeds until convergence to a solution with a better fit value, or2n iterations have elapsed.

The Nelder-Mead optimizer is considered to have successfully converged if (1) the largestl-infinity norm of the vector-differences between the best vertex and the other vertices is less than argumentxTolProx, or (2) if the largest absolute difference in fit value between the best vertex and the other vertices is less thanfTolProx.

If argumentdoPseudoHessian=TRUE, there are no equalityMxConstraints, and the "l1p" method (see below) is not in use for inequalityMxConstraints, then OpenMx will attempt to calculate the "pseudo-Hessian" or "curvature" matrix as described in the appendix to Nelder & Mead (1965). If successful, this matrix will be stored in the 'output' slot of the post-run MxComputeNelderMead object. Although crude, its inverse can be used as an estimate of the repeated-sampling covariance matrix of the free parameters when the usual finite-differences Hessian is unreliable.

OpenMx's implementation of Nelder-Mead can handle nonlinear inequalityMxConstraints reasonably well. Its default method for doing so, with argumentineqConstraintMthd="soft", imposes a "soft" feasibility constraint by assigning a fitfunction value ofbignum to points that violate the constraints by more thanmxOption 'Feasibility tolerance'. Alternately, with argumentineqConstraintMthd="eqMthd", inequalityMxConstraints can be handled by the same method provided to argumenteqConstraintMthd, whether or not equalityMxConstraints are present.

OpenMx's implementation of Nelder-Mead respects equalityMxConstraints, but does not handle them especially well. Its effectiveness at handling equalities may be improved by providing a matrix to argumentiniSimplexMat that ensuresall of the initial vertices are feasible. Users are warned that this Nelder-Mead implementation will not work correctly with MxModels containing redundant equality MxConstraints, and presently has no way of detecting whether any are present. If argumenteqConstraintMthd="GDsearch" (the default), then whenever Nelder-Mead evaluates the fitfunction at an infeasible point, it initiates a subsidiary optimization that usesSLSQP to find the nearest (in squared Euclidean distance) feasible point, and replaces that feasible point for the infeasible one. The user should note that the function evaluations that occur during this subsidiary optimization are counted toward the total number of fitfunction evaluations during the call tomxRun(). The effectiveness of the 'GDsearch' method is often improved by settingmxOption 'Feasibility tolerance' to a stricter (smaller) value than the on-load default. The method specified byeqConstraintMthd="soft" is described in the preceding paragraph. If argumenteqConstraintMthd="backtrack", then the optimizer attempts to backtrack from an infeasible point to a feasible point in a manner similar to that of Ghiasi et al. (2008), except that it used withall new points, and not just those encountered via reflection, expansion and contraction. In this case, the displacement from the prior point to the candidate point is reduced by the proportion provided as the first element of argumentbacktrackCtrl, and thus a new candidate point is considered. This process is repeated until feasibility of the candidate point is restored, or the number of attempts exceeds the second element of argumentbacktrackCtrl. If argumenteqConstraintMthd="l1p", Nelder-Mead is used as part of anl_1-penalty algorithm. When using "l1p", the simplex gradient (Kelley, 1999) and "pseudo-Hessian" are never calculated.

Value

Returns an object of class 'MxComputeNelderMead'.

References

Ghiasi, H., Pasini, D., & Lessard, L. (2008). Constrained globalized Nelder-Mead method for simultaneous structural and manufacturing optimization of a composite bracket.Journal of Composite Materials, 42(7), p. 717-736. doi: 10.1177/0021998307088592

Gill, P. E., Murray, W., & Wright, M. H. (1982).Practical Optimization. Bingley, UK: Emerald Group Publishing Ltd.

Kelley, C. T. (1999). Detection and remediation of stagnation in the Nelder-Mead algorithm using a sufficient decrease condition.SIAM Journal of Optimization 10(1), p. 43-55.

Nelder, J. A., & Mead, R. (1965) . A simplex method for function minimization.The Computer Journal, 7, p. 308-313.

Singer, S., & Nelder, J. (2009). Nelder-Mead algorithm.Scholarpedia, 4(7):2928., revision #91557. http://www.scholarpedia.org/article/Nelder-Mead_algorithm .

Singer, S., & Singer, S. (2004). Efficient implementation of the Nelder-Mead search algorithm.Applied Numerical Analysis & Computational Mathematics Journal, 1(2), p. 524-534. doi: 10.1002/anac.200410015

Examples

foo <- mxComputeNelderMead()str(foo)

Optimize parameters using the Newton-Raphson algorithm

Description

This optimizer requires analytic 1st and 2nd derivatives of thefit function. Box constraints are supported. Parameters canapproach box constraints but will not leave the feasible region(even by some small epsilon>0). Non-finite fit values areinterpreted as soft feasibility constraints. That is, when anon-finite fit is encountered, line search is continued after thestep size is multiplied by 10%. Comprehensive diagnostics areavailable by increasing the verbose level.

Usage

mxComputeNewtonRaphson(  freeSet = NA_character_,  ...,  fitfunction = "fitfunction",  maxIter = 100L,  tolerance = 1e-12,  verbose = 0L)

Arguments

freeSet

names of matrices containing free variables

...

Not used. Forces remaining arguments to be specified by name.

fitfunction

name of the fitfunction (defaults to 'fitfunction')

maxIter

maximum number of iterations

tolerance

optimization is considered converged when the maximum relative change in fit is less than tolerance

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

References

Luenberger, D. G. & Ye, Y. (2008).Linear and nonlinear programming. Springer.


Compute nothing

Description

Note that this compute plan actually does nothing whereasmxComputeOnce("expectation", "nothing") may remove theprediction of an expectation.

Usage

mxComputeNothing()

Numerically estimate Hessian using Richardson extrapolation

Description

For N free parameters, Richardson extrapolation requires(iterations * (N^2 + N)) function evaluations.The implementation is closely based on the numDeriv R package.

Usage

mxComputeNumericDeriv(  freeSet = NA_character_,  ...,  fitfunction = "fitfunction",  parallel = TRUE,  stepSize = imxAutoOptionValue("Gradient step size"),  iterations = 4L,  verbose = 0L,  knownHessian = NULL,  checkGradient = TRUE,  hessian = TRUE,  analytic = TRUE)

Arguments

freeSet

names of matrices containing free variables

...

Not used. Forces remaining arguments to be specified by name.

fitfunction

name of the fitfunction (defaults to 'fitfunction')

parallel

whether to evaluate the fitfunction in parallel (defaults to TRUE)

stepSize

starting set size (defaults to 0.0001)

iterations

number of Richardson extrapolation iterations (defaults to 4L)

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

knownHessian

an optional matrix of known Hessian entries

checkGradient

whether to check the first order convergence criterion (gradient is near zero)

hessian

whether to estimate the Hessian. If FALSE then only the gradient is estimated.

analytic

Use the analytic Hessian, if available.

Details

In addition to an estimate of the Hessian, forward, central, andbackward estimates of the gradient are made available in thiscompute plan's output slot.

WhencheckGradient=TRUE, the central difference estimate ofthe gradient is used to determine whether the first orderconvergence criterion is met. In addition, the forward andbackward difference estimates of the gradient are compared forsymmetry. When sufficient asymmetry is detected, the standarderror is flagged. In the case, profile likelihood confidenceintervals should be used for inference instead of standard errors(seemxComputeConfidenceInterval).

If provided, the square matrixknownHessian should havedimnames set to the names of some subset of the freeparameters. Entries of the matrix set to NA will be estimatednumerically while entries containing finite values will be copiedto the Hessian result.

Examples

library(OpenMx)data(demoOneFactor)factorModel <- mxModel(name ="One Factor",mxMatrix(type = "Full", nrow = 5, ncol = 1, free = FALSE, values = .2, name = "A"),mxMatrix(type = "Symm", nrow = 1, ncol = 1, free = FALSE, values = 1 , name = "L"),mxMatrix(type = "Diag", nrow = 5, ncol = 5, free = TRUE , values = 1 , name = "U"),mxAlgebra(A %*% L %*% t(A) + U, name = "R"),mxExpectationNormal(covariance = "R", dimnames = names(demoOneFactor)),mxFitFunctionML(),mxData(cov(demoOneFactor), type = "cov", numObs = 500),mxComputeSequence(list(mxComputeNumericDeriv(), mxComputeReportDeriv())))factorModelFit <- mxRun(factorModel)factorModelFit$output$hessian

Compute something once

Description

Some models are optimized for a sparse Hessian. Therefore, it canbe much more efficient to compute the inverse Hessian incomparison to computing the Hessian and then inverting it.

Usage

mxComputeOnce(  from,  what = NULL,  how = NULL,  ...,  freeSet = NA_character_,  verbose = 0L,  .is.bestfit = FALSE)

Arguments

from

the object to perform the computation (a vector of expectation or fit function names)

what

what to compute

how

to compute it (optional)

...

Not used. Forces remaining arguments to be specified by name.

freeSet

names of matrices containing free variables

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

.is.bestfit

do not use; for backward compatibility

Details

The information matrix is only valid when parameters are at themaximum likelihood estimate. The information matrix is returned inmodel$output$hessian. You cannot request both the informationmatrix and the Hessian. The information matrix is invariant to thesign of the log likelihood scale whereas the Hessian is not.Use thehow parameter to specify which approximation to use(one of "default", "hessian", "sandwich", "bread", and "meat").

Examples

data(demoOneFactor)factorModel <- mxModel(name ="One Factor",  mxMatrix(type="Full", nrow=5, ncol=1, free=TRUE, values=0.2, name="A"),    mxMatrix(type="Symm", nrow=1, ncol=1, free=FALSE, values=1, name="L"),    mxMatrix(type="Diag", nrow=5, ncol=5, free=TRUE, values=1, name="U"),    mxAlgebra(expression=A %*% L %*% t(A) + U, name="R"),    mxFitFunctionML(),mxExpectationNormal(covariance="R", dimnames=names(demoOneFactor)),    mxData(observed=cov(demoOneFactor), type="cov", numObs=500),    mxComputeOnce('fitfunction', 'fit'))factorModelFit <- mxRun(factorModel)factorModelFit$output$fit  # 972.15

Regularize parameter estimates

Description

Add a penalty to push some subset of the parameter estimates toward zero.

Usage

mxComputePenaltySearch(  plan,  ...,  freeSet = NA_character_,  verbose = 0L,  fitfunction = "fitfunction",  approach = "EBIC",  ebicGamma = 0.5)

Arguments

plan

compute plan to optimize the model

...

Not used. Forces remaining arguments to be specified by name.

freeSet

names of matrices containing free variables

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

fitfunction

the name of the deviance function

approach

what fit function to use to compare regularized models? Currently only EBIC is available

ebicGamma

what Gamma value to use for EBIC? Must be between 0 and 1

References

Jacobucci, R., Grimm, K. J., & McArdle, J. J. (2016).Regularized structural equation modeling.<i>Structural equation modeling: a multidisciplinary journal, 23</i>(4), 555-566.


Report derivatives

Description

Copy the internal gradient and Hessian back to R.

Usage

mxComputeReportDeriv(freeSet = NA_character_)

Arguments

freeSet

names of matrices containing free variables


Report expectation

Description

Copy the internal model expectations back to R.

Usage

mxComputeReportExpectation(freeSet = NA_character_)

Arguments

freeSet

names of matrices containing free variables


Invoke a series of compute objects in sequence

Description

Invoke a series of compute objects in sequence

Usage

mxComputeSequence(  steps = list(),  ...,  freeSet = NA_character_,  independent = FALSE)

Arguments

steps

a list of compute objects

...

Not used; forces argument 'freeSet' to be specified by name.

freeSet

Names of matrices containing free parameters.

independent

Whether the steps could be executed out-of-order.


Reset parameter starting values

Description

Sets the current parameter vector back to the original starting values.

Usage

mxComputeSetOriginalStarts(freeSet = NA_character_)

Arguments

freeSet

names of matrices containing free variables


Optimization using generalized simulated annealing

Description

Performs simulated annealing to minimize the fit function.If the original starting values are outside of the feasible set,a few attempts are made to find viable starting values.

Usage

mxComputeSimAnnealing(freeSet=NA_character_, ..., fitfunction='fitfunction', plan=mxComputeOnce('fitfunction','fit'), verbose=0L, method=c("tsallis1996", "ingber2012"), control=list(), defaultGradientStepSize=imxAutoOptionValue("Gradient step size"), defaultFunctionPrecision=imxAutoOptionValue("Function precision"))

Arguments

freeSet

names of matrices containing free variables

...

Not used. Forces remaining arguments to be specified by name.

fitfunction

name of the fitfunction (defaults to 'fitfunction')

plan

compute plan to optimize the model

verbose

level of debugging output

method

which algorithm to use

control

control parameters specific to the chosen method

defaultGradientStepSize

the default gradient step size

defaultFunctionPrecision

the default function precision

Details

For method ‘tsallis1996’,the number of function evaluations are determined by thetempStart andtempEnd parameters. There is no provision tostop early because there is no way to determine whether the algorithmhas converged. The Markov step is implemented by cycling through eachparameters in turn and considering a univariate jump (like a Gibbs sampler).

Control parameters includeqv to control the shape of thevisiting distribution,qaInit to control the shape of the initialacceptance distribution,lambda to reduce the probability ofacceptance in time,tempStart to specify starting temperature,tempEnd to specify ending temperature, andstepsPerTemp toset the number of Markov steps per temperature step.

Non-linear constraints are accommodated by a penalty function.Inequality constraints work reasonably well, butequality constraints do not work very well.Constrained optimization will likely require increasingstepsPerTemp.

Classical simulated annealing (CSA) can be obtained withqv=qa=1 andlambda=0.Fast simulated annealing (FSA) can be obtained withqv=2,qa=1, andlambda=0.FSA is faster than CSA, but GSA is faster than FSA.GenSA default parameters are set to those identified in Xiang, Sun, Fan & Gong (1997).

Method ‘ingber2012’ has spawned a cultural tradition over morethan 30 years that is documented in Aguiar e Oliveira et al (2012).Options are specified using the traditional option names in thecontrol list. However, there are a few option changes tomake ASA fit better with OpenMx.Instead of optionCurvature_0, usemxComputeNumericDeriv.ASA_PRINT output is directed to/dev/null by default.To direct ASA_PRINT output to console usecontrol=list('Asa_Out_File'= '/dev/fd/1').ASA's option to control the finite differences gradient step size,Delta_X, defaults tomxOption's ‘Gradient stepsize’ instead of ASA's traditional 0.001.Similarly,Cost_Precision defaults tomxOption's‘Function Precision’ instead of ASA's traditional 1e-18.

References

Aguiar e Oliveira, H., Ingber, L., Petraglia, A., Petraglia, M. R., & Machado, M. A. S. (2012).Stochastic global optimization and its applications with fuzzy adaptive simulated annealing. Springer Publishing Company, Incorporated.

Tsallis, C., & Stariolo, D. A. (1996). Generalized simulatedannealing.Physica A: Statistical Mechanics and its Applications,233(1-2), 395-406.

Xiang, Y., Sun, D. Y., Fan, W., & Gong, X. G. (1997). Generalizedsimulated annealing algorithm and its application to the Thomsonmodel.Physics Letters A, 233(3), 216-220.

See Also

mxComputeTryHard

Examples

library(OpenMx)m1 <- mxModel("poly22", # Eqn 22 from Tsallis & Stariolo (1996)mxMatrix(type='Full', values=runif(4, min=-1e6, max=1e6),ncol=1, nrow=4, free=TRUE, name='x'),mxAlgebra(sum((x*x-8)^2) + 5*sum(x) + 57.3276, name="fit"),mxFitFunctionAlgebra('fit'),mxComputeSimAnnealing())m1 <- mxRun(m1)summary(m1)

Compute standard errors

Description

When the fit is in -2 log likelihood units, the SEs are derivedfrom the diagonal of the Hessian or inverse Hessian. The Hessian(in some form) must already be available.

Usage

mxComputeStandardError(freeSet = NA_character_, fitfunction = "fitfunction")

Arguments

freeSet

names of matrices containing free variables

fitfunction

name of the fitfunction (defaults to 'fitfunction')

Details

If there are active MxConstraints and the fit is in -2logL units,the SEs are derived from the Hessian and the Jacobian of theconstraint functions (see references).

References

Moore T & Sadler B. (2006).Maximum-Likelihood Estimation andScoring Under Parametric Constraints. Army Research Laboratoryreport ARL-TR-3805.

Schoenberg R. (1997). Constrained maximum likelihood.Computational Economics, 10, p. 251-266.


Execute a sub-compute plan, catching errors

Description

[Experimental]Any error will be recorded in a subsequent checkpoint. Afterexecution, the context will be reset to continue computation as ifno errors has occurred.

Usage

mxComputeTryCatch(plan, ..., freeSet = NA_character_)

Arguments

plan

compute plan to optimize the model

...

Not used. Forces remaining arguments to be specified by name.

freeSet

names of matrices containing free variables

See Also

mxComputeCheckpoint


Repeatedly attempt a compute plan until successful

Description

The provided compute plan is run until the status code indicatessuccess (0 or 1). It gives up after a small number of retries.

Usage

mxComputeTryHard(  plan,  ...,  freeSet = NA_character_,  verbose = 0L,  location = 1,  scale = 0.25,  maxRetries = 3L)

Arguments

plan

compute plan to optimize the model

...

Not used. Forces remaining arguments to be specified by name.

freeSet

names of matrices containing free variables

verbose

integer. Level of run-time diagnostic output. Set to zero to disable

location

location of the perturbation distribution

scale

scale of the perturbation distribution

maxRetries

maximum number of plan evaluations per invocation (including the first evaluation)

Details

Upon failure, start values are randomly perturbed. Currently onlythe uniform distribution is implemented. The distribution isparameterized by argumentslocation andscale. Thelocation parameter is the distribution's median. For the uniformdistribution,scale is the absolute difference between itsmedian and extrema (i.e., half the width of the rectangle). Eachstart value is multiplied by a random draw and then added to arandom draw from a distribution with the samescale butwith a median of zero.

References

Shanno, D. F. (1985). On Broyden-Fletcher-Goldfarb-Shanno method.Journal ofOptimization Theory and Applications, 46(1), 87-94.

See Also

mxTryHard


Create MxConstraint Object

Description

This function creates a newMxConstraint object.

Usage

mxConstraint(expression, name=NA, ..., jac=character(0), verbose=0L, strict=TRUE)

Arguments

expression

TheMxAlgebra-like expression representing the constraint function.

name

An optional character string indicating the name of the object.

...

Not used. Helps OpenMx catch bad input to argumentexpression, and requires argumentjac–meant for advanced users–to be specified by name.

jac

An optional character string naming theMxAlgebraorMxMatrix representing the Jacobian for the constraintfunction.

verbose

For values greater than zero, enable runtimediagnostics.

strict

Whether to require that all Jacobian entries referencefree parameters.

Details

ThemxConstraint() function defines relationships between twoMxAlgebra orMxMatrix objects. They are used to affect the estimation of free parameters in the referenced objects. The constraint relation is written identically to how aMxAlgebra expression would be written. The outermost operator in this relation must be either ‘<’, ‘==’ or ‘>’. To affect an estimation or optimization, anMxConstraint object must be included in anMxModel object with all referencedMxAlgebra andMxMatrix objects.

Usage Note: Use ofmxConstraint() should be avoided where it is possible to achieve the constraint by equating free parameters by label or position in anMxMatrix orMxAlgebra object, because constraints also add computational overhead. If one labels two parameters the same, the optimizer has one fewer parameter to optimize. However, if one usesmxConstraint() to do the same thing, both parameters remain estimated and a Lagrangian multiplier is added to maintain the constraint. This constraint also has to have its gradients computed and the order of the Hessian grows as well. So while both approaches should work, themxConstraint() will take longer to do so.

Alternatives to mxConstraints include using labels, lbound or ubound arguments or algebras. Free parameters in the sameMxModel may be constrained to equality by giving them the same name in their respective 'labels' matrices. Similarly, parameters may be fixed to an individual element in aMxModel object or the result of anMxAlgebra object through labeling. For example, assigning a label of “name[1,1]“ fixes the value of a parameter at the value in first row and first column of the matrix or algebra “name“. The mxConstraint function should be used to enforce inequalities that cannot be conveyed using other methods.

Note that constraints should not depend ondefinitionvariables. This mode of operation is not supported.

Argumentjac is used to provide the name of anMxMatrix orMxAlgebra that equals the matrix of first derivatives–theJacobian–of the constraint function with respect to the freeparameters. Here, the "constraint function" refers to the constraintexpression in canonical form: an arbitrary matrix expression on theleft-hand side of the comparator, and a matrix of zeroes with the samedimensions on the right-hand side. The rows of the Jacobian correspondto elements of the matrix result of the right-hand side, in column-majororder. Each row of the Jacobian is the vector of first partialderivatives, with respect to the free parameters of the MxModel, of itscorresponding element. Each column of the Jacobian corresponds to afree parameter of the MxModel; each column must be named with the labelof the corresponding free parameter. All thegradient-descent optimizers are ableto take advantage of user-supplied Jacobians. To verify the analyticJacobian against the same values estimated by finite differences, use‘verbose=3’.

In the past, OpenMx has relied on NPSOL's finite differences algorithmto fill in unknown Jacobian entries. When analytic Jacobians are used,OpenMx no longer relies on NPSOL's finite differences algorithm. Anymissing entries are taken care of by OpenMx's finite differencesalgorithm. Whether NPSOL or OpenMx conducts finite differences,the results should be very similar.

Value

Returns anMxConstraint object.

References

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

See Also

MxConstraint for the S4 class created by mxConstraint.

Examples

library(OpenMx)#Create a constraint between MxMatrices 'A' and 'B'constraint <- mxConstraint(A > B, name = 'AdominatesB')# Constrain matrix 'K' to be equal to matrix 'limit'model <- mxModel(model="con_test",    mxMatrix(type="Full", nrow=2, ncol=2, free=TRUE, name="K"),    mxMatrix(type="Full", nrow=2, ncol=2, free=FALSE, name="limit", values=1:4),    mxConstraint(K == limit, name = "Klimit_equality"),    mxAlgebra(min(K), name="minK"),    mxFitFunctionAlgebra("minK"))fit <- mxRun(model)fit$matrices$K$values#      [,1] [,2]# [1,]    1    3# [2,]    2    4# Constrain both free parameters of a matrix to equality using labels (both are set to "eq")equal <- mxMatrix("Full", 2, 1, free=TRUE, values=1, labels="eq", name="D")# Constrain a matrix element in to be equal to the result of an algebrastart <- mxMatrix("Full", 1, 1, free=TRUE,  values=1, labels="param", name="F")alg   <- mxAlgebra(log(start), name="logP")# Force the fixed parameter in matrix G to be the result of the algebraend   <- mxMatrix("Full", 1, 1, free=FALSE, values=1, labels="logP[1,1]", name="G")

Create MxData Object

Description

This function creates a newMxData object. This can be used all forms of analysis (including WLS: seemxFitFunctionWLS).It packages observed data (e.g. a dataframe, matrix, or cov or cor matrix) into an object with additional information allowing it to be processed in an mxModel.

Usage

   mxData(observed=NULL, type="none", means = NA, numObs = NA, acov=NA, fullWeight=NA,          thresholds=NA, ..., observedStats=NA, sort=NA, primaryKey = as.character(NA),          weight = as.character(NA), frequency = as.character(NA),          verbose = 0L, .parallel=TRUE, .noExoOptimize=TRUE,     minVariance=sqrt(.Machine$double.eps), algebra=c(),   warnNPDacov=TRUE, warnNPDuseWeight=TRUE, exoFree=NULL,   naAction=c("pass","fail","omit","exclude"),   fitTolerance=sqrt(as.numeric(mxOption(key="Optimality tolerance"))),   gradientTolerance=1e-2)

Arguments

observed

A matrix or data.frame which provides data to theMxData object. Can be NULL when summary data are provided via ‘observedStats’.

type

A character string defining the type of data in the‘observed’ argument. Must be one of “raw”,“cov”, “cor”, or “acov”. If no observed data areprovided then use “none”.

means

An optional vector of means for use when ‘type’ is “cov”, or “cor”.

numObs

The number of observations in the data supplied in the ‘observed’ argument. Required unless ‘type’ equals “raw”.

...

Not used. Forces remaining arguments to be specified by name.

observedStats

A list containing observed statistics for weighted least squares estimation. See details for contents

sort

Whether to sort raw data prior to use (default NA).

primaryKey

The column name of the primary key used to uniquely identify rows (default NA)

weight

The column name containing row weights.

frequency

The column name containing row frequencies.

verbose

level of diagnostic output.

.parallel

logical. Whether to compute observed summary statistics in parallel.

.noExoOptimize

logical. Whether to use math short-cuts for the case of no exogenous predictors.

minVariance

numeric. The minimum acceptable variance for ‘observedStats$cov’.

acov

Deprecated in favor of the acov element of observedStats.

fullWeight

Deprecated in favor of the fullWeight element of observedStats.

thresholds

Deprecated in favor of the thresholds element of observedStats.

algebra

character vector. Names of algebras used to fill incalculated columns of raw data.[Experimental]

warnNPDacov

[Deprecated]

warnNPDuseWeight

logical. Whether to warn when the asymptoticcovariance matrix is non-positive definite.

exoFree

logical matrix of observed manifests byexogenous predictors. Defaults to all TRUE, but you can fix someregression coefficients in theobservedStatsslopematrix to zero by setting entries to FALSE.[Experimental]

naAction

Specify treatment of missing data. See details.[Maturing]

fitTolerance

fit tolerance used for WLS summary statistics[Experimental]

gradientTolerance

gradient tolerance used for WLS summary statistics[Experimental]

Details

The mxData function createsMxData objects used inmxModels.The ‘observed’ argument may take either a data frame or a matrix, which is then described with the‘type’ argument. Data types describe compatibility and usage with expectation functions in MxModelobjects. Three data types are supported (acov is deprecated).

raw

The contents of the ‘observed’ argument are treated as raw data. Missing values are permitted and must bedesignated as the system missing value. The ‘means’ and ‘numObs’ arguments cannot be specified, as the‘means’ argument is not relevant and the ‘numObs’ argument is automatically populated with the number of rowsin the data. Data of this type may use fit functions such asmxFitFunctionML ormxFitFunctionWLS.mxFitFunctionML will automatically use use full-information maximum likelihood for raw data.

cov

The contents of the ‘observed’ argument are treated as a covariance matrix. The ‘means’ argument isnot required, but may be included for estimations involving means. The ‘numObs’ argument is required, which shouldreflect the number of observations or rows in the data described by the covariance matrix. Cov data typically use themxFitFunctionML fit function, depending on the specified model.

acov

This type was used for WLS data as created bymxDataWLS. Unless you are using summary data, its use is deprecated.Instead, use type =‘raw’ and anmxFitFunctionWLS. If type ‘acov’ is set, the ‘observed’ argument will(usually) contain raw data and the ‘observedStats’ slot contain a list of observed statistics.

cor

The contents of the ‘observed’ argument are treated as a correlation matrix. The ‘means’ argument isnot required, but may be included for estimations involving means. The ‘numObs’ argument is required, which shouldreflect the number of observations or rows in the data described by the covariance matrix. Models with cor data typically usethemxFitFunctionML fit function.

Note on data handling: OpenMx uses the names of variables to map them onto other elements of your model, such as expectation functions.Thus for data provided as a data.frame, ensure the columns have appropriatenames.Covariance and correlation matrices need to have both the row and column names set and these must beidentical, for instance by usingdimnames = list(varNames, varNames).

Correlation data

To obtain accurate parameter estimates and standard errors,it is necessary to constrain the model implied covariance matrix to haveunit variances. This constraint is added automatically if you use anmxModel withtype='RAM' ortype='LISREL'.Otherwise, you will need to add this constraint yourself.

WLS data

TheobservedStats contains the following named objects: cov, slope, means, asymCov, useWeight, and thresholds.

‘cov’ The (polychoric) covariance matrix of raw data variables. An error is raised if any variance is smallerminVariance.

‘slope’ The regression coefficients from all exogenous predictors to all observed variables. Required for exogenous predictors.

‘means’ The means of the data variables. Required for estimations involving means.

‘thresholds’ Thresholds of ordinal variables. Required for models including ordinal variables.

‘asymCov’ The asymptotic covariance matrix (all entriesnon-zero). This matrix is sample size independent. Lavaan'sNACOV iscomparable toasymCov multiplied by N^2.

‘useWeight’ (optional) The weight matrix used in themxFitFunctionWLS. Can be dense or diagonal for diagonallyweighted least squares. This matrix is scaled by the sample size.Lavaan'sWLS.V is comparable touseWeight.

A simple Newton Raphson optimizer is used to obtain the summarystatistics from the raw data. There are two parameters that control theaccuracy of the optimization. In a first pass, the fit function isoptimized to ‘fitTolerance’. However, fit function becomesimprecise as the amount of data increases due to catastrophiccancellation. To fine-tune the fit, the gradient is optimized to‘gradientTolerance’.

note: WLS data typically use themxFitFunctionWLS function.

IMPORTANT: The WLS interface is under heavy development to support both very fast backend processing of raw data whilecontinuing to support modeling applications which require direct access to the object in the front end. Some user-interfacechanges should be expected as we optimize both these workflows.

Missing values

For raw data, the ‘naAction’ option controls the treatment of missing values.When set to ‘pass’, the data is passed as-is.When set to ‘fail’, the presence of any missing value willtrigger an error.When set to ‘omit’, missing data will be discarded row-wise.For example, a single missing value in a row will cause the whole row tobe discarded.When set to ‘exclude’, rows with missing data are retainedbut their ‘frequency’ is set to zero.

Weights

In the case of raw data, the optional ‘weight’ argument names a column in the data that contains per-row weights.Similarly, the optional ‘frequency’ argument names a column in the ‘observed’ data that contains per-rowfrequencies. Frequencies must be integers but weights can be arbitrary real numbers. For data with many repeated responsepatterns, organizing the data into unique patterns and frequencies can reduce model evaluation time.

In some cases, the fit function can be evaluated more efficiently when data are sorted. When a primary key is provided,sorting is disabled. Otherwise, sort defaults to TRUE.

The mxData function does not currently place restrictions on the size, shape, or symmetry of matrices input into the‘observed’ argument. While it is possible to specify MxData objects as covariance or correlation matrices that do nothave the properties commonly associated with these matrices, failure to correctly specify these matrices will likely lead toproblems in model estimation.

note: MxData objects may not be included inmxAlgebras nor in themxFitFunctionAlgebra function. Toreference data in these functions, use amxMatrix or a definition variable (data.var) label.

Also, while column names are stored in the ‘observed’ slot of MxData objects, these names are not automaticallyrecognized as variable names inmxPaths in RAM models. These models use the ‘manifestVars’ ofthemxModel function to explicitly identify used variables used in the model.

Value

Returns a newMxData object.

References

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

See Also

To generate data, seemxGenerateData; For objects which may be entered as arguments in the‘observed’ slot, seematrix anddata.frame. SeeMxData for the S4 class created by mxData.For WLS data, seemxDataWLS (deprecated). More information about the OpenMx package may be foundhere.

Examples

library(OpenMx)# Simple covariance model. See other mxFitFunctions for examples with different data types# 1. Create a covariance matrix x and ycovMatrix <- matrix(nrow = 2, ncol = 2, byrow = TRUE,c(0.77642931, 0.39590663,      0.39590663, 0.49115615))covNames <- c("x", "y")dimList <- list(covNames, covNames)dimnames(covMatrix) <- dimList# 2. Create an MxData object from covMatrixtestData <- mxData(observed=covMatrix, type="cov", numObs = 100)testModel <- mxModel(model="testModel2",mxMatrix(name="expCov", type="Symm", nrow=2, ncol=2,                 values=c(.2,.1,.2), free=TRUE, dimnames=dimList),    mxExpectationNormal("expCov", dimnames=covNames),    mxFitFunctionML(),testData)outModel <- mxRun(testModel)summary(outModel)

Create dynamic data

Description

Create dynamic data

Usage

mxDataDynamic(type, ..., expectation, verbose = 0L)

Arguments

type

type of data

...

Not used. Forces remaining arguments to be specified by name.

expectation

the name of the expectation to provide the data

verbose

Increase runtime debugging output


Create legacy MxData Object for Least Squares (WLS, DWLS, ULS) Analyses

Description

This function creates a newMxData object of type “ULS” (unweighted least squares), “WLS” (weighted least squares) or “DWLS” (diagonally-weighted least squares). The appropriatefit function to include with these models ismxFitFunctionWLS

note: This function continues to work, but is deprecated. UsemxData andmxFitFunctionWLS instead.

Usage

   mxDataWLS(data, type = "WLS", useMinusTwo = TRUE, returnInverted = TRUE,     fullWeight = TRUE, suppressWarnings = TRUE, allContinuousMethod =   c("cumulants", "marginals"), silent=!interactive())

Arguments

data

A matrix or data.frame which provides raw data to be used for WLS.

type

A character string 'WLS' (default), 'DWLS', or 'ULS' forweighted, diagonally weighted, or unweighted least squares, respectively

useMinusTwo

Logical indicating whether to use -2LL (default) or -LL.

returnInverted

Logical indicating whether to return the information matrix (default) or the covariance matrix.

fullWeight

Logical determining if the full weight matrix isreturned (default). Needed for standard error and quasi-chi-squaredcalculation.

suppressWarnings

Logical that determines whether to suppressdiagnostic warnings. These warnings are likely only helpful to developers.

allContinuousMethod

A character string 'cumulants' (default) or'marginals'. See mxFitFunctionWLS.

silent

Whether to report progress

Details

The mxDataWLS function creates anMxData object, which can be used inMxModel objects. This function takes raw data and returns anMxData object to be used in a model to fit with weighted least squares.

note: This function continues to work, but is deprecated. UsemxData andmxFitFunctionWLS instead.

Value

Returns a newMxData object.

References

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

Browne, M. W. (1984). Asymptotically Distribution-Free Methods for the Analysis of Covariance Structures.British Journal of Mathematical and Statistical Psychology,37, 62-83.

See Also

mxFitFunctionWLS.MxData for the S4 class created by mxData.matrix anddata.frame for objects which may be entered as arguments in the ‘observed’ slot. More information about the OpenMx package may be foundhere.

Examples

# Create and fit a model using mxMatrix, mxAlgebra, mxExpectationNormal, and mxFitFunctionWLSlibrary(OpenMx)# Simulate some datax=rnorm(1000, mean=0, sd=1)y= 0.5*x + rnorm(1000, mean=0, sd=1)tmpFrame <- data.frame(x, y)tmpNames <- names(tmpFrame)wdata <- mxDataWLS(tmpFrame)# Define the matricesS <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(1,0,0,1),               free=c(TRUE,FALSE,FALSE,TRUE), labels=c("Vx", NA, NA, "Vy"), name = "S")A <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0),               free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b", NA, NA), name = "A")I <- mxMatrix(type="Iden", nrow=2, ncol=2, name="I")# Define the expectationexpCov <- mxAlgebra(solve(I-A) %*% S %*% t(solve(I-A)), name="expCov")expFunction <- mxExpectationNormal(covariance="expCov", dimnames=tmpNames)# Choose a fit functionfitFunction <- mxFitFunctionWLS()# Define the modeltmpModel <- mxModel(model="exampleModel", S, A, I, expCov, expFunction, fitFunction,                     wdata)# Fit the model and print a summarytmpModelOut <- mxRun(tmpModel)summary(tmpModelOut)

Determine whether a dataset will have weights and summary statistics for the means if used with mxFitFunctionWLS

Description

Given either a data.frame or an mxData of type raw, this function determines whethermxFitFunctionWLSwill generate expectations for means.

Usage

mxDescribeDataWLS(  data,  allContinuousMethod = c("cumulants", "marginals"),  verbose = FALSE)

Arguments

data

the (currently raw) data being used in amxFitFunctionWLS model.

allContinuousMethod

the method used to process data when all columns are continuous.

verbose

logical. Whether to report diagnostics.

Details

All-continuous data processed using the "cumulants" method lack means, whileall continuous data processed with allContinuousMethod = "marginals" will have means.

When data are not all continuous, allContinuousMethod is ignored, and means are modelled.

Value

- list describing the data.

See Also

-mxFitFunctionWLS,omxAugmentDataWithWLSSummary

Examples

# ====================================# = All continuous, data.frame input =# ====================================tmp = mxDescribeDataWLS(mtcars, allContinuousMethod= "cumulants", verbose = TRUE)tmp$hasMeans # FALSE - no means with cumulantstmp = mxDescribeDataWLS(mtcars, allContinuousMethod= "marginals")tmp$hasMeans # TRUE we get means with marginals# ==========================# = mxData object as input =# ==========================tmp = mxData(mtcars, type="raw")mxDescribeDataWLS(tmp, allContinuousMethod= "cumulants", verbose = TRUE)$hasMeans # FALSEmxDescribeDataWLS(tmp, allContinuousMethod= "marginals")$hasMeans  # TRUE# =======================================# = One var is a factor: Means modelled =# =======================================tmp = mtcarstmp$cyl = factor(tmp$cyl)mxDescribeDataWLS(tmp, allContinuousMethod= "cumulants")$hasMeans # TRUE - always has meansmxDescribeDataWLS(tmp, allContinuousMethod= "marginals")$hasMeans # TRUE

Evaluate Values in MxModel

Description

This function can be used to evaluate an arbitrary R expression that includes named entities from aMxModel object, or labels from aMxMatrix object.

Usage

mxEval(expression, model, compute = FALSE, show = FALSE, defvar.row = 1,    cache = new.env(parent = emptyenv()), cacheBack = FALSE, .extraBack=0L)mxEvalByName(name, model, compute = FALSE, show = FALSE, defvar.row = 1,    cache = new.env(parent = emptyenv()), cacheBack = FALSE, .extraBack=0L)

Arguments

expression

An arbitrary R expression.

model

The model in which to evaluate the expression.

compute

If TRUE then compute the value of algebra expressionsand populate square bracket substitutions.

show

If TRUE then print the translated expression.

defvar.row

The row number for definition variables when compute=TRUE; defaults to 1. When compute=FALSE, values for definition variables are always taken from the first (i.e., first before any automated sorting is done) row of the raw data.

cache

An R environment of matrix values used to speedup computation.

cacheBack

If TRUE then return the list pair (value, cache).

name

The character name of an object to evaluate.

.extraBack

Depth of original caller in count of stack frames (environments).

Details

[Stable]The argument ‘expression’ is an arbitrary R expression. Any named entities that are used within the R expression are translated into their current value from the model. Any labels from the matrices within the model are translated into their current value from the model. Finally the expression is evaluated and the result is returned. To enable debugging, the ‘show’ argument has been provided. The most common mistake when using this function is to include named entities in the model that are identical to R function names. For example, if a model contains a named entity named ‘c’, then the following mxEval call will return an error:mxEval(c(A, B, C), model).

ThemxEvalByName function is a wrapper aroundmxEval that takes a character instead of an R expression.

If ‘compute’ is FALSE, then MxAlgebra expressions return theircurrent values as they have been computed by the optimization call(usingmxRun). If the ‘compute’ argument is TRUE, thenMxAlgebra expressions will be calculated in R and square bracketsubstitutions will be performed. Any references to an objectivefunction that has not yet been calculated will return a 1 x 1 matrixwith a value of NA.

The ‘cache’ is used to speedup calculation by storing previously computing values. The cache is a list of matrices, such that names(cache) must all be of the form “modelname.entityname”. Setting ‘cacheBack’ to TRUE will return the pair list(value, cache) where value is the result of the mxEval() computation and cache is the updated cache.

References

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

See Also

mxAlgebra to create algebraic expressions inside your model andmxModel for the model object mxEval looks inside when evaluating.

Examples

library(OpenMx)# Set up a 1x1 matrixmatrixA <- mxMatrix("Full", nrow = 1, ncol = 1, values = 1, name = "A")# Set up an algebraalgebraB <- mxAlgebra(A + A, name = "B")# Put them both in a modeltestModel <- mxModel(model="testModel3", matrixA, algebraB)# Even though the model has not been run, we can evaluate the algebra#   given the starting values in matrixA.mxEval(B, testModel, compute=TRUE)# If we just print the algebra, we can see it has not been evaluatedtestModel$B

Evaluate an algebra on an abscissa grid and collect column results

Description

This function evaluates an algebra on a grid of points provided inan auxiliary abscissa matrix.

Usage

mxEvaluateOnGrid(algebra, abscissa)

Arguments

algebra

the name of the single column matrix to be evaluated.

abscissa

the name of the abscissa matrix. See details.

Details

The abscissa matrix must be in a specific format.The variables are in the rows. Abscissa row names must match names offree variables.The grid points are in columns.For each point (column), the free variables are set to the givenvalues and the algebra is re-evaluated. The resulting columns arecollected as the result.

Value

Returns the collected columns.

Examples

library(OpenMx)test2 <- mxModel("test2",mxMatrix(values=1.1, nrow=1, ncol=1, free=TRUE, name="thang"),mxMatrix(nrow=1, ncol=1, labels="abscissa1", free=TRUE, name="currentAbscissa"),mxMatrix(values=-2:2, nrow=1, ncol=5, name="abscissa", dimnames=list(c('abscissa1'), NULL)),mxAlgebra(rbind(currentAbscissa + thang, currentAbscissa * thang), name="stuff"),mxAlgebra(mxEvaluateOnGrid(stuff, abscissa), name="grid"))test2 <- mxRun(test2)omxCheckCloseEnough(test2$grid$result, matrix(c(-1:3 + .1, -2:2 * 1.1), ncol=5, nrow=2,byrow=TRUE))

Create a Bock & Aitkin (1981) expectation

Description

Used in conjunction withmxFitFunctionML, this expectationmodels ordinal data with a modest number of latent dimensions.Currently, only a multivariate Normal latent distribution issupported. An equal-interval quadrature is used to integrate overthe latent distribution. When all items use the graded responsemodel and items are assumed conditionally independent then itemfactor analysis is equivalent to a factor model.

Usage

mxExpectationBA81(  ItemSpec,  item = "item",  ...,  qpoints = 49L,  qwidth = 6,  mean = "mean",  cov = "cov",  verbose = 0L,  weightColumn = NA_integer_,  EstepItem = NULL,  debugInternal = FALSE)

Arguments

ItemSpec

a single item model (to replicate) or a list ofitem models in the same order as the column ofItemParam

item

the name of the mxMatrix holding item parameterswith one column for each item model with parameters starting atrow 1 and extra rows filled with NA

...

Not used. Forces remaining arguments to be specified by name.

qpoints

number of points to use for equal interval quadrature integration (default 49L)

qwidth

the width of the quadrature as a positive Z score (default 6.0)

mean

the name of the mxMatrix holding the mean vector

cov

the name of the mxMatrix holding the covariance matrix

verbose

the level of runtime diagnostics (default 0L)

weightColumn

the name of the column in the data containing the row weights (DEPRECATED)

EstepItem

a simple matrix of item parameters for theE-step. This option is mainly of use for debugging derivatives.

debugInternal

when enabled, some of the internal tables arereturned in $debug. This is mainly of use to developers.

Details

The conditional likelihood of responsex_{ij} toitemj from personi with item parameters\xi_j and latent ability\theta_i is

L(x_i|\xi,\theta_i) = \prod_j \mathrm{Pr}(\mathrm{pick}=x_{ij} | \xi_j,\theta_i).

Items are assumed to be conditionally independent.That is, the outcome of one item is assumed to not influenceanother item after controlling for\xi and\theta_i.

The unconditional likelihood is obtained by integrating overthe latent distribution\theta_i,

L(x_i|\xi) = \int L(x_i|\xi, \theta_i) L(\theta_i) \mathrm{d}\theta_i.

With an assumption that examinees are independently and identically distributed,we can sum the individual log likelihoods,

\mathcal{L}=\sum_i \log L(x_i | \xi).

Response models\mathrm{Pr}(\mathrm{pick}=x_{ij} |\xi_j,\theta_i)are not implemented in OpenMx, but are importedfrom theRPFpackage. You must pass a list of models obtained from the RPFpackage in the ‘ItemSpec’ argument. All item models must use thesame number of latent factors although some of these factorloadings can be constrained to zero in the item parameter matrix.The ‘item’ matrix contains item parameters with one item percolumn in the same order at ItemSpec.

The ‘qpoints’ and ‘qwidth’ argument control the fineness andwidth, respectively, of the equal-interval quadrature grid. Theinteger ‘qpoints’ is the number of points per dimension. Thequadrature extends from negative qwidth to positive qwidth foreach dimension. Since the latent distribution defaults to standardNormal, qwidth can be regarded as a value in Z-score units.

The optional ‘mean’ and ‘cov’ arguments permit modeling of thelatent distribution in multigroup models (in a single group, thelatent distribution must be fixed). A separate latent covariancemodel is used in combination with mxExpectationBA81. The pointmass distribution contained in the quadrature is converted into amultivariate Normal distribution bymxDataDynamic. TypicallymxExpectationNormal is usedto fit a multivariate Normal model to these data. Some intricateprogramming is required. Examples are given in the manual.mxExpectationBA81 uses a sample size ofN for the covariancematrix. This differs frommxExpectationNormal which uses asample size ofN-1.

The ‘verbose’ argument enables diagnostics that are mainly ofinterest to developers.

When a two-tier covariance matrix is recognized, this expectationautomatically enables analytic dimension reduction (Cai, 2010).

The optional ‘weightColumn’ is superseded by the weightargument inmxData. For data with many repeatedresponse patterns, model evaluation time can bereduced. An easy way to transform your data into this form is tousecompressDataFrame. Non-integer weights are supported except forEAPscores.

mxExpectationBA81 requiresmxComputeEM. During a typicaloptimization run, latent abilities are assumed for examineesduring the E-step. These examinee scores are implied by theprevious iteration's parameter vector. This can be overriddenusing the ‘EstepItem’ argument. This is mainly of use todevelopers for checking item parameter derivatives.

Common univariate priors are available fromunivariatePrior. The standard Normaldistribution of the quadrature acts like a prior distribution fordifficulty. It is not necessary to impose any additional Bayesianprior on difficulty estimates (Baker & Kim, 2004, p. 196).

Many estimators are available for standard errors. Oakes isrecommended (seemxComputeEM). Also available areSupplement EM (mxComputeEM), Richardson extrapolation(mxComputeNumericDeriv), likelihood-based confidenceintervals (mxCI), and the covariance of the rowwisegradients.

References

Bock, R. D., & Aitkin, M. (1981). Marginal maximum likelihood estimation of itemparameters: Application of an EM algorithm.Psychometrika, 46, 443-459.

Cai, L. (2010). A two-tier full-information item factor analysismodel with applications.Psychometrika, 75, 581-612.

Pritikin, J. N., Hunter, M. D., & Boker, S. M. (2015). Modularopen-source software for Item Factor Analysis.Educational andPsychological Measurement, 75(3), 458-474

Pritikin, J. N. & Schmidt, K. M. (in press). Model builder forItem Factor Analysis with OpenMx.R Journal.

Seong, T. J. (1990). Sensitivity of marginal maximum likelihoodestimation of item and ability parameters to the characteristicsof the prior ability distributions.Applied PsychologicalMeasurement, 14(3), 299-311.

See Also

RPF

Examples

library(OpenMx)library(rpf)numItems <- 14# Create item specificationsspec <- list()for (ix in 1:numItems) { spec[[ix]] <- rpf.grm(outcomes=sample(2:7, 1)) }names(spec) <- paste("i", 1:numItems, sep="")# Generate some random "true" parameter valuescorrect.mat <- mxSimplify2Array(lapply(spec, rpf.rparam))# Generate some example datadata <- rpf.sample(500, spec, correct.mat)# Create a matrix of item parameters with starting valuesimat <- mxMatrix(name="item",                 values=mxSimplify2Array(lapply(spec, rpf.rparam)))rownames(imat)[1] <- 'f1'imat$free[!is.na(correct.mat)] <- TRUEimat$values[!imat$free] <- NA# Create a compute planplan <- mxComputeSequence(list(  mxComputeEM('expectation', 'scores',              mxComputeNewtonRaphson(), information="oakes1999",              infoArgs=list(fitfunction='fitfunction')),  mxComputeHessianQuality(),  mxComputeStandardError(),  mxComputeReportDeriv()))# Build the OpenMx modelgrmModel <- mxModel(model="grm1", imat,                    mxData(observed=data, type="raw"),                    mxExpectationBA81(ItemSpec=spec),                    mxFitFunctionML(),                    plan)grmModel <- mxRun(grmModel)summary(grmModel)

Create MxExpectationGREML Object

Description

This function creates a newMxExpectationGREML object.

Usage

mxExpectationGREML(V, yvars=character(0), Xvars=list(), addOnes=TRUE, blockByPheno=TRUE,                   staggerZeroes=TRUE, dataset.is.yX=FALSE, casesToDropFromV=integer(0),                  REML=TRUE, yhat=character(0))

Arguments

V

Character string; the name of theMxAlgebra orMxMatrix to serve as the 'V' matrix (the model-expected covariance matrix). Internally, the 'V' matrix is assumed to be symmetric, and its elements above the main diagonal are ignored.

yvars,Xvars,addOnes,blockByPheno,staggerZeroes

Passed tomxGREMLDataHandler().

dataset.is.yX

Logical; defaults toFALSE. IfTRUE, then the first column of the raw dataset is taken as-is to be the 'y' phenotype vector, and the remaining columns are taken as-is to be the 'X' matrix of covariates. In this case,mxGREMLDataHandler() is never internally called at runtime, and all other arguments besidesV,casesToDropFromV, andREML are ignored.

casesToDropFromV

Integer vector. Its elements are the indices of the rows and columns of covariance matrix 'V' (and if applicable, of the rows of 'yhat') to be dropped at runtime, usually because they correspond to rows of 'y' or 'X' that contained missing observations. By default, no cases are dropped from 'V.' Ignored unlessdataset.is.yX isTRUE.

REML

Logical; defaults toTRUE. Should restricted maximum-likelihood estimation be used?

yhat

Character string; the name of theMxAlgebra orMxMatrix to serve as the model-expected phenotypic mean vector. It is recommended that the algebra or matrix be a column-vector, and some of OpenMx's utility functions (e.g.,mxAutoStart()) assume that to be true. Non-empty (i.e., non-default) values should only be provided ifREML isFALSE.

Details

"GREML" stands for "genomic-relatedness-matrix restricted maximum-likelihood." In the strictest sense of the term, it refers to genetic variance-component estimation from matrices of subjects' pairwise degree of genetic relatedness, as calculated from genome-wide marker data. It is from this original motivation that some of the terminology originates, such as calling 'y' the "phenotype" vector. However, OpenMx's implementation of GREML is applicable for restricted maximum-likelihood analyses from any subject-matter domain, and in which the following assumptions are reasonable:

  1. Conditional on 'X' (the covariates), the phenotype vector (response variable) 'y' is a single realization from a multivariate-normal distribution having (in general) a dense covariance matrix, 'V'.

  2. The parameters of the covariance matrix, such as variance components, are of primary interest.

  3. The random effects are normally distributed.

  4. Weighted least-squares regression, using the inverse of 'V' as a weight matrix, is an adequate model for the phenotypic means. Note that the regression coefficients are not actually free parameters to be numerically optimized.

  5. No variables in the model are treated both as phenotypes in 'y' and as covariates in 'X'.

Computationally, the chief distinguishing feature of an OpenMx GREML analysis is that the phenotype vector, 'y,' is a single realization of a random vector that, in general, cannot be partitioned into independent subvectors. For this reason, definition variables are not compatible (and should be unnecessary with) GREML expectation. GREML expectation can still be used if the covariance matrix is sparse, but as of this writing, OpenMx does not take advantage of the sparseness to improve performance. Partly because of the limitations of restricted maximum likelihood, GREML expectation is incompatible with ordinal variables; with GREML expectation, ordinal phenotypes must be treated as though they were continuous.

WhenREML isTRUE, the phenotypic means are always modeled "implicitly" via weighted least-squares regression onto the covariates in 'X', using the inverse of 'V' as the weight matrix. The phenotypic means can also be modeled "implicitly" in the same way whenREML isFALSE. However, the case ofREML=FALSE also allows the user to model the phenotypic meansexplicitly, as 'yhat', an arbitraryMxAlgebra orMxMatrix to serve as the model-expected phenotypic mean vector. So long as the appropriate care is taken, use of 'yhat' allows one to enter variables into one's model both as phenotypes in 'y' and covariates in 'X'.

WhenREML isFALSE and the user providesyhat, the assumptions of a GREML analysis may be stated as follows:

  1. Phenotype vector 'y' is equal to mean vector 'yhat' plus normally distributed random effects, at least one of which is a single realization from a multivariate-normal distribution having (in general) a dense covariance matrix, 'V'.

  2. The parameters of the covariance matrix and the mean vector are both explicit free parameters of interest.

Value

Returns a new object of classMxExpectationGREML.

References

Kirkpatrick RM, Pritikin JN, Hunter MD, & Neale MC. (2021). Combining structural-equation modeling with genomic-relatedness matrix restricted maximum likelihood in OpenMx. Behavior Genetics 51: 331-342.doi:10.1007/s10519-020-10037-5

The first software implementation of "GREML":
Yang J, Lee SH, Goddard ME, Visscher PM. (2011). GCTA: a tool for genome-wide complex trait analysis. American Journal of Human Genetics 88: 76-82.doi:10.1016/j.ajhg.2010.11.011

One of the first uses of the acronym "GREML":
Benjamin DJ, Cesarini D, van der Loos MJHM, Dawes CT, Koellinger PD, et al. (2012). The genetic architecture of economic and political preferences. Proceedings of the National Academy of Sciences 109: 8026-8031. doi: 10.1073/pnas.1120666109

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

See Also

SeeMxExpectationGREML for the S4 class created bymxExpectationGREML(). More information about the OpenMx package may be foundhere.

Examples

dat <- cbind(rnorm(100),rep(1,100))colnames(dat) <- c("y","x")ge <- mxExpectationGREML(V="V",yvars="y",Xvars=list("X"),addOnes=FALSE)gff <- mxFitFunctionGREML(dV=c(ve="I"))plan <- mxComputeSequence(freeSet=c("Ve"),steps=list(  mxComputeNewtonRaphson(fitfunction="fitfunction"),  mxComputeOnce('fitfunction',    c('fit','gradient','hessian','ihessian')),  mxComputeStandardError(),  mxComputeReportDeriv(),  mxComputeReportExpectation()))testmod <- mxModel(  "GREMLtest",  mxData(observed = dat, type="raw"),  mxMatrix(type = "Full", nrow = 1, ncol=1, free=TRUE,    values = 1, labels = "ve", lbound = 0.0001, name = "Ve"),  mxMatrix("Iden",nrow=100,name="I",condenseSlots=TRUE),  mxAlgebra(I %x% Ve,name="V"),  ge,  gff,  plan)str(testmod)

Hidden Markov expectation

Description

Used in conjunction withmxFitFunctionML, this expectationcan express a mixture model (with the transition matrix omitted)or a Hidden Markov model.

Usage

mxExpectationHiddenMarkov(components, initial="initial", transition=NULL,      ..., verbose=0L, scale=c('softmax', 'sum', 'none'))

Arguments

components

A character vector of model names.

initial

The name of the matrix or algebra column that specifiesthe initial probabilities.

transition

The name of the matrix or algebra that specifiesthe left stochastic transition probabilities.

...

Not used. Forces remaining arguments to be specified by name.

verbose

the level of runtime diagnostics

scale

How the probabilities are rescaled. For 'softmax',the coefficient-wise exponential is taken and then each column isdivided by its column sum. For 'sum', each column is divided by itscolumn sum. For 'none', no scaling is done.

Details

The initial probabilities given ininitial must sum to one. So too must thecolumns of the transition matrix given intransition. The transitions go from a column to a row, similar to how regression effects in the RAM structural equation models go from the column variable to the row variable. This meanstransition is a left stochastic matrix.

For ease of use the raw free parameters of these matrices are rescaled by OpenMx according to thescale argument. Whenscale is set to "softmax" the softmax function is applied to the initial probabilities and the columns of the transition matrix. The softmax function is also sometimes called multinomial logistic regression. Softmax exponentiates each element in a vector and then divides each element by the sum of the exponentiated elements. In equation form the softmax function is

\textrm{softmax}(x_i) = \frac{e^{x_i}}{\sum_{k=1}^{K} e^{x_k} }

When using the softmax scaling no free parameter bounds or constraints are needed. However, for model identification, one element of the initial probabilities vector must be fixed. If the softmax scaling is used, then the usual choice for the fixed parameter value is zero. The regime (or latent class or mixture component) that has its initial probability set to zero becomes the comparison against which other probabilities are evaluated. Likewise for model identification, one element in each column of the transition matrix must be fixed. When the softmax scaling is used, the typical choice is to fix one element in each column to zero. Generally, one row of the transition matrix is fixed to zero, or the diagonal elements of the transition matrix are fixed to zero.

Whenscale is set to "sum" then each element of the initial probabilities and each column of the transition matrix is internally divided by its sum. When using the sum scaling, the same model identification requirements are present. In particular, one element of the initial probabilities must be fixed and one element in each column of the transition matrix must be fixed. The typical value to fix these values at for sum scaling is one. Additionally when using sum scaling, all free parameters in the initial and transition probabilities must have lower bounds of zero. In equation form the sum scaling does the following:

\textrm{sumscale}(x_i) = \frac{x_i}{\sum_{k=1}^{K} x_k }

Whenscale is set to "none" then no re-scaling is done. The parameters ofinitial andtransition are left "as is". This can be dangerous and is not recommended for novice users. It might produce nonsensical results particularly for hidden Markov models. However, some advanced users may find no scaling to be advantageous for certain applications (e.g., they are providing their own scaling), and thus it is provided as an option.

Parameters are estimated in the given scale. To obtain the initialcolumn vector and left stochastic transition matrix in probabilityunits then examine the expectation'soutput slot with for exampleyourModel$expectation$output

Definition variables can be used to assign a separate set of mixtureprobabilities to each row of data.Definition variables can be used in the initial column vector or inthe transition matrix, but not in both at the same time.

Note that, when the transition matrix is omitted,this expectation is the same asmxExpectationMixture.mxGenerateData is not implemented for this type of expectation.

Examples

library(OpenMx)start_prob <- c(.2,.4,.4)transition_prob <- matrix(c(.8, .1, .1,.3, .6, .1,.1, .3, .6), 3, 3)noise <- .5  # simulate a trajectory  state <- sample.int(3, 1, prob=transition_prob %*% start_prob)  trail <- c(state)  for (rep in 1:500) {    state <- sample.int(3, 1, prob=transition_prob[,state])    trail <- c(trail, state)  }    # add noise  trailN <- sapply(trail, function(v) rnorm(1, mean=v, sd=sqrt(noise)))  classes <- list()    for (cl in 1:3) {    classes[[cl]] <- mxModel(paste0("cl", cl), type="RAM",                             manifestVars=c("ob"),                             mxPath("one", "ob", value=cl, free=FALSE),                             mxPath("ob", arrows=2, value=noise, free=FALSE),                             mxFitFunctionML(vector=TRUE))  }  m1 <-      mxModel("hmm", classes,            mxData(data.frame(ob=trailN), "raw"),            mxMatrix(nrow=3, ncol=1,                     labels=paste0('i',1:3), name="initial"),            mxMatrix(nrow=length(classes), ncol=length(classes),                     labels=paste0('t', 1:(length(classes) * length(classes))),                     name="transition"),            mxExpectationHiddenMarkov(              components=sapply(classes, function(m) m$name),              initial="initial",              transition="transition", scale="softmax"),            mxFitFunctionML())  m1$transition$free[1:(length(classes)-1), 1:length(classes)] <- TRUEm1 <- mxRun(m1)summary(m1)print(m1$expectation$output)

Create MxExpectationLISREL Object

Description

This function creates a new MxExpectationLISREL object.

Usage

mxExpectationLISREL(LX=NA, LY=NA, BE=NA, GA=NA, PH=NA, PS=NA, TD=NA, TE=NA, TH=NA,                    TX = NA, TY = NA, KA = NA, AL = NA,                    dimnames = NA, thresholds = NA, threshnames = deprecated(), verbose=0L, ...,  expectedCovariance=NULL, expectedMean=NULL, discrete = as.character(NA))

Arguments

LX

An optional character string indicating the name of the 'LX' matrix.

LY

An optional character string indicating the name of the 'LY' matrix.

BE

An optional character string indicating the name of the 'BE' matrix.

GA

An optional character string indicating the name of the 'GA' matrix.

PH

An optional character string indicating the name of the 'PH' matrix.

PS

An optional character string indicating the name of the 'PS' matrix.

TD

An optional character string indicating the name of the 'TD' matrix.

TE

An optional character string indicating the name of the 'TE' matrix.

TH

An optional character string indicating the name of the 'TH' matrix.

TX

An optional character string indicating the name of the 'TX' matrix.

TY

An optional character string indicating the name of the 'TY' matrix.

KA

An optional character string indicating the name of the 'KA' matrix.

AL

An optional character string indicating the name of the 'AL' matrix.

dimnames

An optional character vector that is currently ignored

thresholds

An optional character string indicating the name of the thresholds matrix.

threshnames

[Deprecated]

verbose

integer. Level of runtime diagnostic output.

...

Not used. Forces remaining arguments to be specified by name.

expectedCovariance

An optional character string indicating thename of a matrix for the model implied covariance.

expectedMean

An optional character string indicating the nameof a matrix for the model implied mean.

discrete

An optional character string indicating the name of the discrete matrix.

Details

Expectation functions define the way that model expectations are calculated. The mxExpectationLISREL calculates the expected covariance and means of a givenMxData object given a LISREL model. This model is defined by LInear Structural RELations (LISREL; Jöreskog & Sörbom, 1982, 1996). Arguments 'LX' through 'AL' must refer toMxMatrix objects with the associated properties of their respective matrices in the LISREL modeling approach.

The full LISREL specification has 13 matrices and is sometimes called the extended LISREL model. It is defined by the following equations.

\eta = \alpha + B \eta + \Gamma \xi + \zeta

y = \tau_y + \Lambda_y \eta + \epsilon

x = \tau_x + \Lambda_x \xi + \delta

The table below is provided as a quick reference to the numerous matrices in LISREL models. Note that NX is the number of manifest exogenous (independent) variables, the number of Xs. NY is the number of manifest endogenous (dependent) variables, the number of Ys. NK is the number of latent exogenous variables, the number of Ksis or Xis. NE is the number of latent endogenous variables, the number of etas.

Matrix Word Abbreviation Dimensions Expression Description
\Lambda_x Lambda x LX NX x NK Exogenous Factor Loading Matrix
\Lambda_y Lambda y LY NY x NE Endogenous Factor Loading Matrix
B Beta BE NE x NE Regressions of Latent Endogenous Variables Predicting Endogenous Variables
\Gamma Gamma GA NE x NK Regressions of Latent Exogenous Variables Predicting Endogenous Variables
\Phi Phi PH NK x NK cov(\xi) Covariance Matrix of Latent Exogenous Variables
\Psi Psi PS NE x NE cov(\zeta) Residual Covariance Matrix of Latent Endogenous Variables
\Theta_{\delta} Theta delta TD NX x NX cov(\delta) Residual Covariance Matrix of Manifest Exogenous Variables
\Theta_{\epsilon} Theta epsilon TE NY x NY cov(\epsilon) Residual Covariance Matrix of Manifest Endogenous Variables
\Theta_{\delta \epsilon} Theta delta epsilson TH NX x NY cov(\delta, \epsilon) Residual Covariance Matrix of Manifest Exogenous with Endogenous Variables
\tau_x tau x TX NX x 1 Residual Means of Manifest Exogenous Variables
\tau_y tau y TY NY x 1 Residual Means of Manifest Endogenous Variables
\kappa kappa KA NK x 1 mean(\xi) Means of Latent Exogenous Variables
\alpha alpha AL NE x 1 Residual Means of Latent Endogenous Variables

From the extended LISREL model, several submodels can be defined. Subtypes of the LISREL model are defined by setting some of the arguments of the LISREL expectation function to NA. Note that because the default values of each LISREL matrix is NA, setting a matrix to NA can be accomplished by simply not giving it any other value.

The first submodel is the LISREL model without means.

\eta = B \eta + \Gamma \xi + \zeta

y = \Lambda_y \eta + \epsilon

x = \Lambda_x \xi + \delta

The LISREL model without means requires 9 matrices: LX, LY, BE, GA, PH, PS, TD, TE, and TH. Hence this LISREL model has TX, TY, KA, and AL as NA. This can be accomplished be leaving these matrices at their default values.

The TX, TY, KA, and AL matrices must be specified if either the mxData type is “cov” or “cor” and a means vector is provided, or if the mxData type is “raw”. Otherwise the TX, TY, KA, and AL matrices are ignored and the model without means is estimated.

A second submodel involves only endogenous variables.

\eta = B \eta + \zeta

y = \Lambda_y \eta + \epsilon

The endogenous-only LISREL model requires 4 matrices: LY, BE, PS, and TE. The LX, GA, PH, TD, and TH must be NA in this case. However, means can also be specified, allowing TY and AL if the data are raw or if observed means are provided.

Another submodel involves only exogenous variables.

x = \Lambda_x \xi + \delta

The exogenous-model model requires 3 matrices: LX, PH, and TD. The LY, BE, GA, PS, TE, and TH matrices must be NA. However, means can also be specified, allowing TX and KA if the data are raw or if observed means are provided.

The model that is run depends on the matrices that are not NA. If all 9 matrices are not NA, then the full model is run. If only the 4 endogenous matrices are not NA, then the endogenous-only model is run. If only the 3 exogenous matrices are not NA, then the exogenous-only model is run. If some endogenous and exogenous matrices are not NA, but not all of them, then appropriate errors are thrown. Means are included in the model whenever their matrices are provided.

TheMxMatrix objects included as arguments may be of any type, but should have the properties described above. The mxExpectationLISREL will not return an error for incorrect specification, but incorrect specification will likely lead to estimation problems or errors in themxRun function.

Like themxExpectationRAM, the mxExpectationLISREL evaluates with respect to anMxData object. TheMxData object need not be referenced in the mxExpectationLISREL function, but must be included in theMxModel object. mxExpectationLISREL requires that the 'type' argument in the associatedMxData object be equal to 'cov', 'cor', or 'raw'.

To evaluate, place mxExpectationLISREL objects, themxData object for which the expected covariance approximates, referencedMxAlgebra andMxMatrix objects, and optionalMxBounds andMxConstraint objects in anMxModel object. This model may then be evaluated using themxRun function. The results of the optimization can be found in the 'output' slot of the resulting model, and may be obtained using themxEval function.

Value

Returns a new MxExpectationLISREL object. One and only one MxExpectationLISREL object can be included with models using one and only one fit function object (e.g., MxFitFunctionML) and with referencedMxAlgebra,MxData andMxMatrix objects.

References

Jöreskog, K. G. & Sörbom, D. (1996). LISREL 8: User's Reference Guide. Lincolnwood, IL: Scientific Software International.

Jöreskog, K. G. & Sörbom, D. (1982). Recent developments in structural equation modeling.Journal of Marketing Research, 19, 404-416.

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

See Also

demo("LISRELJointFactorModel")

Examples

   # Create and fit a model using mxExpectationLISREL, and mxFitFunctionMLlibrary(OpenMx)vNames <- paste("v",as.character(1:6),sep="")dimList <- list(vNames, vNames)covData <- matrix(  c(0.9223099, 0.1862938, 0.4374359, 0.8959973, 0.9928430, 0.5320662,    0.1862938, 0.2889364, 0.3927790, 0.3321639, 0.3371594, 0.4476898,    0.4374359, 0.3927790, 1.0069552, 0.6918755, 0.7482155, 0.9013952,    0.8959973, 0.3321639, 0.6918755, 1.8059956, 1.6142005, 0.8040448,    0.9928430, 0.3371594, 0.7482155, 1.6142005, 1.9223567, 0.8777786,    0.5320662, 0.4476898, 0.9013952, 0.8040448, 0.8777786, 1.3997558    ), nrow=6, ncol=6, byrow=TRUE, dimnames=dimList)# Create LISREL matricesmLX <- mxMatrix("Full", values=c(.5, .6, .8, rep(0, 6), .4, .7, .5),          name="LX", nrow=6, ncol=2,          free=c(TRUE,TRUE,TRUE,rep(FALSE, 6),TRUE,TRUE,TRUE),          dimnames=list(vNames, c("x1","x2")))mTD <- mxMatrix("Diag", values=c(rep(.2, 6)),           name="TD", nrow=6, ncol=6, free=TRUE,          dimnames=dimList)mPH <- mxMatrix("Symm", values=c(1, .3, 1),           name="PH", nrow=2, ncol=2, free=c(FALSE, TRUE, FALSE),          dimnames=list(c("x1","x2"),c("x1","x2")))# Create a LISREL expectation with LX, TD, and PH matrix namesexpFunction <- mxExpectationLISREL(LX="LX", TD="TD", PH="PH")# Create fit function and datatmpData <- mxData(observed=covData, type="cov", numObs=100)fitFunction <- mxFitFunctionML()# Create the model, fit it, and print a summary.tmpModel <- mxModel(model="exampleModel",                    mLX, mTD, mPH, expFunction, fitFunction, tmpData)tmpModelOut <- mxRun(tmpModel)summary(tmpModelOut)#--------------------------------------# Fit factor model with meansrequire(OpenMx)data(demoOneFactor)nvar <- ncol(demoOneFactor)varnames <- colnames(demoOneFactor)factorMeans <- mxMatrix("Zero", 1, 1, name="Kappa",                        dimnames=list("F1", NA))xIntercepts <- mxMatrix("Full", nvar, 1, free=TRUE, name="TauX",                        dimnames=list(varnames, NA))factorLoadings <- mxMatrix("Full", nvar, 1, TRUE, .6, name="LambdaX",                           labels=paste("lambda", 1:nvar, sep=""),                           dimnames=list(varnames, "F1"))factorCovariance <- mxMatrix("Diag", 1, 1, FALSE, 1, name="Phi")xResidualVariance <- mxMatrix("Diag", nvar, nvar, TRUE, .2, name="ThetaDelta",                              labels=paste("theta", 1:nvar, sep=""))liModel <- mxModel(model="LISREL Factor Model",factorMeans, xIntercepts, factorLoadings,factorCovariance, xResidualVariance,mxExpectationLISREL(LX="LambdaX", PH="Phi",TD="ThetaDelta", TX="TauX", KA="Kappa"),mxFitFunctionML(),mxData(cov(demoOneFactor), "cov",means=colMeans(demoOneFactor), numObs=nrow(demoOneFactor)))liRun <- mxRun(liModel)summary(liRun)

Mixture expectation

Description

Used in conjunction withmxFitFunctionML, this expectationcan express a mixture model.

Usage

mxExpectationMixture(components, weights="weights",      ..., verbose=0L, scale=c('softmax', 'sum', 'none'))

Arguments

components

A character vector of model names.

weights

The name of the matrix or algebra column that specifiesthe component weights.

...

Not used. Forces remaining arguments to be specified by name.

verbose

the level of runtime diagnostics

scale

How the probabilities are rescaled. For 'softmax',the coefficient-wise exponential is taken and then each column isdivided by its column sum. For 'sum', each column is divided by itscolumn sum. For 'none', no scaling is done.

Details

The mixture probabilities given inweights must sum to one. As such forK mixture components, onlyK-1 of the elements ofweights can be estimated. The mixture probabilities inweights should be a column vector (i.e., aK by 1 matrix, or algebra with aK by 1 result).

For ease of use the raw free parameters of weights can be rescaled by OpenMx according to thescale argument. Whenscale is set to "softmax" the softmax function is applied to the weights. The softmax function is also sometimes called multinomial logistic regression. Softmax exponentiates each element in a vector and then divides each element by the sum of the exponentiated elements. In equation form the softmax function is

softmax(x_i) = \frac{e^{x_i}}{\sum_{k=1}^{K} } e^{x_k}

When using the softmax scaling no free parameter bounds or constraints are needed. However, for model identification, one element of the weights vector must be fixed. If the softmax scaling is used, then the usual choice for the fixed parameter value is zero. The latent class or mixture component that has its raw weight set to zero becomes the comparison against which other probabilities are evaluated.

Whenscale is set to "sum" then each element of the weights matrix is internally divided by its sum. When using the sum scaling, the same model identification requirements are present. In particular, one element of the weights must be fixed. The typical value to fix this value at for sum scaling is one. Additionally when using sum scaling, all free parameters in the weights must have lower bounds of zero. In equation form the sum scaling does the following:

sumscale(x_i) = \frac{x_i}{\sum_{k=1}^{K} } x_k

Whenscale is set to "none" then no re-scaling is done. The weights are left "as is". This can be dangerous and is not recommended for novice users. However, some advanced users may find no scaling to be advantageous for certain applications (e.g., they are providing their own scaling), and thus it is provided as an option.

Parameters are estimated in the given scale. To obtain the weightscolumn vector, examine the expectation'soutput slot with for exampleyourModel$expectation$output

An extension of this expectation to a Hidden Markov modelis available withmxExpectationHiddenMarkov.mxGenerateData is not implemented for this type of expectation.

Examples

library(OpenMx)set.seed(1)trail <- c(rep(1,480), rep(2,520))trailN <- sapply(trail, function(v) rnorm(1, mean=v))classes <- list()for (cl in 1:2) {  classes[[cl]] <- mxModel(paste0("class", cl), type="RAM",                           manifestVars=c("ob"),                           mxPath("one", "ob", value=cl, free=FALSE),                           mxPath("ob", arrows=2, value=1, free=FALSE),                           mxFitFunctionML(vector=TRUE))}mix1 <- mxModel(  "mix1", classes,  mxData(data.frame(ob=trailN), "raw"),  mxMatrix(values=1, nrow=1, ncol=2, free=c(FALSE,TRUE), name="weights"),  mxExpectationMixture(paste0("class",1:2), scale="softmax"),  mxFitFunctionML())mix1Fit <- mxRun(mix1)

Create MxExpectationNormal Object

Description

This function creates an MxExpectationNormal object.

Usage

mxExpectationNormal(covariance, means=NA, dimnames = NA, thresholds = NA,                    threshnames = dimnames, ...,  discrete = as.character(NA), discreteSpec=NULL)

Arguments

covariance

A character string indicating the name of the expected covariance algebra.

means

A character string indicating the name of the expected means algebra.

dimnames

An optional character vector to be assigned to the dimnames of the covariance and means algebras.

thresholds

An optional character string indicating the name of the thresholds matrix.

threshnames

An optional character vector to be assigned to the column names of the thresholds matrix.

...

Not used. Forces remaining arguments to be specified by name.

discrete

An optional character string indicating the name of the discrete matrix.

discreteSpec

An optional matrix containing maximum counts andmodel IDs.

Details

Expectation functions define the way that model expectations are calculated. The mxExpectationNormal function uses the algebra defined by the 'covariance' and 'means' arguments to define the expected covariance and means under the assumption of multivariate normality. The 'covariance' argument takes anMxAlgebra object, which defines the expected covariance of an associatedMxData object. The 'means' argument takes anMxAlgebra object, which defines the expected means of an associatedMxData object. The 'dimnames' arguments takes an optional character vector. If this argument is not a single NA, then this vector is used to assign the dimnames of the means vector as well as the row and columns dimnames of the covariance matrix.

thresholds: The name of the thresholds matrix. When needed (for modelling ordinal data), this matrix should be created usingmxMatrix(). The thresholds matrix must have as many columns as there are ordinal variables in the model, and number of rows equal to one fewer than the maximum number of levels found in the ordinal variables. The starting values of this matrix must also be set to reasonable values. Fill each column with a set of ordered start thresholds, one for each level of this column's factor levels minus 1. These thresholds may be free if you wish them to be estimated, or fixed. The unused rows in each column, if any, can be set to any value including NA.

threshnames: A character vector consisting of the variables in the thresholds matrix, i.e., the names of ordinal variables in a model. This is necessary for OpenMx to map the thresholds matrix columns onto the variables in your data. If you set thedimnames of the columns in the thresholds matrix then threshnames is not needed.

Usage Notes:dimnames must be supplied where the matrices referenced by the covariance and means algebras are not themselves labeled. Failure to do so leads to an error noting that the covariance or means matrix associated with the FIML objective does not contain dimnames.

mxExpectationNormal evaluates with respect to anMxData object. TheMxData object need not be referenced in the mxExpectationNormal function, but must be included in theMxModel object. When the 'type' argument in the associatedMxData object is equal to 'raw', missing values are permitted in the associatedMxData object.

To evaluate, place an mxExpectationNormal object, themxData object for which the expected covariance approximates, referencedMxAlgebra andMxMatrix objects, optionalMxBounds orMxConstraint objects, and an mxFitFunction such asmxFitFunctionML in anMxModel object. This model may then be evaluated using themxRun function.

The results of the optimization can be reported using thesummary function, or accessed directly in the 'output' slot of the resulting model (i.e., modelName$output). Components of the output may be referenced using theExtract functionality.

Value

Returns an MxExpectationNormal object.

References

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

Examples

# Create and fit a model using mxMatrix, mxAlgebra,#  mxExpectationNormal, and mxFitFunctionMLlibrary(OpenMx)# Simulate some datax=rnorm(1000, mean=0, sd=1)y= 0.5*x + rnorm(1000, mean=0, sd=1)tmpFrame <- data.frame(x, y)tmpNames <- names(tmpFrame)# Define the matricesM <- mxMatrix(type = "Full", nrow = 1, ncol = 2, values=c(0,0),              free=c(TRUE,TRUE), labels=c("Mx", "My"), name = "M")S <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(1,0,0,1),              free=c(TRUE,FALSE,FALSE,TRUE), labels=c("Vx", NA, NA, "Vy"),              name = "S")A <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0),              free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b", NA, NA),              name = "A")I <- mxMatrix(type="Iden", nrow=2, ncol=2, name="I")# Define the expectationexpCov <- mxAlgebra(solve(I-A) %*% S %*% t(solve(I-A)), name="expCov")expFunction <- mxExpectationNormal(covariance="expCov", means="M",dimnames=tmpNames)# Choose a fit functionfitFunction <- mxFitFunctionML()# Define the modeltmpModel <- mxModel(model="exampleModel", M, S, A, I,                    expCov, expFunction, fitFunction,                    mxData(observed=tmpFrame, type="raw"))# Fit the model and print a summarytmpModelOut <- mxRun(tmpModel)summary(tmpModelOut)

Create an MxExpectationRAM Object

Description

This function creates an MxExpectationRAM object.

Usage

mxExpectationRAM(A="A", S="S", F="F", M = NA, dimnames = NA, thresholds = NA,                 threshnames = dimnames, ..., between=NULL, verbose=0L,  .useSparse=NA, expectedCovariance=NULL, expectedMean=NULL,  discrete = as.character(NA), selectionVector = as.character(NA),  expectedFullCovariance=NULL, expectedFullMean=NULL)

Arguments

A

A character string indicating the name of the 'A' matrix.

S

A character string indicating the name of the 'S' matrix.

F

A character string indicating the name of the 'F' matrix.

M

An optional character string indicating the name of the 'M' matrix.

dimnames

An optional character vector to be assigned to the column names of the 'F' and 'M' matrices.

thresholds

An optional character string indicating the name of the thresholds matrix.

threshnames

An optional character vector to be assigned to the column names of the thresholds matrix.

...

Not used. Forces remaining arguments to be specified by name.

between

A character vector of matrices that specify cross model relationships.

verbose

integer. Level of runtime diagnostic output.

.useSparse

logical. Whether to use sparse matrices to computethe expectation. The defaultNA allows the backend to decide.

expectedCovariance

An optional character string indicating thename of a matrix for the observed model implied covariance.

expectedMean

An optional character string indicating the nameof a matrix for the observed model implied mean.

discrete

An optional character string indicating the name ofthe discrete matrix.

selectionVector

An optional character string indicating the name ofthe Pearson selection vector matrix.

expectedFullCovariance

An optional character string indicating thename of a matrix for the full model implied covariance. Both latentand observed variables are included.

expectedFullMean

An optional character string indicating the nameof a matrix for the full model implied mean. Both latentand observed variables are included.

Details

Expectation functions define the way that model expectations are calculated. The mxExpectationRAM calculates the expected covariance and means of a givenMxData object given a RAM model. This model is defined by reticular action modeling (McArdle and McDonald, 1984). The 'A', 'S', and 'F' arguments refer toMxMatrix objects with the associated properties of the A, S, and F matrices in the RAM modeling approach.Note for advanced users: these matrices may be replaced by mxAlgebras. Such a model will lack properties (labels, free, bounds) that other functions may be expecting.

TheMxMatrix objects included as arguments may be of any type, but should have the properties described above. The mxExpectationRAM will not return an error for incorrect specification, but incorrect specification will likely lead to estimation problems or errors in themxRun function.

The 'A' argument refers to the A or asymmetric matrix in the RAM approach. This matrix consists of all of the asymmetric paths (one-headed arrows) in the model. A free parameter in any row and column describes a regression of the variable represented by that row regressed on the variable represented in that column.

The 'S' argument refers to the S or symmetric matrix in the RAM approach, and as such must be square. This matrix consists of all of the symmetric paths (two-headed arrows) in the model. A free parameter in any row and column describes a covariance between the variable represented by that row and the variable represented by that column. Variances are covariances between any variable at itself, which occur on the diagonal of the specified matrix.

The 'F' argument refers to the F or filter matrix in the RAM approach. If no latent variables are included in the model (i.e., the A and S matrices are of both of the same dimension as the data matrix), then the 'F' should refer to an identity matrix. If latent variables are included (i.e., the A and S matrices are not of the same dimension as the data matrix), then the 'F' argument should consist of a horizontal adhesion of an identity matrix and a matrix of zeros.

The 'M' argument refers to the M or means matrix in the RAM approach. It is a 1 x n matrix, where n is the number of manifest variables + the number of latent variables. The M matrix must be specified if either the mxData type is “cov” or “cor” and a means vector is provided, or if the mxData type is “raw”. Otherwise the M matrix is ignored.

The 'dimnames' arguments takes an optional character vector. If this argument is not a single NA, then this vector be assigned to be the column names of the 'F' matrix and optionally to the 'M' matrix, if the 'M' matrix exists.

mxExpectationRAM evaluates with respect to anMxData object. TheMxData object need not be referenced in the mxExpectationRAM function, but must be included in theMxModel object.

To evaluate an mxExpectationRAM object, place it, themxDataobject which the expected covariance approximates, any referencedMxAlgebra andMxMatrix objects, and optionalMxBounds andMxConstraint objects in anMxModelobject and evaluate it usingmxRun. The results of the optimization can be found in the 'output' slot of the resulting model, and may be obtained using themxEval function.

Value

Returns a new MxExpectationRAM object. mxExpectationRAM objects should be included in a model, along with referencedMxAlgebra,MxData andMxMatrix objects.

References

McArdle, J. J. and MacDonald, R. P. (1984). Some algebraic properties of the Reticular Action Model for moment structures.British Journal of Mathematical and Statistical Psychology, 37, 234-251.

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

Examples

# Create and fit a model using mxMatrix, mxAlgebra,#  mxExpectationNormal, and mxFitFunctionMLlibrary(OpenMx)# Simulate some datax=rnorm(1000, mean=0, sd=1)y= 0.5*x + rnorm(1000, mean=0, sd=1)tmpFrame <- data.frame(x, y)tmpNames <- names(tmpFrame)# Define the matricesmatrixS <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(1,0,0,1),              free=c(TRUE,FALSE,FALSE,TRUE), labels=c("Vx", NA, NA, "Vy"),              name = "S")matrixA <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0),              free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b", NA, NA),              name = "A")matrixF <- mxMatrix(type="Iden", nrow=2, ncol=2, name="F")matrixM <- mxMatrix(type = "Full", nrow = 1, ncol = 2, values=c(0,0),              free=c(TRUE,TRUE), labels=c("Mx", "My"), name = "M")# Define the expectationexpFunction <- mxExpectationRAM(M="M", dimnames = tmpNames)# Choose a fit functionfitFunction <- mxFitFunctionML()# Define the modeltmpModel <- mxModel(model="exampleRAMModel",                    matrixA, matrixS, matrixF, matrixM,                    expFunction, fitFunction,                    mxData(observed=tmpFrame, type="raw"))# Fit the model and print a summarytmpModelOut <- mxRun(tmpModel)summary(tmpModelOut)

Create an MxExpectationStateSpace Object

Description

This function creates a new MxExpectationStateSpace object.

Usage

mxExpectationStateSpace(A, B, C, D, Q, R, x0, P0, u,                        dimnames = NA, thresholds = deprecated(),                        threshnames = deprecated(),                        ..., t = NA, scores=FALSE)

Arguments

A

A character string indicating the name of the 'A' matrix.

B

A character string indicating the name of the 'B' matrix.

C

A character string indicating the name of the 'C' matrix.

D

A character string indicating the name of the 'D' matrix.

Q

A character string indicating the name of the 'Q' matrix.

R

A character string indicating the name of the 'R' matrix.

x0

A character string indicating the name of the 'x0' matrix.

P0

A character string indicating the name of the 'P0' matrix.

u

A character string indicating the name of the 'u' matrix.

dimnames

An optional character vector to be assigned to the row names of the 'C' matrix.

thresholds

[Deprecated]

threshnames

[Deprecated]

...

Unused. Requires further arguments to be named.

t

Not to be used

scores

Not to be used

Details

This page presents details for both themxExpectationStateSpace function and for state space modeling generally; however, for much more information on state space modeling see the paper by Hunter (2018) listed under references. Authors using state space modeling in OpenMx should cite Hunter (2018).

Expectation functions define the way that model expectations are calculated. When used in conjunction with themxFitFunctionML, the mxExpectationStateSpace uses maximum likelihood prediction error decomposition (PED) to obtain estimates of free parameters in a model of the rawMxData object. State space expectations treat the raw data as a multivariate time series of equally spaced times with each row corresponding to a single occasion. This is not a model of the block Toeplitz lagged autocovariance matrix. State space expectations implement a classical Kalman filter to produce expectations.

The hybrid Kalman filter (combination of classical Kalman and Kalman-Bucy filters) for continuous latent time with discrete observations is implemented and is available asmxExpectationStateSpaceContinuousTime. The following alternative filters are not yet implemented: square root Kalman filter (in Cholesky or singular value decomposition form), extended Kalman filter for linear approximations to nonlinear state space models, unscented Kalman filter for highly nonlinear state space models, and Rauch-Tung-Striebel smoother for updating forecast state estimates after a complete forward pass through the data has been made.

Missing data handling is implemented in the same fashion as full information maximum likelihood for partially missing rows of data. Additionally, completely missing rows of data are handled by only using the prediction step from the Kalman filter and omitting the update step.

This model uses notation for the model matrices commonly found in engineering and control theory.

The 'A', 'B', 'C', 'D', 'Q', 'R', 'x0', and 'P0' arguments must be the names ofMxMatrix orMxAlgebraobjects with the associated properties of the A, B, C, D, Q, R, x0, and P0 matrices in the state space modeling approach.

The state space expectation is defined by the following model equations.

x_t = A x_{t-1} + B u_t + q_t

y_t = C x_t + D u_t + r_t

withq_t andr_t both independently and identically distributed random Gaussian (normal) variables with mean zero and covariance matricesQ andR, respectively.

The first equation is called the state equation. It describes how the latent states change over time. Also, the state equation in state space modeling is directly analogous to the structural model in LISREL structural equation modeling.

The second equation is called the output equation. It describes how the latent states relate to the observed states at a single point in time. The output equation shows how the observed output is produced by the latent states. Also, the output equation in state space modeling is directly analogous to the measurement model in LISREL structural equation modeling.

Note that the covariates,u, have "instantaneous" effects on both the state and output equations. If lagged effects are desired, then the user must create a lagged covariate by shifting their observed variable to the desired lag.

The state and output equations, together with some minimal assumptions and the Kalman filter, imply a new expected covariance matrix and means vector for every row of data. The expected covariance matrix of rowt is

S_{t} = C ( A P_{t-1} A^{\sf T} + Q ) C^{\sf T} + R

The expected means vector of rowt is

\hat{y}_{t} = C x_{t} + D u_{t}

The 'dimnames' arguments takes an optional character vector.

The 'A' argument refers to theA matrix in the State Space approach. This matrix consists of time regressive coefficients from the latent variable in columnj at timet-1 to the latent variable in rowi at timet. Entries in the diagonal are autoregressive coefficients. Entries in the off-diagonal are cross-lagged regressive coefficients. If theA andB matrices are zero matrices, then the state space model reduces to a factor analysis. TheA matrix is sometimes called the state-transition model.

The 'B' argument refers to theB matrix in the State Space approach. This matrix consists of regressive coefficients from the input (manifest covariate) variablej at timet to the latent variable in rowi at timet. Note that the covariate effect is contemporaneous: the covariate at timet has influence on the latent state also at timet. A lagged effect can be created by lagged the observed variable. TheB matrix is sometimes called the control-input model.

The 'C' argument refers to theC matrix in the State Space approach. This matrix consists of contemporaneous regression coefficients from the latent variable in columnj to the observed variable in rowi. This matrix is directly analogous to the factor loadings matrix in LISREL and Mplus models. TheC matrix is sometimes called the observation model.

The 'D' argument refers to theD matrix in the State Space approach. This matrix consists of contemporaneous regressive coefficients from the input (manifest covariate) variablej to the observed variable in rowi. TheD matrix is sometimes called the feedthrough or feedforward matrix.

The 'Q' argument refers to theQ matrix in the State Space approach. This matrix consists of residual covariances among the latent variables. This matrix must be symmetric. As a special case, it is often diagonal. TheQ matrix is the covariance of the process noise. Just as in factor analysis and general structural equation modeling, the scale of the latent variables is usually set by fixing some factor loadings in theC matrix, or fixing some factor variances in theQ matrix.

The 'R' argument refers to theR matrix in the State Space approach. This matrix consists of residual covariances among the observed (manifest) variables. This matrix must be symmetric As a special case, it is often diagonal. TheR matrix is the covariance of the observation noise.

The 'x0' argument refers to thex_0 matrix in the State Space approach. This matrix consists of the column vector of the initial values for the latent variables. The state space expectation uses thex_0 matrix as the starting point to recursively estimate the latent variables' values at each time. These starting values can be difficult to pick, however, for sufficiently long time series they often do not greatly impact the estimation.

The 'P0' argument refers to theP_0 matrix in the State Space approach. This matrix consists of the initial values of the covariances of the error in the initial latent variable estimates given inx_0. That is, theP_0 matrix gives the covariance ofx_0 - xtrue_0 wherextrue_0 is the vector of true initial values.P_0 is a measure of the accuracy of the initial latent state estimates. The Kalman filter uses this initial covariance to recursively generated a new covariance for each time point based on the previous time point. The Kalman filter updates this covariance so that it is as small as possible (minimum trace). Similar to thex_0 matrix, these starting values are often difficult to choose.

The 'u' argument refers to theu matrix in the State Space approach. This matrix consists of the inputs or manifest covariates of the state space expectation. Theu matrix must be a column vector with the same number of rows as theB andD matrices have columns. If no inputs are desired,u can be a zero matrix. If time-varying inputs are desired, then they should be included as columns in theMxData object and referred to in the labels of theu matrix as definition variables. There is an example of this below.

TheMxMatrix objects included as arguments may be of any type, but should have the properties described above. The mxExpectationStateSpace will not return an error for incorrect specification, but incorrect specification will likely lead to estimation problems or errors in themxRun function.

mxExpectationStateSpace evaluates with respect to anMxData object. TheMxData object need not be referenced in the mxExpectationStateSpace function, but must be included in theMxModel object. mxExpectationStateSpace requires that the 'type' argument in the associatedMxData object be equal to 'raw'. Neighboring rows of theMxData object are treated as adjacent, equidistant time points increasing from the first to the last row.

To evaluate, place mxExpectationStateSpace objects, themxData object for which the expected covariance approximates, referencedMxAlgebra andMxMatrix objects, and optionalMxBounds andMxConstraint objects in anMxModel object. This model may then be evaluated using themxRun function. The results of the optimization can be found in the 'output' slot of the resulting model, and may be obtained using themxEval function.

Value

Returns a new MxExpectationStateSpace object. mxExpectationStateSpace objects should be included with models with referencedMxAlgebra,MxData andMxMatrix objects.

References

K.J. Åström and R.M. Murray (2010). Feedback Systems: An Introduction for Scientists and Engineers. Princeton University Press.

J. Durbin and S.J. Koopman. (2001).Time Series Analysis by State Space Methods. Oxford University Press.

Hunter, M.D. (2018). State Space Modeling in an Open Source, Modular, Structural Equation Modeling Environment.Structural Equation Modeling: A Multidisciplinary Journal, 25(2), 307-324. DOI: 10.1080/10705511.2017.1369354

R.E. Kalman (1960). A New Approach to Linear Filtering and Prediction Problems.Basic Engineering, 82, 35-45.

G. Petris (2010). An R Package for Dynamic Linear Models.Journal of Statistical Software, 36, 1-16.

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

See Also

mxExpectationStateSpaceContinuousTime

Examples

# Create and fit a model using mxMatrix, mxExpectationStateSpace, and mxFitFunctionMLrequire(OpenMx)data(demoOneFactor)nvar <- ncol(demoOneFactor)varnames <- colnames(demoOneFactor)ssModel <- mxModel(model="State Space Manual Example",    mxMatrix("Full", 1, 1, TRUE, .3, name="A"),    mxMatrix("Zero", 1, 1, name="B"),    mxMatrix("Full", nvar, 1, TRUE, .6, name="C", dimnames=list(varnames, "F1")),    mxMatrix("Zero", nvar, 1, name="D"),    mxMatrix("Diag", 1, 1, FALSE, 1, name="Q"),    mxMatrix("Diag", nvar, nvar, TRUE, .2, name="R"),    mxMatrix("Zero", 1, 1, name="x0"),    mxMatrix("Diag", 1, 1, FALSE, 1, name="P0"),    mxMatrix("Zero", 1, 1, name="u"),    mxData(observed=demoOneFactor[1:100,], type="raw"),#fewer rows = fast    mxExpectationStateSpace("A", "B", "C", "D", "Q", "R", "x0", "P0", "u"),    mxFitFunctionML())ssRun <- mxRun(ssModel)summary(ssRun)# Note the freely estimated Autoregressive parameter (A matrix)#  is near zero as it should be for the independent rows of data#  from the factor model.# Create and fit a model with INPUTS using mxMatrix, mxExpectationStateSpace, and mxFitFunctionMLrequire(OpenMx)data(demoOneFactor)nvar <- ncol(demoOneFactor)varnames <- colnames(demoOneFactor)#demoOneFactorInputs <- cbind(demoOneFactor, V1=rep(1, nrow(demoOneFactor)))demoOneFactorInputs <- cbind(demoOneFactor, V1=rnorm(nrow(demoOneFactor)))ssModel <- mxModel(model="State Space Inputs Manual Example",    mxMatrix("Full", 1, 1, TRUE, .3, name="A"),    mxMatrix("Full", 1, 1, TRUE, values=1, name="B"),    mxMatrix("Full", nvar, 1, TRUE, .6, name="C", dimnames=list(varnames, "F1")),    mxMatrix("Zero", nvar, 1, name="D"),    mxMatrix("Diag", 1, 1, FALSE, 1, name="Q"),    mxMatrix("Diag", nvar, nvar, TRUE, .2, name="R"),    mxMatrix("Zero", 1, 1, name="x0"),    mxMatrix("Diag", 1, 1, FALSE, 1, name="P0"),    mxMatrix("Full", 1, 1, FALSE, labels="data.V1", name="u"),    mxData(observed=demoOneFactorInputs[1:100,], type="raw"),#fewer rows = fast    mxExpectationStateSpace("A", "B", "C", "D", "Q", "R", "x0", "P0", u="u"),    mxFitFunctionML())ssRun <- mxRun(ssModel)summary(ssRun)# Note the freely estimated Autoregressive parameter (A matrix)#  and the freely estimated Control-Input parameter (B matrix)#  are both near zero as they should be for the independent rows of data#  from the factor model that does not have inputs, covariates,#  or exogenous variables.

Create an MxExpectationStateSpace Object

Description

This function creates a new MxExpectationStateSpace object.

Usage

mxExpectationStateSpaceContinuousTime(A, B, C, D, Q, R, x0, P0, u, t = NA,                        dimnames = NA, thresholds = deprecated(),      threshnames = deprecated(),  ..., scores=FALSE)mxExpectationSSCT(A, B, C, D, Q, R, x0, P0, u, t = NA,                        dimnames = NA, thresholds = deprecated(),      threshnames = deprecated(),                        ..., scores=FALSE)

Arguments

A

A character string indicating the name of the 'A' matrix.

B

A character string indicating the name of the 'B' matrix.

C

A character string indicating the name of the 'C' matrix.

D

A character string indicating the name of the 'D' matrix.

Q

A character string indicating the name of the 'Q' matrix.

R

A character string indicating the name of the 'R' matrix.

x0

A character string indicating the name of the 'x0' matrix.

P0

A character string indicating the name of the 'P0' matrix.

u

A character string indicating the name of the 'u' matrix.

t

A character string indicating the name of the 't' matrix.

dimnames

An optional character vector to be assigned to the row names of the 'C' matrix.

thresholds

[Deprecated]

threshnames

[Deprecated]

...

Unused. Requires further arguments to be named.

scores

Not to be used

Details

ThemxExpectationStateSpaceContinuousTime andmxExpectationSSCT functions are identical. The latter is simply an abbreviated name. When using the former, tab completion is strongly encouraged to save tedious typing. Both of these functions are wrappers for themxExpectationStateSpace function, which could be used for both discrete and continuous time modeling. However, there is a strong possibility of misunderstanding the model parameters when switching between discrete time and continuous time. The expectation matrices have the same names, but mean importantly different things so caution is warranted. The best practice is to usemxExpectationStateSpace for discrete time models, andmxExpectationStateSpaceContinuousTime for continuous time models.

Expectation functions define the way that model expectations are calculated. That is to say, expectation functions define how a set of model matrices get turned into expectations for the data. When used in conjunction with themxFitFunctionML, the mxExpectationStateSpace uses maximum likelihood prediction error decomposition (PED) to obtain estimates of free parameters in a model of the rawMxData object. Continuous time state space expectations treat the raw data as a multivariate time series of possibly unevenly spaced times with each row corresponding to a single occasion. Continuous time state space expectations implement a hybrid Kalman filter to produce expectations. The hybrid Kalman filter uses a Kalman-Bucy filter for the prediction step and the classical Kalman filter for the update step. It is a hybrid between the classical Kalman filter used for the discrete (but possibly unequally spaced) measurement occasions and the continuous time Kalman-Bucy filter for latent variable predictions.

Missing data handling is implemented in the same fashion as full information maximum likelihood for partially missing rows of data. Additionally, completely missing rows of data are handled by only using the prediction step from the Kalman-Bucy filter and omitting the update step.

This model uses notation for the model matrices commonly found in engineering and control theory.

The 'A', 'B', 'C', 'D', 'Q', 'R', 'x0', and 'P0' arguments must be the names ofMxMatrix orMxAlgebraobjects with the associated properties of the A, B, C, D, Q, R, x0, and P0 matrices in the state space modeling approach. The 't' matrix must be a 1x1 matrix using definition variables that gives the times at which measurements occurred.

The state space expectation is defined by the following model equations.

\frac{d}{dt} x(t) = A x(t) + B u_t + q(t)

y_t = C x_t + D u_t + r_t

withq(t) andr_t both independently and identically distributed random Gaussian (normal) variables with mean zero and covariance matricesQ andR, respectively. Subscripts or square brackets indicate discrete indices; parentheses indicate continuous indices. The derivative ofx(t) with respect tot is\frac{d}{dt} x(t).

The first equation is called the state equation. It describes how the latent states change over time with a first-order linear differential equation. Unlike some other programs, we do not require that the continuous timeA matrix has an inverse. This allows zero dynamics (i.e. no growth models) and many other important kinds of processes.

The second equation is called the output equation. It describes how the latent states relate to the observed states at a single point in time. The output equation shows how the observed output is produced by the latent states. Also, the output equation in state space modeling is directly analogous to the measurement model in LISREL structural equation modeling.

Note that the covariates,u, have "instantaneous" effects on both the state and output equations. If lagged effects are desired, then the user must create a lagged covariate by shifting their observed variable to the desired lag.

The state and output equations, together with some minimal assumptions and the Kalman filter, imply a new expected covariance matrix and means vector for every row of data. The expected covariance matrix of rowt is

S_{t} = C ( A P_{t-1} A^{\sf T} + Q ) C^{\sf T} + R

The expected means vector of rowt is

\hat{y}_{t} = C x_{t} + D u_{t}

The 'dimnames' arguments takes an optional character vector.

The 'A' argument refers to theA matrix in the State Space approach. This matrix gives the dynamics. Entries in the diagonal give the strength of the influence of a variable's position on its slope. Entries in the off-diagonal give the coupling strength from one variable to another. TheA matrix is sometimes called the state-transition model.

The 'B' argument refers to theB matrix in the State Space approach. This matrix consists of exogenous forces that influence the dynamics. Note that the covariate effect is contemporaneous: the covariate at timet has influence on the slope of the latent state also at timet. A lagged effect can be created by lagged the observed variable. TheB matrix is sometimes called the control-input model.

The 'C' argument refers to theC matrix in the State Space approach. This matrix consists of contemporaneous regression coefficients from the latent variable in columnj to the observed variable in rowi. This matrix is directly analogous to the factor loadings matrix in LISREL and Mplus models. TheC matrix is sometimes called the observation model.

The 'D' argument refers to theD matrix in the State Space approach. This matrix consists of contemporaneous regressive coefficients from the input (manifest covariate) variablej to the observed variable in rowi. TheD matrix is sometimes called the feedthrough or feedforward matrix.

The 'Q' argument refers to theQ matrix in the State Space approach. This matrix gives the covariance of the dynamic noise. The dynamic noise can be thought of as unmeasured covariate inputs active at all times. This matrix must be symmetric, diagonal, or zero. As a special case, it is often diagonal. TheQ matrix is the covariance of the process noise. Just as in factor analysis and general structural equation modeling, the scale of the latent variables is usually set by fixing some factor loadings in theC matrix, or fixing some factor variances in theQ matrix.

The 'R' argument refers to theR matrix in the State Space approach. This matrix consists of residual covariances among the observed (manifest) variables. This matrix must be symmetric As a special case, it is often diagonal. TheR matrix is the covariance of the observation noise.

The 'x0' argument refers to thex_0 matrix in the State Space approach. This matrix consists of the column vector of the initial values for the latent variables. The state space expectation uses thex_0 matrix as the starting point to recursively estimate the latent variables' values at each time. These starting values can be difficult to pick, however, for sufficiently long time series they often do not greatly impact the estimation.

The 'P0' argument refers to theP_0 matrix in the State Space approach. This matrix consists of the initial values of the covariances of the error in the initial latent variable estimates given inx_0. That is, theP_0 matrix gives the covariance ofx_0 - xtrue_0 wherextrue_0 is the vector of true initial values.P_0 is a measure of the accuracy of the initial latent state estimates. The Kalman filter uses this initial covariance to recursively generated a new covariance for each time point based on the previous time point. The Kalman filter updates this covariance so that it is as small as possible (minimum trace). Similar to thex_0 matrix, these starting values are often difficult to choose.

The 'u' argument refers to theu matrix in the State Space approach. This matrix consists of the inputs or manifest covariates of the state space expectation. Theu matrix must be a column vector with the same number of rows as theB andD matrices have columns. If no inputs are desired,u can be a zero matrix. If time-varying inputs are desired, then they should be included as columns in theMxData object and referred to in the labels of theu matrix as definition variables. There is an example of this below.

The 't' argument refers to thet matrix in the State Space approach. This matrix should be 1x1 (1 row and 1 column) and not free. The label for the element of this matrix should be 'data.YourTimeVariable'. The 'data' part does not change, but 'YourTimeVariable' should be a name in your data set that gives the times at which measurement happened. The units of time are up to you. Your choice of time units will influence of the values of the parameters you estimate. Also, recall that the model is givenx_0 andP_0. These always happen att=0. So the first row of data happens some amount of time after zero.

TheMxMatrix objects included as arguments may be of any type, but should have the properties described above. The mxExpectationStateSpace will not return an error for incorrect specification, but incorrect specification will likely lead to estimation problems or errors in themxRun function.

mxExpectationStateSpaceContinuousTime evaluates with respect to anMxData object. TheMxData object need not be referenced in the mxExpectationStateSpace function, but must be included in theMxModel object. mxExpectationStateSpace requires that the 'type' argument in the associatedMxData object be equal to 'raw'. Neighboring rows of theMxData object are treated as adjacent, equidistant time points increasing from the first to the last row.

To evaluate, place an mxExpectationStateSpaceContinuousTime object, themxData object for which the expected covariance approximates, referencedMxAlgebra andMxMatrix objects, and optionalMxBounds andMxConstraint objects in anMxModel object. This model may then be evaluated using themxRun function. The results of the optimization can be found in the 'output' slot of the resulting model, and may be obtained using themxEval function.

Value

Returns a new MxExpectationStateSpace object. mxExpectationStateSpace objects should be included with models with referencedMxAlgebra,MxData andMxMatrix objects.

References

K.J. Åström and R.M. Murray (2010). Feedback Systems: An Introduction for Scientists and Engineers. Princeton University Press.

J. Durbin and S.J. Koopman. (2001).Time Series Analysis by State Space Methods. Oxford University Press.

R.E. Kalman (1960). A New Approach to Linear Filtering and Prediction Problems.Basic Engineering, 82, 35-45.

R.E. Kalman and R.S. Bucy (1961). New Results in Linear Filtering and Prediction Theory.Transactions of the ASME, Series D, Journal of Basic Engineering, 83, 95-108.

G. Petris (2010). An R Package for Dynamic Linear Models.Journal of Statistical Software, 36, 1-16.

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

See Also

mxExpectationStateSpace

Examples

#------------------------------------------------------------------------------# Example 1# Undamped linear oscillator, i.e. a noisy sine wave.#Measurement error, but no dynamic error, single indicator.#This example works great.#--------------------------------------# Data Generationrequire(OpenMx)# Limit to 2 cores for CRANmxOption(key="Number of Threads", value=min(2,parallel::detectCores()))set.seed(405)tlen <- 200t <- seq(1.2, 50, length.out=tlen)freqParam <- .5initialCond <- matrix(c(2.5, 0))x <- initialCond[1,1]*cos(freqParam*t)plot(t, x, type='l')measVar <- 1.5y <- cbind(obs=x+rnorm(tlen, sd=sqrt(measVar)), tim=t)plot(t, y[,1], type='l')#--------------------------------------# Model Specification#Note: the bounds are here only to keep SLSQP from# stepping too far off a cliff.  With the bounds in# place, SLSQP finds the right solution.  Without# the bounds, SLSQP goes crazy.cdim <- list('obs', c('ksi', 'ksiDot'))amat <- mxMatrix('Full', 2, 2, c(FALSE, TRUE, FALSE, TRUE), c(0, -.1, 1, -.2),name='A', lbound=-10)bmat <- mxMatrix('Zero', 2, 1, name='B')cmat <- mxMatrix('Full', 1, 2, FALSE, c(1, 0), name='C', dimnames=cdim)dmat <- mxMatrix('Zero', 1, 1, name='D')qmat <- mxMatrix('Zero', 2, 2, name='Q')rmat <- mxMatrix('Diag', 1, 1, TRUE, .4, name='R', lbound=1e-6)xmat <- mxMatrix('Full', 2, 1, TRUE, c(0, 0), name='x0', lbound=-10, ubound=10)pmat <- mxMatrix('Diag', 2, 2, FALSE, 1, name='P0')umat <- mxMatrix('Zero', 1, 1, name='u')tmat <- mxMatrix('Full', 1, 1, name='time', labels='data.tim')osc <- mxModel("LinearOscillator", amat, bmat, cmat, dmat, qmat, rmat, xmat, pmat, umat, tmat,mxExpectationSSCT('A', 'B', 'C', 'D', 'Q', 'R', 'x0', 'P0', 'u', 'time'),mxFitFunctionML(),mxData(y, 'raw'))oscr <- mxRun(osc)#--------------------------------------# Results Examinationsummary(oscr)(ssFreqParam <- mxEval(sqrt(-A[2,1]), oscr))freqParam(ssMeasVar <- mxEval(R, oscr))measVardampingParam <- 0(ssDampingParam <- mxEval(-A[2,2], oscr))dampingParam

DEPRECATED: Create MxFIMLObjective Object

Description

WARNING: Objective functions have been deprecated as of OpenMx 2.0.

Please use mxExpectationNormal() and mxFitFunctionML() instead. As a temporary workaround, mxFIMLObjective returns a list containing an MxExpectationNormal object and an MxFitFunctionML object.

All occurrences of

mxFIMLObjective(covariance, means, dimnames = NA, thresholds = NA, vector = FALSE, threshnames = dimnames)

Should be changed to

mxExpectationNormal(covariance, means, dimnames = NA, thresholds = NA, threshnames = dimnames)mxFitFunctionML(vector = FALSE)

Arguments

covariance

A character string indicating the name of the expected covariance algebra.

means

A character string indicating the name of the expected means algebra.

dimnames

An optional character vector to be assigned to the dimnames of the covariance and means algebras.

thresholds

An optional character string indicating the name of the thresholds matrix.

vector

A logical value indicating whether the objective function result is the likelihood vector.

threshnames

An optional character vector to be assigned to the column names of the thresholds matrix.

Details

NOTE: THIS DESCRIPTION IS DEPRECATED. Please change to usingmxExpectationNormal andmxFitFunctionML as shown in the example below.

Objective functions were functions for which free parameter values are chosen such that the value of the objective function is minimized. The mxFIMLObjective function used full-information maximum likelihood to provide maximum likelihood estimates of free parameters in the algebra defined by the 'covariance' and 'means' arguments. The 'covariance' argument takes anMxAlgebra object, which defines the expected covariance of an associatedMxData object. The 'means' argument takes anMxAlgebra object, which defines the expected means of an associatedMxData object. The 'dimnames' arguments takes an optional character vector. If this argument is not a single NA, then this vector is used to assign the dimnames of the means vector as well as the row and columns dimnames of the covariance matrix.

The 'vector' argument is either TRUE or FALSE, and determines whether the objective function returns a column vector of the likelihoods, or a single -2*(log likelihood) value.

thresholds: The name of the thresholds matrix. When needed (for modelling ordinal data), this matrix should be created usingmxMatrix(). The thresholds matrix must have as many columns as there are ordinal variables in the model, and number of rows equal to one fewer than the maximum number of levels found in the ordinal variables. The starting values of this matrix must also be set to reasonable values. Fill each column with a set of ordered start thresholds, one for each level of this column's factor levels minus 1. These thresholds may be free if you wish them to be estimated, or fixed. The unused rows in each column, if any, can be set to any value including NA.

threshnames: A character vector consisting of the variables in the thresholds matrix, i.e., the names of ordinal variables in a model. This is necessary for OpenMx to map the thresholds matrix columns onto the variables in your data. If you set thedimnames of the columns in the thresholds matrix then threshnames is not needed.

Usage Notes: dimnames must be supplied where the matrices referenced by the covariance and means algebras are not themselves labeled. Failure to do so leads to an error noting that the covariance or means matrix associated with the FIML objective does not contain dimnames.

mxFIMLObjective evaluates with respect to anMxData object. TheMxData object need not be referenced in the mxFIMLObjective function, but must be included in theMxModel object. mxFIMLObjective requires that the 'type' argument in the associatedMxData object be equal to 'raw'. Missing values are permitted in the associatedMxData object.

To evaluate, place MxFIMLObjective objects, themxData object for which the expected covariance approximates, referencedMxAlgebra andMxMatrix objects, and optionalMxBounds andMxConstraint objects in anMxModel object. This model may then be evaluated using themxRun function.

The results of the optimization can be reported using thesummary function, or accessed directly in the 'output' slot of the resulting model (i.e., modelName$output). Components of the output may be referenced using theExtract functionality.

Value

Returns a list containing an MxExpectationNormal object and an MxFitFunctionML object.

References

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

Examples

# Create and fit a model using mxMatrix, mxAlgebra, mxExpectationNormal, and mxFitFunctionMLlibrary(OpenMx)# Simulate some datax=rnorm(1000, mean=0, sd=1)y= 0.5*x + rnorm(1000, mean=0, sd=1)tmpFrame <- data.frame(x, y)tmpNames <- names(tmpFrame)# Define the matricesM <- mxMatrix(type = "Full", nrow = 1, ncol = 2, values=c(0,0),               free=c(TRUE,TRUE), labels=c("Mx", "My"), name = "M")S <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(1,0,0,1),               free=c(TRUE,FALSE,FALSE,TRUE), labels=c("Vx", NA, NA, "Vy"), name = "S")A <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0),               free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b", NA, NA), name = "A")I <- mxMatrix(type="Iden", nrow=2, ncol=2, name="I")# Define the expectationexpCov <- mxAlgebra(solve(I-A) %*% S %*% t(solve(I-A)), name="expCov")expFunction <- mxExpectationNormal(covariance="expCov", means="M", dimnames=tmpNames)# Choose a fit functionfitFunction <- mxFitFunctionML()# Define the modeltmpModel <- mxModel(model="exampleModel", M, S, A, I, expCov, expFunction, fitFunction,                     mxData(observed=tmpFrame, type="raw"))# Fit the model and print a summarytmpModelOut <- mxRun(tmpModel)summary(tmpModelOut)

Fail-safe Factors

Description

This is a wrapper for the R functionfactor.

OpenMx requires ordinal data to be ordered. R'sfactor function doesn't enforce this, hence this wrapper exists to throw an error should you accidentally try and run with ordered = FALSE.

Also, the ‘levels’ parameter is optional in R'sfactor function. However, relying on the data to specify the data is foolhardy for the following reasons: Thefactor function will skip levels missing from the data: Specifying these in levels leaves the list of levels complete. Data will often not explore the min and max level that the user knows are possible. For these reasons this function forces you to write out all possible levels explicitly.

Usage

mxFactor(x = character(), levels, labels = levels,     exclude = NA, ordered = TRUE, collapse = FALSE)

Arguments

x

either a vector of data or a data.frame object.

levels

a mandatory vector of the values that 'x' might have taken.

labels

_either_ an optional vector of labels for the levels, _or_ a character string of length 1.

exclude

a vector of values to be excluded from the set of levels.

ordered

logical flag to determine if the levels should be regarded as ordered (in the order given). Required to be TRUE.

collapse

logical flag to determine if duplicate labels shouldcollapsed into a single level

Details

If ‘x’ is a data.frame, then all of the columns of ‘x’ are converted into ordered factors. If ‘x’ is a data.frame, then ‘levels’ and ‘labels’ may be either a list or a vector. When ‘levels’ is a list, then different levels are assigned to different columns of the constructed data.frame object. When ‘levels’ is a vector, then the same levels are assigned to all the columns of the data.frame object. The function will throw an error if ‘ordered’ is not TRUE or if ‘levels’ is missing. Seefactor for more information on creating ordered factors.

References

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

Examples

myVar <- c("s", "t", "a", "t", "i", "s", "t", "i", "c", "s")ff    <- mxFactor(myVar, levels=letters)# Note: letters is a built in list of all lowercase letters of the alphabetff# [1] s t a t i s t i c s# Levels: a < b < c < d < e < f < g < h < i < j < k < l < m < n < o < p < q <#  r < s < t < u < v < w < x < y < zas.integer(ff)  # the internal codesfactor(ff)      # NOTE: drops the levels that do not occur.                # mxFactor prevents you doing this unintentionally.# This example works on a dataframefoo <- data.frame(x=c(1:3),y=c(4:6),z=c(7:9))# Applys one set of levels to all three columnsmxFactor(foo, c(1:9))# Apply unique sets of levels to each variablemxFactor(foo, list(c(1:3), c(4:6), c(7:9)))mxFactor(foo, c(1:9), labels=c(1,1,1,2,2,2,3,3,3), collapse=TRUE)

Estimate factor scores and standard errors

Description

This function creates the factor scores and their standard errors under different methods for an MxModel object that has either a RAM or LISREL expectation.

Usage

mxFactorScores(model, type=c('ML', 'WeightedML', 'Regression'), minManifests=as.integer(NA))

Arguments

model

An MxModel object with either an MxExpectationLISREL or MxExpectationRAM

type

The type of factor scores to compute

minManifests

Set scores to NA when there are less thanminManifests non-NA manifest variables

Details

This is a helper function to compute or estimate factor scores along with their standard errors. The two maximum likelihood methods create a new model for each data row. They then estimate the factor scores as free parameters in a model with a single data row. For 'ML', the conditional likelihood of the data given the factor scores is optimized:

L(D|F)

. For 'WeightedML', the joint likelihood of the data and the factor scores is optimized:

L(D, F) = L(D|F) L(F)

. The WeightedML scores are akin to the empirical Bayes random effects estimates from mixed effects modeling. They display the same kind of shrinkage as random effects estimates, and for the same reason: they account for the latent variable distribution in their estimation.

In many cases, especially for ordinal data or missing data, the weighted ML scores are to be preferred over alternatives (Estabrook & Neale, 2013). For example, when using ordinal data, a person whose observations are all in the highest ordinal category theoretically has an 'ML' factor score of positive infinity. A similar situation arises for a person whose observations are all in the lowest ordinal category: their 'ML' factor score is theoretically negative infinity. Weighted ML factor scores in these cases remain reasonable.

For type='Regression', with LISREL expectation, factor scores are computed based on a simple formula. This formula is equivalent to the formula for the Kalman updated scores in a state space model with zero dynamics (Priestly & Subba Rao, 1975). Thus, to compute the regression factor scores, the appropriate state space model is set-up and themxKalmanScores function is used to produce the factor scores and their standard errors. With RAM expectation, factor scores are predicted from the non-missing manifest variables for each row of the raw data, using a general linear prediction formula analytically equivalent to that used with LISREL expectation. The standard errors for regression-predicted RAM factor scores are the square roots of the indeterminate variances of the latent variables, given the data row's missing-data pattern and the values of any relevant definition variables. The RAM and LISREL methods for computing regression factor scores with their standard errors are analytically identical. They produce the same score and standard error estimates.

If you have missing data then you must specifyminManifests.This option will set scores to NA when there are too few items to make an accurate score estimate.If you are using the scores as point estimates without considering the standard error then you should set minManifests as high as you can tolerate.This will increase the amount of missing data but scores will be more accurate.If you are carefully considering the standard errors of the scores thenyou can set minManifests to 0.When set to 0, all NA rows are scored to the prior distribution.

Note that for compatibility withfactanal, type='regression' is also acceptable.

Value

An array with dimensions (Number of Rows of Data, Number of Latent Variables, 2). The third dimension has the scores in the first slot and the standard errors in the second slot. The rows are in the order of theunsorted data. Multigroup models are an exception, in that the returned value is instead a list of such arrays, containing one per group.

References

Estabrook, R. & Neale, M. C. (2013). A Comparison of Factor Score Estimation Methods in the Presence of Missing Data: Reliability and an Application to Nicotine Dependence.Multivariate Behavioral Research, 48, 1-27.

Priestley, M. & Subba Rao, T. (1975). The estimation of factor scores and Kalman filtering for discrete parameter stationary processes.International Journal of Control, 21, 971-975.

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

See Also

mxKalmanScores

Examples

# Create and estimate a factor modelrequire(OpenMx)data(demoOneFactor)manifests <- names(demoOneFactor)latents <- c("G")factorModel <- mxModel("OneFactor",                        type="LISREL",                       manifestVars=list(exo=manifests),                        latentVars=list(exo=latents),                       mxPath(from=latents, to=manifests),                       mxPath(from=manifests, arrows=2),                       mxPath(from=latents, arrows=2, free=FALSE, values=1.0),                       mxPath(from='one', to=manifests),                       mxData(observed=cov(demoOneFactor), type="cov", numObs=500,                              means = colMeans(demoOneFactor)))summary(factorRun <- mxRun(factorModel))# Swap in raw data in place of summary datafactorRun <- mxModel(factorRun, mxData(observed=demoOneFactor[1:50,], type="raw"))# Estimate factor scores for the modelr1 <- mxFactorScores(factorRun, 'Regression')

Create MxFitFunctionAlgebra Object

Description

mxFitFunctionAlgebra returns an MxFitFunctionAlgebra object.

Usage

mxFitFunctionAlgebra(algebra, numObs = NA, numStats = NA, ..., gradient =                 NA_character_, hessian = NA_character_, verbose = 0L,   units="-2lnL", strict=TRUE)

Arguments

algebra

A character string indicating the name of anMxAlgebra orMxMatrix object to use for optimization.

numObs

(optional) An adjustment to the total number of observations in the model.

numStats

(optional) An adjustment to the total number ofobserved statistics in the model.

...

Not used. Forces remaining arguments to be specified by name.

gradient

(optional) A character string indicating the name ofanMxAlgebra object.

hessian

(optional) A character string indicating the name ofanMxAlgebra object.

verbose

(optional An integer to increase the level of runtimelog output.

units

(optional) The units of the fit statistic.

strict

Whether to require that all derivative entries referencefree parameters.

Details

If you want to fit a multigroup model, the preferred way is to usemxFitFunctionMultigroup.

Fit functions are functions for which free parameter values are chosen such that the value of the objective function is minimized. While the other fit functions in OpenMx require an expectation function for the model, themxAlgebraObjective function uses the referencedMxAlgebra orMxMatrix object as the function to be minimized.

If a model's fit function is anmxFitFunctionAlgebra objective function, then the referenced algebra in the objective function must return a 1 x 1 matrix (when using OpenMx's default optimizer). There is no restriction on the dimensions of an fit function that is not the primary, or ‘topmost’, objective function.

To evaluate an algebra fit function, place the following objects in aMxModel object: amxFitFunctionAlgebra,MxAlgebra andMxMatrix entities referenced by theMxAlgebraObjective, and optionalMxBounds andMxConstraint objects. This model may then be evaluated using themxRun function. The results of the optimization may be obtained using themxEval function on the name of theMxAlgebra, after the model has been run.

First and second derivatives can be provided with the algebra fitfunction. The dimnames on the gradient and hessian MxAlgebras arematched against names of free variables. Names that do not match areignored. The fit is assumed to be in deviance units (-2 loglikelihood units). If you are working in log likelihood units, the -2scaling factor is not applied automatically. You have tomultiply by -2 yourself.

Value

Returns an MxFitFunctionAlgebra object. MxFitFunctionAlgebra objects should be included with models with referencedMxAlgebra andMxMatrix objects.

References

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

See Also

Other fit functions:mxFitFunctionMultigroup,mxFitFunctionML,mxFitFunctionWLS,mxFitFunctionGREML,mxFitFunctionR,mxFitFunctionRow

To create an algebra suitable as a reference function to be minimized see:mxAlgebra

More information about the OpenMx package may be foundhere.

Examples

# Create and fit a very simple model that adds two numbers using mxFitFunctionAlgebralibrary(OpenMx)# Create a matrix 'A' with no free parametersA <- mxMatrix('Full', nrow = 1, ncol = 1, values = 1, name = 'A')# Create an algebra 'B', which defines the expression A + AB <- mxAlgebra(A + A, name = 'B')# Define the objective function for algebra 'B'objective <- mxFitFunctionAlgebra('B')# Place the algebra, its associated matrix and# its objective function in a modeltmpModel <- mxModel(model="Addition", A, B, objective)# Evalulate the algebratmpModelOut <- mxRun(tmpModel)# View the resultstmpModelOut$output$minimum

Create MxFitFunctionGREML Object

Description

This function creates a newMxFitFunctionGREML object.

Usage

mxFitFunctionGREML(dV=character(0), aug=character(0),   augGrad=character(0), augHess=character(0),    autoDerivType=c("semiAnalyt","numeric"),infoMatType=c("average","expected"),   dyhat=character(0))

Arguments

dV

Vector of character strings; defaults to a character vector of length zero. If a value of non-zero length is provided, it must be anamed character vector. This vector's names must be the labels of free parameters in the model. The vector's elements (i.e., the character strings themselves) must be the names ofMxAlgebra orMxMatrix object(s), each of which equals the first partial derivative of the 'V' matrix with respect to the corresponding free parameter.

aug

Character string; defaults to a character vector of length zero. Any elements after the first are ignored. The string should name a 1x1MxMatrix or anMxAlgebra that evaluates to a 1x1 matrix. The named object will be used as an "augmentation" to the GREML fitfunction–specifically, the [1,1] value of the object named byaug will be added to the GREML fitfunction value at each function evaluation. The augmentation can be used to regularize estimation with a prior likelihood, or to use penalty functions to approximate constraints.

augGrad

Character string; defaults to a character vector of length zero. Any elements after the first are ignored. The string should name aMxMatrix or anMxAlgebra that evaluates to the gradient ofaug with respect to free parameters. The gradient can be either a column or row vector. The free parameters corresponding to the elements of the gradient vector are taken from the names of argumentdV, e.g. if the third name ofdV is'va', then the third element of the gradient vector should be the first partial derivative of the augmentation function with respect to'va'. Ignored unless bothdV andaug have nonzero length.

augHess

Character string; defaults to a character vector of length zero. Any elements after the first are ignored. The string should name aMxMatrix or anMxAlgebra that evaluates to the Hessian ofaug with respect to free parameters. The free parameters corresponding to each row and column of this matrix are dictated by the names of argumentdV, in the same manner as for the elements ofaugGrad. Ignored unless bothdV andaug have nonzero length. Providing a nonzero-length value foraugHess but notaugGrad will result in an error at runtime.

autoDerivType

"Automatic derivative type." Character string, either "semiAnalyt" (default) or "numeric". See details below.

infoMatType

"Information matrix type." Character string, either "average" (default) or "expected". See details below. Ignored ifREML=FALSE and a nonzero-length value foryhat were provided tomxExpectationGREML(), in which case the expected information matrix is always calculated.

dyhat

Vector of character strings; defaults to a character vector of length zero. If a value of non-zero length is provided, it must be anamed character vector. This vector's names must be labels of free parameters in the model. The vector's elements (i.e., the character strings themselves) must be the names ofMxAlgebra orMxMatrix object(s), each of which equals the first partial derivative of the 'yhat' vector with respect to the corresponding free parameter.

Details

Making effective use of argumentsdV,augGrad,augHess, anddyhat may require a custommxComputeSequence(). The derivatives of the loglikelihood function with respect to parameters can be internally computed from the derivatives of the 'V' matrix and 'yhat' vector, respectively supplied viadV anddyhat. The loglikelihood's first derivatives thus computed will always be exact, but its matrix of second partial derivatives (i.e., its Hessian matrix) will be approximated by either the average or expected information matrix, per the value of argumentinfoMatType. The average information matrix is faster to compute, but may not provide a good approximation to the Hessian if 'V' is not linear in the model's free parameters. The expected information matrix is slower to compute, but does not assume that 'V' is linear in the free parameters; however, it is generally only a good approximation to the Hessian in a neighborhood of the MLE. Neither information matrix will be a good approximation to the Hessian unless the derivatives of 'V' evaluate to symmetric matrices the same size as 'V'. Note also that these loglikelihood derivatives do not reflect the influence of any parameter bounds orMxConstraints. Internally, the derivatives of the 'V' matrix are assumed to be symmetric, and the elements above their main diagonals are ignored.

Formerly, if any derivatives were provided viadV, then derivatives had to be provided forevery free parameter in the MxModel. Currently, users may provide derivatives of 'V' viadV with respect to some or all free parameters. Note that, if non-default values for them are provided, the gradient and Hessian of the augmentation must be complete, i.e. contain derivatives of the augmentation with respect to every parameter or pair of parameters respectively.

If there are any free parameters with respect to which the user did not provide an analytic derivative of 'V' (or 'yhat'), OpenMx will automatically calculate the necessary loglikelihood derivatives according toautoDerivType. IfautoDerivType="semiAnalyt", the GREML fitfunction backend will calculate the missing derivatives in a "semi-analytic" fashion. Specifically, the backend will numerically differentiate 'V' (or 'yhat') with respect to the relevant parameter(s), and use those numeric matrix derivatives to analytically calculate the needed loglikelihood derivatives. IfautoDerivType="numeric", the needed loglikelihood derivatives will be calculated numerically, via finite-differences.

Argumentaug is intended to allow users to provide penalty functions or prior likelihoods in order to approximate constraints or to regularize optimization. The user is warned that careless use of this augmentation feature may undermine the validity of his/her statistical inferences.

Value

Returns a new object of classMxFitFunctionGREML.

References

Kirkpatrick RM, Pritikin JN, Hunter MD, & Neale MC. (2021). Combining structural-equation modeling with genomic-relatedness matrix restricted maximum likelihood in OpenMx. Behavior Genetics 51: 331-342.doi:10.1007/s10519-020-10037-5

The first software implementation of "GREML":
Yang J, Lee SH, Goddard ME, Visscher PM. (2011). GCTA: a tool for genome-wide complex trait analysis. American Journal of Human Genetics 88: 76-82.doi:10.1016/j.ajhg.2010.11.011

One of the first uses of the acronym "GREML":
Benjamin DJ, Cesarini D, van der Loos MJHM, Dawes CT, Koellinger PD, et al. (2012). The genetic architecture of economic and political preferences. Proceedings of the National Academy of Sciences 109: 8026-8031. doi: 10.1073/pnas.1120666109

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

See Also

SeeMxFitFunctionGREML for the S4 class created bymxFitFunctionGREML(). For more information generally concerning GREML analyses, including a complete example, seemxExpectationGREML().

Other fit functions:mxFitFunctionMultigroup,mxFitFunctionML,mxFitFunctionWLS,mxFitFunctionAlgebra,mxFitFunctionR,mxFitFunctionRow

More information about the OpenMx package may be foundhere.

Examples

gff <- mxFitFunctionGREML()str(gff)

Create MxFitFunctionML Object

Description

This function creates a new MxFitFunctionML object.

Usage

mxFitFunctionML(vector = FALSE, rowDiagnostics = FALSE, ..., fellner =  as.logical(NA), verbose=0L, profileOut=c(),  rowwiseParallel=as.logical(NA), jointConditionOn = c("auto", "ordinal", "continuous"))

Arguments

vector

A logical value indicating whether the objective function result is the likelihood vector.

rowDiagnostics

A logical value indicating whether the row-wiseresults of the objective function should be returned as an attributeof the fit function.

...

Not used. Forces remaining arguments to be specified by name.

fellner

Whether to fully expand the covariance matrix formaximum flexibility.

verbose

Level of diagnostic output

profileOut

Character vector naming constant coefficients toprofile out of the likelihood (sometimes known as REML)

rowwiseParallel

For raw data only, whether to use OpenMP to parallelize theevaluation of rows

jointConditionOn

The evaluation strategy when both continuousand ordinal data are present.

Details

Fit functions are functions for which free parameter values are optimized such that the value of a cost function is minimized. The mxFitFunctionML function computes -2*(log likelihood) of the data given the current values of the free parameters and the expectation function (e.g.,mxExpectationNormal ormxExpectationRAM) selected for the model.

The 'vector' argument is either TRUE or FALSE, and determines whether the objective function returns a column vector of the likelihoods, or a single -2*(log likelihood) value.

The 'rowDiagnostics' argument is either TRUE or FALSE, and determines whether the row likelihoods are returned as an attribute of the fit function. Additionally, the squared Mahalanobis distance and the number of observed (non-missing) variables) for each row are returned under the namesrowDist androwObs, respectively. It is sometimes useful to inspect the likelihoods for outliers, diagnostics, or other anomalies. Each rowwise squared Mahalanobis distance should be chi-squared distributed with degrees of freedom equal to the number of observed variables. In the case of no missing data, all of the rowwise squared Mahalanobis distances should theoretically be chi-squared distributed with the same degrees of freedom. In the case of some missing data, the rowwise squared Mahalanobis distances should theoretically be a mixture of chi-squared distributions with mixing proportions equal to the proportions of each number of observed variables.

If there are ordinal data, then only the row likelihoods are returned among the row diagnostics.

Whenvector=FALSE androwDiagnostics=TRUE, the fit function can be referenced in the model and included in algebras as a scalar. The row likelihoods, row distances, and row observations are then an attribute of the fit function but are not accessible in the model during optimization. The row likelihoods and other diagnostics are accessible to the user after the model has been run.

By default,jointConditionOn='auto' and a heuristic will be usedto select the fastest algorithm. Conditioning the continuous data onordinal will be superior when there are relatively few unique ordinalpatterns. Otherwise, conditioning the ordinal data on continuous willperform better when there are relatively many ordinal patterns.

Usage Notes:

The results of the optimization can be reported using thesummary function, or accessed directly in the 'output' slot of the resulting model (i.e., modelName$output). Components of the output may be referenced using theExtract functionality.

Value

Returns a new MxFitFunctionML object. One and only one MxFitFunctionML object should be included in each model along with an associatedmxExpectationNormal ormxExpectationRAM object.

References

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

See Also

Other fit functions:mxFitFunctionMultigroup,mxFitFunctionWLS,mxFitFunctionAlgebra,mxFitFunctionGREML,mxFitFunctionR,mxFitFunctionRow

More information about the OpenMx package may be foundhere.

Examples

# Create and fit a model using mxMatrix, mxAlgebra, mxExpectationNormal, and mxFitFunctionMLlibrary(OpenMx)# Simulate some datax=rnorm(1000, mean=0, sd=1)y= 0.5*x + rnorm(1000, mean=0, sd=1)tmpFrame <- data.frame(x, y)tmpNames <- names(tmpFrame)# Define the matricesM <- mxMatrix(type = "Full", nrow = 1, ncol = 2, values=c(0,0),               free=c(TRUE,TRUE), labels=c("Mx", "My"), name = "M")S <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(1,0,0,1),               free=c(TRUE,FALSE,FALSE,TRUE), labels=c("Vx", NA, NA, "Vy"), name = "S")A <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0),               free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b", NA, NA), name = "A")I <- mxMatrix(type="Iden", nrow=2, ncol=2, name="I")# Define the expectationexpCov <- mxAlgebra(solve(I-A) %*% S %*% t(solve(I-A)), name="expCov")expFunction <- mxExpectationNormal(covariance="expCov", means="M", dimnames=tmpNames)# Choose a fit functionfitFunction <- mxFitFunctionML(rowDiagnostics=TRUE)# also return row likelihoods, even though the fit function#  value is still 1x1# Define the modeltmpModel <- mxModel(model="exampleModel", M, S, A, I, expCov, expFunction, fitFunction,                     mxData(observed=tmpFrame, type="raw"))# Fit the model and print a summarytmpModelOut <- mxRun(tmpModel)summary(tmpModelOut)fitResOnly <- mxEval(fitfunction, tmpModelOut)attributes(fitResOnly) <- NULLfitResOnly# Look at the row likelihoods alonefitLikeOnly <- attr(mxEval(fitfunction, tmpModelOut), 'likelihoods')head(fitLikeOnly)

Create a fit function used to fit multiple-group models

Description

mxFitFunctionMultigroup creates a fit function consisting of the sum of the fit statisticsfrom a list of submodels provided. Thus, it aggregates fit statistics from multiple submodels.

This total provides the optimization target for fitting a multi-group model.

In addition to being more compact and readable, usingmxFitFunctionMultigroup hasadditional side effects which are valuable for multi-group modeling.

First, it aggregates analytic derivative calculations.

Second, it allowsmxRefModels to compute saturated models for raw data, as this function can learn which are the constituent submodels.

Third, and finally, it allowsmxCheckIdentification to evaluate the local identification of the multigroup model.

Usage

mxFitFunctionMultigroup(groups, ..., verbose = 0L)

Arguments

groups

vector of submodel names (strings)

...

Not used. Forces subsequent arguments to be specified by name.

verbose

the level of debugging output

Details

Conceptually,mxFitFunctionMultigroup is equivalent to summing the subModel objectives in anmxAlgebra,and using anmxFitFunctionAlgebra to optimize the model based on this summed likelihood.

e.g. this 1-line call to mxFitFunctionMultigroup:

mxFitFunctionMultigroup(c("model1", "model2"))

is equivalent to the following pair of statements:

mxAlgebra(name = "myAlgebra", model1.objective + model2.objective)

mxFitFunctionAlgebra("myAlgebra")

Note: If needed, you can refer to the algebra generated bymxFitFunctionMultigroup as:

modelName.fitfunction

Where "modelName" is the name of the container or supermodel.

See Also

Other fit functions:mxFitFunctionML,mxFitFunctionWLS,mxFitFunctionAlgebra,mxFitFunctionGREML,mxFitFunctionR,mxFitFunctionRow

More information about the OpenMx package may be foundhere.

Examples

#------------------------------------------------# Brief non-running examplerequire("OpenMx")mxFitFunctionMultigroup(c("model1", "model2")) # names of sub-models to be jointly optimised# ===========================================# = Longer, fully featured, running example =# ===========================================# Create and fit a model using mxMatrix, mxExpectationRAM, mxFitFunctionML,# and mxFitFunctionMultigroup.# The model is multiple group regression.# Only the residual variances are allowed to differ across groups.library(OpenMx)# Simulate some data# Group 1N1 = 100x = rnorm(N1, mean= 0, sd= 1)y = 0.5*x + rnorm(N1, mean= 0, sd= 1)ds1 <- data.frame(x, y)dsNames <- names(ds1)# Group 2: y has greater variance; x & y slightly lower correlation...N2= 150x= rnorm(N2, mean= 0, sd= 1)y= 0.5*x + rnorm(N2, mean= 0, sd= sqrt(1.5))ds2 <- data.frame(x, y)# Define the matrices (A matrix implementation of 2 RAM models)I <- mxMatrix(name="I", type="Iden", nrow=2, ncol=2)M <- mxMatrix(name = "M", type = "Full", nrow = 1, ncol = 2, values=0,              free=TRUE, labels=c("Mean_x", "Mean_y"))# A matrix containing a path "b" of x on yA <- mxMatrix(name = "A", type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0),              free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b", NA, NA))S1 <- mxMatrix(name = "S", type = "Diag", nrow = 2, ncol = 2, values=1,              free=TRUE, labels=c("Var_x", "Resid_y_group1"))S2 <- mxMatrix(name = "S", type = "Diag", nrow = 2, ncol = 2, values=1,              free=TRUE, labels=c("Var_x", "Resid_y_group2"))# Define the expectationexpect <- mxExpectationRAM('A', 'S', 'I', 'M', dimnames= dsNames)# Choose a fit functionfitFunction <- mxFitFunctionML(rowDiagnostics=TRUE)# Also return row likelihoods (the fit function value is still 1x1)# Multiple-group fit function sums the model likelihoods# from its component modelsmgFitFun <- mxFitFunctionMultigroup(c('g1model', 'g2model'))# Define model 1 and model 2m1 = mxModel(model="g1model",M, S1, A, I, expect, fitFunction,    mxData(cov(ds1), type="cov", numObs=N1, means=colMeans(ds1)))m2 = mxModel(model="g2model",M, S2, A, I, expect, fitFunction,    mxData(cov(ds2), type="cov", numObs=N2, means=colMeans(ds2)))mg <- mxModel(model='multipleGroup', m1, m2, mgFitFun)# note!: Paths with the same name in both submodels are# constrained to the same value across models. i.e.,# b has only 1 value, as does Var_x. But Resid_y can take distinct# values in the two groups.# Fit the model and print a summarymg <- mxRun(mg)summary(mg)# Examine fit function results# Fit in -2lnL units)mxEval(fitfunction, mg)# Fit function results for each submodel:mxEval(g1model.fitfunction, mg)mxEval(g2model.fitfunction, mg)mg2 = omxSetParameters(mg,  labels = c("Resid_y_group1", "Resid_y_group2"),  newlabels = "Resid_y", name = "equated")mg2 = omxAssignFirstParameters(mg2)mg2 = mxRun(mg2)mxCompare(mg, mg2)# ouch... that was a significant loss in fit: the residuals definately are larger in group2!

Create MxFitFunctionR Object

Description

mxFitFunctionR returns an MxFitFunctionR object.

Usage

mxFitFunctionR(fitfun, ..., units="-2lnL")

Arguments

fitfun

A function that accepts two arguments.

...

The initial state information to the objective function.

units

(optional) The units of the fit statistic.

Details

The mxFitFunctionR function evaluates a user-defined R function called the 'fitfun'. mxFitFunctionR is useful in defining new mxFitFunctions, since any calculation that can be performed in R can be treated as an mxFitFunction.

The 'fitfun' argument must be a function that accepts two arguments. The first argumentis the mxModel that should be evaluated, and the second argument is some persistent state information that can be stored between one iteration of optimization to the nextiteration. It is valid for the function to simply ignore the second argument.

The function must return either a single numeric value, or a list of exactly two elements.If the function returns a list, the first argument must be a single numeric value and the second element will be the new persistent state information to be passed into this functionat the next iteration. The single numeric value will be used by the optimizer to performoptimization.

The initial default value for the persistent state information is NA.

Throwing an exception (via stop) from inside fitfun may resultin unpredictable behavior. You may want to wrap your code intryCatch while experimenting.

fitfun should not call R functions that use OpenMx's compiled backend, including (but not limited to)omxMnor(), because doing so can crash R.

Value

Returns an MxFitFunctionR object.

References

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

See Also

Other fit functions:mxFitFunctionMultigroup,mxFitFunctionML,mxFitFunctionWLS,mxFitFunctionAlgebra,mxFitFunctionGREML,mxFitFunctionRow

More information about the OpenMx package may be foundhere.

Examples

# Create and fit a model using mxFitFunctionRlibrary(OpenMx)A <- mxMatrix(nrow = 2, ncol = 2, values = c(1:4), free = TRUE, name = 'A')squared <- function(x) { x ^ 2 }# Define the objective function in RobjFunction <- function(model, state) {    values <- model$A$values     return(squared(values[1,1] - 4) + squared(values[1,2] - 3) +        squared(values[2,1] - 2) + squared(values[2,2] - 1))}# Define the expectation functionfitFunction <- mxFitFunctionR(objFunction)# Define the modeltmpModel <- mxModel(model="exampleModel", A, fitFunction)# Fit the model and print a summarytmpModelOut <- mxRun(tmpModel)summary(tmpModelOut)

Create an MxFitFunctionRow Object

Description

mxFitFunctionRow returns an MxFitFunctionRow object.

Usage

mxFitFunctionRow(rowAlgebra, reduceAlgebra, dimnames,   rowResults = "rowResults", filteredDataRow = "filteredDataRow",   existenceVector = "existenceVector", units="-2lnL")

Arguments

rowAlgebra

A character string indicating the name of the algebra to be evaluated row-wise.

reduceAlgebra

A character string indicating the name of the algebra that collapses the row results into a single number which is then optimized.

dimnames

A character vector of names corresponding to columns be extracted from the data set.

rowResults

The name of the auto-generated "rowResults" matrix. See details.

filteredDataRow

The name of the auto-generated "filteredDataRow" matrix. See details.

existenceVector

The name of the auto-generated "existenceVector" matrix. See details.

units

(optional) The units of the fit statistic.

Details

Fit functions are functions for which free parameter values are optimized such that the value of a cost function is minimized. The mxFitFunctionRow function evaluates a user-definedMxAlgebra object called the ‘rowAlgebra’ in a row-wise fashion. It then stores results of the row-wise evaluation in anotherMxAlgebra object called the ‘rowResults’. Finally, the mxFitFunctionRow function collapses the row results into a single number which is then used for optimization. TheMxAlgebra object named by the ‘reduceAlgebra’ collapses the row results into a single number.

The ‘filteredDataRow’ is populated in a row-by-row fashion with all the non-missing data from the current row. You cannot assume that the length of the filteredDataRow matrix remains constant (unless you have no missing data). The ‘existenceVector’ is populated in a row-by-row fashion with a value of 1.0 in column j if a non-missing value is present in the data set in column j, and a value of 0.0 otherwise. Use the functionsomxSelectRows,omxSelectCols, andomxSelectRowsAndCols to shrink other matrices so that their dimensions will be conformable to the size of ‘filteredDataRow’.

Value

Returns a new MxFitFunctionRow object. Only one MxFitFunction object should be included in each model. There is no need for an MxExpectation object when using mxFitFunctionRow.

References

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

See Also

Other fit functions:mxFitFunctionMultigroup,mxFitFunctionML,mxFitFunctionWLS,mxFitFunctionAlgebra,mxFitFunctionGREML,mxFitFunctionR

More information about the OpenMx package may be foundhere.

Examples

# Model that adds two data columns row-wise, then sums that column# Notice no optimization is performed here.library(OpenMx)xdat <- data.frame(a=rnorm(10), b=1:10) # Make data setamod <- mxModel(model="example1",            mxData(observed=xdat, type='raw'),            mxAlgebra(sum(filteredDataRow), name = 'rowAlgebra'),            mxAlgebra(sum(rowResults), name = 'reduceAlgebra'),            mxFitFunctionRow(                rowAlgebra='rowAlgebra',                reduceAlgebra='reduceAlgebra',                dimnames=c('a','b')))amodOut <- mxRun(amod)mxEval(rowResults, model=amodOut)mxEval(reduceAlgebra, model=amodOut)# Model that find the parameter that minimizes the sum of the#  squared difference between the parameter and a data row.bmod <- mxModel(model="example2",            mxData(observed=xdat, type='raw'),            mxMatrix(values=.75, ncol=1, nrow=1, free=TRUE, name='B'),            mxAlgebra((filteredDataRow - B) ^ 2, name='rowAlgebra'),            mxAlgebra(sum(rowResults), name='reduceAlgebra'),            mxFitFunctionRow(                rowAlgebra='rowAlgebra',                reduceAlgebra='reduceAlgebra',                dimnames=c('a')))bmodOut <- mxRun(bmod)mxEval(B, model=bmodOut)mxEval(reduceAlgebra, model=bmodOut)mxEval(rowResults, model=bmodOut)

Create MxFitFunctionWLS Object

Description

This function creates a new MxFitFunctionWLS object.

Usage

mxFitFunctionWLS(type=c('WLS','DWLS','ULS'),     allContinuousMethod=c("cumulants", "marginals"),     fullWeight=TRUE)

Arguments

type

A character string 'WLS' (default), 'DWLS', or 'ULS' for weighted, diagonally weighted, or unweighted least squares, respectively

allContinuousMethod

A character string 'cumulants' (default) or 'marginals'. See Details.

fullWeight

Logical determining if the full weight matrix is returned (default). Needed for standard error and quasi-chi-squared calculation.

Details

As with other fit functions,mxFitFunctionWLS optimizes free parameter values such that the value of a cost function is minimized. FormxFitFunctionWLS, this cost function is the weighted least squares difference between the data and the model-implied expectations for the data based on the free parameters and the expectation function (e.g.,mxExpectationNormal ormxExpectationRAM) selected for the model.

Bias and sensitivity to model misspecificationBoth ordinal and continuous data are supported, as well as combinations of these data types. All three methods ('WLS', 'ULS' and 'DWLS') are unbiased when the model is correct. Full 'WLS' is highly sensitive to model misspecification – it can heavily weight the fourth-order moments of the distribution, so small deviations between the observed fourth-order moments and those implied by the model can lead to poor estimates.

Behavior with all-continuous dataWhen only continuous variables are present, the argumentallContinuousMethod dictates how to process the data.

The default,cumulants is a good choice for non-normal data. This uses the asymptotically distribution free (ADF) method of Browne (1984) and computes the fourth ordercumulants for the weight matrix: thus, the name. It is generally fast and ADF up to elliptical distributions. Data computed using cumulants should also be more accurate than via marginals (because the whole covariance is a single analytic expression, with no estimation involved).

note: Thecumulants method does not handle missing data. It also does not return weights or summary statistics for the means.

The alternative option, 'marginals', uses methods similar to those used in processing ordinal and joint ordinal-continuous data. By contrast with cumulants, marginals returns weights and summary statistics for the means.

When data are not all continuous,allContinuousMethod is ignored, and means are modelled.

Usage Notes:

Model results can be reported using thesummary function, or accessed directly in the 'output' slot of the model (i.e.,model$output). Components of the output may also be accessed and used in the same way, i.e., via the$ and[]Extract functions.

Summary statistics are returned in the MxData object in anobservedStats list. IfobservedStats are already presentand in the appropriate shape then they are reused. It is also possibleto provide your own arbitrary user supplied observed statistics usingthis same approach.

Value

Returns a new MxFitFunctionWLS object. One and only one fit function object should be included in each model, along with an associatedmxExpectationNormal ormxExpectationRAM object.

References

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

Browne, M. W. (1984). Asymptotically distribution-free methods for the analysis of covariance structures.British Journal of Mathematical and Statistical Psychology,37, 62-83.

See Also

Other fit functions:mxFitFunctionMultigroup,mxFitFunctionML,mxFitFunctionAlgebra,mxFitFunctionGREML,mxFitFunctionR,mxFitFunctionRow

More information about the OpenMx package may be foundhere.

Examples

# Create and fit a WLS model using RAM, and then using matrices.library(OpenMx)# Simulate some data where y = .5x + errorx = rnorm(1000, mean = 0, sd = 1)y = 0.5*x + rnorm(1000, mean = 0, sd = 1)tmpFrame = data.frame(x, y)varNames = names(tmpFrame)# =======================# = A RAM model example =# =======================m1 = mxModel("my_first_WLS", type = "RAM",manifestVars = c("x", "y"),mxPath(c("x", "y"), arrows = 2, values = 1, labels = c("xVar", "yVar")),mxPath("x", to = "y", labels = "x_to_y"),mxFitFunctionWLS(),mxData(tmpFrame, 'raw'))m1 = mxRun(m1)summary(m1)$parameters# Here are the cov, acov and Weight matrices:print(m1$data$observedStats)# Use a different weight matrixm2 = m1os <- m1$data$observedStatsos$asymCov <- solve(rWishart(n=1, df= nrow(tmpFrame), Sigma= diag(3))[,,1])os$useWeight <- solve(os$asymCov * nrow(tmpFrame))m2$data$observedStats <- os# Set verbose to check if our new weights are usedm2$data$verbose <- 1L# Run modelm2 <- mxRun(m2)# SE indeed changed due to new weightsprint(m2$output$standardErrors - m1$output$standardErrors)# ==========================# = A matrix-based example =# ==========================# Define matrices for Symmetric (S) and Asymmetric (A) paths and an Identity matrix.S <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(1,0,0,1),              free=c(TRUE,FALSE,FALSE,TRUE), labels=c("Vx", NA, NA, "Vy"), name = "S")A <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0),              free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b", NA, NA), name = "A")I <- mxMatrix(type="Iden", nrow=2, ncol=2, name="I")# Build the modeltmpModel <- mxModel(model="exampleModel",# Add the S, A, and I matrices constructed aboveS, A, I,# Define the expectationmxAlgebra(name="expCov", solve(I-A) %*% S %*% t(solve(I-A))),# Choose a normal expectation and WLS as the fit functionmxExpectationNormal(covariance= "expCov", dimnames= varNames),mxFitFunctionWLS(),   # Add the datamxData(tmpFrame, 'raw'))# Fit the model and print a summarytmpModel <- mxRun(tmpModel)summary(tmpModel)

Helper Function for Structuring GREML Data

Description

This function takes a dataframe or matrix and uses it to setup the 'y' and 'X' matrices for a GREML analysis; this includes trimming outNAs from 'X' and 'y.' The result is a matrix the first column of which is the 'y' vector, and the remaining columns of which constitute 'X.'

Usage

mxGREMLDataHandler(data, yvars=character(0), Xvars=list(), addOnes=TRUE,                   blockByPheno=TRUE, staggerZeroes=TRUE)

Arguments

data

Either a dataframe or matrix, with column names, containing the variables to be used as phenotypes and covariates in 'y' and 'X,' respectively.

yvars

Character vector. Each string names a column of the raw dataset, to be used as a phenotype.

Xvars

A list of data column names, specifying the covariates to be used with each phenotype. The list should have the same length as argumentyvars. If there are no covariates of interest, then the default value (an empty list) should be used, in which case the 'X' matrix will be constructed for estimating the regression intercept(s) only.

addOnes

Logical; should lead columns of ones (for the regression intercepts) be adhered to the covariates when assembling the 'X' matrix? Defaults toTRUE.

blockByPheno

Logical; relevant to polyphenotype analyses. IfTRUE (default), then the resulting 'y' will contain phenotype #1 for individuals 1 thrun, phenotype #2 for individuals 1 thrun, ... IfFALSE, then observations are "blocked by individual", and the resulting 'y' will contain individual #1's scores on phenotypes 1 thrup, individual #2's scores on phenotypes 1 thrup, ... Note that in either case, 'X' will be structured appropriately for 'y.'

staggerZeroes

Logical; relevant to polyphenotype analyses. IfTRUE (default), then each phenotype's covariates in 'X' are "staggered," and 'X' is padded out with zeroes. IfFALSE, then 'X' is formed simply by stacking the phenotypes' covariates; this requires each phenotype to have the same number of covariates (i.e., each character vector inXvars must be of the same length). The default (TRUE) is intended for instances where the multiple phenotypes truly are different variables, whereasstaggerZeroes=FALSE is intended for instances where the multiple "phenotypes" actually represent multiple observations on the same variable. One example of the latter case is longitudinal data where the multiple "phenotypes" are repeated measures on a single phenotype.

Details

For a monophenotype analysis (only), argumentXvars can be a character vector. In a polyphenotype analysis, if the same covariates are to be used with all phenotypes, thenXvars can be a list of length 1.

Note the synergy between the output ofmxGREMLDataHandler() and argumentsdataset.is.yX andcasesToDropFromV tomxExpectationGREML().

If the dataframe or matrix supplied for argumentdata hasn rows, and argumentyvars is of lengthp, then the resulting 'y' and 'X' matrices will havenp rows. Then, if either matrix contains anyNA's, the rows containing theNA's are trimmed from both 'X' and 'y' before being returned in the output (in which case they will obviously have fewer thannp rows). FunctionmxGREMLDataHandler() reports which rows of the full-size 'X' and 'y' were trimmed out due to missing observations. These row indices can be provided as argumentcasesToDropFromV tomxExpectationGREML().

Value

A list with these two components:

yX

Numeric matrix. The first column is the phenotype vector, 'y,' while the remaining columns constitute the 'X' matrix of covariates. If this matrix is used as the raw dataset for a model, then the model's GREML expectation can be constructed withdataset.is.yX=TRUE inmxExpectationGREML().

casesToDrop

Numeric vector. Contains the indices of the rows of 'y' and 'X' that were dropped due to containingNA's. Can be provided as as argumentcasesToDropFromV tomxExpectationGREML().

References

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

See Also

For more information generally concerning GREML analyses, including a complete example, seemxExpectationGREML(). More information about the OpenMx package may be foundhere.

Examples

dat <- cbind(rnorm(100),rep(1,100))colnames(dat) <- c("y","x")dat[42,1] <- NAdat[57,2] <- NAdat2 <- mxGREMLDataHandler(data=dat, yvars="y", Xvars=list("x"),  addOnes = FALSE)str(dat2)

Generate data based on an mxModel (or a data.frame)

Description

This function returns a new (simulated) data set based on either the model-implied distribution ifa model is provided, OR saturated model if a data.frame is given in the model parameter.

See below for important details

Usage

mxGenerateData(model, nrows, returnModel=FALSE, use.miss = TRUE, ..., .backend=TRUE, subname=NULL, empirical=FALSE, nrowsProportion, silent=FALSE)

Arguments

model

A data.frame or MxModel object upon which the data are generated.

nrows

Numeric. The number of rows of data to generate (default = same as in the original data)

returnModel

Whether to return the model with new data, or just return the new data.frames (default)

use.miss

Whether to approximate the missingness pattern of the original data (TRUE by default).

...

Not used; forces remaining arguments to be specified by name.

.backend

Whether to use the backend to generate data (TRUE by default for speed)

subname

If given, limits data generation to this sub model.

empirical

Whether the generate data should match the distributionof the current data exactly. Usesmvrnorm instead ofrmvnorm

nrowsProportion

Numeric. The number of rows of data to generateexpressed as a proportion of the current number of rows.

silent

Logical. Whether to report progress during time consumingdata generation.

Details

When given a data.frame as a model, the model is assumed to besaturated multivariate Gaussian and the expected distributionis obtained usingmxDataWLS. In this case, the default number of rows is assumed to be the number of rows in the original data.frame, but any other number of rows can also be requested.

When given an MxModel,the model-implied means and covariance are extracted. It then generates data with the same mean and covariance. Data can be generated based on Normal (mxExpectationNormal), RAM (mxExpectationRAM), LISREL (mxExpectationLISREL), and state space (mxExpectationStateSpace) models.

Please note that this function samples data from the model-implied distribution(s); it does not sample from the data object in the model. That is, this function generates new data rather than pulling data that already exist from the model.

Thresholds and ordinal data are implemented by generating continuous data and then usingcut andmxFactor to break the continuous data at the thresholds into an ordered factor.

If the model has definition variables, then a data set must be included in the model object and the number of rows requested must match the number of rows in the model data. In this case the means, covariance, and thresholds are reevaluated for each row of data, potentially creating a a different mean, covariance, and threshold structure for every generated row of data.

For state space models (i.e. models with anmxExpectationStateSpace ormxExpectationStateSpaceContinuousTime expectation), the data are generated based on the autoregressive structure of the model. The rows of data in a state space model are not independent replicates of a stationary process. Rather, they are the result of a latent (possibly non-stationary) autoregressive process. For state space models different rows of data often correspond to different times. As alluded to above, data generation works for discrete time state space models and hybrid continuous-discrete time state space models. The latter have a continuous process that is measured as discrete times.

Thesubname parameter is used to limit data generation tothe given submodel. The reason you wouldn't pass the submodel inthemodel argument is that some parts of the submodel mightdepend on objects in other submodels that are part of the model.

Value

A data.frame, list of data.frames, or model populated with the new data(depending on thereturnModel parameter).Raw data is always returned even if the original model containedcovariance or some other non-raw data.

References

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

Examples

# ====================================# = Demonstration for empirical=TRUE =# ====================================popCov <- cov(Bollen[, 1:8])*(nrow(Bollen)-1)/nrow(Bollen)got <- mxGenerateData(Bollen[, 1:8], nrows=nrow(Bollen), empirical = TRUE)cov(got) - popCov  # pretty close, given 8 variables to juggle!round(cov2cor(cov(got)) - cov2cor(popCov), 4)# ===========================================# = Create data based on state space model. =# ===========================================require(OpenMx)nvar <- 5varnames <- paste("x", 1:nvar, sep="")ssModel <- mxModel(model="State Space Manual Example",    mxMatrix("Full", 1, 1, TRUE, .3, name="A"),    mxMatrix("Zero", 1, 1, name="B"),    mxMatrix("Full", nvar, 1, TRUE, .6, name="C", dimnames=list(varnames, "F1")),    mxMatrix("Zero", nvar, 1, name="D"),    mxMatrix("Diag", 1, 1, FALSE, 1, name="Q"),    mxMatrix("Diag", nvar, nvar, TRUE, .2, name="R"),    mxMatrix("Zero", 1, 1, name="x0"),    mxMatrix("Diag", 1, 1, FALSE, 1, name="P0"),    mxMatrix("Zero", 1, 1, name="u"),    mxExpectationStateSpace("A", "B", "C", "D", "Q", "R", "x0", "P0", "u"),    mxFitFunctionML())ssData <- mxGenerateData(ssModel, 200) # 200 time points# Add simulated data to model and runssModel <- mxModel(ssModel, mxData(ssData, 'raw'))ssRun <- mxRun(ssModel)# Compare parameters from random data to the generating modelcbind(Rand = omxGetParameters(ssRun), Gen = omxGetParameters(ssModel))# Note the parameters should be "close" (up to sampling error)# to the generating values# =========================================# = Demo generating new data from a model =# =========================================require(OpenMx)manifests <- paste0("x", 1:5)originalModel <- mxModel("One Factor", type="RAM",      manifestVars = manifests,      latentVars = "G",      mxPath(from="G", to=manifests, values=.8),      mxPath(from=manifests, arrows=2, values=.2),      mxPath(from="G"  , arrows=2, free=FALSE, values=1.0),      mxPath(from = 'one', to = manifests))factorData <- mxGenerateData(originalModel, 1000)newData = mxData(cov(factorData), type="cov",numObs=nrow(factorData), means = colMeans(factorData))newModel <- mxModel(originalModel, newData)newModel <- mxRun(newModel)cbind(Original = omxGetParameters(originalModel),Generated = round(omxGetParameters(newModel), 4),Delta = round(omxGetParameters(originalModel) -omxGetParameters(newModel), 3))# And again with empirical = TRUEfactorData <- mxGenerateData(originalModel, 1000, empirical = TRUE)newData = mxData(cov(factorData),type = "cov",numObs = nrow(factorData),means = colMeans(factorData))newModel <- mxModel(originalModel, newData)newModel <- mxRun(newModel)cbind(Original  = omxGetParameters(originalModel),Generated = round(omxGetParameters(newModel), 4),Delta     = omxGetParameters(originalModel) -     omxGetParameters(newModel))

Extract the component from a model's expectation

Description

This function extracts the expected means, covariance, or thresholds from a model.

Usage

mxGetExpected(model, component, defvar.row=1, subname=model$name)imxGetExpectationComponent(model, component, defvar.row=1, subname=model$name)

Arguments

model

MxModel object from which to extract the expectation component.

component

Character vector. The name(s) of the component(s) to extract. Recognized names are “covariance”, “means”, and “thresholds”.

defvar.row

A row index. Which row to load for definition variables.

subname

Name of the submodel to evaluate.

Details

The expected means, covariance, or thresholds can be extracted fromNormal (mxExpectationNormal), RAM (mxExpectationRAM), andLISREL (mxExpectationLISREL) models. When more than one componentis requested, the components will be returned as a list.

If component 'vector' is requested then the non-redundant coefficientsof the expected manifest distribution will be returned as a vector.

If component 'standVector' is requested then the same parameter structure as'vector' is returned, but it is standardized. For Normal expectations the covariancesare returned as correlations, the means are returned as zeros, and thethresholds are returned as z-scores. For the thresholds the z-scoresare computed by using the model-implied means and variances.

Note that capitalization is ignored for the 'standVector' option, so 'standvector'is also acceptable.

Value

See details.

References

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

Examples

   # ===============================================# = Build a 1-factor CFA, with bad start values =# ===============================================require(OpenMx)manifests = paste("x", 1:5, sep="")latents = c("G")factorModel = mxModel("One Factor", type="RAM",      manifestVars = manifests,      latentVars = latents,      mxPath(from = latents, to = manifests),      mxPath(from = manifests, arrows = 2),      mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),      mxPath(from = 'one', to = manifests),  mxData(demoOneFactor, type = "raw"))# ============================================================================# = What do our starting values indicate about the expected data covariance? =# ============================================================================mxGetExpected(factorModel, "covariance")# Oops. Starting values indicate an expected zero-covariance matrix.# The model likely won't run from these start values.# Let's adjust them:factorModel = mxModel("One Factor", type = "RAM",      manifestVars = manifests, latentVars = latents,      # Reasonable start VALUES  mxPath(from = latents, to = manifests, values = .2),      mxPath(from = manifests, arrows = 2),      mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),      mxPath(from = 'one', to = manifests),  mxData(demoOneFactor, type = "raw"))mxGetExpected(factorModel, "covariance")#      x1   x2   x3   x4   x5# x1 0.04 0.04 0.04 0.04 0.04# x2 0.04 0.04 0.04 0.04 0.04# x3 0.04 0.04 0.04 0.04 0.04# x4 0.04 0.04 0.04 0.04 0.04# x5 0.04 0.04 0.04 0.04 0.04# And this version will run:factorModel = mxRun(factorModel)

Jiggle parameter values.

Description

Jiggle free parameter values, subject to box constraints.imxJiggle() is called internally bymxTryHard() (q.v.).mxJiggle() provides a more user-friendly wrapper toimxJiggle(), and can alternately emulate the 'JIGGLE' behavior of classic Mx.

Usage

mxJiggle(model, classic=FALSE, dsn=c("runif","rnorm","rcauchy"), loc=1, scale=0.25)imxJiggle(params, lbounds, ubounds, dsn, loc, scale)

Arguments

model

An object of class MxModel.

classic

Logical; shouldmxJiggle() emulate the classic-Mx behavior elicited by keyword JIGGLE? Defaults toFALSE. See below, under "Details," for additional information.

dsn

Character string naming which random-number distribution–eitheruniform (rectangular),normal (Gaussian), orCauchy–to be used to perturb free-parameter values. Defaults to the uniform distribution (formxJiggle()).

loc,scale

Numeric. The location and scale parameters of the distribution from which random values are drawn to perturb free-parameter values, defaulting respectively to 1 and 0.25 (formxJiggle()).

params

Numeric vector of current free parameter values.

lbounds

Numeric vector of lower bounds on parameters.

ubounds

Numeric vector of upper bounds on parameters.

Details

IfmxJiggle() argumentclassic=FALSE (the default),mxJiggle() callsimxJiggle(). In that case,mxJiggle() passesimxJiggle() its own values for argumentsdsn,loc, andscale, and extracts values for argumentsparams,lbounds, andubounds frommodel. Then,model's free-parameter values are randomly perturbed before being re-assigned to it. The distributional family from which the perturbations are randomly generated is dictated by argumentdsn. The distribution is parameterized by argumentsloc andscale, respectively the location and scale parameters. The location parameter is the distribution's median. For the uniform distribution,scale is the absolute difference between its median and extrema (i.e., half the width of the rectangle); for the normal distribution,scale is its standard deviation; and for the Cauchy,scale is one-half its interquartile range. Free-parameter values are first multiplied by random draws from a distribution with the providedloc andscale, then added to random draws from a distribution with the samescale but with a median of zero.

IfmxJiggle() argumentclassic=TRUE, then each free-parameter valuex_i is replaced withx_i + 0.1(x_i + 0.5); this is the same behavior elicited in classic Mx by keyword JIGGLE.

Value

imxJiggle() returns a numeric vector of randomly perturbed free-parameter values.mxJiggle() returnsmodel, with its free parameter values altered according to the other function arguments.

See Also

mxTryHard()

Examples

data(demoOneFactor)manifests <- names(demoOneFactor)latents <- c("G")factorModel <- mxModel("One Factor",type="RAM",manifestVars = manifests,latentVars = latents,mxPath(from=latents, to=manifests,values=0.8),mxPath(from=manifests, arrows=2,values=1),mxPath(from=latents, arrows=2, free=FALSE, values=1.0),mxData(cov(demoOneFactor), type="cov", numObs=500))iniPars <- coef(factorModel)print(iniPars)pars2 <- imxJiggle(params=iniPars,lbounds=NA,ubounds=NA,dsn="runif",loc=1,scale=0.05)print(pars2)mod2 <- mxJiggle(model=factorModel,scale=0.05)coef(mod2)mod3 <- mxJiggle(model=factorModel,classic=TRUE)coef(mod3)

Estimate Kalman scores and error covariance matrices

Description

This function creates the Kalman predicted, Kalman updated, and Rauch-Tung-Striebel smoothed latent state and error covariance estimates for an MxModel object that has an MxExpectationStateSpace object.

Usage

mxKalmanScores(model, data=NA, frontend=TRUE)

Arguments

model

An MxModel object with an MxExpectationStateSpace.

data

An optional data.frame or matrix.

frontend

When TRUE, compute score in the frontend, otherwise use the backend.

Details

This is a helper function that computes the results of the classical Kalman filter. In particular, for every row of data there is a predicted latent score, an error covariance matrix for the predicted latent scores that provides an estimate of the predictions precision, an updated latent score, and an updated error covariance matrix for the updated latent scores. Additionally, the Rauch-Tung-Striebel (RTS) smoothed latent scores and error covariance matrices are returned.

Value

A list with components xPredicted, PPredicted, xUpdated, PUpdated, xSmoothed, PSmoothed, m2ll, and L. When using backend scores, this list also has components for yPredicted and SPredicted which have the same number of time points as the other components but relate to the observed variables instead of the latent variables. The rows of xPredicted, xUpdated, and xSmoothed correspond to different time points. The columns are the different latent variables. The third index of PPredicted, PUpdated, and PSmoothed corresponds to different times. This works nicely with the R default print method for arrays. At each time there is a covariance matrix of the latent variable scores. For all items listed below, the first element goes with the zeroth time point (See example).

xPredicted

matrix of Kalman predicted scores

PPredicted

array of Kalman predicted error covariances

xUpdated

matrix of Kalman updated scores

PUpdated

array of Kalman updated error covariances

xSmoothed

matrix of RTS smoothed scores

PSmoothed

array of RTS smoothed error covariances

m2ll

minus 2 log likelihood

L

likelihood, i.e., the multivariate normal probability density

yPredicted

matrix of Kalman predicted scores for the observed variables, i.e., the predicted means. Only available for backend scores.

SPredicted

array of Kalman predicted error covariances for the observed variables, i.e., the predicted covariances. Only available for backend scores.

References

J. Durbin and S.J. Koopman. (2001).Time Series Analysis by State Space Methods. Oxford University Press.

R.E. Kalman (1960). A New Approach to Linear Filtering and Prediction Problems.Basic Engineering, 82, 35-45.

H.E. Rauch, F. Tung, C.T. Striebel. (1965). Maximum Likelihood Estimates of Linear Dynamic Systems.American Institute of Aeronautics and Astronautics Journal, 3, 1445-1450.

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

See Also

mxExpectationStateSpace

Examples

   # Create and fit a model using mxMatrix, mxExpectationStateSpace, and mxFitFunctionMLrequire(OpenMx)data(demoOneFactor)# Use only first 50 rows, for speed of exampledata <- demoOneFactor[1:50,]nvar <- ncol(demoOneFactor)varnames <- colnames(demoOneFactor)ssModel <- mxModel(model="State Space Manual Example",    mxMatrix("Full", 1, 1, TRUE, .3, name="A"),    mxMatrix("Zero", 1, 1, name="B"),    mxMatrix("Full", nvar, 1, TRUE, .6, name="C", dimnames=list(varnames, "F1")),    mxMatrix("Zero", nvar, 1, name="D"),    mxMatrix("Diag", 1, 1, FALSE, 1, name="Q"),    mxMatrix("Diag", nvar, nvar, TRUE, .2, name="R"),    mxMatrix("Zero", 1, 1, name="x0"),    mxMatrix("Diag", 1, 1, FALSE, 1, name="P0"),    mxMatrix("Zero", 1, 1, name="u"),    mxData(observed=data, type="raw"),    mxExpectationStateSpace("A", "B", "C", "D", "Q", "R", "x0", "P0", "u"),    mxFitFunctionML())ssRun <- mxRun(ssModel)summary(ssRun)# Note the freely estimated Autoregressive parameter (A matrix)#  is near zero as it should be for the independent rows of data#  from the factor model.ssScores <- mxKalmanScores(ssRun)cor(cbind(ssScores$xPredicted[,1], ssScores$xUpdated[,1], ssScores$xSmoothed[,1]))# Because the autoregressive dynamics are near zero, the predicted and updated scores# correlate minimally, and the updated and smoothed latent state estimates# are extremely close.# The first few latent predicted scoreshead(ssScores$xPredicted)# The predicted latent score for time 10ssScores$xPredicted[10+1,]# The error covariance of the predicted score at time 10ssScores$PPredicted[,,10+1]

Create MxLISRELObjective Object

Description

This function creates a new MxLISRELObjective object.

Usage

mxLISRELObjective(LX=NA, LY=NA, BE=NA, GA=NA, PH=NA, PS=NA, TD=NA, TE=NA, TH=NA,   TX = NA, TY = NA, KA = NA, AL = NA,   dimnames = NA, thresholds = NA, vector = FALSE, threshnames = dimnames)

Arguments

LX

An optional character string indicating the name of the 'LX' matrix.

LY

An optional character string indicating the name of the 'LY' matrix.

BE

An optional character string indicating the name of the 'BE' matrix.

GA

An optional character string indicating the name of the 'GA' matrix.

PH

An optional character string indicating the name of the 'PH' matrix.

PS

An optional character string indicating the name of the 'PS' matrix.

TD

An optional character string indicating the name of the 'TD' matrix.

TE

An optional character string indicating the name of the 'TE' matrix.

TH

An optional character string indicating the name of the 'TH' matrix.

TX

An optional character string indicating the name of the 'TX' matrix.

TY

An optional character string indicating the name of the 'TY' matrix.

KA

An optional character string indicating the name of the 'KA' matrix.

AL

An optional character string indicating the name of the 'AL' matrix.

dimnames

An optional character vector that is currently ignored

thresholds

An optional character string indicating the name of the thresholds matrix.

vector

A logical value indicating whether the objective function result is the likelihood vector.

threshnames

An optional character vector to be assigned to the column names of the thresholds matrix.

Details

Objective functions are functions for which free parameter values are chosen such that the value of the objective function is minimized. The mxLISRELObjective provides maximum likelihood estimates of free parameters in a model of the covariance of a givenMxData object. This model is defined by LInear Structural RELations (LISREL; Jöreskog & Sörbom, 1982, 1996). Arguments 'LX' through 'AL' must refer toMxMatrix objects with the associated properties of their respective matrices in the LISREL modeling approach.

The full LISREL specification has 13 matrices and is sometimes called the extended LISREL model. It is defined by the following equations.

\eta = \alpha + B \eta + \Gamma \xi + \zeta

y = \tau_y + \Lambda_y \eta + \epsilon

x = \tau_x + \Lambda_x \xi + \delta

The table below is provided as a quick reference to the numerous matrices in LISREL models. Note that NX is the number of manifest exogenous (independent) variables, the number of Xs. NY is the number of manifest endogenous (dependent) variables, the number of Ys. NK is the number of latent exogenous variables, the number of Ksis or Xis. NE is the number of latent endogenous variables, the number of etas.

Matrix Word Abbreviation Dimensions Expression Description
\Lambda_x Lambda x LX NX x NK Exogenous Factor Loading Matrix
\Lambda_y Lambda y LY NY x NE Endogenous Factor Loading Matrix
B Beta BE NE x NE Regressions of Latent Endogenous Variables Predicting Endogenous Variables
\Gamma Gamma GA NE x NK Regressions of Latent Exogenous Variables Predicting Endogenous Variables
\Phi Phi PH NK x NK cov(\xi) Covariance Matrix of Latent Exogenous Variables
\Psi Psi PS NE x NE cov(\zeta) Residual Covariance Matrix of Latent Endogenous Variables
\Theta_{\delta} Theta delta TD NX x NX cov(\delta) Residual Covariance Matrix of Manifest Exogenous Variables
\Theta_{\epsilon} Theta epsilon TE NY x NY cov(\epsilon) Residual Covariance Matrix of Manifest Endogenous Variables
\Theta_{\delta \epsilon} Theta delta epsilson TH NX x NY cov(\delta, \epsilon) Residual Covariance Matrix of Manifest Exogenous with Endogenous Variables
\tau_x tau x TX NX x 1 Residual Means of Manifest Exogenous Variables
\tau_y tau y TY NY x 1 Residual Means of Manifest Endogenous Variables
\kappa kappa KA NK x 1 mean(\xi) Means of Latent Exogenous Variables
\alpha alpha AL NE x 1 Residual Means of Latent Endogenous Variables

From the extended LISREL model, several submodels can be defined. Subtypes of the LISREL model are defined by setting some of the arguments of the LISREL objective to NA. Note that because the default values of each LISREL matrix is NA, setting a matrix to NA can be accomplished by simply not giving it any other value.

The first submodel is the LISREL model without means.

\eta = B \eta + \Gamma \xi + \zeta

y = \Lambda_y \eta + \epsilon

x = \Lambda_x \xi + \delta

The LISREL model without means requires 9 matrices: LX, LY, BE, GA, PH, PS, TD, TE, and TH. Hence this LISREL model has TX, TY, KA, and AL as NA. This can be accomplished be leaving these matrices at their default values.

The TX, TY, KA, and AL matrices must be specified if either the mxData type is “cov” or “cor” and a means vector is provided, or if the mxData type is “raw”. Otherwise the TX, TY, KA, and AL matrices are ignored and the model without means is estimated.

A second submodel involves only endogenous variables.

\eta = B \eta + \zeta

y = \Lambda_y \eta + \epsilon

The endogenous-only LISREL model requires 4 matrices: LY, BE, PS, and TE. The LX, GA, PH, TD, and TH must be NA in this case. However, means can also be specified, allowing TY and AL if the data are raw or if observed means are provided.

Another submodel involves only exogenous variables.

x = \Lambda_x \xi + \delta

The exogenous-model model requires 3 matrices: LX, PH, and TD. The LY, BE, GA, PS, TE, and TH matrices must be NA. However, means can also be specified, allowing TX and KA if the data are raw or if observed means are provided.

The model that is run depends on the matrices that are not NA. If all 9 matrices are not NA, then the full model is run. If only the 4 endogenous matrices are not NA, then the endogenous-only model is run. If only the 3 exogenous matrices are not NA, then the exogenous-only model is run. If some endogenous and exogenous matrices are not NA, but not all of them, then appropriate errors are thrown. Means are included in the model whenever their matrices are provided.

TheMxMatrix objects included as arguments may be of any type, but should have the properties described above. The mxLISRELObjective will not return an error for incorrect specification, but incorrect specification will likely lead to estimation problems or errors in themxRun function.

Like themxRAMObjective, the mxLISRELObjective evaluates with respect to anMxData object. TheMxData object need not be referenced in the mxLISRELObjective function, but must be included in theMxModel object. mxLISRELObjective requires that the 'type' argument in the associatedMxData object be equal to 'cov', 'cor', or 'raw'.

To evaluate, place MxLISRELObjective objects, themxData object for which the expected covariance approximates, referencedMxAlgebra andMxMatrix objects, and optionalMxBounds andMxConstraint objects in anMxModel object. This model may then be evaluated using themxRun function. The results of the optimization can be found in the 'output' slot of the resulting model, and may be obtained using themxEval function.

Value

Returns a new MxLISRELObjective object. MxLISRELObjective objects should be included with models with referencedMxAlgebra,MxData andMxMatrix objects.

References

Jöreskog, K. G. & Sörbom, D. (1996). LISREL 8: User's Reference Guide. Lincolnwood, IL: Scientific Software International.

Jöreskog, K. G. & Sörbom, D. (1982). Recent developments in structural equation modeling.Journal of Marketing Research, 19, 404-416.

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

Examples

      #####------------------------------#####   ##### Factor Model   mLX <- mxMatrix("Full", values=c(.5, .6, .8, rep(0, 6), .4, .7, .5),      name="LX", nrow=6, ncol=2,      free=c(TRUE,TRUE,TRUE,rep(FALSE, 6),TRUE,TRUE,TRUE))   mTD <- mxMatrix("Diag", values=c(rep(.2, 6)), name="TD", nrow=6, ncol=6,      free=TRUE)   mPH <- mxMatrix("Symm", values=c(1, .3, 1), name="PH", nrow=2, ncol=2,      free=c(FALSE, TRUE, FALSE))      # Create a LISREL objective with LX, TD, and PH matrix names   objective <- mxLISRELObjective(LX="LX", TD="TD", PH="PH")      testModel <- mxModel(model="testModel4", mLX, mTD, mPH, objective)

Estimate Modification Indices for MxModel Objects

Description

This function estimates the change in fit function value resulting from freeing currently fixed parameters.

Usage

mxMI(model, matrices=NA, full=TRUE)

Arguments

model

An MxModel for which modification indices are desired.

matrices

Character vector. The names of the matrices in which to search for modification

full

Logical. Whether or not to return the full modification index in addition to the restricted.

Details

Modification indices provide an estimate of how much the fit function value would change if a parameter that is currently fixed was instead freely estimated. There are two versions of this estimate: a restricted version and an full version. The restricted version is reported as the MI and is much faster to compute. The full version is reported as MI.Full. The full version accounts for thetotal change in fit function value resulting from the newly freed parameter. The restricted version only accounts for the change in the fit function due to the movement of the new free parameter. In particular, the restricted version does not account for the change in fit function value due to the other free parameters moving in response to the new parameter. In addition to the fit function value change, the expected parameter change (EPC) can be computed for each parameter that is newly freed.

The algorithm respects fixed parameter labels. That is, when a fixed parameter has a label and occurs in more than one spot, then that fixed parameter is freed in all locations in which it occurs to evaluate the modification index for that fixed parameter.

When the fit function is in minus two log likelihood units (e.g.mxFitFunctionML), then the MI will be approximately chi squared distributed with 1 degree of freedom. Using a p-value of 0.01 has been suggested. Hence, a MI greater thanqchisq(p=1-0.01, df=1), or 6.63, is suggestive of a modification.

Users should be cautious in their use of modification indices. If a model was created with the aid of MIs, then it shouldalways be reported.Do not pretend that you have a theoretical reason for part of a model that was put there because it was suggested by a modification index. This is fraud. When using modification indices there are two options for best practices. First, you can report the analyses as exploratory. Document all the explorations that you did, and know that your results may or may not generalize. Second, you can use cross-validation. Reserve part of your data for exploration, and use the remaining data to test if the exploratory model generalizes to new data.

Value

A data.frame with named columns

MI

The restricted modification index.

MI.Full

The full modification index.

plusOneParamModels

A list of models with one additional free parameter

EPC

The expected parameter change. Only available whenfull=TRUE

References

Sörbom, D. (1989). Model Modification.Psychometrika, 54, 371-384.

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

Examples

# Create a modelrequire(OpenMx)data(demoOneFactor)manifests <- names(demoOneFactor)latents <- c("G")factorModel <- mxModel("One Factor",      type="RAM",      manifestVars = manifests,      latentVars = latents,      mxPath(from=latents, to=manifests),      mxPath(from=manifests, arrows=2),      mxPath(from=latents, arrows=2,            free=FALSE, values=1.0),      mxPath(from = 'one', to = manifests),      mxData(observed=cov(demoOneFactor), type="cov", numObs=500,             means = colMeans(demoOneFactor)))#No SEs for speedfactorModel <- mxOption(factorModel, 'Standard Errors', 'No')factorRun <- mxRun(factorModel)# See if it should be modified# Notes#  Using full=FALSE for faster performance#  Using matrices= 'A' and 'S' to not get MIs for#    the F matrix which is always fixed.fim <- mxMI(factorRun, matrices=c('A', 'S'), full=FALSE)round(fim$MI, 3)plot(fim$MI, ylim=c(0, 10))abline(h=qchisq(p=1-0.01, df=1)) # line of "significance"

DEPRECATED: Create MxMLObjective Object

Description

WARNING: Objective functions have been deprecated as of OpenMx 2.0.

Please use mxExpectationNormal() and mxFitFunctionML() instead. As a temporary workaround, mxMLObjective returns a list containing an MxExpectationNormal object and an MxFitFunctionML object.

mxMLObjective(covariance, means = NA, dimnames = NA, thresholds = NA)All occurrences of

mxMLObjective(covariance, means = NA, dimnames = NA, thresholds = NA)

Should be changed to

mxExpectationNormal(covariance, means = NA, dimnames = NA, thresholds = NA, threshnames = dimnames)mxFitFunctionML(vector = FALSE)

Arguments

covariance

A character string indicating the name of the expected covariance algebra.

means

An optional character string indicating the name of the expected means algebra.

dimnames

An optional character vector to be assigned to the dimnames of the covariance and means algebras.

thresholds

An optional character string indicating the name of the thresholds matrix.

Details

NOTE: THIS DESCRIPTION IS DEPRECATED. Please change to usingmxExpectationNormal andmxFitFunctionML as shown in the example below.

Objective functions are functions for which free parameter values are chosen such that the value of the objective function is minimized. The mxMLObjective function uses full-information maximum likelihood to provide maximum likelihood estimates of free parameters in the algebra defined by the 'covariance' argument given the covariance of anMxData object. The 'covariance' argument takes anMxAlgebra object, which defines the expected covariance of an associatedMxData object. The 'dimnames' arguments takes an optional character vector. If this argument is not a single NA, then this vector be assigned to be the dimnames of the means vector, and the row and columns dimnames of the covariance matrix.

mxMLObjective evaluates with respect to anMxData object. TheMxData object need not be referenced in the mxMLObjective function, but must be included in theMxModel object. mxMLObjective requires that the 'type' argument in the associatedMxData object be equal to 'cov' or 'cov'. The 'covariance' argument of this function evaluates with respect to the 'matrix' argument of the associatedMxData object, while the 'means' argument of this function evaluates with respect to the 'vector' argument of the associatedMxData object. The 'means' and 'vector' arguments are optional in both functions. If the 'means' argument is not specified (NA), the optional 'vector' argument of theMxData object is ignored. If the 'means' argument is specified, the associatedMxData object should specify a 'means' argument of equivalent dimension as the 'means' algebra.

dimnames must be supplied where the matrices referenced by the covariance and means algebras are not themselves labeled. Failure to do so leads to an error noting that the covariance or means matrix associated with the ML objective does not contain dimnames.

To evaluate, place MxMLObjective objects, themxData object for which the expected covariance approximates, referencedMxAlgebra andMxMatrix objects, and optionalMxBounds andMxConstraint objects in anMxModel object. This model may then be evaluated using themxRun function. The results of the optimization can be found in the 'output' slot of the resulting model, or using themxEval function.

Value

Returns a list containing an MxExpectationNormal object and an MxFitFunctionML object.

References

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

Examples

# Create and fit a model using mxMatrix, mxAlgebra, mxExpectationNormal, and mxFitFunctionMLlibrary(OpenMx)# Simulate some datax=rnorm(1000, mean=0, sd=1)y= 0.5*x + rnorm(1000, mean=0, sd=1)tmpFrame <- data.frame(x, y)tmpNames <- names(tmpFrame)# Define the matricesS <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(1,0,0,1),               free=c(TRUE,FALSE,FALSE,TRUE), labels=c("Vx", NA, NA, "Vy"), name = "S")A <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0),               free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b", NA, NA), name = "A")I <- mxMatrix(type="Iden", nrow=2, ncol=2, name="I")# Define the expectationexpCov <- mxAlgebra(solve(I-A) %*% S %*% t(solve(I-A)), name="expCov")expFunction <- mxExpectationNormal(covariance="expCov", dimnames=tmpNames)# Choose a fit functionfitFunction <- mxFitFunctionML()# Define the modeltmpModel <- mxModel(model="exampleModel", S, A, I, expCov, expFunction, fitFunction,                     mxData(observed=cov(tmpFrame), type="cov", numObs=dim(tmpFrame)[1]))# Fit the model and print a summarytmpModelOut <- mxRun(tmpModel)summary(tmpModelOut)

mxMakeNames

Description

Adjust a character vector so that it is valid when used as MxMatrix columnor row names.

Usage

mxMakeNames(names, unique = FALSE)

Arguments

names

a character vector

unique

whether to pass the result throughmake.unique

Details

note: OpenMx is (much) more restrictive than base R's make.names.

See Also

make.names

Examples

demo <- c("", "103", "data", "foo.bar[3,2]", "+!", "!+")mxMakeNames(demo, unique=TRUE)

Indicator with marginal Negative Binomial distribution

Description

Indicator with marginal Negative Binomial distribution

Usage

mxMarginalNegativeBinomial(  vars,  maxCount = NA,  size,  prob = c(),  mu = c(),  zeroInf = 0.01,  free = TRUE,  labels = NA,  lbound = NA,  ubound = NA)

Arguments

vars

character vector of manifest indicators

maxCount

maximum observed count

size

positive target number of successful trials

prob

probability of success in each trial

mu

alternative parametrization via mean

zeroInf

zero inflation parameter in probability units

free

logical vector indicating whether paremeters are free

labels

character vector of parameter labels

lbound

numeric vector of lower bounds

ubound

numeric vector of upper bounds

Value

a list of MxMarginPoisson obects


Indicator with marginal Poisson distribution

Description

Indicator with marginal Poisson distribution

Usage

mxMarginalPoisson(  vars,  maxCount = NA,  lambda,  zeroInf = 0.01,  free = TRUE,  labels = NA,  lbound = 0,  ubound = c(1, NA))

Arguments

vars

character vector of manifest indicators

maxCount

maximum observed count

lambda

non-negative means

zeroInf

zero inflation parameter in probability units

free

logical vector indicating whether paremeters are free

labels

character vector of parameter labels

lbound

numeric vector of lower bounds

ubound

numeric vector of upper bounds

Value

a list of MxMarginPoisson obects


Create MxMatrix Object

Description

This function creates a newMxMatrix object.

Usage

mxMatrix(type = c('Full', 'Diag', 'Iden', 'Lower','Sdiag', 'Stand', 'Symm', 'Unit', 'Zero'), nrow = NA, ncol = NA,     free = FALSE, values = NA, labels = NA, lbound = NA,     ubound = NA, byrow = getOption('mxByrow'), dimnames = NA, name = NA,     condenseSlots=getOption('mxCondenseMatrixSlots'),    ..., joinKey=as.character(NA), joinModel=as.character(NA))

Arguments

type

A character string indicating the matrix type, where type indicates the range of values and equalities in the matrix. Must be one of: ‘Diag’, ‘Full’, ‘Iden’, ‘Lower’, ‘Sdiag’, ‘Stand’, ‘Symm’, ‘Unit’, or ‘Zero’.

nrow

Integer; the desired number of rows. One or both of ‘nrow’ and ‘ncol’ is required when ‘values’, ‘free’, ‘labels’, ‘lbound’, and ‘ubound’ arguments are not matrices, depending on the desiredMxMatrix type.

ncol

Integer; the desired number of columns. One or both of ‘nrow’ and ‘ncol’ is required when ‘values’, ‘free’, ‘labels’, ‘lbound’, and ‘ubound’ arguments are not matrices, depending on the desiredMxMatrix type.

free

A vector or matrix of logicals for free parameter specification. A single ‘TRUE’ or ‘FALSE’ will set all allowable variables to free or fixed, respectively.

values

A vector or matrix of numeric starting values. By default, all values are set to zero.

labels

A vector or matrix of characters for variable label specification.

lbound

A vector or matrix of numeric lower bounds. Default bounds are specified with anNA.

ubound

A vector or matrix of numeric upper bounds. Default bounds are specified with anNA.

byrow

Logical; defaults to value of globaloption 'mxByRow'. IfFALSE (default), the ‘values’, ‘free’, ‘labels’, ‘lbound’, and ‘ubound’ matrices are populated by column rather than by row.

dimnames

List. The dimnames attribute for the matrix: a list of length 2 giving the row and column names respectively. An empty list is treated as NULL, and a list of length one as row names. The list can be named, and the list names will be used as names for the dimensions.

name

An optional character string indicating the name of theMxMatrix object.

condenseSlots

Logical; defaults to value of globaloption 'mxCondenseMatrixSlots'. IfTRUE, then the resultingMxMatrix will "condense" its ‘labels’, ‘free’, ‘lbound’, and ‘ubound’ down to 1x1 matrices if they contain onlyFALSE (‘free’) orNA (the other three). IfFALSE, those four matrices and the ‘values’ matrix will all be of equal dimensions.

...

Not used. Forces remaining arguments to be specified byname.

joinKey

The name of the column in current model's raw data thatis used as a foreign key to match against the primary key in thejoinModel's raw data.

joinModel

The name of the model that this matrix joins against.

Details

The mxMatrix function createsMxMatrix objects, which consist of five matrices and a ‘type’ argument. The ‘values’ matrix is made up of numeric elements whose usage and capabilities in other functions are defined by the ‘free’ matrix. If an element is specified as a fixed parameter in the ‘free’ matrix, then the element in the ‘values’ matrix is treated as a constant value and cannot be altered or updated by an objective function when included in anmxRun function. If an element is specified as a free parameter in the ‘free’ matrix, the element in the ‘value’ matrix is considered a starting value and can be changed by an objective function when included in anmxRun function.

Element labels beginning with'data.' can be used if theMxMatrix is to be used in anMxModel object that has a raw dataset (i.e., anMxData object oftype="raw"). Such a label instructs OpenMx to use a particular column of the raw dataset to fill in the value of that element. For historical reasons, the variable contained in that column is called a "definition variable." For example, if anMxMatrix element has the label'data.x', then OpenMx will use the first value of the data column named "x" when evaluating the fitfunction for the first row, and will use the second value of column "x" when evaluating the fitfunction for the second row, and so on. After the call tomxRun(), the values for elements labeled with'data.x' are returned as the value from the first (i.e., first before any automated sorting is done) element of column "x" in the data.

Objects created by themxMatrix() function are of a specific ‘type’, which specifies the number and location of parameters in the ‘labels’ matrix and the starting values in the ‘values’ matrix. Input ‘values’, ‘free’, and ‘labels’ matrices must be of appropriate shape and have appropriate values for the matrix type requested. Nine types of matrices are supported:

‘Diag’ matrices must be square, and only elements on the principal diagonal may be specified as free parameters or take non-zero values. All other elements are required to be fixed parameters with a value of 0.
‘Full’ matrices may be either rectangular or square, and all elements in the matrix may be freely estimated. This type is the default for the mxMatrix() function.
‘Iden’ matrices must be square, and consist of no free parameters. Matrices of this type have a value of 1 for all entries on the principal diagonal and the value 0 in all off-diagonal entries.
‘Lower’ matrices must be square, with a value of 0 for all entries in the upper triangle and no free parameters in the upper triangle.
‘Sdiag’ matrices must be square, with a value of 0 for all entries in the upper triangle and along the diagonal. No free parameters in the upper triangle or along the diagonal.
‘Symm’ matrices must be square, and elements in the principle diagonal and lower triangular portion of the matrix may be free parameters of any value. Elements in the upper triangular portion of the matrix are constrained to be equal to those in the lower triangular portion, such that the value and parameter specification of the element in row i and column j is identical to to the value and specification of the element in row j and column i.
‘Stand’ matrices are symmetric matrices (see 'Symm') with 1's along the main diagonal.
‘Unit’ matrices may be either rectangular or square, and contain no free parameters. All elements in matrices of this type have a value of 1 for all elements.
‘Zero’ matrices may be either rectangular or square, and contain no free parameters. All elements in matrices of this type have a value of 0 for all elements.

When ‘type’ is ‘Lower’ or ‘Symm’, then the arguments to ‘free’, ‘values’, ‘labels’, ‘lbound’, or ‘ubound’ may be vectors of lengthN * (N + 1) / 2, where N is the number of rows and columns of the matrix. When ‘type’ is ‘Sdiag’ or ‘Stand’, then the arguments to ‘free’, ‘values’, ‘labels’, ‘lbound’, or ‘ubound’ may be vectors of lengthN * (N - 1) / 2.

Value

Returns a newMxMatrix object, which consists of a ‘values’ matrix of numeric starting values, a ‘free’ matrix describing free parameter specification, a ‘labels’ matrix of labels for the variable names, and ‘lbound’ and ‘ubound’ matrices of the lower and upper parameter bounds. ThisMxMatrix object can be used as an argument in themxAlgebra(),mxBounds(),mxConstraint() andmxModel() functions.

References

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

See Also

MxMatrix for the S4 class created by mxMatrix. More information about the OpenMx package may be foundhere.

Examples

# Create a 3 x 3 identity matrixidenMatrix <- mxMatrix(type = "Iden", nrow = 3,     ncol = 3, name = "I")# Create a full 4 x 2 matrix from existing # value matrix with all free parametersvals <- matrix(1:8, nrow = 4)fullMatrix <- mxMatrix(type = "Full", values = vals,     free = TRUE, name = "foo") # Create a 3 x 3 symmetric matrix with free off-# diagonal parameters and starting valuessymmMatrix <- mxMatrix(type = "Symm", nrow = 3, ncol = 3,    free = c(FALSE, TRUE, TRUE, FALSE, TRUE, FALSE),    values = c(1, .8, .8, 1, .8, 1),    labels = c(NA, "free1", "free2", NA, "free3", NA),    name = "bar")# Create an mxMatrix from a character matrix.  All numbers are# interpreted as fixed and non-numbers are interpreted as free# parameters.matrixFromChar <- function(inputm, name=NA) {  inputmFixed <- suppressWarnings(matrix(    as.numeric(inputm),nrow = nrow(inputm), ncol = ncol(inputm)))  inputmCharacter <- inputm  inputmCharacter[!is.na(inputmFixed)] <- NA  mxMatrix(nrow=nrow(inputm), ncol=ncol(inputm),           free=!is.na(inputmCharacter),           values=inputmFixed,           labels=inputmCharacter,           dimnames=dimnames(inputm), name=name)}# Demonstrate some of the behavior of the condensed slots# Create a 3x3 matrix with condensed slotsa <- mxMatrix('Full', 3, 3, values=1, condenseSlots=TRUE)a@free # at operator returns the stored 1x1 matrixa$free # dollar operator constructs full matrix for printing# assignment with the dollar operator#  de-condenses the slots to create the#  full 3x3 matrixa$free[1,1] <- TRUEa@free

Create MxModel Object

Description

Create or modify anMxModel.

Usage

mxModel(model = NA, ..., manifestVars = NA, latentVars = NA,          remove = FALSE, independent = NA, type = NA, name = NA)

Arguments

model

This argument is either anMxModel object or a string. If 'model' is an MxModel object, then all elements of that model are placed in the resulting MxModel object. If 'model' is a string, then a new model is created with the string as its name. If 'model' is either unspecified or 'model' is a named entity, data source, or MxPath object, then a new model is created.

...

An arbitrary number ofmxMatrix,mxPath,mxData, and other functions such asmxConstraints andmxCI. These will all be added or removed from the model as specified in the 'model' argument, based on the 'remove' argument.

manifestVars

For RAM-type models, A list of manifest variables to be included in the model.

latentVars

For RAM-type models, A list of latent variables to be included in the model.

remove

logical. If TRUE, elements listed in this statement are removed from the original model. If FALSE, elements listed in this statement are added to the original model.

independent

logical. If TRUE then the model is evaluated independently of other models.

type

character vector. The model type to assign to this model. Defaults to options("mxDefaultType"). See below for valid types

name

An optional character vector indicating the name of the object.

Details

The mxModel function is used to createMxModels. Models created by this function may be new, or may be modified versions of existingMxModel objects. By default a newMxModel object will be created: To create a modified version of an existingMxModel object, include this model in the 'model' argument.

Othernamed-entities may be added as arguments to the mxModel function, which are then added to or removed from the model specified in the ‘model’ argument. Functions you can use to add objects to the model to this way includemxPath,mxCI,mxAlgebra,mxBounds,mxConstraint,mxData, andmxMatrix objects, as well as fit functions and expectations (see below). You can also include sub-models as components of a model. These sub-models may be estimated separately or jointly depending on shared parameters and the ‘independent’ flag (see below). Only oneMxData object and one fit function and expectation may be included per model, but there are no restrictions on the number of othernamed-entities included in an mxModel statement.

All other arguments must be named (i.e. ‘latentVars = names’), or they will be interpreted as elements of the ellipsis list. The ‘manifestVars’ and ‘latentVars’ arguments specify the names of the manifest and latent variables, respectively, for use with themxPath function.

The ‘remove’ argument may be used when mxModel is used to create a modified version of an existingMxMatrix object. When ‘remove’ is set to TRUE, the listed objects are removed from the model specified in the ‘model’ argument. When ‘remove’ is set to FALSE, the listed objects are added to the model specified in the ‘model’ argument.

Model independence may be specified with the ‘independent’ argument. If a model is independent (‘independent = TRUE’), then the parameters of this model are not shared with any other model. An independent model may be estimated with no dependency on any other model. If a model is not independent (‘independent = FALSE’), then this model shares parameters with one or more other models such that these models must be jointly estimated. These dependent models must be entered as arguments in another model, so that they are simultaneously optimized.

The model type is determined by a character vector supplied to the ‘type’ argument. The type of a model is a dynamic property, ie. it is allowed to change during the lifetime of the model. To see a list of available types, use themxTypes command. When a new model is created and no type is specified, the type specified byoptions("mxDefaultType") is used.

Expectations and Fit functions

To be estimated,MxModel objects must include fit functions and expectations as arguments. Fit functions includemxFitFunctionML,mxFitFunctionMultigroup,mxFitFunctionWLS,mxFitFunctionAlgebra,mxFitFunctionGREML,mxFitFunctionR, andmxFitFunctionRow. Expectations includemxExpectationBA81,mxExpectationGREML,mxExpectationHiddenMarkovmxExpectationLISREL,mxExpectationMixture,mxExpectationNormal,mxExpectationRAM,mxExpectationStateSpace,mxExpectationStateSpaceContinuousTime. The 'type' of the model may imply a certain fit function or expectation (e.g. type = "RAM" implies mxExpectationRAM). The model data may also constrain which fit and expectation are appropriate.

The model, complete with fit function and expectation can then be executed usingmxRun.

Accessing model components

You can view a model summary with summary. You can also accessNamed entities inMxModel directly via the $ symbol. For instance, for an MxModel named "yourModel" containing an MxMatrix named "yourMatrix", the contents of "yourMatrix" can be accessed as yourModel$yourMatrix. Slots (i.e., matrices, algebras, etc.) in an mxMatrix may also be referenced with the $ symbol (e.g., yourModel$matrices or yourModel$algebras). See the documentation forClasses and the examples inClasses for more information.

Value

Returns a newMxModel object. To be run,MxModel object must include a fit function and expectation.

References

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

See Also

SeemxCI for information about adding Confidence Interval calculations to a model. SeemxPath for information about adding paths to RAM-type models.SeemxMatrix for information about adding matrices to models.SeemxData for specifying the data a model is to be evaluated against.Many advanced options can be set viamxOption. More information about the OpenMx package may be foundhere.

Examples

library(OpenMx)# At the simplest, you can create an empty model,#  placing it in an object, and add to it lateremptyModel <- mxModel(model="IAmEmpty")# Create a model named 'firstdraft' with one matrix 'A'firstModel <- mxModel(model='firstdraft',                  mxMatrix(type='Full', nrow = 3, ncol = 3, name = "A"))# Update 'firstdraft', and rename the model 'finaldraft'finalModel <- mxModel(model=firstModel,                 mxMatrix(type='Symm', nrow = 3, ncol = 3, name = "S"),                 mxMatrix(type='Iden', nrow = 3, name = "F"),                 name= "finaldraft")# Add data to the model from an existing data frame in object 'data'data(twinData)  # load some datafinalModel <- mxModel(model=finalModel, mxData(twinData, type='raw'))# Two ways to view the matrix named "A" in MxModel object 'model'finalModel$AfinalModel$matrices$A# A working example using OpenMx Path Syntaxdata(HS.ability.data)  # load the data# The manifest variables loading on each proposed latent variableSpatial   <- c("visual", "cubes", "paper")Verbal    <- c("general", "paragrap", "sentence")Math      <- c("numeric", "series", "arithmet")latents   <- c("vis", "math", "text")manifests <-  c(Spatial, Math, Verbal)HSModel <- mxModel(model="Holzinger_and_Swineford_1939", type="RAM",     manifestVars = manifests, # list the measured variables (boxes)    latentVars   = latents,   # list the latent variables (circles)    # factor loadings from latents to  manifests    mxPath(from="vis",  to=Spatial),# factor loadings    mxPath(from="math", to=Math),   # factor loadings    mxPath(from="text", to=Verbal), # factor loadings    # Allow latent variables to covary     mxPath(from="vis" , to="math", arrows=2, free=TRUE),    mxPath(from="vis" , to="text", arrows=2, free=TRUE),    mxPath(from="math", to="text", arrows=2, free=TRUE),    # Allow latent variables to have variance    mxPath(from=latents, arrows=2, free=FALSE, values=1.0),    # Manifest have residual variance    mxPath(from=manifests, arrows=2),       # the data to be analysed    mxData(cov(HS.ability.data[,manifests]), type = "cov", numObs = 301))    fitModel <- mxRun(HSModel) # run the modelsummary(fitModel) # examine the output: Fit statistics and path loadings

Information-Theoretic Model-Averaging and Multimodel Inference

Description

omxAkaikeWeights() orders a list ofMxModels (hereinafter, the "candidate set" of models) from best to worst AIC, reports their Akaike weights, and indicates which are in the confidence set for best-approximating model.mxModelAverage() callsomxAkaikeWeights() and includes its output, and also reports model-average point estimates and (if requested) their standard errors.

Usage

mxModelAverage(reference=character(0), models=list(),include=c("onlyFree","all"), SE=NULL, refAsBlock=FALSE, covariances=list(), type=c("AIC","AICc"), conf.level=0.95)omxAkaikeWeights(models=list(), type=c("AIC","AICc"), conf.level=0.95)

Arguments

reference

Vector of character strings referring toparameters,MxMatrices, orMxAlgebras for which model-average estimates are to be computed. Defaults toNULL. If a zero-length value is provided, only the output ofomxAkaikeWeights() is returned, with a warning.

models

The candidate set of models: a list of at least twoMxModel objects, each of which must be uniquely identified by the value of itsname slot. Defaults to an empty list.

include

Character string, either"onlyFree" (default) or"all". When calculating model-average estimates for a given reference quantity, should all the MxModels in the candidate set be included in the calculations, or only those in which the quantity is freely estimated? See below, under "Details," for additional information.

SE

Logical; should standard errors be reported for the model-average point estimates? Defaults toNULL, in which case standard errors are reported if argumentinclude="onlyFree", and not reported otherwise.

refAsBlock

Logical. IfFALSE (default),mxModelAverage() will include a matrix of model-conditional sampling variances for the reference quantities in its output, and model-average results may be based on different subsets of the candidate set ifinclude="onlyFree". IfTRUE,mxModelAverage() will instead include a joint sampling covariance matrix for all reference quantities, and will throw an error ifinclude="onlyFree" and if it is not the case that all reference quantities are freely estimated in all models in the candidate set.

covariances

Optional list of repeated-sampling covariance matrices of free parameter estimates (possibly from bootstrapping or the sandwich estimator); defaults to an empty list. A non-empty list must either be of the same length asmodels, or have named elements corresponding to names of MxModels in the candidate set. See below, under "Details," for additional information.

type

Character string specifying which information criterion to use: either"AIC" for the ordinary AIC (default), or"AICc" for Hurvich & Tsai's (1989) sample-size corrected AIC.

conf.level

Numeric proportion specifying the desired coverage probability of the confidence set for best-approximating model among the candidate set (Burnham & Anderson, 2002). Defaults to 0.95.

Details

If statistical inferences (hypothesis tests and confidence intervals) are the motivation for calculating model-average point estimates and their standard errors, theninclude="onlyFree" (the default) is recommended. Note that, if models in which a quantity is held fixed are included in calculating the quantity's model-average estimate, then that estimate cannot even asymptotically be normally distributed (Bartels, 1997).

If argumentcovariances is non-empty, then either it must be of the same length as argumentmodels, or all of its elements must be named after an MxModel inmodels (an MxModel's name is the character string in itsname slot). Ifcovariances is of the same length asmodels but lacks element names,mxModelAverage() will assume that they are ordered so that the first element ofcovariances is to be used with the first MxModel, the second element is to be used with the second MxModel, and so on. Otherwise,mxModelAverage() assigns the elements ofcovariances to the MxModels by matching element names to MxModel names. Ifcovariances doesn't provide a covariance matrix for a given MxModel–perhaps because it is empty, or only provides matrices for a nonempty proper subset of the candidate set–mxModelAverage() will fall back to its default behavior of applying the"vcov" method to the MxModel. If a covariance matrix cannot be thus calculated andSE=TRUE,SE is coerced toFALSE, with a warning.

The matrices incovariances must have complete row and column names, equal to the free parameter labels of the corresponding MxModel. These names indicate to which free parameter a given row or column corresponds.

Value

omxAkaikeWeights() returns a dataframe, with one row for each element ofmodels. The rows are sorted by their MxModel's AIC (or AICc), from best to worst. The dataframe has five columns:

  1. "model": Character string. The name of the MxModel.

  2. "AIC" or"AICc": Numeric. The MxModel's AIC or AICc.

  3. "delta": Numeric. The MxModel's AIC (or AICc) minus the best (smallest) AIC (or AICc) in the candidate set.

  4. "AkaikeWeight": Numeric. The MxModel's Akaike weight. This column will sum to unity.

  5. "inConfidenceSet": Character. Will contain an asterisk if the MxModel is in the confidence set for best-approximating model.

The dataframe also has an attribute,"unsortedModelNames", which contains the names of the MxModels in the same order as they appear inmodels (i.e., without sorting them by their AIC).

If a zero-length value is provided for argumentreference, thenmxModelAverage() returns only the output ofomxAkaikeWeights(), with a warning. Otherwise, for the default values of its arguments,mxModelAverage() returns a list with four elements:

  1. "Model-Average Estimates": A numeric matrix with one row for each distinct quantity specified byreference, and as many as two columns. Its rows are named for the corresponding reference quantities. Its first column,"Estimate", contains the model-average point estimates. If standard errors are being calculated, then its second column,"SE", contains the "model-unconditional" standard errors of the model-average point estimates. Otherwise, there is no second column.

  2. "Model-wise Estimates": A numeric matrix with one row for each distinct quantity specified byreference (indicated by row name), and one column for each MxModel (indicated by column name). Each element is an estimate of the given reference quantity, from the given MxModel. Quantities that cannot be evaluated for a given MxModel are reported asNA.

  3. "Model-wise Sampling Variances": A numeric matrix just like the one in list element 2, except that its elements are the estimated sampling variances of the corresponding model-conditional point estimates in list element 2. Variances for fixed quantities are reported as 0 ifinclude="all", and asNA ifinclude="onlyFree"; however, if no covariance matrix is available for a model, all of that model's sampling variances will be reported asNA.

  4. "Akaike-Weights Table": The output fromomxAkaikeWeights().

IfrefAsBlock=TRUE, list element 3 will instead contain be named"Joint Covariance Matrix", and ifSE=TRUE, it will contain the joint sampling covariance matrix for the model-average point estimates.

Note

The "best-approximating model" is defined as the model that truly ("in the population," so to speak) has the smallest Kullback-Leibler divergence from full reality, among the models in the candidate set (Burnham & Anderson, 2002).

A model's Akaike weight is interpretable as the relative weight-of-evidence for that model being the best-approximating model, given the observed data and the candidate set. It has a Bayesian interpretation as the posterior probability that the given model is the best-approximating model in the candidate set, assuming a "savvy" prior probability that depends upon sample size and the number of free parameters in the model (Burnham & Anderson, 2002).

The confidence set for best-approximating model serves to reflect sampling error in the AICs. When fitting the candidate set to data over repeated sampling, the confidence set is expected to contain the best-approximating model with probability equal to its confidence level.

The sampling variances and covariances of the model-average point estimates are calculated from Equations (4) and (5) in Burnham & Anderson (2004). The standard errors reported bymxModelAverage() are the square roots of those sampling variances.

For an example of model-averaging and multimodel inference applied to structural equation modeling using OpenMx v1.3 (i.e., well before the functions documented here were implemented), see Kirkpatrick, McGue, & Iacono (2015).

References

Bartels, L. M. (1997). Specification uncertainty and model averaging.American Journal of Political Science, 41(2), 641-674.

Burnham, K. P., & Anderson, D. R. (2002).Model Selection and Multimodel Inference: A Practical Information-Theoretic Approach (2nd ed.). New York: Springer.

Burnham, K. P., & Anderson, D. R. (2004). Multimodel inference: Understanding AIC and BIC in model selection.Sociological Methods & Research, 33(2), 261-304. doi:10.1177/0049124104268644

Hurvich, C. M., & Tsai, C-L. (1989). Regression and time series model selection in small samples.Biometrika, 76(2), 297-307.

Kirkpatrick, R. M., McGue, M., & Iacono, W. G. (2015). Replication of a gene-environment interaction via multimodel inference: Additive-genetic variance in adolescents' general cognitive ability increases with family-of-origin socioeconomic status.Behavior Genetics, 45, 200-214.

See Also

mxCompare()

Examples

require(OpenMx)data(demoOneFactor)factorModel1 <- mxModel("OneFactor1",mxMatrix("Full", 5, 1, values=0.8, labels=paste("a",1:5,sep=""),free=TRUE, name="A"),mxMatrix("Full", 5, 1, values=1,labels=paste("u",1:5,sep=""),free=TRUE, name="Udiag"),mxMatrix("Symm", 1, 1, values=1,free=FALSE, name="L"),mxAlgebra(vec2diag(Udiag),name="U"),mxAlgebra(A %*% L %*% t(A) + U, name="R"),mxExpectationNormal(covariance = "R",dimnames = names(demoOneFactor)),mxFitFunctionML(),mxData(cov(demoOneFactor), type="cov", numObs=500))factorFit1 <- mxRun(factorModel1)#Constrain unique variances equal:factorModel2 <- omxSetParameters(model=factorModel1,labels=paste("u",1:5,sep=""),newlabels="u",name="OneFactor2")factorFit2 <- mxRun(factorModel2)omxAkaikeWeights(models=list(factorFit1,factorFit2))mxModelAverage(reference=c("A","Udiag"), include="all",models=list(factorFit1,factorFit2))

mxNormalQuantiles

Description

Get quantiles from a normal distribution

Usage

mxNormalQuantiles(nBreaks, mean = 0, sd = 1)

Arguments

nBreaks

the number of thresholds, or a vector of the number of thresholds

mean

the mean of the underlying normal distribution

sd

the standard deviation of the underlying normal distribution

Value

a vector of quantiles

Examples

mxNormalQuantiles(3)mxNormalQuantiles(3, mean=7)mxNormalQuantiles(2, mean=1, sd=3)

Set or Clear an OpenMx Option

Description

The function sets, shows, or clears an option that is specific to OpenMx's backend. For globalRoptions that affect OpenMx's frontend, please refer to the "See Also" section below.

Usage

mxOption(model=NULL, key=NULL, value, reset = FALSE)

Arguments

model

AnMxModel object or NULL

key

The name of the option.

value

The value of the option.

reset

If TRUE then reset all options to their defaults.

Details

mxOption is used to set, clear, or query an option (given in the ‘key’ argument)pertaining to the backend. Valid option keys are listed below.

Use value = NULL to remove an existing option. Leaving value blank will returnthe current value of the option specified by ‘key’.

To reset all options to their default values, use ‘reset = TRUE’.When reset = TRUE, ‘key’ and ‘value’ are ignored.

If the ‘model’ argument is set to NULL, the option will be set globally (i.eapplying to all models by default).

To see the current values of the global options, usegetOption('mxOptions').

Before the model is submitted to the backend, all keys and values are converted intostrings using theas.character function.

Optimizer specific options

The “Default optimizer” option can only be set globally (i.e., withmodel=NULL), and not locally (i.e., specifically to a given MxModel). Although the checkpointing options may be set globally, OpenMx's behavior is only affected by locally set checkpointing options (that is, global checkpointing options are ignored atruntime).

Gradient-based optimizers require the gradient of the fitfunction. When analytic derivatives are not available,the gradient is estimated numerically. There are a varietyof options to control the numerical estimation of thegradient. One option for CSOLNP and SLSQP isthe gradient algorithm. CSOLNP uses theforward methodby default, while SLSQP uses thecentral method. Theforward method requires 1 times “Gradient iterations”function evaluation per parameterper gradient, whilecentral method requires 2 times“Gradient iterations” function evaluations per parameterper gradient. Users can change the default methods for either of theseoptimizers by setting the “Gradient algorithm” option.NPSOL usually uses theforward method, butadaptively switches tocentral under certain circumstances.

Options “Gradient step size”, “Gradient iterations”, and “Function precision” have on-load global defaults of"Auto". If value"Auto" is in effect for any of these three options atruntime, then OpenMx selects a reasonable numerical value in its place. These automated numerical values are intended to (1) adjust for the limited precision of the algorithm for computing multivariate-normal probability integrals, and (2) calculate accurate numeric derivatives at the optimizer's solution. If the user replaces"Auto" with a valid numerical value, then OpenMx uses that value as-is.

By default, CSOLNP uses a step size of 10^-7 whereas SLSQP uses10^-5. The purpose of this difference is to obtain roughly the sameaccuracy given other differences in numerical procedure.If you set a non-default “Gradient step size”,it will be used as-is. NPSOL ignores“Gradient step size”, and instead uses a function ofmxOption “Function precision” to determine its gradientstep size.

Some options only affect certain optimizers. Option “Gradient algorithm” is used by CSOLNP and SLSQP, and ignored by NPSOL. Option “Gradient iterations” only affects SLSQP. Option “Gradient step size” is used slightly differently by SLSQP and CSOLNP, and is ignored by NPSOL (seemxComputeGradientDescent() for details).

If an mxModel containsmxConstraints, NPSOL is given .4 times the value of the option “Feasibility tolerance”. If there are no constraints, NPSOL is given a hard-coded value of 1e-5 (its own native default).

Note: Where constraints are present, NPSOL is given 0.4 times the value of the mxOption “Feasibility Tolerance”, and this is about a million times bigger than NPSOL's own native default. Values of “Feasibility Tolerance” around 1e-5 may be needed to get constraint performance similar to NPSOL's default. Note also that NPSOL's criterion for returning a status code of 0 versus 1 for a given solution depends partly on “Optimality tolerance”.

For a block ofn ordinal variables, the maximum number of integration points that OpenMx may use to calculate multivariate-normal probability integrals is given bymvnMaxPointsA + mvnMaxPointsB*n + mvnMaxPointsC*n*n + exp(mvnMaxPointsD + mvnMaxPointsE * n * log(mvnRelEps)).Integral approximation is stopped once either ‘mvnAbsEps’ or‘mvnRelEps’ is satisfied.Use of ‘mvnAbsEps’ is deprecated.

The maximum number of major iterations (the option “Major iterations”)for optimization for NPSOL can be specified either by using anumeric value (such as 50, 1000, etc) or by specifying a user-defined function.The user-defined function should accept two arguments as input, the number ofparameters and the number of constraints, and return a numeric value as output.

OpenMx options

Calculate Hessian [Yes | No] calculate the Hessian explicitly after optimization.
Standard Errors [Yes | No] return standard error estimates.
Default optimizer [NPSOL | SLSQP | CSOLNP] the gradient-descent optimizer to use
Number of Threads [0|1|2|...|10|...] number of threads usedfor optimization. Default value is taken from the environment variableOMP_NUM_THREADS or, if that is not set, 1.
Feasibility tolerancer the maximum acceptable absolute violations in linear and nonlinear constraints.
Optimality tolerancer the accuracy with which the final iterate approximates a solution to the optimization problem; roughly, the number of reliable significant figures that the fitfunction value should have at the solution.
Gradient algorithm see list finite difference method, either 'forward' or 'central'.
Gradient iterations 1:4 the number of Richardson extrapolation iterations
Gradient step sizer amount of change made to free parameters when numerically calculating gradient
Analytic Gradients [Yes | No] should the optimizer use analytic gradients (if available)?
loglikelihoodScalei factor by which the loglikelihood is scaled.
Parallel diagnostics [Yes | No] whether to issue diagnosticmessages about use of multiple threads
Nudge zero starts [TRUE | FALSE] Should OpenMx"nudge" starting values of zero to 0.1 at runtime?
Status OK character vector Status codes that are considered to indicate a successful optimization
Max minutes numeric Maximum backend elapsed time, in minutes
Analytic RAM derivatives [Yes | No] Should theML fitfunction compute analytic first and second derivatives forRAM models? Note that mxOption "Analytic Gradients" must also be set to "Yes" for these derivatives to be used. These derivatives are currently only implemented in the case of all-continuous variables, MxData oftype="cov" ortype="raw", and absence of the following: definition variables, multilevel data, product nodes, Fellner fitfunction,MxAlgebras onpaths, andpenalties.

NPSOL-specific options

Nolist this option suppresses printing of the options
Print leveli the value ofi controls the amount of printout produced by the major iterations
Minor print leveli the value ofi controls the amount of printout produced by the minor iterations
Print filei fori > 0 a full log is sent to the file with logical unit numberi.
Summary filei fori > 0 a brief log will be output to filei.
Function precisionr a measure of accuracy with which the fitfunction and constraint functions can be computed.
Infinite bound sizer ifr > 0 defines the "infinite" bound bigbnd.
Major iterationsi or a function the maximum number of major iterations before termination.
Verify level [-1:3 | Yes | No] see NPSOL manual.
Line search tolerancer controls the accuracy with which a step is taken.
Derivative level [0-3] see NPSOL manual.
Hessian [Yes | No] return the Hessian (Yes) or the transformed Hessian (No).
Step Limitr maximum change in free parameters at first step of linesearch.

Checkpointing options

Always Checkpoint [Yes | No] whether to checkpoint all models during optimization.
Checkpoint Directory path the directory into which checkpoint files are written.
Checkpoint Prefix string the string prefix to add to all checkpoint filenames.
Checkpoint Fullpath path overrides the directory and prefix (useful to output to /dev/fd/2)
Checkpoint Units see list the type of units for checkpointing: 'minutes', 'iterations', or 'evaluations'.
Checkpoint Counti the number of units between checkpoint intervals.

Model transformation options

Error Checking [Yes | No] whether model consistency checks are performed in the OpenMx front-end
No Sort Data character vector of model names for which FIML data sorting is not performed
RAM Inverse Optimization [Yes | No] whether to enable solve(I - A) optimization
RAM Max Depthi the maximum depth to be used when solve(I - A) optimization is enabled

Multivariate normal integration parameters

maxOrdinalPerBlocki maximum number of ordinal variablesto evaluate together
mvnMaxPointsAi base number of integration points
mvnMaxPointsBi number of integration points per ordinal variable
mvnMaxPointsCi number of integration points per squared ordinal variables
mvnMaxPointsDi see details
mvnMaxPointsEi see details
mvnAbsEpsi absolute error tolerance
mvnRelEpsi relative error tolerance

Value

If a model is provided, it is returned with the optimizer option either setor cleared. If value is empty, the current value is returned.

References

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

See Also

SeemxModel(), as almost all uses ofmxOption() are via an mxModel whose options are set or cleared. SeemxComputeGradientDescent() for details on how different optimizers are affected by different options. Seeas.statusCode for information about theStatus OK option.

The OpenMx frontend is affected by five globalRoptions. For option "mxDefaultType", seemxModel(). For options "mxByrow" and "mxCondenseMatrixSlots", seemxMatrix(). Option "evalMxObjectAlgebraEnv" governs the behavior of two internal OpenMx functions–evaluateMxObject() andevaluateAlgebraWithContext()–and is primarily of interest to third-party package developers. Option "swift.initialexpr" is for developer use when testing OpenMx on a computing cluster.

Examples

# set the Numbder of Threads (cores to use)mxOption(key="Number of Threads", value=imxGetNumThreads())testModel <- mxModel(model = "testModel5") # make a model to use for exampletestModel$options   # show the model options (none yet)options()$mxOptions # list all mxOptions (global settings)testModel <- mxOption(testModel, "Function precision", 1e-5) # set precisiontestModel <- mxOption(testModel, "Function precision", NULL) # clear precision# N.B. This is model-specific precision (defaults to global setting)# may optimize for speed# at cost of not getting standard errorstestModel <- mxOption(testModel, "Calculate Hessian", "No")testModel <- mxOption(testModel, "Standard Errors"  , "No")testModel$options # see the list of options you set

Assess whether potential parameters should be freed usingparametric bootstrap

Description

Data is simulated from ‘nullModel’. The parameters named by‘labels’ are freed to obtain the alternative model. Thealternative model is fit against each simulated data set.

Usage

mxParametricBootstrap(nullModel, labels,   alternative=c("two.sided", "greater", "less"),   ..., alpha=0.05, correction=p.adjust.methods,   previousRun=NULL, replications=400, checkHess=FALSE,   signif.stars = getOption("show.signif.stars"))

Arguments

nullModel

The model specifying the null distribution

labels

A character vector of parameters to free to obtainthe alternative model

alternative

a character string specifying the alternative hypothesis

...

Not used. Forces remaining arguments to be specified byname.

alpha

The false positive rate

correction

How to adjust the p values for multiple tests.

replications

The number of resampling replications. Ifavailable, replications from prior invocation will be reused.

previousRun

Results to re-use from a previous bootstrap.

checkHess

Whether to approximate the Hessian in eachreplication

signif.stars

logical. If TRUE, ‘significance stars’ areprinted for each coefficient.

Details

When the model has a default compute plan and ‘checkHess’ iskept at FALSE then the Hessian will not be approximated or checked.On the other hand, ‘checkHess’ is TRUE then the Hessian will beapproximated by finite differences. This procedure is of some valuebecause it can be informative to check whether the Hessian is positivedefinite (seemxComputeHessianQuality). However,approximating the Hessian is often costly in terms of CPU time. Forbootstrapping, the parameter estimates derived from the resampled dataare typically of primary interest.

Value

A data frame is returned containing the test results.Details of the bootstrap replications are stored in the‘bootData’ attribute on the data frame.

Examples

library(OpenMx)data(demoOneFactor)manifests <- names(demoOneFactor)latents <- c("G")base <- mxModel(  "OneFactorCov", type="RAM",  manifestVars = manifests,  latentVars = latents,  mxPath(from=latents, to=manifests, values=0,  free=FALSE, labels=paste0('l',1:length(manifests))),  mxPath(from=manifests, arrows=2, values=rlnorm(length(manifests)), lbound=.01),  mxPath(from=latents, arrows=2, free=FALSE, values=1.0),  mxPath(from = 'one', to = manifests, values=0, free=TRUE, labels=paste0('m',1:length(manifests))),  mxData(demoOneFactor, type="raw"))base <- mxRun(base)# use more replications, 8 is for demonstration purpose onlymxParametricBootstrap(base, paste0('l', 1:length(manifests)),                      "two.sided", replications=8)

Create List of Paths

Description

This function creates a list of paths.

Usage

mxPath(from, to = NA, connect = c("single", "all.pairs", "unique.pairs",    "all.bivariate", "unique.bivariate"), arrows = 1,    free = TRUE, values = NA, labels = NA,    lbound = NA, ubound = NA, ..., joinKey = as.character(NA), step = c())

Arguments

from

character vector. These are the sources of the new paths.

to

character vector. These are the sinks of the new paths.

connect

String. Specifies the type of source to sink connection: "single", "all.pairs", "all.bivariate", "unique.pairs", "unique.bivariate". Default value is "single".

arrows

numeric value. Must be either 0 (for Pearson selection), 1 (for single-headed), or 2 (for double-headed arrows).

free

boolean vector. Indicates whether paths are free or fixed.

values

numeric vector. The starting values of the parameters.

labels

character vector. The names of the paths.

lbound

numeric vector. The lower bounds of free parameters.

ubound

numeric vector. The upper bounds of free parameters.

...

Not used. Allows OpenMx to catch the use of thedeprecated ‘all’ argument.

joinKey

character vector. The name of the foreign key to joinagainst some other model to create a cross model path (regression orfactor loading.

step

numeric vector. The priority for processing arrows=0paths. For example, step 1 is processed before step 2.

Details

The mxPath function createsMxPath objects. These consist of a list of paths describing the relationships between variables in a model using the RAM modeling approach (McArdle and MacDonald, 1984). Variables are referenced by name, and these names must appear in the ‘manifestVars’ and ‘latentVars’ arguments of themxModel function.

Paths are specified as going "from" one variable (or set of variables) "to" another variable or set of variables using the ‘from’ and ‘to’ arguments, respectively. If ‘to’ is left empty, it will be set to the value of ‘from’.

‘connect’ has five possible connection types: "single", "all.pairs", "all.bivariate", "unique.pairs", "unique.bivariate". The default value is "single". Assuming the values c(‘a’,‘b’,‘c’) for the ‘to’ and ‘from’ fields the paths produced by each connection type are as follows:

"all.pairs":

(a,a), (a,b), (a,c), (b,a), (b,b), (b,c), (c,a), (c,b), (c,c).

"unique.pairs":

(a,a), (a,b), (a,c), (b,b), (b,c), (c,c).

"all.bivariate":

(a,b), (a,c), (b,a), (b,c), (c,a), (c,b).

"unique.bivariate":

(a,b), (a,c), (b,c).

"single":

(a,a), (b,b), (c,c).

Multiple variables may be input as a vector of variable names. If the ‘connect’ argument is set to "single", then paths are created going from each entry in the ‘from’ vector to the corresponding entry in the ‘to’ vector. If the ‘to’ and ‘from’ vectors are of different lengths when the ‘connect’ argument is set to "single", the shorter vector is repeated to make the vectors of equal length.

The ‘free’ argument specifies whether the paths created by the mxPath function are free or fixed parameters. This argument may take either TRUE for free parameters, FALSE for fixed parameters, or a vector of TRUEs and FALSEs to be applied in order to the created paths.

The ‘arrows’ argument specifies the type of paths created. A value of 1 indicates a one-headed arrow representing regression. This path represents a regression of the ‘to’ variable on the ‘from’ variable, such that the arrow points to the ‘to’ variable in a path diagram. A value of 2 indicates a two-headed arrow, representing a covariance or variance. If multiple paths are created in the same mxPath function, then the ‘arrows’ argument may take a vector of 1s and 2s to be applied to the set of created paths.

The ‘values’ is a numeric vectors containing the starting values of the created paths. ‘values’ gives a starting value for estimation. The ‘labels’ argument specifies the names of the resultingMxPath object. The ‘lbound’ and ‘ubound’ arguments specify lower and upper bounds for the created paths.

Value

Returns a list of paths.

Note

The previous implementation of ‘all’ had unsafe features. Its use is now deprecated, and has been replaced by the new mechanism ‘connect’ which supports safe and controlled generation of desired combinations of paths.

References

McArdle, J. J. and MacDonald, R. P. (1984). Some algebraic properties of the Reticular Action Model for moment structures.British Journal of Mathematical and Statistical Psychology, 37, 234-251.

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

See Also

mxMatrix for a matrix-based approach to path specification;mxModel for the container in which mxPaths are embedded. More information about the OpenMx package may be foundhere.

Examples

# A simple Example: 1 factor Confirmatory Factor Analysislibrary(OpenMx)data(demoOneFactor)manifests <- names(demoOneFactor)latents   <- c("G")factorModel <- mxModel(model="One Factor", type="RAM",      manifestVars = manifests,      latentVars   = latents,      mxPath(from=latents, to=manifests),      mxPath(from=manifests, arrows=2),      mxPath(from=latents, arrows=2,free=FALSE, values=1.0),      mxData(cov(demoOneFactor), type="cov",numObs=500))factorFit <-mxRun(factorModel)summary(factorFit)# A more complex example using features of R to compress#  what would otherwise be a long and error-prone script# list of 100 variable names: "01"  "02"  "03"...myManifest <- sprintf("%02d", c(1:100))# the latent variables for the modelmyLatent <- c("G1", "G2", "G3", "G4", "G5")# Start building the model:#  Define its type, and add the manifest and latent variable name liststestModel <- mxModel(model="testModel6", type = "RAM",                     manifestVars = myManifest, latentVars = myLatent)# Create covariances between the latent variables and add to the model# Here we use combn to create the covariances# nb: To create the variances and covariances in one operation you could use# expand.grid(myLatent,myLatent) to specify from and touniquePairs <- combn(myLatent,2)covariances <- mxPath(from = uniquePairs[1,],                      to=uniquePairs[2,], arrows = 2, free = TRUE, values = 1)testModel <- mxModel(model=testModel, covariances)# Create variances for the latent variablesvariances <- mxPath(from = myLatent,                    to=myLatent, arrows = 2, free = TRUE, values = 1)testModel <- mxModel(model=testModel, variances) # add variances to the model# Make a list of paths from each packet of 20 manifests#  to one of the 5 latent variables# nb: The first loading to each latent is fixed to 1 to scale its variance.singles <- list()for (i in 1:5) {    j <- i*20    singles <- append(singles, mxPath(                        from = myLatent[i], to = myManifest[(j - 19):j],                        arrows = 1,                        free   = c(FALSE, rep(TRUE, 19)),                        values = c(1, rep(0.75, 19))))}# add single-headed paths to the modeltestModel <- mxModel(model=testModel, singles)## Suppose you want to have a one-headed path AND a two-headed path## between the same pair of variables in a RAM model?# One approach: use "dummy" latent variables:mvars <- c("x1", "x2") #<--Manifest variables.lvars <- c("dummy1","dummy2") #<--Latent variables.model <- mxModel(type = "RAM",manifestVars=mvars,latentVars=lvars,# One-headed path from 'x1' to 'x2', freely estimated:mxPath(from = "x1", to = "x2", arrows = 1, labels = "b_x2_x1", values=0.1),# Each latent variable "causes" its corresponding manifest variable:mxPath(from=lvars,to=mvars,arrows=1,free=FALSE,values=1),# Each latent variable has its variance fixed to 1.0:mxPath(from=lvars,arrows=2,free=FALSE,values=1),# The covariance between the two latent variables is freely estimated;# it is also the covariance between the two manifest variables:mxPath(from=lvars[1],to=lvars[2],arrows=2,free=TRUE,values=0.1))## Not run: # Another approach: directly modify matrices:# Will raise a warning:model <- mxModel(type = "RAM",manifestVars = c("x1", "x2"),mxPath(from = "x1", to = "x2", arrows = 1, labels = "b_x2_x1"),mxPath(from = "x1", to = "x2", arrows = 2, labels = "v_x2_x1"))coef(model) #<--Only the two-headed path is there.# Directly modify the MxModel's 'A' matrix:model$A$free["x2","x1"] <- TRUEmodel$A$labels["x2","x1"] <- "b_x2_x1"# Alternately:# Will raise a warning:model <- mxModel(type = "RAM",manifestVars = c("x1", "x2"),mxPath(from = "x1", to = "x2", arrows = 2, labels = "v_x2_x1"),mxPath(from = "x1", to = "x2", arrows = 1, labels = "b_x2_x1"))coef(model) #<--Only the one-headed path is there.# Directly modify the MxModel's 'S' matrix:model$S$free["x2","x1"] <- TRUEmodel$S$labels["x2","x1"] <- "v_x2_x1"model$S$free["x1","x2"] <- TRUEmodel$S$labels["x1","x2"] <- "v_x2_x1"#^^^The 'S' matrix is symmetric, so so if you modify an off-diagonal element of 'S', # you have to likewise modify the corresponding element on the other side of the diagonal.## End(Not run)

Perform Pearson Aitken selection

Description

[Maturing]These functions implement the Pearson Aitken selection formulae.

Usage

mxPearsonSelCov(origCov, newCov)mxPearsonSelMean(origCov, newCov, origMean)

Arguments

origCov

covariance matrix. The covariance prior to selection.

newCov

covariance matrix. A subset oforigCov to replace.

origMean

column vector. A mean vector to adjust.

Details

Which dimensions to condition on can be communicated in oneof two ways: (1)newCov is a submatrix oforigCov.The dimnames are matched to determine whichpartition oforigCov to replace withnewCov.Or (2)newCov is the same dimension asorigCov.The matrix entries are inspected to determine which entries havechanged. The changed entries determine which partition oforigCov to replace withnewCov.

Let then \times n covariance matrix R (origCov) be partitioned into non-empty,disjoint sets p and q.LetR_{ij} denote the covariance matrix between the pand q variables where the subscripts denote the variable subsets (e.g.R_{pq}).Let column vectors\mu_p and\mu_q contain the means of p and qvariables, respectively.We wish to compute the conditional covariances of the variables in qfor a subset of the population whereR_{pp} and\mu_p are known (or partially known)—that is, we wishtocondition the covariances and means of q on those of p.LetV_{pp} (newCov) be an arbitrary covariance matrix of the samedimension asR_{pp}.If we replaceR_{pp} byV_{pp} then the meanof q (origMean) is transformed as

\mu_q \to \mu_q + R_{qp} R_{pp}^{-1} \mu_p

and the covariance of p and q are transformed as

\left[\begin{array}{c|c}R_{pp} & R_{pq} \\\hlineR_{qp} & R_{qq}\end{array}\right] \to\left[\begin{array}{c|c}V_{pp} & V_{pp}R_{pp}^{-1}R_{pq} \\\hlineR_{qp}R_{pp}^{-1}V_{pp} & R_{qq}-R_{qp} (R_{pp}^{-1} - R_{pp}^{-1} V_{pp} R_{pp}^{-1}) R_{pq}\end{array}\right]

References

Aitken, A. (1935). Note on selection from a multivariate normal population.Proceedings ofthe Edinburgh Mathematical Society (Series 2), 4(2), 106-110.doi:10.1017/S0013091500008063

Examples

library(OpenMx)m1 <- mxModel(  'selectionTest',  mxMatrix('Full', 10, 10, values=rWishart(1, 20, toeplitz((10:1)/10))[,,1],           dimnames=list(paste0('c',1:10),paste0('c',1:10)), name="m1"),  mxMatrix('Full', 2, 2, values=diag(2),           dimnames=list(paste0('c',1:2),paste0('c',1:2)), name="m2"),  mxMatrix('Full', 10, 1, values=runif(10),           dimnames=list(paste0('c',1:10),c('v')), name="u1"),  mxAlgebra(mxPearsonSelCov(m1, m2), name="c1"),  mxAlgebra(mxPearsonSelMean(m1, m2, u1), name="u2"))m1 <- mxRun(m1)

This function creates a penalty object

Description

This function creates a penalty object

Usage

mxPenalty(  what,  epsilon = 1e-05,  scale = 1,  how = imxPenaltyTypes,  smoothProportion = 0.05,  hyperparams = c(),  hpranges = list(),  name = NULL)

Arguments

what

A character vector of parameters to regularize

epsilon

how close to zero is zero?

scale

a given parameter is divided byscale before comparison withepsilon

how

what kind of function to use

smoothProportion

what proportion of the region betweenepsilon and zero should be used to smooth the penalty function

hyperparams

a character vector of hyperparameter names

hpranges

a named list of hyperparameter ranges. Used in search if no ranges are specified.

name

Name of the regularizer object

Details

mxPenalty expects to find anmxMatrix withfree parameters that correspond to all named hyperparameters.

Gradient descent optimizers are designed for and work best onsmooth functions. All of the regularization penalties implementedtraditionally contain discontinuities. By default, OpenMx usessmoothed versions of these functions. Smoothing is controlled bysmoothProportion. IfsmoothProportion is zero thenthe traditional discontinuous functions are used. Otherwise,smoothProportion of the region betweenepsilon andzero is used for smoothing.


mxPenaltyElasticNet

Description

Elastic net regularization

Usage

mxPenaltyElasticNet(  what,  name,  alpha = 0,  alpha.step = 0.1,  alpha.max = 1,  lambda = 0,  lambda.step = 0.1,  lambda.max = 0.4,  alpha.min = NA,  lambda.min = NA,  epsilon = 1e-05,  scale = 1,  ...,  hyperparams = c("alpha", "lambda"))

Arguments

what

A character vector of parameters to regularize

name

Name of the regularizer object

alpha

strength of the mixing parameter to be applied at start (default 0.5). Note that 0 indicates a ridge regression with penalty

\frac{lambda}{2}

, and 1 indicates a LASSO regression with penalty lambda.

alpha.step

alpha step during penalty search (default 0.1)

alpha.max

when to end the alpha search (default 1)

lambda

strength of the penalty to be applied at starting values (default 0)

lambda.step

step function for lambda step (default .01)

lambda.max

end of lambda range (default .4)

alpha.min

beginning of the alpha range (default 0)

lambda.min

beginning of the lambda range (default lambda)

epsilon

how close to zero is zero?

scale

a given parameter is divided byscale before comparison withepsilon

...

Not used. Forces remaining arguments to be specified by name

hyperparams

a character vector of hyperparameter names

Details

Applies elastic net regularization. Elastic net is a weighted combination of ridge and LASSO penalties.


mxPenaltyLASSO

Description

Least Absolute Selection and Shrinkage Operator regularization

Usage

mxPenaltyLASSO(  what,  name,  lambda = 0,  lambda.step = 0.01,  lambda.max = NA,  lambda.min = NA,  epsilon = 1e-05,  scale = 1,  ...,  hyperparams = c("lambda"))

Arguments

what

A character vector of parameters to regularize

name

Name of the regularizer object

lambda

strength of the penalty to be applied at starting values (default 0)

lambda.step

step function for lambda step (default .01)

lambda.max

end of lambda range (default .4)

lambda.min

minimum lambda value (default lambda)

epsilon

how close to zero is zero?

scale

a given parameter is divided byscale before comparison withepsilon

...

Not used. Forces remaining arguments to be specified by name

hyperparams

a character vector of hyperparameter names


mxPenaltyRidge

Description

Ridge regression regularization

Usage

mxPenaltyRidge(  what,  name,  lambda = 0,  lambda.step = 0.01,  lambda.max = 0.4,  lambda.min = NA,  epsilon = 1e-05,  scale = 1,  ...,  hyperparams = c("lambda"))

Arguments

what

A character vector of parameters to regularize

name

Name of the regularizer object

lambda

strength of the penalty to be applied at start (default 0)

lambda.step

lambda step during penalty search (default 0.01)

lambda.max

when to end the lambda search (default 0.4)

lambda.min

minimum lambda value (default lambda)

epsilon

how close to zero is zero?

scale

a given parameter is divided byscale before comparison withepsilon

...

Not used. Forces remaining arguments to be specified by name

hyperparams

a character vector of hyperparameter names


mxPenaltySearch

Description

Grid search for the bestMxPenalty hyperparameters. UsesomxDefaultComputePlan withpenaltySearch=TRUE. Specifically, wrapsmxComputeGradientDescent withmxComputePenaltySearchand passes the model to the backend.

Usage

mxPenaltySearch(  model,  ...,  silent = FALSE,  suppressWarnings = FALSE,  unsafe = FALSE,  checkpoint = FALSE,  useSocket = FALSE,  onlyFrontend = FALSE,  beginMessage = !silent)

Arguments

model

AMxModel object to be optimized.

...

Not used. Forces remaining arguments to be specified by name

silent

A boolean indicating whether to print status to terminal.

suppressWarnings

A boolean indicating whether to suppress warnings.

unsafe

A boolean indicating whether to ignore errors.

checkpoint

A boolean indicating whether to periodically write parameter values to a file.

useSocket

A boolean indicating whether to periodically write parameter values to a socket.

onlyFrontend

A boolean indicating whether to run only front-end model transformations.

beginMessage

A boolean indicating whether to print the number of parameters before invoking the backend.


mxPenaltyZap

Description

Fix any free parameters withinepsilon of zero tozero. These parameters are no longer estimated. Remove allMxPenalty objects from the model. This is envisioned to beused after usingmxPenaltySearch to locate the best penaltyhyperparameters and apply penalties to model estimation. Whilepenalties can simplify a model, they also bias parameters towardzero. By re-estimating the model after usingmxPenaltyZap,parameters that remain free are likely to exhibit less bias.

Usage

mxPenaltyZap(model, silent = FALSE)

Arguments

model

anMxModel

silent

whether to suppress diagnostic output


Power curve

Description

mxPower is used to evaluate the power to distinguish between a hypothesized effect (trueModel)and a model where this effect is set to the value of the null hypothesis (falseModel).

mxPowerSearch evaluates power across a range of sample sizes or effect sizes,choosing intelligent values of, for example, sample size to explore.

Both functions are flexible, with multiple options to controln,sig.level,method, and other factors. Several parameters can take a vector as input. These options are described in detail below.

Evaluation can either use the non-centrality parameter (which can be very quick) or conduct an empirical evaluation.

note: During longer evaluations, the functions printout helpful progress consisting of a note about whattask is being conducted, e.g. "Search n:power relationship for 'A11'" and, beneath that, an update on therun, the model being evaluated, and the current candidate value being considered, e.g. "R 15 1p N 79"

Usage

mxPowerSearch(trueModel, falseModel, n=NULL, sig.level=0.05, ...,        probes=300L, previousRun=NULL,        gdFun=mxGenerateData,        method=c('empirical', 'ncp'),        grid=NULL,        statistic=c('LRT','AIC','BIC'),OK=mxOption(trueModel, "Status OK"),checkHess=FALSE,silent=!interactive())mxPower(trueModel, falseModel, n=NULL, sig.level=0.05, power=0.8, ...,        probes=300L, gdFun=mxGenerateData,        method=c('empirical', 'ncp'),        statistic=c('LRT','AIC','BIC'),        OK=mxOption(trueModel, "Status OK"), checkHess=FALSE,        silent=!interactive())

Arguments

trueModel

The true generating model for the data.

falseModel

Model representing the null hypothesis that we wish to reject.

n

Total rows summing across all submodels proportioned as given in the trueModel. Default = NULL.If provided, result (power or alpha) solved-for at the giventotal sample size.

sig.level

A single value for the p-value (aka false positive or type-1 error rate). Default = .05.

power

One or values for power (a.k.a. 1 - type 2 error) to evaluate. Default = .80

...

Not used.

probes

The number of probes to use when method = ‘empirical’.

previousRun

Output from a prior run of ‘mxPowerSearch’ to build on.

gdFun

The function invoked to generate new data for each Monte Carlo probe. Default =mxGenerateData

method

To estimate power: ‘empirical’ (Monte Carlo method) or ‘ncp’ (average non-centrality method).

grid

A vector of locations at which to evaluate the power. If not provided, a reasonable default will be chosen.

statistic

Which test to use to compare models (Default = 'LRT').

OK

The set of status codes that are considered successful.

checkHess

Whether to approximate the Hessian in each replication.

silent

Whether to show a progress indicator.

Details

Power is the chance of obtaining a significant difference when thereis a true difference, i.e., (1 - false negative rate).The likelihood ratio test is used by default. There are twomethods available to produce a power curve. The default,method = empirical, works for any model where the likelihoodratio test works. For example, definition variables and missing dataare fine, but parameters estimated at upper or lower bounds will causeproblems. Themethod = empirical can require a lot of timebecause the models need to be fit 100s of times. An alternateapproach,method = ncp, is much more efficient and takesadvantage of the fact that the non-null distribution of likelihoodratio test statistic is often\chi^2(df_1 - df_0, N \lambda).That is, the non-centrality parameter,\lambda (lambda), can be assumed, on average, to contribute equally per row. This permits essentiallyinstant power curves without the burden of tedious simulation. However, definitionvariables, missing data, or unconventional models (e.g., mixture distributions) canviolate this assumption. Therefore, we recommend verifying that the output frommethod = empirical roughly matchesmethod = ncp on the model of interestbefore relying onmethod = ncp.

note: Unlikemethod = empirical,method = ncp does not use thegdFun argument and can be used with models that have summary statistics rather than raw data.

Whenmethod = ncp, parameters of both ‘trueModel’ and‘falseModel’ are assumed to be converged to their desired values.In contrast, whenmethod = empirical, ‘trueModel’need not be run or even contain data. On each replication,data are generated from ‘trueModel’ at the given parametervector. Then both ‘trueModel’ and ‘falseModel’ arefit against these data.

Whenstatistic = 'LRT' then the models must be nested andsig.level is used to determine whether the test is rejected.For ‘AIC’ and ‘BIC’, the test is regarded as rejectedwhen the ‘trueModel’ obtains a lower score than the‘falseModel’. In contrast tostatistic='LRT', there isno nesting requirement. For example, ‘AIC’ can be used tocompare a ‘trueModel’ against its corresponding saturatedmodel.

mxPower operates in many modes.When power is passed asNULL then power is calculated and returned.When power (as a scalar or vector) is given then sample or effect size is (are) returned.If you pass a list of models for ‘falseModel’, each modelwill be checked in turn and the results returned as a vector.If you pass a vector of sample sizes, each sample size willbe checked in turn and the results returns as a vector.

mxPowerSearch

In contrast tomxPower,mxPowerSearch attempts to modelthe whole relationship between sample size or effect size and power.A naive Monte Carlo estimate of power examines a single candidatesample size at a time. To obtain the whole curve, and simultaneously,to reduce the number of simulation probes,mxPowerSearchemploys a binomial family generalized linear model with a logit linkto predict the power curve across the sample sizes of interest(similar to Schoemann et al, 2014).

ThemxPowerSearch algorithm works in 3stages. Without loss of generality, our description will use thesample size to power relationship, but a similar process is used when evaluatingthe relationship of parameter value to power. In the first stage, a crudebinary search is used to find the range reasonable values for N. Thisstage is complete once we have at least two rejections and at least twonon-rejections. At this point, the binomial intercept and slope modelis fit to these data. If thep-value for the slope is less than0.25 then we jump to stage 3. Otherwise, we fit an intercept onlybinomial model. Our goal is to nail down the intercept (wherepower=0.5) because this is the easiest point to find and is anecessary prerequisite to estimate the variance (a.k.a. slope).Therefore, we probe at the median of previous probes stepping by 10%in the direction of the model's predicted intercept. Eventually, after enoughprobes, we reach stage 3 where thep-value for the slope isless than 0.25. At stage 3, our goal is to nail down the interestingpart of the power curve. Therefore, we cycle serially through probesat 0, 1, and 2 logits from the intercept. This process is continuedfor the permitted number ofprobes.Occasionally, thep-value for the slope in the stage 3 modelgrows larger than 0.25. In this case, we switch back to stage 2(intercept only) until the stage 3 model start working again.There are no other convergence criteria. Accuracy continues to improves until the probelimit is reached.

note: AftermxPowerSearch returns, you might find you wanted to run additional probes (i.e., bounds are wider than you'd like). You can run more probeswithout starting from scratch by passing the previous result back into the function using thepreviousRun argument.

When ‘n’ is fixed thenmxPowerSearch helps answer thequestion, “how small of a true effect is likely to be detectedat a particular sample size?” Only one parameter can be considered ata time. The way the simulation works is that a candidate value forthe parameter of interest is loaded into thetrueModel, dataare generated, then both the true and false model are fit to the data toobtain the difference in fit. The candidate parameter is initially setto halfway between thetrueModel andfalseModel. Thepower curve will reflect the smallest distance, relative to the falsemodel, required to have a good chance to reject the false modelaccording to the chosen statistic.

Note that the defaultgrid is chosen to show the interestingpart of the power curve (from 0.25 to 0.97).Especially formethod=ncp, this curve is practicallyidentical for any pair of models (but located at a different range ofsample sizes). However, if you wish to align power curves from more than one power analysis, you should select your owngrid points (perhaps pass in thepower array from the first to subsequent usinggrid =).

Note: CI is not given for method=ncp: The estimates are exact(to the precision of the true and null/false model solutions provided by the user).

Value

mxPower returns a vector of sample sizes, powers, or effect sizes.

mxPowerSearch returns a data.frame with one row for each ‘grid’ point. Thefirst column is either the sample size ‘N’ (given as theproportion of rows provided intrueModel) or the parameterlabel. The second column is the power. Ifmethod=empirical,lower andupper provide a +/-2 SE confidence interval (CI95) for the power (as estimated by the binomial logit linear model).Whenmethod=empirical then the ‘probes’ attributecontains a data.frame record of the power estimation process.

References

Schoemann, A. M., Miller, P., Pornprasertmanit, S. & Wu, W. (2014). Using Monte Carlo simulations to determine power and sample size for planned missing designs.International Journal of Behavioral Development,38, 471-479.

See Also

mxCompare,mxRefModels

Examples

library(OpenMx)# Make a 1-factor model of 5 correlated variablesdata(demoOneFactor)manifests <- names(demoOneFactor)latents <- c("G")factorModel <- mxModel("One Factor", type="RAM",   manifestVars = manifests,   latentVars = latents,   mxPath(from= latents, to= manifests, values= 0.8),   mxPath(from= manifests, arrows= 2,values= 1),   mxPath(from= latents, arrows= 2, free= FALSE, values= 1),   mxPath(from= "one", to= manifests),   mxData(demoOneFactor, type= "raw"))factorModelFit <- mxRun(factorModel)# The loading of x1 on G is estimated ~ 0.39# Let's test fixing it to .3indModel <- factorModelFitindModel$A$values['x1','G'] <- 0.3indModel$A$free['x1','G'] <- FALSEindModel <- mxRun(indModel)# What power do we have at different sample sizes# to detect that the G to x1 factor loading is# really 0.3 instead of 0.39?mxPowerSearch(factorModelFit, indModel, method='ncp')# If we want to conduct a study with 80% power to# find that  the G to x1 factor loading is# really 0.3 instead of 0.39, what sample size# should we use?mxPower(factorModelFit, indModel, method='ncp')

DEPRECATED: Create MxRAMObjective Object

Description

WARNING: Objective functions have been deprecated as of OpenMx 2.0.

Please use mxExpectationRAM() and mxFitFunctionML() instead. As a temporary workaround, mxRAMObjective returns a list containing an MxExpectationNormal object and an MxFitFunctionML object.

All occurrences of

mxRAMObjective(A, S, F, M = NA, dimnames = NA, thresholds = NA, vector = FALSE, threshnames = dimnames)

Should be changed to

mxExpectationRAM(A, S, F, M = NA, dimnames = NA, thresholds = NA, threshnames = dimnames)mxFitFunctionML(vector = FALSE)

Arguments

A

A character string indicating the name of the 'A' matrix.

S

A character string indicating the name of the 'S' matrix.

F

A character string indicating the name of the 'F' matrix.

M

An optional character string indicating the name of the 'M' matrix.

dimnames

An optional character vector to be assigned to the column names of the 'F' and 'M' matrices.

thresholds

An optional character string indicating the name of the thresholds matrix.

vector

A logical value indicating whether the objective function result is the likelihood vector.

threshnames

An optional character vector to be assigned to the column names of the thresholds matrix.

Details

NOTE: THIS DESCRIPTION IS DEPRECATED. Please change to usingmxExpectationRAM andmxFitFunctionML as shown in the example below.

Objective functions were functions for which free parameter values are chosen such that the value of the objective function was minimized. The mxRAMObjective provided maximum likelihood estimates of free parameters in a model of the covariance of a givenMxData object. This model is defined by reticular action modeling (McArdle and McDonald, 1984). The 'A', 'S', and 'F' arguments must refer toMxMatrix objects with the associated properties of the A, S, and F matrices in the RAM modeling approach.

The 'dimnames' arguments takes an optional character vector. If this argument is not a single NA, then this vector be assigned to be the column names of the 'F' matrix and optionally to the 'M' matrix, if the 'M' matrix exists.

The 'A' argument refers to the A or asymmetric matrix in the RAM approach. This matrix consists of all of the asymmetric paths (one-headed arrows) in the model. A free parameter in any row and column describes a regression of the variable represented by that row regressed on the variable represented in that column.

The 'S' argument refers to the S or symmetric matrix in the RAM approach, and as such must be square. This matrix consists of all of the symmetric paths (two-headed arrows) in the model. A free parameter in any row and column describes a covariance between the variable represented by that row and the variable represented by that column. Variances are covariances between any variable at itself, which occur on the diagonal of the specified matrix.

The 'F' argument refers to the F or filter matrix in the RAM approach. If no latent variables are included in the model (i.e., the A and S matrices are of both of the same dimension as the data matrix), then the 'F' should refer to an identity matrix. If latent variables are included (i.e., the A and S matrices are not of the same dimension as the data matrix), then the 'F' argument should consist of a horizontal adhesion of an identity matrix and a matrix of zeros.

The 'M' argument refers to the M or means matrix in the RAM approach. It is a 1 x n matrix, where n is the number of manifest variables + the number of latent variables. The M matrix must be specified if either the mxData type is “cov” or “cor” and a means vector is provided, or if the mxData type is “raw”. Otherwise the M matrix is ignored.

TheMxMatrix objects included as arguments may be of any type, but should have the properties described above. The mxRAMObjective will not return an error for incorrect specification, but incorrect specification will likely lead to estimation problems or errors in themxRun function.

mxRAMObjective evaluates with respect to anMxData object. TheMxData object need not be referenced in the mxRAMObjective function, but must be included in theMxModel object. mxRAMObjective requires that the 'type' argument in the associatedMxData object be equal to 'cov' or 'cor'.

To evaluate, place MxRAMObjective objects, themxData object for which the expected covariance approximates, referencedMxAlgebra andMxMatrix objects, and optionalMxBounds andMxConstraint objects in anMxModel object. This model may then be evaluated using themxRun function. The results of the optimization can be found in the 'output' slot of the resulting model, and may be obtained using themxEval function..

Value

Returns a list containing an MxExpectationRAM object and an MxFitFunctionML object.

References

McArdle, J. J. and MacDonald, R. P. (1984). Some algebraic properties of the Reticular Action Model for moment structures.British Journal of Mathematical and Statistical Psychology, 37, 234-251.

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

Examples

   # Create and fit a model using mxMatrix, mxAlgebra,#  mxExpectationNormal, and mxFitFunctionMLlibrary(OpenMx)# Simulate some datax=rnorm(1000, mean=0, sd=1)y= 0.5*x + rnorm(1000, mean=0, sd=1)tmpFrame <- data.frame(x, y)tmpNames <- names(tmpFrame)# Define the matricesmatrixS <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(1,0,0,1),               free=c(TRUE,FALSE,FALSE,TRUE), labels=c("Vx", NA, NA, "Vy"),              name = "S")matrixA <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0),               free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b", NA, NA),              name = "A")matrixF <- mxMatrix(type="Iden", nrow=2, ncol=2, name="F")matrixM <- mxMatrix(type = "Full", nrow = 1, ncol = 2, values=c(0,0),               free=c(TRUE,TRUE), labels=c("Mx", "My"), name = "M")# Define the expectationexpFunction <- mxExpectationRAM(M="M", dimnames = tmpNames)# Choose a fit functionfitFunction <- mxFitFunctionML()# Define the modeltmpModel <- mxModel(model="exampleRAMModel",                    matrixA, matrixS, matrixF, matrixM,                    expFunction, fitFunction,                    mxData(observed=cov(tmpFrame), type="cov", numObs=nrow(tmpFrame),                              means = colMeans(tmpFrame)))# Fit the model and print a summarytmpModelOut <- mxRun(tmpModel)summary(tmpModelOut)

DEPRECATED: Create MxRObjective Object

Description

WARNING: Objective functions have been deprecated as of OpenMx 2.0.

Please use mxFitFunctionR() instead. As a temporary workaround, mxRObjective returns a list containing a NULL MxExpectation object and an MxFitFunctionR object.

All occurrences of

mxRObjective(fitfun, ...)

Should be changed to

mxFitFunctionR(fitfun, ...)

Arguments

objfun

A function that accepts two arguments.

...

The initial state information to the objective function.

Details

NOTE: THIS DESCRIPTION IS DEPRECATED. Please change to usingmxExpectationNormal andmxFitFunctionML as shown in the example below.

The fitfun argument must be a function that accepts two arguments. The first argumentis the mxModel that should be evaluated, and the second argument is some persistent state information that can be stored between one iteration of optimization to the nextiteration. It is valid for the function to simply ignore the second argument.

The function must return either a single numeric value, or a list of exactly two elements.If the function returns a list, the first argument must be a single numeric value and the second element will be the new persistent state information to be passed into this functionat the next iteration. The single numeric value will be used by the optimizer to performoptimization.

The initial default value for the persistent state information is NA.

Throwing an exception (via stop) from inside fitfun may resultin unpredictable behavior. You may want to wrap your code intryCatch while experimenting.

Value

Returns a list containing a NULL mxExpectation object and an MxFitFunctionR object.

References

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

Examples

# Create and fit a model using mxFitFunctionRlibrary(OpenMx)A <- mxMatrix(nrow = 2, ncol = 2, values = c(1:4), free = TRUE, name = 'A')squared <- function(x) { x ^ 2 }# Define the objective function in RobjFunction <- function(model, state) {    values <- model$A$values     return(squared(values[1,1] - 4) + squared(values[1,2] - 3) +        squared(values[2,1] - 2) + squared(values[2,2] - 1))}# Define the expectation functionfitFunction <- mxFitFunctionR(objFunction)# Define the modeltmpModel <- mxModel(model="exampleModel", A, fitFunction)# Fit the model and print a summarytmpModelOut <- mxRun(tmpModel)summary(tmpModelOut)

Rename a model or submodel

Description

This function re-names a model. By default, the top model will be renamed. To rename a specific model, set oldname (see examples).Importantly, all internal references to the old model name (e.g. in algebras) will be updated to reference the new name.

Usage

mxRename(model, newname, oldname = NA)

Arguments

model

a MxModel object.

newname

the new name of the model.

oldname

the name of the target model to rename. If NA then rename top model.

Value

Return amxModel object with the target model renamed.

References

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

Examples

library(OpenMx)# Create a parent model with two submodels:modelC <- mxModel(model= 'modelC', mxModel(model= 'modelA'),mxModel(model= 'modelB'))# Rename modelC (the top model) to "model1"model1 <- mxRename(modelC, 'model_1')# Rename submodel "modelB" to "model_2"model1 <- mxRename(model1, oldname = 'modelB', newname = 'model_2')model1

Restore model state from a checkpoint file

Description

Restore model state from a checkpoint file

Usage

mxRestore(  model,  chkpt.directory = mxOption(model, "Checkpoint directory"),  chkpt.prefix = mxOption(model, "Checkpoint Prefix"),  line = NULL,  strict = FALSE)mxRestoreFromDataFrame(model, checkpoint, line = NULL)

Arguments

model

anMxModel object

chkpt.directory

character. Directory where the checkpoint file is located

chkpt.prefix

character. Prefix of the checkpoint file

line

integer. Which line from the checkpoint file to restore (defaults to the last line)

strict

logical. Require that the checkpoint name and model name match

checkpoint

a data.frame containing the model state

Details

In general, the arguments ‘chkpt.directory’ and ‘chkpt.prefix’ should be identical to themxOption: ‘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 and passed tomxRestoreFromDataFrame.Useread.table with the optionsheader=TRUE, sep="\t", stringsAsFactors=FALSE, check.names=FALSE.

Value

Returns an MxModel object with free parameters updated to the lastsaved values. When ‘line’ is provided, the MxModel is updatedto the values on that line within the checkpoint file.

References

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

See Also

Other model state:mxComputeCheckpoint(),mxSave()

Examples

library(OpenMx)# Simulate some datax=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 filesmxOption(key="Checkpoint Directory", value=dir)# Create a model that includes an expected covariance matrix,# an expectation function, a fit function, and an observed covariance matrixdata <- 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 matrixmodelOut <- mxRun(testModel, checkpoint = TRUE)modelOut$expCov#Use mxRestore to load the last checkpoint saved state of the modelmodelRestore <- mxRestore(testModel)modelRestore$expCov

Return random classic Mx error message

Description

This function allows you to obtain a classic Mx error message.The message returned is random.

Usage

mxRetro()

Details

If you're a nostalgic old sod and you miss the warm, fuzzyfeelings you got from reading one of Mike Neale's patented error messages,then this function is here to save you from the depths of dire depression.All credit for this function is due to Sarah Medland, but of course the wisdomis from Mike Neale.

References

-https://en.wikipedia.org/wiki/OpenMx

See Also

-omxBrownie

Examples

require(OpenMx)mxRetro()

DEPRECATED: Create MxRowObjective Object

Description

WARNING: Objective functions have been deprecated as of OpenMx 2.0.

Please use mxFitFunctionRow() instead. As a temporary workaround, mxRowObjective returns a list containing a NULL MxExpectation object and an MxFitFunctionRow object.

All occurrences of

mxRowObjective(rowAlgebra, reduceAlgebra, dimnames,rowResults = "rowResults", filteredDataRow = "filteredDataRow",existenceVector = "existenceVector")

Should be changed to

mxFitFunctionRow(rowAlgebra, reduceAlgebra, dimnames,rowResults = "rowResults", filteredDataRow = "filteredDataRow",existenceVector = "existenceVector")

Arguments

rowAlgebra

A character string indicating the name of the algebra to be evaluated row-wise.

reduceAlgebra

A character string indicating the name of the algebra that collapses the row results into a single number which is then optimized.

dimnames

A character vector of names corresponding to columns be extracted from the data set.

rowResults

The name of the auto-generated "rowResults" matrix. See details.

filteredDataRow

The name of the auto-generated "filteredDataRow" matrix. See details.

existenceVector

The name of the auto-generated "existenceVector" matrix. See details.

Details

Objective functions are functions for which free parameter values are chosen such that the value of the objective function is minimized. The mxRowObjective function evaluates a user-definedMxAlgebra object called the ‘rowAlgebra’ in a row-wise fashion. It then stores results of the row-wise evaluation in anotherMxAlgebra object called the ‘rowResults’. Finally, the mxRowObjective function collapses the row results into a single number which is then used for optimization. TheMxAlgebra object named by the ‘reduceAlgebra’ collapses the row results into a single number.

The ‘filteredDataRow’ is populated in a row-by-row fashion with all the non-missing data from the current row. You cannot assume that the length of the filteredDataRow matrix remains constant (unless you have no missing data). The ‘existenceVector’ is populated in a row-by-row fashion with a value of 1.0 in column j if a non-missing value is present in the data set in column j, and a value of 0.0 otherwise. Use the functionsomxSelectRows,omxSelectCols, andomxSelectRowsAndCols to shrink other matrices so that their dimensions will be conformable to the size of ‘filteredDataRow’.

Value

Please use mxFitFunctionRow() instead. As a temporary workaround, mxRowObjective returns a list containing a NULL MxExpectation object and an MxFitFunctionRow object.

References

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

Examples

# Model that adds two data columns row-wise, then sums that column# Notice no optimization is performed here.library(OpenMx)xdat <- data.frame(a=rnorm(10), b=1:10) # Make data setamod <- mxModel(model="example1",            mxData(observed=xdat, type='raw'),            mxAlgebra(sum(filteredDataRow), name = 'rowAlgebra'),            mxAlgebra(sum(rowResults), name = 'reduceAlgebra'),            mxFitFunctionRow(                rowAlgebra='rowAlgebra',                reduceAlgebra='reduceAlgebra',                dimnames=c('a','b')))amodOut <- mxRun(amod)mxEval(rowResults, model=amodOut)mxEval(reduceAlgebra, model=amodOut)# Model that find the parameter that minimizes the sum of the#  squared difference between the parameter and a data row.bmod <- mxModel(model="example2",            mxData(observed=xdat, type='raw'),            mxMatrix(values=.75, ncol=1, nrow=1, free=TRUE, name='B'),            mxAlgebra((filteredDataRow - B) ^ 2, name='rowAlgebra'),            mxAlgebra(sum(rowResults), name='reduceAlgebra'),            mxFitFunctionRow(                rowAlgebra='rowAlgebra',                reduceAlgebra='reduceAlgebra',                dimnames=c('a')))bmodOut <- mxRun(bmod)mxEval(B, model=bmodOut)mxEval(reduceAlgebra, model=bmodOut)mxEval(rowResults, model=bmodOut)

Run an OpenMx model

Description

This function sends ‘model’ to the optimizer, and returns the optimized model if it ran without error.

Ifintervals = TRUE, then confidence intervals will be computed onanymxCIs added to the model.

During a run, ‘mxRun’ will print the context (e.g. optimizer name or step in the analysis e.g. MxComputeNumericDeriv ), followed by the current evaluation count, fit value, and the change in fit compared to the last status report. e.g.:

MxComputeGradientDescent(CSOLNP) evaluations 1258 fit 37702.6 change -0.05861

This may be followed by progress on the numeric derivative

MxComputeNumericDeriv 313/528

note: For models that prove difficult to run, you might try usingmxTryHard in place of mxRun.

Usage

mxRun(model, ..., intervals = NULL, silent = FALSE, suppressWarnings = FALSE,     unsafe = FALSE, checkpoint = FALSE, useSocket = FALSE, onlyFrontend = FALSE,     useOptimizer = TRUE, beginMessage=!silent)

Arguments

model

AMxModel object to be optimized.

...

Not used. Forces remaining arguments to be specified by name.

intervals

A boolean indicating whether to compute the specified confidence intervals.

silent

A boolean indicating whether to print status to terminal.

suppressWarnings

A boolean indicating whether to suppress warnings.

unsafe

A boolean indicating whether to ignore errors.

checkpoint

A boolean indicating whether to periodically write parameter values to a file.

useSocket

A boolean indicating whether to periodically write parameter values to a socket.

onlyFrontend

A boolean indicating whether to run only front-end model transformations.

useOptimizer

A boolean indicating whether to run only thelog-likelihood of the current free parameter values but not move anyof the free parameters.

beginMessage

A boolean indicating whether to print thenumber of parameters before invoking the backend.

Details

The mxRun function is used to optimize free parameters inMxModel objects based on an expectation function and fit function. MxModel objects included in the mxRun function must include an appropriate expectation and fit functions.

If the ‘silent’ flag is TRUE, then model execution will not print any status messages to the terminal.

If the ‘suppressWarnings’ flag is TRUE, then model execution will not issue a warning if NPSOL returns a non-zero status code.

If the ‘unsafe’ flag is TRUE, then many error conditions will notbe detected. Any error condition detected will be downgraded to warnings. It is strongly recommended to use this feature only for debugging purposes.

Free parameters are estimated or updated based on the expectation and fit functions. These estimated values, along with estimation information and model fit, can be found in the 'output' slot of MxModel objects after mxRun has been used.

If a model is dependent on or shares parameters with another model, both models must be included as arguments in another MxModel object. This top-level MxModel object must include expectation and fit functions in both submodels, as well as an additional fit function describing how the results of the first two should be combined (e.g.mxFitFunctionMultigroup).

Value

Returns an MxModel object with free parameters updated to their final values.The return value contains an "output" slot with the results of optimization.

References

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

See Also

mxTryHard for running models which prove difficult to optimize;summary to print a summary of a run model;mxModel for more on the model itself; More information about the OpenMx package may be foundhere.

Examples

# Create and run the 1-factor CFA on the openmx.ssri.psu.edu front page# 1. Load OpenMx and the demoOneFactor dataframelibrary(OpenMx)data(demoOneFactor)  # 2. Define the manifests (5 demo variables) and latents for use in the modelmanifests <- names(demoOneFactor) latents   <- c("G")# 3. Build the model, adding paths and datamodel <- 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))# 4. Run the model, returning the result into modelmodel <- mxRun(model) # 5. Show a summary of the fitted model and parameter valuessummary(model) # 6. Print SE-based CIs for the fitted parameter valuesconfint(model)# 7. Add likelihood-based CIs to the model and run thesemodel = mxModel(model, mxCI(paste0("b", 1:5))) model <- mxRun(model, intervals = TRUE) summary(model)$CI#       lbound  estimate    ubound note# b1 0.3675940 0.3967545 0.4285895     # b2 0.4690663 0.5031569 0.5405838     # b3 0.5384588 0.5766635 0.6186705     # b4 0.6572678 0.7020702 0.7514609     # b5 0.7457231 0.7954529 0.8503486     # 8. Demonstrate mxTryHardmodel <- mxTryHard(model, intervals = TRUE)

Compute standard errors in OpenMx

Description

This function allows you to obtain standard errors for arbitraryexpressions, named entities, and algebras.

Usage

mxSE(  x,  model,  details = FALSE,  cov,  forceName = FALSE,  silent = FALSE,  ...,  defvar.row = as.integer(NA),  data = "data")

Arguments

x

the parameter to get SEs on (reference or expression)

model

themxModel to use.

details

logical. Whether to provide further details, e.g. the fullsampling covariance matrix of x.

cov

optional matrix of covariances among the free parameters. If missing,vcov(model) is used.

forceName

logical; defaults toFALSE. Set toTRUEifx is an R symbol that refers to a character string.

silent

logical; defaults toFALSE. IfTRUE,message-printing is suppressed.

...

further named arguments passed tomxEval

defvar.row

which row to load for any definition variables

data

name of data from which to load definition variables

Details

x can be the name of an algebra, a bracket address, named entityor arbitrary expression.When thedetails argument is TRUE, the fullsampling covariance matrix ofx is also returned as part of a list.The square root of the diagonals of this sampling covariance matrix arethe standard errors.

When supplying thecov argument, take care that the free parametercovariance matrix is given, not the information matrix. These two are inverses of one another.

This function uses the delta method to compute the standard error of arbitraryand possibly nonlinear functions of the free parameters. The delta methodmakes a first-order Taylor approximation of the nonlinear function. Thenonlinear function is a map from all the free parameters to some transformedsubset of parameters: the linearization of this map is given by the JacobianJ. In equation form, the delta method computes standard errors by the following:

J^T C J

whereJ is the Jacobian of the nonlinear parameter transformationandC is the covariance matrix of the free parameters (e.g., twotimes the inverse of the Hessian of the minus two log likelihood function).

Value

SE value(s) returned as a matrix whendetails is FALSE.Whendetails is TRUE, a list of the SE value(s) and the full sampling covariance matrix.

References

-https://en.wikipedia.org/wiki/Standard_error

See Also

-mxCI

Examples

library(OpenMx)data(demoOneFactor)# ===============================# = Make and run a 1-factor CFA =# ===============================latents  = c("G") # the latent factormanifests = names(demoOneFactor) # manifest variables to be modeled# ===========================# = Make and run the model! =# ===========================m1 <- mxModel("One Factor", type = "RAM", manifestVars = manifests, latentVars = latents, mxPath(from = latents, to = manifests, labels=paste0('lambda', 1:5)),mxPath(from = manifests, arrows = 2),mxPath(from = latents, arrows = 2, free = FALSE, values = 1),mxData(cov(demoOneFactor), type = "cov", numObs = 500))m1 = mxRun(m1)mxSE(lambda5, model = m1)mxSE(lambda1^2, model = m1)

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

anMxModel 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 themxOption: ‘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. Useread.table with the optionsheader=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 athttps://openmx.ssri.psu.edu/documentation

See Also

Other model state:mxComputeCheckpoint(),mxRestore()

Examples

library(OpenMx)# Simulate some datax=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 filesmxOption(key="Checkpoint Directory", value=dir)# Create a model that includes an expected covariance matrix,# an expectation function, a fit function, and an observed covariance matrixdata <- 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 matrixmodelOut <- mxRun(testModel)modelOut$expCov# Save the ending state of modelOut in a checkpoint filemxSave(modelOut)# Restore the saved model from the checkpoint filemodelSaved <- mxRestore(testModel)modelSaved$expCov

Reset global options to the default

Description

Reset global options to the default

Usage

mxSetDefaultOptions()

Like simplify2array but works with vectors of different lengths

Description

Vectors are filled column-by-column into a matrix. Shorter vectorsare padded with NAs to fill whole columns.

Usage

mxSimplify2Array(x, higher = FALSE)

Arguments

x

a list of vectors

higher

whether to produce a higher rank array (defaults to FALSE)

Examples

v1 <- 1:3v2 <- 4:5v3 <- 6:10mxSimplify2Array(list(v1,v2,v3))#     [,1] [,2] [,3]# [1,]    1    4    6# [2,]    2    5    7# [3,]    3   NA    8# [4,]   NA   NA    9# [5,]   NA   NA   10

Standardize RAM models' path coefficients

Description

Provides a dataframe containing the standardized values of all nonzero path coefficients appearing in theA andS matrices of models that use RAM expectation (either oftype="RAM" or containing an explicitmxExpectationRAM() statement). These standardized values are what the path coefficients would be if all variables in the analysis–both manifest and latent–were standardized to zero mean and unit variance. If the means are being modeled in addition to the covariance structure, then the dataframe will also contain values of the nonzero elements of theM matrix after they have been re-scaled to standard deviation units. Can optionally include asymptotic standard errors for the standardized and re-scaled coefficients, computed via the delta method. Not intended for use with models that contain definition variables.

Usage

mxStandardizeRAMpaths(model,SE=FALSE,cov=NULL)

Arguments

model

AnmxModel object, that either uses RAM expectation or contains at least one submodel that does.

SE

Logical. Should standard errors be included with the standardized point estimates? Defaults toFALSE. Certain conditions are required for use ofSE=TRUE; see "Details" below.

cov

A repeated-sampling covariance matrix for the free-parameter estimates–say, from the robust "sandwich estimator," or from bootstrapping–used to calculate SEs for the standardized path coefficients. Defaults toNULL, in which casevcov(model) is used. See below for details concerning cases whenmodel contains independent RAM submodels.

Details

MatrixA contains theAsymmetric paths, i.e. the single-headed arrows. MatrixS contains theSymmetric paths, i.e. the double-headed arrows. The function will work even ifmxMatrix objects named "A" and "S" are absent from the model, since it identifies which matrices in the model have been assigned the roles ofA andS in themxExpectationRAM statement. Note that, in models oftype="RAM", the necessary matrices and expectation statement are automatically assembled from themxPath objects. If present, theM matrix will contain the means of exogenous variables and the intercepts of endogenous variables.

Ifmodel contains any submodels withindependent=TRUE that use RAM expectation,mxStandardizeRAMpaths() automatically applies itself recursively over those submodels. However, if a non-NULL matrix has been supplied for argumentcov, that matrix is only used for the "container" model, and is not passed as argument to the recursive calls of the function. To provide a covariance matrix for calculating SEs in an independent submodel, usemxStandardizeRAMpaths() directly on that submodel.

Use ofSE=TRUE requires that packagenumDeriv be installed. Further, ifcov=NULL, it requiresvcov(model) to return a valid result. There are three common reasons why the latter condition may not be met. First, the model may not have been run yet, i.e. it was not output bymxRun(). Second, in the case of maximum-likelihood estimation,mxOption"Hessian" might be set to"No". Third, some calculations carried out by default might possibly have been skipped per a user-definedmxCompute* statement (if any are present in the model). Ifmodel contains RAM-expectation submodels withindependent=TRUE, these conditions are checked separately for each such submodel.

In any event, using these standard errors for hypothesis-testing or forming confidence intervals isnot generally advised. Instead, it is considered best practice to conduct likelihood-ratio tests or compute likelihood-based confidence intervals (frommxCI()), as in examples below.

The user should note thatmxStandardizeRAMpaths() only cares whether an element ofA orS (orM) is nonzero, and not whether it is a fixed or free parameter. So, for instance, if the function is used on a model not yet run, any free parameters inA orS initialized at zero will not appear in the function's output.

The user is warned to interpret the output ofmxStandardizeRAMpaths() cautiously if any elements ofA orS depend upon "definition variables" (you have definition variables in your model if thelabels of anyMxPath orMxMatrix begin with"data."). Typically, eithermxStandardizeRAMpaths()'s results will be valid only for the first row of the raw dataset (and any rows identical to it), or some of the standardized coefficients will be incorrectly reported as zero.

Value

If argumentmodel is a single-group model that uses RAM expecation, thenmxStandardizeRAMpaths() returns a dataframe, with one row for each nonzero path coefficient inA andS (andM, if present), and with the following columns:

name

Character strings that uniquely identify each nonzero path coefficient in terms of the model name, the matrix ("A", "S", or "M"), the row number, and the column number.

label

Character labels for those path coefficients that are labeled elements of anmxMatrix object, andNA for those that are not. Note that path coefficients having the same label (and therefore the same UNstandardized value) can have different standardized values, and therefore the same label may appear more than once in this dataframe.

matrix

Character strings of "A", "S", or "M", depending on which matrix contains the given path coefficient.

row

Character. The rownames of the matrix containing each path coefficient; row numbers are used instead if the matrix has no rownames.

col

Character. The colnames of the matrix containing each path coefficient; column numbers are used instead if the matrix has no colnames.

Raw.Value

Numeric values of the raw (i.e., UNstandardized) path coefficients.

Raw.SE

Numeric values of the asymptotic standard errors of the raw path coefficients if ifSE=TRUE, or "not_requested" otherwise.

Std.Value

Numeric values of the standardized path coefficients.

Std.SE

Numeric values of the asymptotic standard errors of the standardized path coefficients ifSE=TRUE, or "not_requested" otherwise.

Ifmodel is a multi-group model containing at least one submodel with RAM expectation, thenmxStandardizeRAMpaths() returns a list. The list has a number of elements equal to the number of submodels that either have RAM expectation or contain a submodel that does. List elements corresponding to RAM-expectation submodels contain a dataframe, as described above. List elements corresponding to "container" submodels are themselves lists, of the kind described here.

See Also

mxBootstrapStdizeRAMpaths()

Examples

library(OpenMx)data(demoOneFactor)manifests <- names(demoOneFactor)latents   <- c("G")factorModel <- mxModel(model="One Factor", type="RAM",      manifestVars = manifests,      latentVars   = latents,      mxPath(from=latents, to=manifests),      mxPath(from=manifests, arrows=2, values=0.1),      mxPath(from=latents, arrows=2,free=FALSE, values=1.0),      mxData(cov(demoOneFactor), type="cov",numObs=500))factorFit <-mxRun(factorModel)summary(factorFit)$parametersmxStandardizeRAMpaths(model=factorFit,SE=FALSE)## Likelihood ratio test of variable x1's factor loading:factorModelNull <- omxSetParameters(factorModel,labels="One Factor.A[1,6]",                    values=0,free=FALSE)factorFitNull <- mxRun(factorModelNull)mxCompare(factorFit,factorFitNull)[2,"p"] #<--p-value## Confidence intervals for all standardized paths:factorModel2 <- mxModel(model=factorModel,                        mxMatrix(type="Iden",nrow=nrow(factorModel$A),name="I"),                        mxAlgebra( vec2diag(diag2vec( solve(I-A)%*%S%*%t(solve(I-A)) )%^%-0.5) ,                                   name="InvSD"),                        mxAlgebra( InvSD %*% A %*% solve(InvSD),                                   name="Az",dimnames=dimnames(factorModel$A)),                        mxAlgebra( InvSD %*% S %*% InvSD,                                    name="Sz",dimnames=dimnames(factorModel$S)),                        mxCI(c("Az","Sz")))factorFit2 <- mxRun(factorModel2,intervals=TRUE)## Contains point values and confidence limits for all paths:summary(factorFit2)$CI

Create List of Thresholds

Description

This function creates a list of thresholds which mxModel can use to set up a thresholds matrix for a RAM model.

Usage

mxThreshold(vars, nThresh=NA,free=FALSE, values=mxNormalQuantiles(nThresh), labels=NA,lbound=NA, ubound=NA)

Arguments

vars

character vector. These are the variables for which thresholds are to be specified.

nThresh

numeric vector. These are the number of thresholds for each variables listed in ‘vars’.

free

boolean vector. Indicates whether threshold parameters are free or fixed.

values

numeric vector. The starting values of the parameters.

labels

character vector. The names of the parameters.

lbound

numeric vector. The lower bounds of free parameters.

ubound

numeric vector. The upper bounds of free parameters.

Details

If you are new to ordinal data modeling and just want something quick to make your ordinal data work, we recommend you try theumxThresholdMatrix function in theumx package.

The mxPath function createsMxThreshold objects. These consist of a list of ordinal variables and the thresholds that define the relationship between the observed ordinal variable and the continuous latent variable assumed to underlie it. This function directly mirrors the usage ofmxPath, but is used to specify thresholds rather than means, variances and bivariate relationships.

The ‘vars’ argument specifies which variables you wish to specify thresholds for. Variables are referenced by name, and these names must appear in the ‘manifestVar’ argument of themxModel function if thresholds are to be correctly processed. Additionally, variables for which thresholds are specified must be specified as ordinal factors in whatever data is included in the model.

The ‘nThresh’ argument specifies how many thresholds are to be specified for the variable or variables included in the ‘vars’ argument. The number of thresholds for a particular variable should be one fewer than the number of categories specified for that variable.

The ‘free’ argument specifies whether the thresholds created by the mxThreshold function are free or fixed parameters. This argument may take either TRUE for free parameters, FALSE for fixed parameters, or a vector of TRUEs and FALSEs to be applied in order to the created thresholds.

‘values’ is a numeric vector containing the starting values of the created thresholds. This gives a starting point for estimation. The ‘labels’ argument specifies the names of the parameters in the resultingMxThreshold object. The ‘lbound’ and ‘ubound’ arguments specify lower and upper bounds for the created threshold parameters.

Thresholds for multiple variables may be specified simultaneously by including a vector of variable names to the ‘vars’ argument. When multiple variables are included in the ‘vars’ argument, the length of the ‘vars’ argument must be evenly divisable by the length of the ‘nThresh’ argument. All subsequent arguments (‘free’ through ‘ubound’) should have their lengths be a factor of the total number of thresholds specified for all variables.

If four variables are included in the ‘vars’ argument, then the ‘nThresh’ argument should contain either one, two or four elements. If the ‘nThresh’ argument specifies two thresholds for each variable, then ‘free’, ‘values’, and all subsequent arguments should specify eight values by including one, two, four or eight elements. Whenever fewer values are specified than are required (e.g., specify two values for eight thresholds), then the entire vector of values is repeated until the required number of values is reached, and will return an error if the correct number of values cannot be achieved by repeating the entire vector.

Value

Returns a list of thresholds.

References

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

See Also

umxThresholdMatrixdemo("mxThreshold")mxPath for comparable specification of paths.mxMatrix for a matrix-based approach to thresholds specification;mxModel for the container in which mxThresholds are embedded. More information about the OpenMx package may be foundhere.

Examples

library(OpenMx)# threshold objects for three variables: 2 binary, and one ordinal.mxThreshold(vars = c("z1", "z2", "z3"), nThresh = c(1,1,2),  free = TRUE, values = c(-1, 0, -.5, 1.2) )

Make multiple attempts to run a model

Description

Makes multiple attempts to fit an MxModel object withmxRun() until the optimizer yields an acceptable solution or the maximum number of attempts (set byextraTries) is reached. Between attempts, start values are perturbed by random numbers (see details). Optimization-control parameters may also be altered. From among its attempts, the function returns the fitted model with the best fit (smallest fit-function value). IfbestInitsOutput is TRUE, then in addition the start values used for the best-fitting model will be printed to the console.

note: If the model containsmxConstraints, or ifmxFitFunctionWLS is being used, the Hessian cannot be checked, and socheckHess will be coerced to FALSE.

Usage

mxTryHard(model, extraTries = 10, greenOK = FALSE, loc = 1, scale = 0.25,initialGradientStepSize = imxAutoOptionValue("Gradient step size"),initialGradientIterations = imxAutoOptionValue('Gradient iterations'),initialTolerance=as.numeric(mxOption(NULL,'Optimality tolerance')), checkHess = TRUE, fit2beat = Inf, paste = TRUE,iterationSummary=FALSE, bestInitsOutput=TRUE, showInits=FALSE, verbose=0, intervals = FALSE,finetuneGradient=TRUE, jitterDistrib=c("runif","rnorm","rcauchy"), exhaustive=FALSE,maxMajorIter=3000, OKstatuscodes, wtgcsv=c("prev","best","initial"), silent=interactive())mxTryHardOrig(model, finetuneGradient=FALSE, maxMajorIter=NA, wtgcsv=c("prev","best"), silent=FALSE, ...)mxTryHardctsem(model, initialGradientStepSize = .00001, initialGradientIterations = 1,initialTolerance=1e-12,jitterDistrib="rnorm", ...)mxTryHardWideSearch(model, finetuneGradient=FALSE, jitterDistrib="rcauchy", exhaustive=TRUE, wtgcsv="prev", ...)mxTryHardOrdinal(model, greenOK = TRUE,checkHess = FALSE, finetuneGradient=FALSE, exhaustive=TRUE,OKstatuscodes=c(0,1,5,6), wtgcsv=c("prev","best"), ...)

Arguments

model

The MxModel to be run.

extraTries

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

greenOK

Logical; is a solution with Mx status GREEN (optimizer status code 1) acceptable? Defaults toFALSE (formxTryHard()). Ignored if a value is provided forOKstatuscodes.

loc,scale

Numeric. The location and scale parameters of the distribution from which random values are drawn to perturb start values between attempts, defaulting respectively to 1 and 0.25. See below, under "Details," for additional information.

initialGradientStepSize,initialGradientIterations,initialTolerance

Numeric. Initial values of optimization-control parameters passed tomxComputeGradientDescent() ifmodel is using the default compute plan.

checkHess

Logical; is a positive-definite Hessian a requirement for an acceptable solution? Defaults toTRUE (formxTryHard()). IfTRUE, the Hessian and standard errors are calculated with each fit attempt, irrespective of the value of relevantoptions. The exception is ifmodel or any of its submodels containsMxConstraints, in which casecheckHess is coerced toFALSE.

fit2beat

Numeric upper limit to the fitfunction value that an acceptable solution may have. Useful if a nested submodel ofmodel has already been fitted, sincemodel, with its additional free parameters, should not yield a fitfunction value any greater than that of the submodel.

paste

Logical. IfTRUE (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 anR script, say, in anomxSetParameters() statement. IfFALSE, the vector of start values is printed as-is. Note that this vector, fromomxGetParameters(), has names corresponding to the free parameters; these names are not displayed whenpaste=TRUE.

iterationSummary

Logical. IfTRUE, displays parameter estimates and fit values for every fit attempt, even ifsilent=TRUE. Defaults toFALSE.

bestInitsOutput

Logical. IfTRUE and ifsilent=FALSE,mxTryHard() displays the starting values that resulted in the best fit, according to format specified bypaste argument. Defaults toTRUE.

showInits

Logical. IfTRUE, displays starting values for every fit attempt, even ifsilent=TRUE. Defaults toFALSE.

verbose

Ifmodel is using the default compute plan, is passed tomxComputeGradientDescent() to specify level of output printed to console during optimization.

intervals

Logical. If TRUE, OpenMx will estimate any specified confidence intervals.

finetuneGradient

Logical. IfTRUE (default formxTryHard()), then as repeated fit attempts appear to be improving,mxTryHard() will adjust optimization-control parametersgradientStepSize,gradientIterations, andtolerance, as well as argumentscale, to "fine-tune" its convergence toward an optimal solution.finetuneGradient=FALSE is recommended for analyses involving thresholds.

jitterDistrib

Character string naming which random-number distribution–eitheruniform (rectangular),normal (Gaussian), orCauchy–to be used to perturb start values. Defaults to the uniform distribution (formxTryHard()). See below, under "Details," for additional information.

exhaustive

Logical. IfFALSE (default formxTryHard()),mxTryHard() stops making additional attempts once it reaches an acceptable solution. IfTRUE, the function instead continues until it reaches its maximum number of attempts (as perextraTries), and returns the best solution it found.

maxMajorIter

Integer; passed tomxComputeGradientDescent(). Defaults to 3000, which was the internally hard-coded valuemxTryHard() used in a prior version of OpenMx. Value ofNA is permitted, in which casemxTryHard() will calculate a value via the on-load default formula for the "Major iterations"option.

OKstatuscodes

Optional integer vector containing optimizer status codes that an acceptable solution is permitted to have.mxTryHard() always considers a status code of 0 to be acceptable, this argument notwithstanding. By default,mxTryHard() will consider status code 0 acceptable, and, ifgreenOK=TRUE, status code 1 as well. If a value is supplied forOKstatuscodes that conflicts withgreenOK,OKstatuscodes controls.

wtgcsv

Character vector. "Where to get current start values." See below, under "Details," for additional information.

silent

Logical; formxTryHard(), defaults toTRUE if running interactively, and toFALSE otherwise. IfTRUE, persistentmessage-printing during execution ofmxTryHard() is suppressed, and non-persistent printing is used instead. The two exceptions are the persistent printing requested byTRUE values ofiterationSummary andshowInits.

...

Additional arguments to be passed tomxTryHard().

Details

mxTryHardOrig(),mxTryHardctsem(),mxTryHardWideSearch(), andmxTryHardOrdinal() are wrapper functions to the main workhorse functionmxTryHard(). Each wrapper function has default values for certain arguments that are tailored toward a specific purpose.mxTryHardOrig() imitates the functionality of the earliest implementations ofmxTryHard() in OpenMx's history; its chief purpose is to find good start values that lead to an acceptable solution.mxTryHardctsem() usesmxTryHard() to "zero in" on an acceptable solution with models that can be difficult to optimize, such as continuous-time state-space models.mxTryHardWideSearch() usesmxTryHard() to search a wide region of the parameter space, in hope of avoiding local fitfunction minima.mxTryHardOrdinal() attempts to usemxTryHard() as well as it can be used with models involving ordinal data.

Argumentwtgcsv dictates wheremxTryHard() is permitted to find free-parameter values, at the start of each fit attempt after the first, before randomly perturbing them to create the current fit attempt's start values. If"prev" is included, thenmxTryHard() is permitted to use the parameter estimates of the most recent non-error fit attempt. If"best" is included, thenmxTryHard() is permitted to use the parameter estimates at the best solution so far. If"initial" is included, thenmxTryHard() is permitted to use the initial start values inmodel, as provided by the user. The default is to permit all three, in which casemxTryHard() is written to use the best solution's values if available, and otherwise to use the most recent solution's values, but to periodically revert to the initial values if recent fit attempts have not improved on the best solution.

Once the start values are located for the current fit attempt, they are randomly perturbed before being assigned to the MxModel. The distributional family from which the perturbations are randomly generated is dictated by argumentjitterDistrib. The distribution is parameterized by argumentsloc andscale, respectively the location and scale parameters. The location parameter is the distribution's median. For the uniform distribution,scale is the absolute difference between its median and extrema (i.e., half the width of the rectangle); for the normal distribution,scale is its standard deviation; and for the Cauchy,scale is one-half its interquartile range. Start values are first multiplied by random draws from a distribution with the providedloc andscale, then added to random draws from a distribution with the samescale but with a median of zero.

Value

Usually,mxTryHard() returns a post-mxRun()MxModel object. Specifically, this will be the fitted model having the smallest fit-function value found bymxTryHard() during its attempts. The start values used to obtain this fitted model are printed to console ifbestInitsOutput=TRUE.

If every attempt at runningmodel fails,mxTryHard() returns an object of class 'try-error'.

mxTryHard() throws a warning if the returnedMxModel object has a nonzero status code (unless nonzero status codes are considered acceptable per argumentgreenOK orOKstatuscodes).

See Also

mxRun(),mxComputeTryHard

Examples

 library(OpenMx)data(demoOneFactor)  # load the demoOneFactor dataframemanifests <- names(demoOneFactor) # set the manifest to the 5 demo variableslatents   <- c("G")  # define 1 latent variablemodel <- 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 modelsummary(model) # Show summary of the fitted model

List Currently Available Model Types

Description

This function returns a vector of the currently available type names.

Usage

mxTypes()

Value

Returns a character vector of type names.

Examples

    mxTypes()

Returns Current Version String

Description

This function returns a string with the current version number of OpenMx.Optionally (with verbose = TRUE (the default)), it prints a message containingthe version of R, the platform, and the optimizer.

Usage

mxVersion(model = NULL, verbose = TRUE)

Arguments

model

optionalMxModel to request optimizer from (default = NULL)

verbose

Whether to print version information to the console (default = TRUE)

References

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

Examples

# Print useful version information.mxVersion()# If you just want the version, use this call.x = mxVersion(verbose=FALSE)library(OpenMx)data(demoOneFactor)  # load the demoOneFactor dataframemanifests <- names(demoOneFactor) # set the manifest to the 5 demo variableslatents   <- c("G")  # define 1 latent variablemodel <- 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))mxVersion(model, verbose = TRUE)

Example data with autoregressively related columns

Description

Data set used in some of OpenMx's examples.

Usage

data("myAutoregressiveData")

Format

A data frame with 100 observations on the following variables.

x1

x variable and time 1

x2

x variable and time 2

x3

x variable and time 3

x4

x variable and time 4

x5

x variable and time 5

Details

The rows are independently and identically distributed, but the columns are and auto-correlation structure.

Source

Simulated.

References

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

Examples

data(myAutoregressiveData)round(cor(myAutoregressiveData), 2)# note the sub-diagonal correlations (lag 1)#  x1-x2, x2-x3, x3-x4, x4-x5# and the second sub-diagonal correlations (lag 2)#  x1-x3, x2-x4, x3-x5

Example 500-row dataset with 12 generated variables

Description

Twelve columns of generated numeric data: x1 x2 x3 x4 x5 x6 y1 y2 y3 z1 z2 z3.

Usage

data(myFADataRaw)

Details

The x variables intercorrelate around .6 with each other.

The y variables intercorrelate around .5 with each other, and correlate around .3 with the X vars.

There are three ordinal variables, z1, z2, and z3.

The data are used in some OpenMx examples, especially confirmatory factor analysis.

There are no missing data.

Examples

data(myFADataRaw)str(myFADataRaw)

Data for a growth mixture model with the true class membership

Description

Data set used in some of OpenMx's examples.

Usage

data("myGrowthKnownClassData")

Format

A data frame with 500 observations on the following variables.

x1

x variable and time 1

x2

x variable and time 2

x3

x variable and time 3

x4

x variable and time 4

x5

x variable and time 5

c

Known class membership variable

Details

The same asmyGrowthMixtureData, but with the class membership variable.

Source

Simulated.

References

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

Examples

data(myGrowthKnownClassData)#plot the observed trajectories# blue lines are class 1, green lines are class 2colSel <-c('blue', 'green')[myGrowthKnownClassData$c]matplot(t(myGrowthKnownClassData[,-6]), type='l', lty=1, col=colSel)

Data for a growth mixture model

Description

Data set used in some of OpenMx's examples.

Usage

data("myGrowthMixtureData")

Format

A data frame with 500 observations on the following variables.

x1

x variable and time 1

x2

x variable and time 2

x3

x variable and time 3

x4

x variable and time 4

x5

x variable and time 5

Details

The same asmyGrowthKnownClassData, but without the class membership variable.

Source

Simulated.

References

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

Examples

data(myGrowthMixtureData)matplot(t(myGrowthMixtureData), type='l', lty=1)data(myGrowthKnownClassData)all(myGrowthKnownClassData[,-6]==myGrowthMixtureData)

Data for a linear latent growth curve model

Description

Data set used in some of OpenMx's examples.

Usage

data("myLongitudinalData")

Format

A data frame with 500 observations on the following variables.

x1

x variable and time 1

x2

x variable and time 2

x3

x variable and time 3

x4

x variable and time 4

x5

x variable and time 5

Details

Linear growth model with mean intercept around 10, and slope of about 1.5.

Source

Simulated.

References

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

Examples

data(myLongitudinalData)matplot(t(myLongitudinalData), type='l', lty=1)

Example regression data with correlated predictors

Description

Data set used in some of OpenMx's examples.

Usage

data("myRegData")

Format

A data frame with 100 observations on the following variables.

w

Predictor variable

x

Predictor variable

y

Predictor variable

z

Outcome variable

Details

w, x, and y are predictors of z. x and y are correlated.

Source

Simulated.

References

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

Examples

data(myRegData)summary(lm(z ~ ., data=myRegData))

Example regression data with correlated predictors

Description

Data set used in some of OpenMx's examples.

Usage

data("myRegDataRaw")

Format

A data frame with 100 observations on the following variables.

w

Predictor variable

x

Predictor variable

y

Predictor variable

z

Outcome variable

Details

w, x, and y are predictors of z. x and y are correlated. Equal tomyRegData.

Source

Simulated.

References

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

Examples

data(myRegData)data(myRegDataRaw)all(myRegDataRaw == myRegData)

Duplicate of twinData

Description

Legacy dataset from early teaching examples. SeetwinData for a more current file.

Usage

data("myTwinData")

Format

A data frame with 3808 observations on the following variables.

fam

Family ID variable

age

Age of the twin pair. Range: 17 to 88.

zyg

Integer codes for zygosity and gender combinations

part

Cohort

wt1

Weight in kilograms for twin 1

wt2

Weight in kilograms for twin 2

ht1

Height in meters for twin 1

ht2

Height in meters for twin 2

htwt1

Product of ht and wt for twin 1

htwt2

Product of ht and wt for twin 2

bmi1

Body Mass Index for twin 1

bmi2

Body Mass Index for twin 2

Details

Height and weight are highly correlated, and each individually highly heritable. These data present and opportunity for multivariate behavior genetics modeling.

Source

Timothy Bates

References

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

Examples

data(myTwinData)plot( ht1 ~ wt1, myTwinData)

Example twin extended kinship data: MZ female twins

Description

Data for extended twin example ETC88.R

Usage

data("mzfData")

Format

A data frame with 3099 observations on the following 37 variables.

famid

a numeric vector

e1

a numeric vector

e2

a numeric vector

e3

a numeric vector

e4

a numeric vector

e5

a numeric vector

e6

a numeric vector

e7

a numeric vector

e8

a numeric vector

e9

a numeric vector

e10

a numeric vector

e11

a numeric vector

e12

a numeric vector

e13

a numeric vector

e14

a numeric vector

e15

a numeric vector

e16

a numeric vector

e17

a numeric vector

e18

a numeric vector

a1

a numeric vector

a2

a numeric vector

a3

a numeric vector

a4

a numeric vector

a5

a numeric vector

a6

a numeric vector

a7

a numeric vector

a8

a numeric vector

a9

a numeric vector

a10

a numeric vector

a11

a numeric vector

a12

a numeric vector

a13

a numeric vector

a14

a numeric vector

a15

a numeric vector

a16

a numeric vector

a17

a numeric vector

a18

a numeric vector

Examples

data(mzfData)str(mzfData)

Example twin extended kinship data: MZ Male data

Description

Data for extended twin example ETC88.R

Usage

data("mzmData")

Format

A data frame with 3019 observations on the following 37 variables.

famid

a numeric vector

e1

a numeric vector

e2

a numeric vector

e3

a numeric vector

e4

a numeric vector

e5

a numeric vector

e6

a numeric vector

e7

a numeric vector

e8

a numeric vector

e9

a numeric vector

e10

a numeric vector

e11

a numeric vector

e12

a numeric vector

e13

a numeric vector

e14

a numeric vector

e15

a numeric vector

e16

a numeric vector

e17

a numeric vector

e18

a numeric vector

a1

a numeric vector

a2

a numeric vector

a3

a numeric vector

a4

a numeric vector

a5

a numeric vector

a6

a numeric vector

a7

a numeric vector

a8

a numeric vector

a9

a numeric vector

a10

a numeric vector

a11

a numeric vector

a12

a numeric vector

a13

a numeric vector

a14

a numeric vector

a15

a numeric vector

a16

a numeric vector

a17

a numeric vector

a18

a numeric vector

Examples

data(mzmData)str(mzmData)

Modified National Health and Nutrition Examination Survey demographic data

Description

This is a national survey run by CDC from 2015-16. More information at: https://wwwn.cdc.gov/Nchs/Nhanes/analyticguidelines.aspx

Usage

data("nhanesDemo")

Format

A data frame with 9971 observations and 53 variables.

Source

https://wwwn.cdc.gov/Nchs/Nhanes/2015-2016/DEMO_I.XPT

Examples

data(nhanesDemo)

Twin data from a nuclear family design

Description

Data set used in some of OpenMx's examples.

Usage

data("nuclear_twin_design_data")

Format

A data frame with 1743 observations on the following variables.

Twin1
Twin2
Father
Mother
zyg

Zygosity of the twin pair

Details

This is a wide format data set. A single variable has values for different member of the same nuclear family.

Source

Likely simulated.

References

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

Examples

data(nuclear_twin_design_data)cor(nuclear_twin_design_data[,-5], use="pairwise.complete.obs")

numeric Hessian data 1

Description

data file used by the HessianTest.R script

Usage

data("numHess1")

Format

A 12 by 12 data frame containing Hessian (numeric variables a-l)

Examples

data(numHess1)str(numHess1)

numeric Hessian data 2

Description

data file used by the HessianTest.R script

Usage

data("numHess2")

Format

A 12 by 12 data frame containing Hessian matrix (numeric variables a-l)

Examples

data(numHess2)str(numHess2)

All Interval Multivariate Normal Integration

Description

omxAllInt computes the probabilities of a large number of cells of a multivariate normal distribution that has been sliced by a varying number of thresholds in each dimension. While the same functionality can be achieved by repeated calls toomxMnor,omxAllInt is more efficient for repeated operations on a single covariance matrix.omxAllInt returns an nx1 matrix of probabilities cycling from lowest to highest thresholds in each column with the rightmost variable incovariance changing most rapidly.

Usage

omxAllInt(covariance, means, ...)

Arguments

covariance

the covariance matrix describing the multivariate normal distribution.

means

a row vector containing means of the variables of the underlying distribution.

...

a matrix or set of matrices containing one column of thresholds for each column ofcovariance. Each column must contain a strictly increasing set of thresholds for the corresponding variable of the underlying distribution.NA values in these thresholds indicate that the list of thresholds in that column has ended.

Details

covariance andmeans contain the covariances and means of the multivariate distribution from which probabilities are to be calculated.

covariance must be a square covariance or correlation matrix with one row and column for each variable.

means must be a vector of lengthnrows(covariance) that contains the mean for each corresponding variable.

All further arguments are considered threshold matrices.

Threshold matrices contain locations of the hyperplanes delineating the intervals to be calculated. The first column of the first matrix corresponds to the thresholds for the first variable represented by the covariance matrix. Subsequent columns of the same matrix correspond to thresholds for subsequent variables in the covariance matrix. If more variables exist in the covariance matrix than in the first threshold matrix, the first column of the second threshold matrix will be used, and so on. That is, ifcovariance is a 4x4 matrix, and the three threshold matrices are specified, one with a single column and the others with two columns each, the first column of the first matrix will contain thresholds for the first variable incovariance, the two columns of the second matrix will correspond to the second and third variables ofcovariance, respectively, and the first column of the third threshold matrix will correspond to the fourth variable. Any extra columns will be ignored.

Each column in the threshold matrices must contain some number of strictly increasing thresholds, delineating the boundaries of a cell of integration. That is, if the integral from -1 to 0 and 0 to 1 are required for a given variable, the corresponding threshold column should contain the values -1, 0, and 1, in that order. Thresholds may be set to Inf or -Inf if a boundary at positive or negative infinity is desired.

Within a threshold column, a value of +Inf, if it exists, is assumed to be the largest threshold, and any rows after it are ignored in that column. A value of NA, if it exists, indicates that there are no further thresholds in that column, and is otherwise ignored. A threshold column consisting of only +Inf or NA values will cause an error.

For all i>1, the value in row i must be strictly larger than the value in row i-1 in the same column.

The return value ofomxAllInt is a matrix consisting of a single column with one row for each combination of threshold levels.

See Also

omxMnor

Examples

data(myFADataRaw)covariance <- cov(myFADataRaw[,1:5])means <- colMeans(myFADataRaw[,1:5])# Integrate from -Infinity to 0 and 0 to 1 on first variablethresholdForColumn1 <- cbind(c(-Inf, 0,   1))# Note: The first variable will never be calculated from 1 to +Infinity.# These columns will be integrated from -Inf to -1, -1 to 0, etc.thresholdsForColumn2 <- cbind(c(-Inf, -1, 0, 1, Inf))thresholdsForColumns3and4 <- cbind(c(-Inf, 1.96, 2.326, Inf),                                   c(-Inf, -1.96, 2.326, Inf))# The integrationomxAllInt(covariance, means,  thresholdForColumn1, thresholdsForColumn2,  thresholdsForColumns3and4, thresholdsForColumn2)# Notice that columns 2 and 5 are assigned identical thresholds.#-------------------------------------------------------------# An alternative specification of the same calculation followscovariance <- cov(myFADataRaw[,1:5])means <- colMeans(myFADataRaw[,1:5])# Note NAs to indicate the end of the sequence of thresholds.thresholds <- cbind(c(-Inf,     0,     1,  NA,  NA),                    c(-Inf,    -1,     0,   1, Inf),                    c(-Inf,  1.96,  2.32, Inf,  NA),                    c(-Inf, -1.96,  2.32, Inf,  NA),                    c(-Inf,    -1,     0,   1, Inf))omxAllInt(covariance, means, thresholds)

On-Demand Parallel Apply

Description

If the snowfall library is loaded, then this function callssfApply. Otherwise it invokesapply.

Usage

omxApply(x, margin, fun, ...)

Arguments

x

a vector (atomic or list) or an expressions vector. Other objects (including classed objects) will be coerced byas.list.

margin

a vector giving the subscripts which the function will be applied over.

fun

the function to be applied to each element ofx.

...

optional arguments tofun.

See Also

omxLapply,omxSapply

Examples

x <- cbind(x1 = 3, x2 = c(4:1, 2:5))dimnames(x)[[1]] <- letters[1:8]omxApply(x, 2, mean, trim = .2)

Assign First Available Values to Model Parameters

Description

Sometimes, in your model, you may have a free parameter with two or more different starting values, lower bounds, and/or upper bounds. OpenMx will not run a model until all instances of a free parameter have the same starting value, lower bound, and upper bound. It is often sufficient to arbitrarily select one of those starting values for optimization; bounds may also be selected arbitrarily, but users should do so with more caution.

This function accomplishes that task of assigning valid starting values and bounds to the free parameters of a model. It selects an arbitrary current value (the "first" value it finds, where "first" is not defined) for each free parameter and uses that value for all instances of that parameter in the model.

Usage

omxAssignFirstParameters(model, indep = FALSE)

Arguments

model

a MxModel object.

indep

assign parameters to independent submodels.

See Also

omxGetParameters,omxSetParameters

Examples

A     <- mxMatrix('Full', 3, 3, values = c(1:9), labels = c('a','b', NA),                  free = TRUE, name = 'A')model <- mxModel(model=A, name = 'model')model <- omxAssignFirstParameters(model)# Note: All cells with the same label now have the same start value.# Note also that NAs are untouched.model$matrices$A# $labels#      [,1] [,2] [,3]# [1,] "a"  "a"  "a" # [2,] "b"  "b"  "b" # [3,] NA   NA   NA  # # $values#      [,1] [,2] [,3]# [1,]    1    1    1# [2,]    2    2    2# [3,]    3    6    9

Estimate summary statistics used by the WLS fit function

Description

The summary statistics are returned in the observedStats slot ofthe MxData object.

Usage

omxAugmentDataWithWLSSummary(  mxd,  type = c("WLS", "DWLS", "ULS"),  allContinuousMethod = c("cumulants", "marginals"),  ...,  exogenous = c(),  fullWeight = TRUE,  returnModel = FALSE,  silent = TRUE)

Arguments

mxd

an MxData object containing raw data

type

the type of WLS weight matrix

allContinuousMethod

which method to use when all indicators are continuous

...

Not used. Forces remaining arguments to be specified by name.

exogenous

names variables to be modelled as exogenous

fullWeight

whether to produce a fullWeight matrix

returnModel

whether to return the whole mxModel (TRUE) or just the mxData (FALSE)

silent

logical. Whether to print status to terminal.

See Also

mxFitFunctionWLS

Examples

omxAugmentDataWithWLSSummary(mxData(Bollen[,1:8], 'raw'))

Make Brownies in OpenMx

Description

This function returns a brownie recipe.

Usage

omxBrownie(quantity=1, walnuts=TRUE, wfpb=FALSE)

Arguments

quantity

Number of batches of brownies desired. Defaults to one.

walnuts

Logical. Indicates whether walnuts are to be included in the brownies. Defaults to TRUE.

wfpb

Logical. Indicates whether to display the whole food plant based version. Defaults to FALSE.

Details

Returns a brownie recipe. Alter the 'quantity' variable to make morepans of brownies. Ingredients, equipment and procedure are listed,but neither ingredients nor equipment are provided.

Raw cocoa powder can be used instead of Dutch processed cocoafor approximately double the antioxidants and flavonols. However,raw cocoa powder is not as smooth and delicious in taste.

For the whole food plant based (wfpb) version of the recipe,we substitute coconut butter for dairy butter because dairy buttercontains a large proportion of saturated fat that raises deadly LDLcholesterol (Trumbo & Shimakawa, 2011). In contrast, coconut butterhas so much fiber that the considerable saturated fat that itcontains is mostly not absorbed (Padmakumaran, Rajamohan & Kurup,1999).You can substitute erythritol (den Hartog et al, 2010) for sucanat(Lustig, Schmidt, & Brindis, 2012) to improve the glycemic index andreduce calorie density. We substitute whole wheat flour for all-purposewheat flour because whole grains are associated with improvement inblood pressure (Tighe et al, 2010).

Value

Returns a brownie recipe.

References

Padmakumaran Nair K.G, Rajamohan T, Kurup P.A. (1999). Coconut kernel proteinmodifies the effect of coconut oil on serum lipids. Plant Foods HumNutr. 53(2):133-44.

Tighe P, Duthie G, Vaughan N, Brittenden J, Simpson W.G, Duthie S, MutchW, Wahle K, Horgan G, Thies F. (2010). Effect of increased consumption ofwhole-grain foods on blood pressure and other cardiovascular riskmarkers in healthy middle-aged persons: a randomized controlledtrial. Am. J. Clin. Nutr. 92(4), 733-40.

R H Lustig, L A Schmidt, C D Brindis. (2012). Public health: The toxic truthabout sugar. Nature. 482 27-29.

den Hartog G.J, Boots A.W, Adam-Perrot A, Brouns F, Verkooijen I.W, WeselerA.R, Haenen G.R, Bast A. (2010). Erythritol is a sweet antioxidant. Nutrition. 26(4), 449-58.

Trumbo P.R, Shimakawa T. (2011). Tolerable upper intake levels for transfat, saturated fat, and cholesterol. Nutr. Rev. 69(5), 270-8. doi:10.1111/j.1753-4887.2011.00389.x.

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

See Also

More information about the OpenMx package may be foundhere.

Examples

# Return a brownie recipeomxBrownie()

Build the model used for mxAutoStart

Description

Build the model used for mxAutoStart

Usage

omxBuildAutoStartModel(model, type = c("ULS", "DWLS"))

Arguments

model

The MxModel for which starting values are desired

type

The type of starting values to obtain, currently unweighted or diagonally weighted least squares, ULS or DWLS

Value

an MxModel that can be run to obtain starting values

See Also

mxAutoStart


Approximate Equality Testing Function

Description

This function tests whether two numeric vectors or matrixes areapproximately equal to one another, within a specified threshold.

Usage

omxCheckCloseEnough(a, b, epsilon = 10^(-15))

Arguments

a

a numeric vector or matrix

b

a numeric vector or matrix

epsilon

a non-negative tolerance threshold

Details

Arguments ‘a’ and ‘b’ must be of the same type,ie. they must be either vectors of equal dimension or matrices ofequal dimension. The two arguments are compared element-wise forapproximate equality. If the absolute value of the difference ofany two values is greater than the threshold, then an error willbe thrown.

References

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

See Also

omxCheckWithinPercentError,omxCheckIdentical,omxCheckSetEquals,omxCheckTrue,omxCheckEquals

Examples

omxCheckCloseEnough(c(1, 2, 3), c(1.1, 1.9 ,3.0), epsilon = 0.5)omxCheckCloseEnough(matrix(3, 3, 3), matrix(4, 3, 3), epsilon = 2)# Throws an errortry(omxCheckCloseEnough(c(1, 2, 3), c(1.1, 1.9 ,3.0), epsilon = 0.01))

Equality Testing Function

Description

This function tests whether two objects are equal using the ‘==’ operator.

Usage

omxCheckEquals(...)

Arguments

...

arguments forwarded toexpect_equivalent

Details

Performs the ‘==’ comparison on the two arguments. If the two arguments are not equal, then an error will be thrown.

References

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

See Also

omxCheckCloseEnough,omxCheckWithinPercentError,omxCheckSetEquals,omxCheckTrue,omxCheckIdentical

Examples

omxCheckEquals(c(1, 2, 3), c(1, 2, 3))omxCheckEquals(FALSE, FALSE)# Throws an errortry(omxCheckEquals(c(1, 2, 3), c(2, 1, 3)))

Correct Error Message Function

Description

This function tests whether the correct error message is thrown.

Usage

omxCheckError(expression, message)

Arguments

expression

an R expression that produces an error

message

a character string with the desired error message

Details

Arguments ‘expression’ and ‘message’ give the expressionthat generates the error and the message that is supposed to be generated, respectively.

References

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

See Also

omxCheckWarningomxCheckWithinPercentError,omxCheckIdentical,omxCheckSetEquals,omxCheckTrue,omxCheckEquals


Exact Equality Testing Function

Description

This function tests whether two objects are equal.

Usage

omxCheckIdentical(...)

Arguments

...

arguments forwarded toexpect_identical

Details

Performs the ‘identical’ comparison on the two arguments. If the two arguments are not equal, then an error will be thrown.

References

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

See Also

omxCheckCloseEnough,omxCheckWithinPercentError,omxCheckSetEquals,omxCheckTrue,omxCheckEquals

Examples

omxCheckIdentical(c(1, 2, 3), c(1, 2, 3))omxCheckIdentical(FALSE, FALSE)# Throws an errortry(omxCheckIdentical(c(1, 2, 3), c(2, 1, 3)))

omxCheckNamespace

Description

This is an internal function exported for those people who knowwhat they are doing.

Usage

omxCheckNamespace(model, namespace)

Arguments

model

model

namespace

namespace

Details

This function checks that the named entities in the model are valid.


Set Equality Testing Function

Description

This function tests whether two vectors contain the same elements.

Usage

omxCheckSetEquals(...)

Arguments

...

arguments forwarded toexpect_setequal

Details

Performs the ‘setequal’ function on the two arguments. If the two arguments do not contain the same elements, then an error will be thrown.

References

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

See Also

omxCheckCloseEnough,omxCheckWithinPercentError,omxCheckIdentical,omxCheckTrue,omxCheckEquals

Examples

omxCheckSetEquals(c(1, 1, 2, 2, 3), c(3, 2, 1))omxCheckSetEquals(matrix(1, 1, 1), matrix(1, 3, 3))# Throws an errortry(omxCheckSetEquals(c(1, 2, 3, 4), c(2, 1, 3)))

Boolean Equality Testing Function

Description

This function tests whether an object is equal to TRUE.

Usage

omxCheckTrue(a)

Arguments

a

the value to test.

Details

Checks element-wise whether an object is equal to TRUE. If any of the elements are false, then an error will be thrown.

References

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

See Also

omxCheckCloseEnough,omxCheckWithinPercentError,omxCheckIdentical,omxCheckSetEquals,omxCheckEquals

Examples

omxCheckTrue(1 + 1 == 2)omxCheckTrue(matrix(TRUE, 3, 3))# Throws an errortry(omxCheckTrue(FALSE))

Correct Warning Message Function

Description

This function tests whether the correct warning message is thrown.Arguments ‘expression’ and ‘message’ give the expressionthat generates the warning and the message that is supposed to be generated, respectively.

Usage

omxCheckWarning(expression, message)

Arguments

expression

an R expression that produces a warning

message

a character string with the desired warning message

Details

note: to test for no warning, setmessage = NA.

References

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

See Also

omxCheckErroromxCheckWithinPercentError,omxCheckIdentical,omxCheckSetEquals,omxCheckTrue,omxCheckEquals

Examples

foo <- omxCheckWarning(mxFIMLObjective('cov', 'mean'), "deprecated")# Test for no warningomxCheckWarning(2+2, message = NA)

Approximate Percent Equality Testing Function

Description

This function tests whether two numeric vectors or matrixes are approximately equal to one another, within a specified percentage.

Usage

omxCheckWithinPercentError(a, b, percent = 0.1)

Arguments

a

a numeric vector or matrix.

b

a numeric vector or matrix.

percent

a non-negative percentage.

Details

Arguments ‘a’ and ‘b’ must be of the same type, ie. they must be either vectors of equal dimension or matrices of equal dimension. The two arguments are compared element-wise for approximate equality. If the absolute value of the difference of any two values is greater than the percentage difference of ‘a’, then an error will be thrown.

References

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

See Also

omxCheckCloseEnough,omxCheckIdentical,omxCheckSetEquals,omxCheckTrue,omxCheckEquals

Examples

omxCheckWithinPercentError(c(1, 2, 3), c(1.1, 1.9 ,3.0), percent = 50)omxCheckWithinPercentError(matrix(3, 3, 3), matrix(4, 3, 3), percent = 150)# Throws an errortry(omxCheckWithinPercentError(c(1, 2, 3), c(1.1, 1.9 ,3.0), percent = 0.01))

omxConstrainMLThresholds

Description

Add constraint to ML model to keep thresholds in order

Usage

omxConstrainMLThresholds(model, dist = 0.1)

Arguments

model

the MxModel to which constraints should be added

dist

unused

Details

This function adds a nonlinear constraint to an ML model. The constraintkeeps the thresholds in order. Constraints often slow model estimation,however, keeping the thresholds in increasing order helps ensure the likelihoodfunction is well-defined. If you're having problems with ordinal data, this isone of the things to try.

Value

a new MxModel object with the constraints added

See Also

demo("omxConstrainMLThresholds")


Construct default compute plan

Description

This function generates a default compute plan, where "default compute plan" refers to an object of classMxComputeSequence which is appropriate for use in a wide variety of cases. The exact specification of the plan will depend upon the arguments provided toomxDefaultComputePlan().

Usage

omxDefaultComputePlan(modelName=NULL, intervals=FALSE,  useOptimizer=TRUE, optionList=options()$mxOption, penaltySearch=FALSE)

Arguments

modelName

Optional (defaults toNULL) character string, providing the name of theMxModel the fitfunction of which is to be evaluated, and usually, optimized.

intervals

Logical; willconfidence intervals be computed? Defaults toFALSE.

useOptimizer

Logical; will a fitfunction be minimized? Defaults toTRUE.

optionList

List ofmxOptions. Defaults to the currentlist of globalmxOptions.

penaltySearch

Logical; whether to wrap the optimizer step withmxComputePenaltySearch

Details

At minimum, argumentoptionList must include “Gradient algorithm”, “Gradient iterations”, “Gradient step size”, “Calculate Hessian”, and “Standard Errors”.

Value

Returns an object of classMxComputeSequence.

Examples

foo <- omxDefaultComputePlan(modelName="bar")str(foo)

omxDetectCores

Description

Detects the number of cores on the local machine

Usage

omxDetectCores(...)

Arguments

...

unused

Examples

omxDetectCores()

omxGetBootstrapReplications

Description

Checks a variety of conditions to ensure that bootstrap replications areavailable and valid. Throws exception if things go wrong. Otherwise,replications are returned to the caller.

Usage

omxGetBootstrapReplications(model)omxBootstrapCov(model)

Arguments

model

an MxModel object

Value

a matrix or covariance matrix of bootstrap parameter estimates


omxGetNPSOL

Description

Get the non-CRAN version of OpenMx from the OpenMx website.

Usage

omxGetNPSOL()

Details

This function

Value

Invisible NULL


Fetch Model Parameters

Description

Return a vector of the chosen parameters from the model.

Usage

omxGetParameters(model, indep = FALSE, free = c(TRUE, FALSE, NA),    fetch = c('values', 'free', 'lbound', 'ubound', 'all'),    labels = c())

Arguments

model

a MxModel object

indep

fetch parameters from independent submodels.

free

fetch either free parameters (TRUE), or fixed parameters or both types. Default value is TRUE.

fetch

which attribute of the parameters to fetch. Default choice is ‘values’.

labels

additional labels to fetch

Details

The argument ‘free’ dictates whether to return only freeparameters or only fixed parameters or both free and fixedparameters. The function can return unlabeled free parameters(parameters with a label of NA). These anonymous free parameters willbe identified as ‘modelname.matrixname[row,col]’. It will notreturn fixed parameters that have a label of NA.

If provided, the argument ‘labels’ takes precedent over theselection criteria specified by ‘free’. Any labels mentioned in‘labels’, including those of the form‘modelname.matrixname[row,col]’, will be returned.

No distinction is made between ordinary labels, definition variables, and square bracket constraints. The function will return either a vector of parameter values, or free/fixed designations, or lower bounds, or upper bounds, depending on the ‘fetch’ argument. Using fetch with ‘all’ returns a data frame that is populated with all of the attributes.

See Also

omxSetParameters,omxLocateParameters,omxAssignFirstParameters

Examples

library(OpenMx)A <- mxMatrix('Full', 2, 2, labels = c("A11", "A12", "A21", NA), values= 1:4,     free = c(TRUE,TRUE,FALSE,TRUE), byrow=TRUE, name = 'A')model <- mxModel(A, name = 'model')# Request all free parameters in modelomxGetParameters(model)# A11  A12 model.A[2,2] #   1    2    4 # Request fixed parameters from modelomxGetParameters(model, free = FALSE)# A21 #   3A$labels#      [,1]  [,2] # [1,] "A11" "A12"# [2,] "A21" NA   A$free#       [,1] [,2]# [1,]  TRUE TRUE# [2,] FALSE TRUEA$values#      [,1] [,2]# [1,]    1    2# [2,]    3    4# Example using un-labelled parameters# Read in some demo datadata(demoOneFactor)# Grab the names for manifestVars manifestVars <- names(demoOneFactor)nVar = length(manifestVars) # 5 variablesfactorModel <- mxModel("One Factor",    mxMatrix(name="A", type="Full", nrow=nVar, ncol=1, values=0.2, free=TRUE,         lbound = 0.0, labels=letters[1:nVar]),    mxMatrix(name="L", type="Symm", nrow=1, ncol=1, values=1, free=FALSE),    # the "U" matrix has nVar (5) anonymous free parameters    mxMatrix(name="U", type="Diag", nrow=nVar, ncol=nVar, values=1, free=TRUE),    mxAlgebra(expression=A %&% L + U, name="R"),    mxExpectationNormal(covariance="R", dimnames=manifestVars),    mxFitFunctionML(),    mxData(observed=cov(demoOneFactor), type="cov", numObs=500))# Get all free parametersparams         <- omxGetParameters(factorModel)lbound         <- omxGetParameters(factorModel, fetch="lbound")# Set new values for these params, saving them in a new modelnewFactorModel <- omxSetParameters(factorModel, names(params), values = 1:10)# Read out the values from the new modelnewParams      <- omxGetParameters(newFactorModel)

omxGetRAMDepth

Description

Get the potency of a matrix for inversion speed-up

Usage

omxGetRAMDepth(A, maxdepth = nrow(A) - 1)

Arguments

A

MxMatrix object

maxdepth

Numeric. maximum depth to check

Details

This function is used internally by themxExpectationRAM functionto determine how far to expand(I-A)^{-1} = I + A + A^2 + A^3 + .... It issimilarly used bymxExpectationLISREL in expanding(I-B)^{-1} = I + B + B^2 + B^3 + ....In many situationsA^2 is a zero matrix (nilpotent of order 2). So whenA has largedimension it is much faster to computeI+A than(I-A)^{-1}.


Show RAM Model in Graphviz Format

Description

The function accepts a RAM style model and outputs a visual representationof the model in Graphviz format. The function will output either to a file or to the console. The recommended file extension for an output file is ".dot".

Usage

omxGraphviz(model, dotFilename = "")

Arguments

model

An RAM-type model.

dotFilename

The name of the output file. Use "" to write to console.

Value

Invisibly returns a string containing the model description in Graphviz format.

References

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


omxHasDefaultComputePlan

Description

Determine whether the model has a default complete plan (i.e., not custom).

Usage

omxHasDefaultComputePlan(model)

Arguments

model

model


On-Demand Parallel Lapply

Description

If the snowfall library is loaded, then this function callssfLapply. Otherwise it invokeslapply.

Usage

omxLapply(x, fun, ...)

Arguments

x

a vector (atomic or list) or an expressions vector. Other objects (including classed objects) will be coerced byas.list.

fun

the function to be applied to each element ofx.

...

optional arguments tofun.

See Also

omxApply,omxSapply

Examples

x <- list(a = 1:10, beta = exp(-3:3), logic = c(TRUE,FALSE,FALSE,TRUE))# compute the list mean for each list elementomxLapply(x,mean)

Get the location (model, matrix, row, column) and other info for a parameter

Description

Returns a data.frame summarizing thefree parameters in a model,possibly filtered using ‘labels’.

For each located parameter, the label, model, matrix, row, col, value,and lbound & ubound are given as a row in the dataframe.

Duplicated labels return a row for each location in which they are found.

Usage

omxLocateParameters(model, labels = NULL, indep = FALSE, free = c(TRUE, FALSE, NA))

Arguments

model

a MxModel object

labels

optionally specify which free parameters to retrieve.

indep

fetch parameters from independent submodels.

free

fetch either free parameters (TRUE), or fixed parameters or both types. Default value is TRUE.

Details

Invoking the function with the default value for the ‘labels’argument retrieves all the free parameters. The ‘labels’argument can be used to select a subset of the free parameters.Note that ‘NA’ is a valid input to ‘labels’.

See Also

omxGetParameters,omxSetParameters,omxAssignFirstParameters

Examples

A <- mxMatrix('Full', 2, 2, labels = c("A11", "A12", NA, "A11"), values= 1:4,   free = TRUE, byrow = TRUE, name = 'A')model <- mxModel(A, name = 'model')# Request all free parameters in modelomxLocateParameters(model)# Request free parameters "A11" and all NAsomxLocateParameters(model, c("A11", NA))# Works with submodelB = mxMatrix(name = 'B', 'Full', 1, 2, labels = c("B11", "notme"),  free = c(TRUE, FALSE), values= pi)model <- mxModel(model, mxModel(B, name = 'subB'))# nb: only returns free parameters ('notme' not shown)omxLocateParameters(model)

Logical mxAlgebra() operators

Description

omxNot computes the unary negation of the values of a matrix.omxAnd computes the binary and of two matrices.omxOr computes the binary or of two matrices.omxGreaterThan computes a binary greater than of two matrices.omxLessThan computes the binary less than of two matrices.omxApproxEquals computes a binary equals within a specified epsilon of two matrices.

Usage

omxNot(x)omxAnd(x, y)omxOr(x, y)omxGreaterThan(x, y)omxLessThan(x, y)omxApproxEquals(x, y, epsilon)

Arguments

x

the first argument, the matrix which the logical operation will be applied to.

y

the second argument, applicable to binary functions.

epsilon

the third argument, specifies the error threshold for omxApproxEquals. Abs(x[i][j]-y[i][j]) must be less than epsilon[i][j].

Examples

A <- mxMatrix(values = runif(25), nrow = 5, ncol = 5, name = 'A')B <- mxMatrix(values = runif(25), nrow = 5, ncol = 5, name = 'B')EPSILON <- mxMatrix(values = 0.04*1:25, nrow = 5, ncol = 5, name = "EPSILON")model <- mxModel(A, B, EPSILON, name = 'model')mxEval(omxNot(A), model)mxEval(omxGreaterThan(A,B), model)mxEval(omxLessThan(B,A), model)mxEval(omxOr(omxNot(A),B), model)mxEval(omxAnd(omxNot(B), A), model)mxEval(omxApproxEquals(A,B, EPSILON), model)

Estimate the Jacobian of manifest model with respect to parameters

Description

The manifest model excludes any latent variables or processes. ForRAM and LISREL models, the manifest model contains only themanifest variables with free means, covariance, and thresholds.

Usage

omxManifestModelByParameterJacobian(model, defvar.row = 1, standardize = FALSE)

Arguments

model

an mxModel

defvar.row

which row to use for definition variables

standardize

logical, whether or not to standardize the parameters

Details

The Jacobian is estimated by the central finite difference.

If thestandardize argument is TRUE, then the Jacobian is for the standardized model.For Normal expectations the standardized manifest model has the covariances returned as correlations, the variances returned as ones, the means returned as zeros, and the thresholds are returned as z-scores.For the thresholds the z-scores are computed by using the model-implied means and variances.

Value

a matrix with manifests in the rows and original parameters in the columns

See Also

mxGetExpected


MxMatrix operations

Description

omxCbind columnwise binding of two or more MxMatrices.omxRbind rowwise binding of two or more MxMatrices.omxTranspose transpose of MxMatrix.

Usage

omxCbind(..., allowUnlabeled =     getOption("mxOptions")[["Allow Unlabeled"]],     dimnames = NA, name = NA)omxRbind(..., allowUnlabeled =     getOption("mxOptions")[["Allow Unlabeled"]],     dimnames = NA, name = NA)omxTranspose(matrix, allowUnlabeled =     getOption("mxOptions")[["Allow Unlabeled"]],     dimnames = NA, name = NA)

Arguments

...

two or more MxMatrix objects

matrix

MxMatrix input

allowUnlabeled

whether or not to accept free parameters with NA labels

dimnames

list. The dimnames attribute for the matrix: a list of length 2 giving the row and column names respectively. An empty list is treated as NULL, and a list of length one as row names. The list can be named, and the list names will be used as names for the dimensions.

name

an optional character string indicating the name of the MxMatrix object


Multivariate Normal Integration

Description

Given a covariance matrix, a means vector, and vectors of lower and upper bounds, returns the multivariate normal integral across the space between bounds.

Usage

omxMnor(covariance, means, lbound, ubound)

Arguments

covariance

the covariance matrix describing the multivariate normal distribution.

means

a row vector containing means of the variables of the underlying distribution.

lbound

a row vector containing the lower bounds of the integration in each variable.

ubound

a row vector containing the upper bounds of the integration in each variable.

Details

The order of columns in the ‘means’, ‘lbound’, and ‘ubound’ vectors are assumed to be the same as that of the covariance matrix. That is, means[i] is considered to be the mean of the variable whose variance is in covariance[i,i]. That variable will be integrated from lbound[i] to ubound[i] as part of the integration.

The value of ubound[i] or lbound[i] may be set to Inf or -Inf if a boundary at positive or negative infinity is desired.

For all i, ubound[i] must be strictly greater than lbound[i].

The algorithm for multivariate normal integration we use is Alan Genz's FORTRAN implementation of the SADMVN routine described by Genz (1992).

References

Genz, A. (1992). Numerical Computation of Multivariate Normal Probabilities.Journal of Computational Graphical Statistics, 1, 141-149.

Examples

data(myFADataRaw)covariance <- cov(myFADataRaw[,1:3])means <- colMeans(myFADataRaw[,1:3])lbound <- c(-Inf, 0,   1)    # Integrate from -Infinity to 0 on first variable ubound <- c(0,    Inf, 2.5)  # From 0 to +Infinity on second, and from 1 to 2.5 on thirdomxMnor(covariance, means, lbound, ubound)# 0.0005995# An alternative specification of the bounds follows# Integrate from -Infinity to 0 on first variable v1bound = c(-Inf, 0)# From 0 to +Infinity on secondv2bound = c(0, Inf)# and from 1 to 2.5 on thirdv3bound = c(1, 2.5)bounds <- cbind(v1bound, v2bound, v3bound)lbound <- bounds[1,]  ubound <- bounds[2,]  omxMnor(covariance, means, lbound, ubound)

Remove all instances of data from a model

Description

For very large data, it can be desirable to discard data after the modelis run. That is what the purpose of this function.

Data is discarded from the model and all submodels recursively.

Usage

omxModelDeleteData(model)

Arguments

model

a MxModel object.

Examples

library(OpenMx)data(demoOneFactor)manifests <- names(demoOneFactor)latents   <- c("G")factorModel <- mxModel(model="One Factor", type="RAM",      manifestVars = manifests,      latentVars   = latents,      mxPath(from=latents, to=manifests),      mxPath(from=manifests, arrows=2),      mxPath(from=latents, arrows=2,free=FALSE, values=1.0),      mxData(cov(demoOneFactor), type="cov",numObs=500))factorFit <-mxRun(factorModel)object.size(factorFit)factorFit <- omxModelDeleteData(factorFit)object.size(factorFit)factorFit$data

omxNameAnonymousParameters

Description

Assign new names to the unnamed parameters

Usage

omxNameAnonymousParameters(model, indep = FALSE)

Arguments

model

the MxModel

indep

whether models are independent

Value

a list with components for the new MxModel with named parameters, and the new names.


Calculate confidence intervals without re-doing the primary optimization.

Description

OpenMx provides two functions to calculate confidence intervals for already-runMxModel objects that contain anMxInterval object (i.e., anmxCI() statement), without recalculating point estimates, fitfunction derivatives, or expectations.

The primary function isomxRunCI(). This is a wrapper foromxParallelCI() with argumentsrun=TRUE andindependentSubmodels=FALSE, and is the recommended interface.

omxParallelCI() does the work of calculating confidence intervals. The "parallel" in the function's name refers to the not-yet-implemented feature of running independentsubmodels in parallel.

Usage

omxRunCI(model, verbose = 0, optimizer = "SLSQP")omxParallelCI(model, run = TRUE, verbose = 0, independentSubmodels = TRUE,optimizer = mxOption(NULL, "Default optimizer"))

Arguments

model

AnMxModel object that contains anMxInterval object (i.e., anmxCI() statement).

run

Logical; ForomxParallelCI(), determines if the model with its new compute plan ismxRun() before being returned. Hard-codedTRUE for omxRunCI.

verbose

Integer; defaults to zero; verbosity level passed to MxCompute* objects.

independentSubmodels

Logical; ForomxParallelCI() defaults toTRUE. Hard coded FALSE foromxRunCI(). Also see "Details."

optimizer

Character string selecting the gradient-descent optimizer to be used to find confidence limits; one of "NPSOL", "CSOLNP", or "SLSQP". The default foromxParallelCI() is the current value ofmxOption "Default optimizer", and foromxRunCI(), is "SLSQP".

Details

WhenindependentSubmodels=TRUE,omxParallelCI() creates an independent MxModel object for each quantity specified in the 'reference' slot ofmodel'sMxInterval object, and places these independent MxModels insidemodel. Each of these independent submodels calculates the confidence limits of its own quantity when the container model is run. WhenindependentSubmodels=FALSE, no submodels are added tomodel. Instead,model is provided with a dedicatedcompute plan consisting only of anMxComputeConfidenceInterval step. Note that usingindependentSubmodels=FALSE will overwrite any compute plan already insidemodel.

Value

The functions returnmodel, augmented with independent submodels (ifindependentSubmodels=TRUE) or with a non-default compute plan (ifindependentSubmodels=FALSE), and possibly having been passed throughmxRun() (ifrun=TRUE). Naturally, ifrun=FALSE, the user can subsequentlyrun the returned model to obtain confidence intervals. Users are cautioned that the returned model may not be very amenable to being further modified and re-fitted (e.g., having some free parameters fixed viaomxSetParameters() and passed throughmxRun() to get new point estimates) unless the added submodels or the non-default compute plan are eliminated. The exception is ifrun=TRUE andindependentSubmodels=TRUE (which is always the case withomxRunCI()), since the non-default compute plan is set to be non-persistent, and will automatically be replaced with a default compute plan the next time the model is passed tomxRun().

See Also

mxCI(),MxInterval,mxComputeConfidenceInterval()

Examples

require(OpenMx)# 1. Build and run a model, don't compute intervals yetdata(demoOneFactor)manifests <- names(demoOneFactor)latents <- c("G")factorModel <- mxModel("One Factor", type="RAM",manifestVars=manifests, latentVars=latents,mxPath(from=latents, to=manifests), mxPath(from=manifests, arrows=2),mxPath(from=latents, arrows=2, free=FALSE, values=1.0),mxData(observed=cov(demoOneFactor), type="cov", numObs=500),# Add confidence intervals for (free) params in A and S matrices.mxCI(c('A', 'S')))factorRun <- mxRun(factorModel)# 2. Compute the CIs on factorRun, and view summaryfactorCI1 <- omxRunCI(factorRun)summary(factorCI1)$CI# 3. Use low-level omxParallelCI interfacefactorCI2 <- omxParallelCI(factorRun) # 4. Build, but don't run the newly-created modelfactorCI3 <- omxParallelCI(factorRun, run= FALSE)

omxQuotes

Description

Quote helper function, often for error messages.

Usage

omxQuotes(name)

Arguments

name

a character vector

Details

This is a helper function for creating a nicelyput together formatted string.

Value

a character string

Examples

omxQuotes(c("Oh", "blah", "dee", "Oh", "blah", "da"))omxQuotes(c("A", "S", "F"))omxQuotes("Hello World")

omxRAMtoML

Description

Convert a RAM model to an ML model

Usage

omxRAMtoML(model)

Arguments

model

the MxModel

Details

This is a legacy function that was once used to convert RAM models to ML modelsin the old (1.0 release of OpenMx) objective function style.

Value

an ML model with an ML objective


Get the RMSEA with confidence intervals from model

Description

This function calculates the Root Mean Square Error of the Approximation (RMSEA) for a model and computes confidence intervals for that fit statistic.

Usage

omxRMSEA(model, lower=.025, upper=.975, null=.05, ...)

Arguments

model

An MxModel object for which the RMSEA is desired

lower

The lower confidence bound for the confidence interval

upper

The upper confidence bound for the confidence interval

null

Value of RMSEA used to test for close fit

...

Further named arguments passed to summary

Details

To help users obtain fit statistics related to the RMSEA, this function confidence intervals and a test for close fit. The user determines how close the fit is required to be by setting thenull argument to the value desired for comparison.

Value

A named vector with elements lower, est.rmsea, upper, null, and 'Prob(x <= null)'.

References

Browne, M. W. & Cudeck, R. (1992). Alternative Ways of Assessing Model Fit.Sociological Methods and Research,21, 230-258.

Examples

require(OpenMx)data(demoOneFactor)manifests <- names(demoOneFactor)latents <- c("G")factorModel <- mxModel("One Factor",                        type="RAM",                       manifestVars=manifests,                        latentVars=latents,                       mxPath(from=latents, to=manifests),                       mxPath(from=manifests, arrows=2),                       mxPath(from=latents, arrows=2, free=FALSE, values=1.0),                       mxData(observed=cov(demoOneFactor), type="cov", numObs=500))factorRun <- mxRun(factorModel)factorSat <- mxRefModels(factorRun, run=TRUE)summary(factorRun, refModels=factorSat)# Gives RMSEA with 95% confidence intervalomxRMSEA(factorRun, .05, .95, refModels=factorSat)# Gives RMSEA with 90% confidence interval#  and probability of 'close enough' fit

Read a GCTA-Format Binary GRM into R.

Description

This simple function is adapted from syntax in the GCTA User Manual. It loads a binary genomic-relatedness matrix (GRM) from disk into R's workspace.

Usage

omxReadGRMBin(prefix, AllN=FALSE, size=4, returnList=FALSE)

Arguments

prefix

Character string: everything in the path, relative toR's working directory, and filenames of the GRM files preceding '.grm.*'. See below, under "Details"

AllN

Logical. IfFALSE (default), then whenomxReadGRMBin() callsreadBin(), it passes a value of 1 for argumentn. ifTRUE, then it instead passes a value equal to the number of nonredundant elements in the GRM.

size

Passed toreadBin().

returnList

Logical. IfFALSE (default),omxReadGRMBin returns the GRM. IfTRUE, thenomxReadGRMBin returns a list as described below, under "Value".

Details

A GRM calculated in GCTA that is saved to disk in binary format comprises three files, the filenames of which have the same stem but different extensions. The first, with extension "grm.bin", is the actual binary file containing the GRM elements. The second, with extension "grm.N.bin", contains information about how many genetic markers were used to calculate the GRM. The third, with extension "grm.id", is a text file containing two columns of data, respectively, the participant family and individual IDs.omxReadGRMBin() is meant to be used with all three files together in the same directory. Thus, argumentprefix should be everything in the path (relative toR's working directory) and filenames of those GRM files, up to the first period in their extensions. In practice, it is simplest to setR's working directory to whichever directory contains the files, and simply provide the filename stem for argumentprefix.

omxReadGRMBin() opens three file connections, one for each file.

Value

IfreturnList=FALSE (the default), then the GRM itself is returned as a numeric matrix, with each row and column named as the adhesion of the corresponding participant's family ID and individual ID, separated by an underscore. Otherwise, a list of the following four elements is returned:

  1. "diag": Numeric vector containing the GRM's diagonal elements.

  2. "off": Numeric vector containing the GRM's off-diagonal elements.

  3. "id": Dataframe containing the family and individual IDs corresponding to the rows and columns of the GRM.

  4. "N": Numeric; number of markers used to calculate the GRM.

References

Yang J, Lee SH, Goddard ME, Visscher, PM. GCTA: A tool for genome-wide complex trait analysis. American Journal of Human Genetics 2011;88:76-82. doi: 10.1016/j.ajhg.2010.11.011.

Yang J, Lee SH, Goddard ME, Visscher, PM. Genome-wide complex trait analysis (GCTA): Methods, data analyses, and interpretations. In Gondro, C et al. (Eds.),Genome-Wide Association Studies and Genomic Prediction. New York: Springer;2013. p. 215-236.

GCTA website:https://cnsgenomics.com/software/gcta/#Overview.

Code foromxReadGRMBin() was adapted from syntax by Jiang Yang in the GCTA User Manual, version 1.24, dated 28 July 2014, retrieved from http://cnsgenomics.com/software/gcta/GCTA_UserManual_v1.24.pdf .


On-Demand Parallel Sapply

Description

If the snowfall library is loaded, then this function callssfSapply. Otherwise it invokessapply.

Usage

omxSapply(x, fun, ..., simplify = TRUE, USE.NAMES = TRUE)

Arguments

x

a vector (atomic or list) or an expressions vector. Other objects (including classed objects) will be coerced byas.list.

fun

the function to be applied to each element ofx.

...

optional arguments tofun.

simplify

logical; should the result be simplified to a vector or matrix if possible?

USE.NAMES

logical; ifTRUE and ifx is a character, usex asnames for the result unless it had names already.

See Also

omxApply,omxLapply

Examples

x <- list(a = 1:10, beta = exp(-3:3), logic = c(TRUE,FALSE,FALSE,TRUE))# compute the list mean for each list elementomxSapply(x, quantile)

Create Reference (Saturated and Independence) Models

Description

This function creates and, optionally, runs saturated and independence (null) models of a base model or data set for use withmxSummary to enable fit indices that depend on these models. Note that there are cases where this function is not valid for use, or should be used with caution (see below, under "Warnings").

Usage

mxRefModels(x, run=FALSE, ..., distribution="default", equateThresholds = TRUE)

Arguments

x

A MxModel object, data frame, or matrix.

run

logical. If TRUE, runs the models before returning;otherwise returns built models without running.

...

Not used. Forces remaining arguments to be specified by name.

distribution

character. Which distribution to assume.

equateThresholds

logical. Whether ordinal thresholds should beconstrained equal across groups.

Details

For typical structural equation models the saturated model is the free-est possible model. Not only all variances (and, when possible, all means) are estimated, but also all covariances. In the case of ordinal data, the ordinal means are fixed to zero and the thresholds are estimated. For binary variables, those variances are also constrained to one. This is the free-est possible model that is identified. The saturated model is used in calculating fit statistics such as the RMSEA, and Chi-squared fit indices.

The independence model, sometimes called the null model, is a model in which each variable is treated as being completely independent of every other variable. As such, all the variances and, when possible, all means are estimated. However, covariances are set to zero. Ordinal variables are handled the same for the independence and saturated models. The independence model is used, along with the saturated model, to create CFI and TLI fit indices.

The saturated and independence models could be used to create further fit indices. However, OpenMx does not recommend using GFI, AGFI, NFI (aka Bentler-Bonett), or SRMR. The page formxSummary has information about why.

When themxFitFunctionMultigroup fit function is used,mxRefModels creates the appropriate multi-group saturated and independence models. Saturated and independence models are created separately for each group. Each group has its own saturated and independence model. The multi-group saturated model is a multi-group model where each group has its own saturated model, and similarly for the independence model.

When an MxModel has been run, some effort is made to make the reference models for only the variables used in the model. For covariance data, all variables are modeled by default. For raw data when the model has been run, only the modeled variables are used in the reference models. This matches the behavior ofmxModel.

In general, it is best practice to givemxRefModels a model that has already been run.

Multivariate normal models with all ordinal data and no missing valuescan use the saturated multinomial distribution. This is much faster thanestimation of the saturated multivariate normal model. Usedistribution='multinomial' to avail this option.

Warnings

One potentially important limitation of themxRefModels function is for behavior-genetic models. If variables 'x', 'y', and 'z' are measured on twins 1 and 2 creating the modeled variables 'x1', 'y1', 'z1', 'x2', 'y2', 'z2', then this function may not create the intended saturated or independence models. In particular, the means of 'x1' and 'x2' are estimated separately. Similarly, the covariance of 'x1' with 'y1' and 'x2' with 'y2' are allowed be be distinct:cov(x1, y1) != cov{x2, y2}. Moreover, the cross-twin covariances are estimated: e.g.cov(x1, y2) != 0.

Another potential misuse of this function is for models with definition variables. If definition variables are used, the saturated and independence model may not be correct because they do not account for the definition variables.

The are a few considerations specific to IFA models(mxExpectationBA81).The independence model preserves equality constraints among itemparameters from the original model.The saturated model is a multinomial distribution with the proportionsequal to the proportions in your data. For example, if you have 2dichotomous items then there are 4 possible response patterns: 00, 01, 10, 11.A multinomial distribution for these 2 items is fully specified by 3proportions or 3 parameters: a, b, c,1.0-(a+b+c).Hence, there is no need to optimize the saturated model.When there is no missing data,the deviance is immediately known as-2 * sum(log proportions).Typical Bayesian priors involve latentfactors (various densities on the pseudo-guessing lower bound, log normon loading, and uniqueness prior). These priors cannot be includedin the independence model because there are no latent factors.Therefore, exercise caution when comparing the independence modelto a model that includes Bayesian priors.

mxRefModels() is not compatible withGREML expectation, as there is nosensible general definition for a saturated GREML-type model.

References

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

Examples

require(OpenMx)data(demoOneFactor)manifests <- names(demoOneFactor)latents <- c("G")factorModel <- mxModel("OneFactor", type = "RAM",    manifestVars = manifests, latentVars = latents,    mxPath(from = latents, to=manifests, values = diag(var(demoOneFactor))*.2),    mxPath(from = manifests, arrows = 2, values = diag(var(demoOneFactor))*.8),    mxPath(from = latents, arrows = 2, free = FALSE, values = 1),    mxData(cov(demoOneFactor), type = "cov", numObs = 500))factorRun <- mxRun(factorModel)factorSat <- mxRefModels(factorRun, run=TRUE)summary(factorRun)summary(factorRun, refModels=factorSat)# A raw-data example where using mxRefModels adds fit indicesm1 <- mxModel("OneFactor", type = "RAM",    manifestVars = manifests, latentVars = latents,    mxPath(latents, to=manifests, values = diag(var(demoOneFactor))*.2),    mxPath(manifests, arrows = 2, values = diag(var(demoOneFactor))*.8),    mxPath(latents, arrows = 2, free = FALSE, values = 1),    mxPath("one", to = latents, free = FALSE, values = 0),    mxPath("one", to = manifests, values = 0),    mxData(demoOneFactor, type = "raw"))m1 <- mxRun(m1)summary(m1) # CFI, TLI, RMSEA missingsummary(m1, refModels=mxRefModels(m1, run = TRUE))

Filter rows and columns from an mxMatrix

Description

This function filters rows and columns from a matrix using a single row or column R matrix as a selector.

Usage

omxSelectRowsAndCols(x, selector)omxSelectRows(x, selector)omxSelectCols(x, selector)

Arguments

x

the matrix to be filtered

selector

A single row or single column R matrix indicating which values should be filtered from the mxMatrix.

Details

omxSelectRowsAndCols, omxSelectRows, and omxSelectCols returns the filtered entries in a target matrix specified by a single row or single column selector matrix. Each entry in the selector matrix is treated as a logical data indicating if the corresponding entry in the target matrix should be excluded (0 or FALSE) or included (not 0 or TRUE). Typically the function is used to filter data from a target matrix using an existence vector which specifies what data entries are missing. This can be seen in the demo: RowObjectiveFIMLBivariateSaturated.

Value

Returns a new matrix with the filtered data.

References

The function is most often used when filtering data for missingness. This can be seen in the demo: RowObjectiveFIMLBivariateSaturated. The OpenMx User's guide can be found athttps://openmx.ssri.psu.edu/documentation. The omxSelect* functions share some similarity to the Extract function in the R programming language.

Examples

loadings <- matrix(1:9, 3, 3, byrow= TRUE)existenceList <- c(1, 0, 1)existenceList <- matrix(existenceList, 1, 3, byrow= TRUE)rowsAndCols <- omxSelectRowsAndCols(loadings, existenceList)rows <- omxSelectRows(loadings, existenceList)cols <- omxSelectCols(loadings, existenceList)

Assign Model Parameters

Description

Modify the attributes of parameters in a model. This function cannot modify parameters that have NA labels.Often you will want to callomxAssignFirstParameters after using this, to force the startingvalues of equated parameters to the same value (otherwise the model cannot begin to be evaluated)

Usage

omxSetParameters(model, labels=names(coef(model)), free = NULL, values = NULL,    newlabels = NULL, lbound = NULL, ubound = NULL, indep = FALSE,    strict = TRUE, name = NULL)

Arguments

model

an MxModel object.

labels

a character vector of target parameter names.

free

a boolean vector of parameter free/fixed designations.

values

a numeric vector of parameter values.

newlabels

a character vector of new parameter names.

lbound

a numeric vector of lower bound values.

ubound

a numeric vector of upper bound values.

indep

boolean. set parameters in independent submodels.

strict

boolean. If TRUE then throw an error when a label does not appear in the model.

name

character string. (optional) a new name for the model.

See Also

omxGetParameters,omxAssignFirstParameters

Examples

A <- mxMatrix('Full', 3, 3, labels = c('a','b', NA), free = TRUE, name = 'A')model <- mxModel(model="testModel7", A, name = 'model')# set value of cells labelled "a" and "b" to 1 and 2 respectivelymodel <- omxSetParameters(model, c('a', 'b'), values = c(1, 2))# set label of cell labelled "a" to "b" and vice versamodel <- omxSetParameters(model, c('a', 'b'), newlabels = c('b', 'a'))# set label of cells labelled "a" to "b"model <- omxSetParameters(model, c('a'), newlabels = 'b')# ensure initial values are the same for each instance of a labeled parametermodel <- omxAssignFirstParameters(model)

Internal OpenMx algebra operations

Description

This is an internal table used in the OpenMx backend.


Data for ordinal twin model

Description

Example data for ordinal twin-data modelling. Three variables measured in each twin.

Usage

data("ordinalTwinData")

Format

A data frame with 139 observations on the following 7 variables.

zyg

a numeric vector

var1_twin1

a numeric vector

var2_twin1

a numeric vector

var3_twin1

a numeric vector

var1_twin2

a numeric vector

var2_twin2

a numeric vector

var3_twin2

a numeric vector

Examples

data(ordinalTwinData)str(ordinalTwinData)

predict method forMxModel objects

Description

predict method forMxModel objects

Usage

## S3 method for class 'MxModel'predict(  object,  newdata = NULL,  interval = c("none", "confidence", "prediction"),  method = c("ML", "WeightedML", "Regression", "Kalman"),  level = 0.95,  type = c("latent", "observed"),  ...)

Arguments

object

an MxModel object from which predictions are desired

newdata

an optionaldata.frame object. See details.

interval

character indicating what kind of intervals are desired. 'none' gives no intervals, 'confidence', gives confidence intervals, 'prediction' gives prediction intervals.

method

character the method used to create the predictions. See details.

level

the confidence or predictions level, ignored if not using intervals

type

character the type of thing you want predicted: latent variables or manifest variables.

...

further named arguments

Details

Thenewdata argument is either adata.frame orMxData object. In the latter case is replaces the data in the top level model. In the former case, it is passed as theobserved argument ofmxData withtype='raw' and must accept the same further arguments as the data in the model passed in theobject argument.

The available methods for prediction are 'ML', 'WeightedML', 'Regression', and 'Kalman'. See the help page formxFactorScores for details on the first three of these. The 'Kalman' method uses the Kalman filter to create predictions for state space models.


Vectorize By Row

Description

This function returns the vectorization of an input matrix in a row by row traversal of the matrix. The output is returned as a column vector.

Usage

rvectorize(x)

Arguments

x

an input matrix.

See Also

cvectorize,vech,vechs

Examples

rvectorize(matrix(1:9, 3, 3))rvectorize(matrix(1:12, 3, 4))

Model Summary

Description

This function returns summary statistics of a model. These include model statistics (parameters, degrees of freedom and likelihood),fit statistics such as AIC, parameter estimates and standard errors (when available), as well as version and timing informationand possible warnings about estimates.

Usage

## S3 method for class 'MxModel'summary(object, ..., verbose=FALSE)

Arguments

object

A MxModel object.

...

Any number of named arguments (see below).

verbose

Whether to include extra diagnostic information.

Details

mxSummary allows the user to set or override the following parameters of the model:

numObs

Numeric. Specify the total number of observations for the model.

numStats

Numeric. Specify the total number of observed statistics for the model.

refModels

List of MxModel objects. Specify a saturated and independence likelihoods in single argument for testing.

SaturatedLikelihood

Numeric or MxModel object. Specify a saturated likelihood for testing.

SaturatedDoF

Numeric. Specify the degrees of freedom of the saturated likelihood for testing.

IndependenceLikelihood

Numeric or MxModel object. Specify an independence likelihood for testing.

IndependenceDoF

Numeric. Specify the degrees of freedom of the independence likelihood for testing.

indep

[Deprecated]

verbose

logical. Changes the printing style for summary (see Details)

boot.quantile

numeric. A vector of quantiles to be used tosummarize bootstrap replication.

boot.SummaryType

character. One of ‘quantile’ or ‘bcbci’.

Standard Output

The standard output consists of a table of free parameters, tables of model and fit statistics, information on the time taken to run the model, the optimizer used, and the version of OpenMx.

Table of free parameters

Free parameters in the model are reported in a table with columns for the name (label) of the parameter, the matrix, row and col containing the parameter, the parameter estimate itself, and any lower or upper bounds set for the parameter.

Additional columns: standard errors, exclamation marks ("!"), and the 'A' (asymmetry) warning column

When the covariance matrix of the parameter estimates is available, either via the inverse Hessian, or from bootstrap resampling, or as a function of the full-weight matrix in the case of WLS, standard errors are reported in the column "Std.Error".

An exclamation mark ("!") can appear in two places: after a lower or upper bound, and in the 'A' column. When an exclamation mark appears after a bound in the lbound or ubound columns, it indicates that the solution was sufficiently close to the bound that the optimizer could not ignore the bound during its last few iterations.

An exclamation mark may also appear under the 'A' column, but in this case it has a different meaning. If the information matrix was estimated using finite differences then an additional diagnostic column 'A' is displayed. An exclamation point in the 'A' column indicates that the gradient appears to be asymmetric and the standard error might not accurately reflect the sampling variability of that parameter. As a precaution, it is recommended that you compare the SEs with profile likelihood-based confidence intervals (mxCI) or bootstrap confidence intervals.

Fit statistics

AIC and BICInformation Criteria are reported in a table showing different versions of the information criteria obtained using different penalties. AIC is reported with both a Parameters Penalty and a Degrees of Freedom Penalty version. AIC generally takes the formFit + 2*k. With the Parameters Penalty version,k is the number of free parameters:AIC.param = Fit + 2*param. With the Degrees of Freedom Penalty,k is minus one times the model degrees of freedom. So the penalty is subtracted instead of added:AIC.param = Fit - 2*df. The Degrees of Freedom penalty was used in Classic Mx. BIC is defined similarly:Fit + k*log(N) wherek is either the number of free parameters or minus one times the model degrees of freedom. The Sample-Size-Adjusted BIC is only defined for the parameters penalty:Fit + k*log((N+2)/24). Similarly, the Sample-Size-Adjusted AIC isFit + 2*k + 2*k*(k+1)/(N-k-1). For raw data models,Fit is the minus 2 log likelihood,-2LL. For covariance data,Fit is the Chi-squared statistic. The-2LL and saturated likelihood values reported under covariance data are not necessarily meaningful on their own, but their difference yields the Chi-squared value.

Additional fit statistics

When the model has a saturated likelihood, several additional fit indices are printed, including Chi-Squared, CFI, TLI, RMSEA and p RMSEA <= 0.05. For covariance data, saturated and independence models are fitted automatically so all fit indices are reported.

For raw data (to save computational time), the reference models needed to compute these absolute statistics arenot estimated by default. They are available once you fit reference models.

TherefModels,SaturatedLikelihood,SaturatedDoF,IndependenceLikelihood, andIndependenceDoF arguments can be used to obtain these additional fit statistics. An easy way to make reference models for most cases is provided by themxRefModels function (see the example given inmxRefModels).

When theSaturatedLikelihood orIndependenceLikelihood arguments are used, OpenMx attempts to calculate the appropriate degrees of freedom. However, depending on the model, it may sometimes be necessary for the user to also explicitly provide the correspondingSaturatedDoF and/orIndependenceDoF. Again, for the vast majority of cases, themxRefModels function handles these situations effectively and conveniently.

Notes on fit statistics

With regard to RMSEA, it is important to note that OpenMx does not currently make a multigroup adjustment that some other structural equation modeling programs make. In particular, we do not multiply the single-group RMSEA by the square root of the number of groups as suggested by Steiger (1998). The RMSEA we use is based on the model likelihood (and degrees of freedom) as compared to the saturated model likelihood (and degrees of freedom), and we do not feel the adjustment is appropriate in this case.

OpenMx does not recommend (and does not compute) some fit indices including GFI, AGFI, NFI, and SRMR. The Goodness of Fit Index (GFI) and Adjusted Goodness of Fit Index (AGFI) are not recommended because they are strongly influenced by sample size and have rather high Type I error rates (Sharma, Mukherjee, Kumar, & Dillon, 2005). The Normed Fit Index (NFI) has no penalty for model complexity. That is, adding more parameters to a model always improves the NFI, regardless of how useful those parameters are. Because the Non-Normed Fit Index (NNFI), also known as the Tucker-Lewis Index (TLI), does adjust for model complexity it is used instead. Lastly, the Standardized Root Mean Square Residual (SRMR) is not reported because it (1) only applies to covariance models, having no direct extension to missing data, (2) has no penalty for model complexity, similar to the NFI, and (3) is positively biased (Hu & Bentler, 1999).

verbose

Theverbose argument changes the printing style for thesummary of a model. Whenverbose=FALSE, a relatively minimal amount of information is printed: the free parameters, the likelihood, and a few fit indices. Whenverbose=TRUE, the compute plan, data summary, and additional timing information are always printed. Moreover, available fit indices are printed regardless of whether or not they are defined. The undefined fit indices are printed asNA. In addition, the condition number of the information matrix, and the maximum absolute gradient may also be shown.

note: Theverbose argument only changes the printing style, all of the same information is calculated and exists in the output ofsummary. More information is displayed whenverbose=TRUE, and less whenverbose=FALSE.

Summary for bootstrap replications

Summarization of bootstrap replications is controlled by two options: ‘boot.quantile’ and ‘boot.SummaryType’. To obtain a two-sided 95% width confidence interval, useboot.quantile=c(.025,.975). Options for ‘boot.SummaryType’ are ‘quantile’ (using R's standardstats::quantile function) and ‘bcbci’ for bias-corrected bootstrap confidence intervals. The latter, ‘bcbci’, is the default due to its superior theoretical properties.

References

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

Hu, L., & Bentler, P. M. (1999). Cutoff criteria for fit indexes in covariance structure analysis: Conventional criteria versus new alternatives.Structural Equation Modeling, 6, 1-55.

Savalei, V. (2012). The relationship between root mean square error of approximation and model misspecification in confirmatory factor analysis models.Educational and Psychological Measurement, 72(6), 910-932.

Sharma, S., Mukherjee, S., Kumar, A., & Dillon, W.R. (2005). A simulation study to investigate the use of cutoff values for assessing model fit in covariance structure models.Journal of Business Research, 58, 935-43.

Steiger, J. H. (1998). A note on multiple sample extensions of the RMSEA fit index.Structural Equation Modeling: A Multidisciplinary Journal, 5(4), 411-419. DOI: 10.1080/10705519809540115

See Also

mxBootstrapmxCIas.statusCode

Examples

library(OpenMx)data(demoOneFactor)  # load the demoOneFactor dataframemanifests <- names(demoOneFactor) # set the manifest to the 5 demo variableslatents <- c("G")  # define 1 latent variablemodel <- 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 <- mxRun(model) # Run the model, returning the result into model# Show summary of the fitted modelsummary(model)# Compute the summary and store in the variable "statistics"statistics <- summary(model)# Access components of the summarystatistics$parametersstatistics$SaturatedLikelihood# Specify a saturated likelihood for testingsummary(model, SaturatedLikelihood = -3000)# Add a CI and view it in the summarymodel = mxRun(mxModel(model=model, mxCI("b5")), intervals = TRUE)summary(model)## How to use summary() with reference models, to get fit indices:## Not run: model <- mxModel("One Factor",type="RAM",manifestVars = manifests,latentVars = latents,mxPath(from=latents, to=manifests,values=0.8),mxPath(from=manifests, arrows=2,values=1),mxPath(from=latents, arrows=2, free=FALSE, values=1.0),mxPath(from="one",to=manifests,values=0.1),mxData(demoOneFactor, type="raw"))model <- mxRun(model)summary(model) #<--Some fit indices missing.referenceModelList <- mxRefModels(x=model,run=T)summary(model,refModels=referenceModelList) #<--Fit indices present## End(Not run)

trace

Description

This function returns the trace of an n-by-n square matrix x, defined to be the sum of the elementson the main diagonal (the diagonal from the upper left to the lower right).

Usage

tr(x)

Arguments

x

an input matrix. Must be square

Details

The input matrix must be square.

See Also

vech,rvectorize,cvectorize

Examples

tr(matrix(1:9, 3, 3))tr(matrix(1:12, 3, 4))

Australian twin sample biometric data.

Description

Australian twin data with 3,808 observations on the 12 variables including body mass index (BMI) assessed in both MZ and DZ twins.

Questionnaires were mailed to 5,967 pairs age 18 years and over. These data consist of completed questionnaires returned by both members of 3,808 (64 percent) pairs. There are two cohort blocks in the data: a younger group (zyg 1:5), and an older group (zyg 6:10)

It is a wide dataset, with two individuals per line. Families are identified by the variable “fam”.

Data include zygosity (zyg), along with heights in meters, weights inkg, and the derived variables BMI in kg/m^2 (stored as “htwt1”and “htwt2”), as well as the 7 times the natural log of this variable,stored as bmi1 and bmi2. The logged values are more closelynormally distributed while scaling by 7 places them into a similar rangeto the original variable.

For convenience, zyg is broken out into separate “zygosity” and “cohort” factors. “zygosity” iscoded as a factor with 5-levels: MZFF, MZMM, DZFF, DZMM, DZOS. DZOS are in Female/Male wide order.

Usage

data(twinData)

Format

A data frame with 3808 observations on the following 12 variables.

fam

The family ID

age

Age in years (of both twins)

zyg

Code for zygosity and cohort (see details)

part

A numeric vector

wt1

Weight of twin 1 (kg)

wt2

Weight of twin 2 (kg)

ht1

Height of twin 1 (m)

ht2

Height of twin 2 (m)

htwt1

Raw BMI of twin 1 (kg/m^2)

htwt2

Raw BMI of twin 2 (kg/m^2)

bmi1

7*log(BMI) of twin 1

bmi2

7*log(BMI) of twin 2

cohort

Either “younger” or “older”

zygosity

Zygosity factor with levels: MZFF, MZMM, DZFF, DZMM, DZOS

age1

Age of Twin 1

age2

Age of Twin 2

Details

“zyg” codes twin-zygosity as follows:1 == MZFF (i.e MZ females)2 == MZMM (i.e MZ males)3 == DZFF4 == DZMM5 == DZOS opposite sex pairs

Note: zyg 6:10 are for an older cohort in the sample. So:6 == MZFF (i.e MZ females)7 == MZMM (i.e MZ males)8 == DZFF9 == DZMM10 == DZOS opposite sex pairs

The “zygosity” and “cohort” variables take care of this for you (conventions differ).

References

Martin, N. G. & Jardine, R. (1986). Eysenck's contribution to behavior genetics. In S. Modgil & C. Modgil (Eds.),Hans Eysenck: Consensus and Controversy. Falmer Press: Lewes, Sussex.

Martin, N. G., Eaves, L. J., Heath, A. C., Jardine, R., Feingold, L. M., & Eysenck, H. J. (1986). Transmission of social attitudes.Proceedings of the National Academy of Science,83, 4364-4368.

Examples

data(twinData)str(twinData)plot(wt1 ~ wt2, data = twinData)selVars = c("bmi1", "bmi2")mzData <- subset(twinData, zyg == 1, selVars)dzData <- subset(twinData, zyg == 3, selVars)# equivalentlymzData <- subset(twinData, zygosity == "MZFF", selVars)# Disregard sex, pick older cohortmz <- subset(twinData, zygosity %in% c("MZFF","MZMM") & cohort == "older", selVars)

Twin biometric data (Practice cleaning: "." for missing data, wrong data types etc.)

Description

Data set used in some of OpenMx's examples.

Usage

data("twin_NA_dot")

Format

A data frame with 3808 observations on the following variables.

fam

Family ID variable

age

Age of the twin pair. Range: 17 to 88, coded as factor

zyg

Integer codes for zygosity and gender combinations

part

Cohort

wt1

Weight in kilograms for twin 1 (this and following have "." embedded as NA...)

wt2

Weight in kilograms for twin 2

ht1

Height in meters for twin 1

ht2

Height in meters for twin 2

htwt1

Product of ht and wt for twin 1

htwt2

Product of ht and wt for twin 2

bmi1

Body Mass Index for twin 1

bmi2

Body Mass Index for twin 2

Details

Same asmyTwinData but has . as the missing data value instead of NA.

Source

Timothy Bates

References

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

Examples

data(twin_NA_dot)summary(twin_NA_dot)# Note that all variables are treated as factors because of the missing data coding.

Create Diagonal Matrix From Vector

Description

Given an input row or column vector,vec2diag returns a diagonal matrix with the input argument along the diagonal.

Usage

vec2diag(x)

Arguments

x

a row or column vector.

Details

Similar to the functiondiag, except that the input argument is alwaystreated as a vector of elements to place along the diagonal.

See Also

diag2vec

Examples

vec2diag(matrix(1:4, 1, 4))vec2diag(matrix(1:4, 4, 1))

Half-vectorization

Description

This function returns the half-vectorization of an input matrix as a column vector.

Usage

vech(x)

Arguments

x

an input matrix.

Details

The half-vectorization of an input matrix consists of the elements in the lower triangle of the matrix, including the elements along the diagonal of the matrix, as a column vector. The column vector is created by traversing the matrix in column-major order.

See Also

vech2full,vechs,rvectorize,cvectorize

Examples

vech(matrix(1:9, 3, 3))vech(matrix(1:12, 3, 4))

Inverse Half-vectorization

Description

This function returns the symmetric matrix constructed from a half-vectorization.

Usage

vech2full(x)

Arguments

x

an input single column or single row matrix.

Details

The half-vectorization of an input matrix consists of the elements in the lower triangle of the matrix, including the elements along the diagonal of the matrix, as a column vector. The column vector is created by traversing the matrix in column-major order. The inverse half-vectorization takes a vector and reconstructs a symmetric matrix such thatvech2full(vech(x)) is identical tox ifx is symmetric.

Note that very few vectors have the correct number of elements to construct a symmetric matrix. For example, vectors with 1, 3, 6, 10, and 15 elements can be used to make a symmetric matrix, but none of the other numbers between 1 and 15 can. An error is thrown if the number of elements inx cannot be used to make a symmetric matrix.

See Also

vechs2full,vech,vechs,rvectorize,cvectorize

Examples

vech2full(1:10)matrix(1:16, 4, 4)vech(matrix(1:16, 4, 4))vech2full(vech(matrix(1:16, 4, 4)))

Strict Half-vectorization

Description

This function returns the strict half-vectorization of an input matrix as a column vector.

Usage

vechs(x)

Arguments

x

an input matrix.

Details

The half-vectorization of an input matrix consists of the elements in the lower triangle of the matrix, excluding the elements along the diagonal of the matrix, as a column vector. The column vector is created by traversing the matrix in column-major order.

See Also

vech,rvectorize,cvectorize

Examples

vechs(matrix(1:9, 3, 3))vechs(matrix(1:12, 3, 4))

Inverse Strict Half-vectorization

Description

This function returns the symmetric matrix constructed from a strict half-vectorization.

Usage

vechs2full(x)

Arguments

x

an input single column or single row matrix.

Details

The strict half-vectorization of an input matrix consists of the elements in the lower triangle of the matrix, excluding the elements along the diagonal of the matrix, as a column vector. The column vector is created by traversing the matrix in column-major order. The inverse strict half-vectorization takes a vector and reconstructs a symmetric matrix such thatvechs2full(vechs(x)) is equal tox with zero along the diagonal ifx is symmetric.

Note that very few vectors have the correct number of elements to construct a symmetric matrix. For example, vectors with 1, 3, 6, 10, and 15 elements can be used to make a symmetric matrix, but none of the other numbers between 1 and 15 can. An error is thrown if the number of elements inx cannot be used to make a symmetric matrix.

See Also

vech2full,vech,vechs,rvectorize,cvectorize

Examples

vechs2full(1:10)matrix(1:16, 4, 4)vechs(matrix(1:16, 4, 4))vechs2full(vechs(matrix(1:16, 4, 4)))

[8]ページ先頭

©2009-2025 Movatter.jp