| mxDataWLS {OpenMx} | R Documentation |
This function creates a new MxData object for use with fitting models with WLS.
mxDataWLS(data, type = "WLS", useMinusTwo = TRUE, returnInverted = TRUE,
debug = FALSE, fullWeight = TRUE)
data |
A matrix or data.frame which provides raw data to be used for WLS. |
type |
A character string 'WLS', 'DLS', or 'ULS' for weight, diagonal, or unweighted least squares |
useMinusTwo |
Logical. Use -2LL or -LL. |
returnInverted |
Logical. Return the information matrix or the covariance matrix. |
debug |
Logical. Is debugging being done? |
fullWeight |
Logical. Should the full weight matrix be returned? Needed for standard error and quasi-chi-squared calculation. |
The mxDataWLS function creates an MxData object, which can be used as arguments in MxModel objects. This function takes raw data and gives back the MxData object to be used in a model to fit with weighted least squares.
Ordinal data are supported. Continuous data are also supported. A combination of ordinal and continuous data succeeds, but when using 'WLS' or 'DLS' the answers appear incorrect. The 'ULS' estimates for joint ordinal and continuous data appear accurate. Consequently, do not use this function for joint problems unless type='ULS'.
Returns a new MxData object.
The OpenMx User's guide can be found at http://openmx.psyc.virginia.edu/documentation.
mxFitFunctionWLS. MxData for the S4 class created by mxData. matrix and data.frame for objects which may be entered as arguments in the ‘observed’ slot. More information about the OpenMx package may be found here.
# Create and fit a model using mxMatrix, mxAlgebra, mxExpectationNormal, and mxFitFunctionWLS
library(OpenMx)
# Simulate some data
x=rnorm(1000, mean=0, sd=1)
y= 0.5*x + rnorm(1000, mean=0, sd=1)
tmpFrame <- data.frame(x, y)
tmpNames <- names(tmpFrame)
wdata <- mxDataWLS(tmpFrame)
# Define the matrices
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 expectation
expCov <- mxAlgebra(solve(I-A) %*% S %*% t(solve(I-A)), name="expCov")
expFunction <- mxExpectationNormal(covariance="expCov", dimnames=tmpNames)
# Choose a fit function
fitFunction <- mxFitFunctionWLS()
# Define the model
tmpModel <- mxModel(model="exampleModel", S, A, I, expCov, expFunction, fitFunction,
wdata)
# Fit the model and print a summary
tmpModelOut <- mxRun(tmpModel)
summary(tmpModelOut)