Learn R Programming

metaSEM (version 1.2.4)

create.mxModel: Create an mxModel

Description

It creates a mxModel from a RAM object.

Usage

create.mxModel(model.name="mxModel", RAM=NULL, Amatrix=NULL,
               Smatrix=NULL, Fmatrix=NULL, Mmatrix=NULL,
               Vmatrix=NULL, data, intervals.type = c("z", "LB"),
               mx.algebras=NULL, mxModel.Args=NULL,
               mxRun.Args=NULL, var.names=NULL,
               suppressWarnings=TRUE,
               silent=TRUE, run=TRUE, ...)

Arguments

model.name

A string for the model name in mxModel.

RAM

A RAM object including a list of matrices of the model returned from lavaan2RAM.

Amatrix

If RAM is not specified, an Amatrix is required.

Smatrix

If RAM is not specified, an Smatrix is required.

Fmatrix

If RAM is not specified, an Fmatrix is required.

Mmatrix

If RAM is not specified, an Mmatrix is required.

Vmatrix

A V-known matrix of the variables. If it is specified, it will be added into the Smatrix.

data

A data frame or matrix of data. Alternatively, users may provide a mxData object.

intervals.type

Either z (default if missing) or LB. If it is z, it calculates the 95% confidence intervals (CIs) based on the estimated standard error. If it is LB, it calculates the 95% likelihood-based CIs on the parameter estimates.

mx.algebras

A list of mxMatrix or mxAlgebra objects on the Amatrix, Smatrix, Fmatrx, and Mmatrix. It can be used to define new functions of parameters and their LBCIs. For example, if the regression coefficients to calculate an indirect effect are stored in A[1,2] and A[1,3], we may define list(ind=mxAlgebra(Amatrix[1,2]*Amatrix[1,3], name="ind"))

mxModel.Args

A list of arguments passed to mxModel.

mxRun.Args

A list of arguments passed to mxRun.

var.names

If it is NULL (the default), the var.names are extracted from Fmatrix$values.

suppressWarnings

Logical. If it is TRUE, warnings are suppressed. This argument is passed to mxRun.

silent

Logical. An argument is passed to mxRun

run

Logical. If FALSE, only return the mx model without running the analysis.

Not used yet.

Value

An object of class mxModel

Examples

Run this code
# NOT RUN {
## Generate data
set.seed(100)
n <- 100
x <- rnorm(n)
y <- 0.5*x + rnorm(n, mean=0, sd=sqrt(1-0.5^2))
my.df <- data.frame(y=y, x=x)

## Regression model
model <- "y ~ x   # Regress y on x
          y ~ 1   # Intercept of y
          x ~ 1   # Mean of x"
plot(model)

RAM <- lavaan2RAM(model, obs.variables=c("y", "x"))

my.fit <- create.mxModel(RAM=RAM, data=my.df)
summary(my.fit)

## A meta-analysis
model <- "yi ~~ tau2*yi
          yi ~ mu*1"

RAM <- lavaan2RAM(model, obs.variables=c("yi"))

## Create a v-known matrix
Vmatrix <- as.mxMatrix("0*data.vi", name="Vmatrix")

my.fit <- create.mxModel(RAM=RAM, Vmatrix=Vmatrix, data=Hox02)
summary(my.fit)
# }

Run the code above in your browser using DataLab