Learn R Programming

metaSEM (version 1.4.0)

lavaan2RAM: Convert lavaan models to RAM models

Description

It converts models specified in lavaan model syntax to RAM models.

Usage

lavaan2RAM(model, obs.variables = NULL, A.notation = "ON",
           S.notation = "WITH", M.notation = "mean",
           A.start=0.1, S.start=0.5, M.start=0,
           auto.var = TRUE, std.lv = TRUE, ngroups = 1, ...)

Value

A list of RAM specification with A, S, F, and M matrices.

Arguments

model

A character string of model using the lavaan model syntax.

obs.variables

A character vector of the observed variables. The observed variables in the RAM specification will follow the order specified in obs.variables. It is important to check whether the order of the observed variables matches the order in the dataset.

A.notation

A character string to be used in the A matrix if the labels are not included in the lavaan model. For example, the label will be "yONx" for regressing "y" on "x".

S.notation

A character string to be used in the S matrix if the labels are not included in the lavaan model. For example, the label will be "yWITHx" for the covariance between "y" with "x" and "yWITHy" for the (error) variance of "y".

M.notation

A character string to be used in the M matrix if the labels are not included in the lavaan model. For example, the label will be "ymean" for the mean of "y" if M.notation="mean".

A.start

A numeric value of starting value for the Amatrix when the starting values are not provided.

S.start

A numeric value of starting value for the Smatrix when the starting values are not provided.

M.start

A numeric value of starting value for the Mmatrix when the starting values are not provided.

auto.var

Logical. If TRUE, the residual variances and the variances of exogenous latent variables are included in the model and set free. See model.syntax.

std.lv

Logical. If TRUE, the metric of each latent variable is determined by fixing their variances to 1.0. If FALSE, the metric of each latent variable is determined by fixing the factor loading of the first indicator to 1.0. See model.syntax.

ngroups

Number. The number of groups in the model. See model.syntax.

...

Further arguments to be passed to model.syntax

. Please note that fixed.x is set at FALSE. Thus it cannot be passed to ....

Author

Mike W.-L. Cheung <mikewlcheung@nus.edu.sg>

Details

It uses the model.syntax to do the conversion. Experimental: functions of parameters (`:=` in lavaan) and constraints (`==`, `>`, and `<` in lavaan) will be converted to mxAlgebra and mxConstraint in OpenMx. As there are differences between lavaan and OpenMx, they may not work properly.

See Also

ramModel, Becker92, Becker09, Digman97, Hunter83, as.mxMatrix, checkRAM

Examples

Run this code
## Regression model on correlation matrix
model1 <- "## y is modelled by x1, x2, and x3
           y ~ b1*x1 + b2*x2 + b3*x3
           ## Fix the independent variables at 1
           x1 ~~ 1*x1
           x2 ~~ 1*x2
           x3 ~~ 1*x3
           ## Declare the correlations among the independent variables
           x1 ~~ x2
           x1 ~~ x3
           x2 ~~ x3
           ## Constraint
           b3 == b1 + b2
           ## Function of parameters
           fn1 := b1*b2^b3"

## Compare the arrangements of variables with and without
## specifying the obs.variables arguments. 
lavaan2RAM(model1, obs.variables=c("y", "x1", "x2", "x3"))

## Two-factor CFA model
model2 <- "f1 =~ x1 + x2 + x3
           f2 =~ x4 + x5 + x6
           ## Declare the correlation between f1 and f2
           ## and label it with cor_f1f2
           f1 ~~ cor_f1f2*f2"

lavaan2RAM(model2)

## Regression model with the mean structure
model3 <- "y ~ x
           ## Intercept of y
           y ~ 1
           ## Mean of x
           x ~ 1"

lavaan2RAM(model3)

## Multiple group regression model
## Different intercepts with a common slope
model4 <- "y ~ c(a1, a2)*1 + c(b, b)*x"

lavaan2RAM(model4, ngroups=2)

Run the code above in your browser using DataLab