R: Create MxData Object for Least Squares (WLS, DWLS, ULS)...

mxDataWLS {OpenMx} | R Documentation

## Create MxData Object for Least Squares (WLS, DWLS, ULS) Analyses

### Description

This function creates a new MxData object of type “ULS” (unweighted least squares), “WLS” (weighted least squares) or “DWLS” (diagonally-weighted least squares). The appropriate fit function to include with these models is `mxFitFunctionWLS`

### Usage

       mxDataWLS(data, type = "WLS", useMinusTwo = TRUE, returnInverted = TRUE,
        fullWeight = TRUE, suppressWarnings = TRUE, allContinuousMethod =
       "cumulants", ..., 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' for weighted, 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 is returned (default). Needed for standard error and quasi-chi-squared calculation.
`suppressWarnings` | Logical that determines whether to suppress diagnostic warnings. These warnings are likely only helpful to developers.
`allContinuousMethod` | A character string 'cumulants' (default) or 'marginals'. See Details.
`...` | Not used. Forces remaining arguments to be specified by name.
`silent` | Whether to report progress

### Details

The mxDataWLS function creates an MxData object, which can be used in MxModel objects. This function takes raw data and returns an `MxData` object to be used in a model to fit with weighted least squares.

Both Ordinal and continuous data are supported. A combination of these data types also succeeds. Early tests suggested that full 'WLS' might be biased in this joint ordinal and continuous case, whereas 'ULS' and 'DWLS' were unbiased. However further investigation revealed that all of these were unbiased when the model is correct, but full 'WLS' is highly sensitive to model misspecification. Full 'WLS' 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.

By default when only continuous variables are present, the argument `allContinuousMethod` dictates that the asymptotically distribution free (ADF) method of Browne (1984) is used. This method computes the fourth order cumulants for the weight matrix: thus, the name. The method does not readily handle missing data and does not return weights or summary statistics for the means, but it is generally fast and ADF up to elliptical distributions. The other option, 'marginals', uses similar methods to the ordinal and joint ordinal-continuous cases. It does return weights and summary statistics for the means. When there are any ordinal variables present, `allContinuousMethod` is ignored.

### Value

Returns a new MxData object.

### References

The OpenMx User's guide can be found at http://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, p. 62-83.

### See Also

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.

### Examples

    # 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)

[Package OpenMx version 2.11.4 Index]