Skip to content

OpenMx package for Structural Equation Model in R


OpenMx (Boker et al, 2011) is claimed to be a “ free and open source software for use with R that allows estimation of a wide variety of advanced multivariate statistical models.” contributed by experts in R and SEM.

The following is my OpenMx script I used in my presentation at R useR! 2011.

##-------------------------------------------------##
##    Measuring Transaction Cost in Supply Chains  ##
##               Pairach Piboonrungroj             ##
##         R useR conference August 2011           ##
##-------------------------------------------------##

#install OpenMx
source('http://openmx.psyc.virginia.edu/getOpenMx.R')
require(OpenMx)

# load the OpenMx package into R

library(OpenMx)

# read the data into an R dataframe

hoteldata <- read.csv("http://dl.dropbox.com/u/46344142/useR2011/cleandata.csv")

# define which indicators load on each factor

indicatorsTC <- c("TC1", "TC2", "TC3", "TC6", "TC7" , "TC11" , "TC13")

indicatorsAS <- c("AS1", "AS2")

indicatorsUN <- c("UN1", "UN2")

# create a vector of all of the manifest variables

manifests <- c(indicatorsTC, indicatorsAS, indicatorsUN)

# define which indicator is to be used to scale each factor

scaleTC <- c("TC1")

scaleAS <- c("AS1")

scaleUN <- c("UN1")

# define the names of the factors

latents <- c("TC", "AS", "UN")

# define the MxModel and store it into "factorModel"

factorModel <- mxModel("TC Model",

type="RAM",

manifestVars = manifests,

latentVars = latents,

# specify the free factor loadings

mxPath(from="TC", to=indicatorsTC, free=TRUE, values=.2),

mxPath(from="AS", to=indicatorsAS, free=TRUE, values=.2),

mxPath(from="UN", to=indicatorsUN, free=TRUE, values=.2),

# scale the two latent variables

mxPath(from="TC", to=scaleTC, free=FALSE, values=1),

mxPath(from="AS", to=scaleAS, free=FALSE, values=1),

mxPath(from="UN", to=scaleUN, free=FALSE, values=1),

# specify the unique variances

mxPath(from=manifests, arrows=2, free=TRUE, values=.8),

# specify the factor variances

mxPath(from=latents, arrows=2, free=TRUE, values=.8),

# specify the path

mxPath(from="AS", to="TC", arrows=2, free=TRUE, values=.3),

mxPath(from="UN", to="TC", arrows=2, free=TRUE, values=.3),

mxPath(from="AS", to="UN", arrows=2, free=TRUE, values=.3),

# specify the mean structure

mxPath(from="one", to=c(manifests, latents), arrows=1, free=FALSE, values=0),

# attach the data to the model

mxData(hoteldata, type="raw")

)

# run the factor model

factorModelOut <- mxRun(factorModel)

# print a summary of the results

summary(factorModelOut)
<pre>

See more details about the model and the comparison with other R packages and software

6 Comments Post a comment
  1. I do not leave a response, but after browsing a bunch of comments here OpenMx package for Structural Equation Model in R | Pairach Piboonrungroj.
    I do have a few questions for you if you tend not to
    mind. Could it be just me or do a few of these comments appear like they are written by brain
    dead folks? :-P And, if you are writing at
    additional online sites, I would like to keep up with
    anything new you have to post. Could you list of every one
    of all your shared pages like your Facebook page, twitter feed, or linkedin profile?

    June 2, 2013
  2. Hi there! Someone in my Facebook group shared this website with us so I came to give it a look.
    I’m definitely enjoying the information. I’m book-marking and
    will be tweeting this to my followers! Terrific blog and fantastic style and design.

    April 23, 2014
  3. Я считаю, что Вы не правы. Предлагаю это обсудить.
    Пишите мне в PM.

    May 27, 2014

Trackbacks & Pingbacks

  1. My presentation at The R useR! Conference 2011 | Pairach Piboonrungroj
  2. R packages for Structural Equation Model | Pairach Piboonrungroj
  3. sem package in R: a sample of transaction cost measurement | Pairach Piboonrungroj

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 2,778 other followers

%d bloggers like this: