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