This function creates a new MxData object. (for WLS data see mxDataWLS).
mxData(observed, type, 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)
A matrix or data.frame which provides data to the MxData object.
A character string defining the type of data in the ‘observed’ argument. Must be one of “raw”, “cov”, “cor”, “'sscp'” or “acov”.
An optional vector of means for use when ‘type’ is “cov”, or “cor”.
The number of observations in the data supplied in the ‘observed’ argument. Required unless ‘type’ equals “raw”.
Deprecated.
Deprecated.
Deprecated.
Not used. Forces remaining arguments to be specified by name.
A list containing observed statistics for weighted least squares estimation.
Whether to sort raw data prior to use (default NA)
The column name of the primary key used to uniquely identify rows (default NA)
The column name containing row weights
The column name containing row frequencies
level of diagnostic output
Returns a new MxData object.
The mxData function creates MxData objects, which can be used as arguments in MxModel objects. 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 MxModel objects. Four different data types are supported (a fifth, sscp, is not yet implemented):
The contents of the ‘observed’ argument are treated as raw data. Missing values are permitted and must be designated 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 rows in the data. Data of this type may use fit functions such as mxFitFunctionML function in MxModel objects, which will automatically use covariance estimation under full-information maximum likelihood for this data type.
The contents of the ‘observed’ argument are treated as a covariance matrix. The ‘means’ argument is not required, but may be included for estimations involving means. The ‘numObs’ argument is required, which should reflect the number of observations or rows in the data described by the covariance matrix. Data of this type may use the fit functions such as mxFitFunctionML, depending on the specified model.
The contents of the ‘observed’ argument are treated as a correlation matrix. The ‘means’ argument is not required, but may be included for estimations involving means. The ‘numObs’ argument is required, which should reflect the number of observations or rows in the data described by the covariance matrix. Data of this type may use the fit functions such as mxFitFunctionML functions, depending on the specified model.
The best way to create data of this type is to use the mxDataWLS function. The contents of the ‘observed’ argument is regarded as raw data. The ‘observedStats’ slot contains a list of observed statistics. The list is expected to contain a number of named objects: ‘cov’ is the (polychoric) covariance matrix of the continuous and ordinal variables. ‘means’ (optional) may be included for estimations involving means. ‘thresholds’ should be included for estimation involving thresholds and ordinal variables. ‘acov’ is the asymptotic covariance matrix. ‘acov’ can be diagonal for diagonally weighted least squares. ‘fullWeight’ (optional) is the complete asymptotic weight matrix (all entries non-zero). Data of this type almost certainly use the mxFitFunctionWLS function, but may depend on the specified model.
MxData objects may not be included in MxAlgebra objects or use the mxFitFunctionAlgebra function. If these capabilities are desired, data should be appropriately input or transformed using the mxMatrix and mxAlgebra functions.
While column names are stored in the ‘observed’ slot of MxData objects, these names are not recognized as variable names in MxPath objects. Variable names must be specified using the ‘manifestVars’ argument of the mxModel function prior to use in MxPath 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.
OpenMx uses the names of variables to map them onto the expectation functions and other elements associated with your model. For data.frames, ensure you have set the names(). For matrices set names using, for instance, row.names=c(“your”, “columns”). Covariance and correlation matrices need to have both the row and column names set and these must be identical, for instance by using dimnames = list(varNames, varNames)
.
In the case of raw data, the optional ‘weight’ argument names a column in the ‘observed’ data that contains per-row weights. Similarly, the optional ‘frequency’ argument names a column in the ‘observed’ data that contains per-row frequencies. Frequencies must be integral but weights can be arbitrary real numbers. For data with many repeated response patterns, 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 OpenMx User's guide can be found at http://openmx.ssri.psu.edu/documentation.
For WLS data, see mxDataWLS. To generate data, see mxGenerateData
; For objects which may be entered as arguments in the ‘observed’ slot, see matrix and data.frame. See MxData for the S4 class created by mxData. More information about the OpenMx package may be found here.
# NOT RUN {
library(OpenMx)
# Create a covariance matrix
covMatrix <- matrix( c(0.77642931, 0.39590663,
0.39590663, 0.49115615),
nrow = 2, ncol = 2, byrow = TRUE)
covNames <- c("x", "y")
dimList <- list(covNames, covNames)
dimnames(covMatrix) <- dimList
# Create an MxData object including that covariance matrix
testData <- mxData(observed=covMatrix, type="cov", numObs = 100)
testModel <- mxModel(model="testModel",
mxMatrix(type="Symm", nrow=2, ncol=2, values=c(.2,.1,.2),
free=TRUE, name="expCov", dimnames=dimList),
mxExpectationNormal(covariance="expCov", dimnames=covNames),
mxFitFunctionML(),
testData)
outModel <- mxRun(testModel)
summary(outModel)
# }
Run the code above in your browser using DataLab