A sneak peek of the result of a Structural Equation Model using sem package in R.
I will present in the R User Conference in Warwick next week, is reveal first here.
The following are the codes of ‘sem’ package I used in the paper.
You may also view the code of other packages to run SEM models as well.
##-------------------------------------------------##
## Measuring Transaction Cost in Supply Chains ##
## Pairach Piboonrungroj ##
## R useR conference August 2011 ##
##-------------------------------------------------##
install.packages("sem")
library(sem)
# 1. Load data
hoteldata <- read.csv("http://dl.dropbox.com/u/46344142/useR2011/cleandata.csv")
#Input covariance matrix
data.tc.1 <- cor(hoteldata)
# Have a look at the top of the data
# to check it we import the right one
head(data.tc.1)
#Create an object contains correlation matrix of the data for fitting the model in the next step
hotel.cor <- cor(hoteldata)
# path parameter start-value
model.TC.1 <- specify.model()
TC -> TC1, gamma1, NA # measurement item
TC -> TC2, gamma2, NA
TC -> TC3, gamma3, NA
TC -> TC6, gamma6, NA
TC -> TC7, gamma7, NA
TC -> TC11, gamma11, NA
TC -> TC13, gamma13, NA
TC1 <-> TC1, e1, NA # measurement error
TC2 <-> TC2, e2, NA
TC3 <-> TC3, e3, NA
TC6 <-> TC6, e6, NA
TC7 <-> TC7, e7, NA
TC11 <-> TC11, e11, NA
TC13 <-> TC13, e13, NA
TC <-> TC, NA, 1
model.TC.1
sem.TC.1 <- sem(model.TC.1, data.tc.1, 53)
# print result (fit indices, parameters, hypothesis tests)
summary(sem.TC.1)
# standardised coefficients (loadings)
std.coef(sem.TC.1)
Like this:
Like Loading...