lavaan package for Structural Equation Model in R
lavaan is a package for running a “Structural Equation Models” or SEM in R. The script of lavaan is similar to Mplus, which is very comprehensive and compact. The lavaan package is developed by Yves Rosseel.
The following is my lavaan script I used in my presentation at R useR! 2011.
##-------------------------------------------------## ## Measuring Transaction Cost in Supply Chains ## ## Pairach Piboonrungroj ## ## R useR conference August 2011 ## ##-------------------------------------------------## # 1. Load data hoteldata <- read.csv("https://www.dropbox.com/s/fzh040xkhofozjy/cleandata.csv") # 2. Install Package install.packages("lavaan") # 3. Load Package library(lavaan) #5. Structural Model TC.Model <- ' # latent variable definitions cost =~ TC1 + TC2 + TC3 +TC6 + TC7 +TC11 + TC13 asset =~ AS1 + AS2 uncertainty =~ UN1 + UN2 # regression cost ~ uncertainty + asset # resident (co)variance TC1 ~~ TC3 TC6 ~~ TC13 TC11 ~~ TC13 TC13 ~~ AS1 ' fitTC <- sem(TC.Model, data = hoteldata) summary(fitTC, standardized = TRUE, fit.measures=TRUE) # Coefficients # coef(fitTC) #More indices # Fit indices e.g. CFI fit.indices <- inspect(fitTC, what = "fit") fit.indices["cfi"] # Calling Modification Indices # inspect(fitTC, what = "mi")
See more details about the model and the comparison with other R packages and software






