Learn R Programming

metaSEM (version 1.5.0)

sem: Fit a structural equation model using OpenMx

Description

It fits a structural equation model by creating a mxModel from a RAM object.

Usage

## Depreciated in the future
create.mxModel(model.name="sem", RAM=NULL, data=NULL,
               Cov=NULL, means=NULL, numObs,
               intervals.type=c("z", "LB"), startvalues=NULL,
               replace.constraints=FALSE, mxModel.Args=NULL,
               run=TRUE, silent=TRUE, ...)
sem(model.name="sem", RAM=NULL, data=NULL,
    Cov=NULL, means=NULL, numObs,
    intervals.type=c("z", "LB"), startvalues=NULL,
    lbound=NULL, ubound=NULL, replace.constraints=FALSE,
    mxModel.Args=NULL, run=TRUE, silent=TRUE, ...)

Value

An object of class mxsem

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.

data

A data frame or matrix of data.

Cov

A covariance matrix may also be used if data==NULL.

means

A named vector of means (options) if Cov is used.

numObs

If Cov is used, a sample size must be provided.

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.

startvalues

A list of named starting values of the free parameters, e.g., list(a=1, b=2)

lbound

A list of lower bound of the free parameters. If it is not provided, all free parameters are assumed NA.

ubound

A list of upper bound of the free parameters. If it is not provided, all free parameters are assumed NA.

replace.constraints

Logical. If TRUE, the parameters on the left hand side will be replaced by the constraints on the right hand side. That is, the parameters on the left hand side are no longer parameters in the model.

mxModel.Args

A list of arguments passed to mxModel.

run

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

silent

Logical. An argument is passed to either mxRun or mxTryHard

...

Further arguments will be passed to either mxRun or mxTryHard

Author

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

Examples

Run this code
# \donttest{
## 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)

## A 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 <- sem(RAM=RAM, data=my.df)
summary(my.fit)

## A meta-analysis
model <- "f =~ 1*yi
          f ~ mu*1          ## Average effect
          f ~~ tau2*f       ## Heterogeneity variance
          yi ~~ data.vi*yi  ## Known sampling variance"
plot(model)

## Do not standardize the latent variable (f): std.lv=FALSE 
RAM <- lavaan2RAM(model, obs.variables="yi", std.lv=FALSE)

## Use likelihood-based CI 
my.fit <- sem(RAM=RAM, data=Hox02, intervals="LB")
summary(my.fit)
# }

Run the code above in your browser using DataLab