Skip to content

Posts by Pairach

A gift from Heaven


Thanks God I found Peun.

R packages for Structural Equation Model: SEM with R


Structural Equation Model (SEM) was first examined by a software called LISREL. Then, SEM has been mainly run by several proprietary software i.e., Mplus, AMOS, EQS, SAS and a new version of Stata (v.12).

However, you may also run SEM with a great but free software like R.

To the best of my knowledge, there are now four active packages that you can use to fit SEM. Here they are:

Main Packages (for fitting SEM models) 

  1. sem (John Fox, 2006):The first R package for SEM ” fit by maximum likelihood assuming multinormality, and single-equation estimation for observed-variable models by two-stage least.squares.” It was also the first package I tried to run SEM in R. Thanks to a very quick response from Prof.Fox on my question I emailed him.
    See Example of ‘sem’ package here.
  2. OpenMx (Boker et al, 2011)
    A very active package that “is 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.
    See Example of ‘OpenMx’ package here.
  3. lavaan (Yves Rosseel, 2012)
    A promising package for SEM. Its command language is similar to those of Mplus. Hence it is perhaps the most user-friendly package for SEM to date.
    See Example of ‘lavaan’ package here.
    Link to JSS paper
  4. semPLS (Armin Monecke, 2012)
    Fitting Structural Equation Model Using Partial Least Squares
    See: CRAN link, JSS paper
  5. plspm (Gaston Sanchez, 2012)
    R package dedicated to Partial Least Squares (PLS) methods (CRAN, plsmodeling.com)
    by Gaston Sanchez and Laura Trinchera
    A corresponding book titled “PLS Path Modeling with R” can be downloaded here.
My paper in useR! 2011 has evaluated R packages vs. Proprietary software i.e., AMOS & Lisrel.

Today (30 May 2012), I gladly found that there are also complementary packages for SEM in R as follows.

Complementary packages

  • SEMplusR: Functions, examples and datasets to learn, use and teach Structural Equation Modeling (SEM)  [GitHub]
    by Pairach Piboonrungroj 
  • SEMModComp: Model Comparisons for SEM [CRAN link, Additional Documents]
    by  Roy Levy
  • semGOF: an add-on package which provides fourteen goodness-of-fit indeces for structural equation models using ‘sem’ package.[CRAN]
    by Elena Bertossi 
  • stremo: Functions to help the process of learning structural equation modelling [CRAN link]
    by  Gustavo Carvalho, Marco Batalha, and Owen Petchey
  • FIAR: Functional Integration Analysis in R [CRAN link]
    by  Bjorn Roelstraete
  • semTools: Useful tools for structural equation modeling [CRAN link]
    by  Sunthud Pornprasertmanit, Patrick Miller, Alex Schoemann, Yves Rosseel
  • simsem: SIMulated Structural Equation Modeling [CRAN link]
    by  Sunthud Pornprasertmanit, Patrick Miller, Alexander Schoemann
  • pathmox R package dedicated to segmentation trees in PLS Path Modeling [CRAN, plsmodeling.com]

Packages for SEM plotting and graphics

  • qgraph: Network representations of relationships in data [CRAN link]
    by  Sacha Epskamp, Angelique O. J. Cramer, Lourens J. Waldorp, Verena D. Schmittmann and Denny Borsboom
  • psych: Procedures for Psychological, Psychometric, and Personality Research [CRAN link]
    by William Revelle

Packages that link R with other software to fit SEM

  • Mplus
    Automating Mplus Model Estimation and Interpretation [CRAN link]
    by  Michael Hallquist
  • EQS
    R/EQS Interface [CRAN link]
    by  Patrick Mair and Eric Wu

More external resources on SEM in R

  • CRAN Task view on ‘Structural Equation Models, Factor Analysis, PCA’ in Psychometrics [url]
    by Patrick Mair
  • A tutorial on the use of sem package  [url]
    by William Revelle
  • A post on ‘Structural Equation Modeling in R‘  [url]
    by Jeromy Anglim

Pairach.com has now linked to R-Bloggers.com


Finally, in the light of the greater contribution, this website will be a part of one of the largest R websites, R-Bloggers.com after following this site for a while.

For those who are using R or interested in this great but free software, R-Bloggers.com is a must!

sem package in R: a sample of transaction cost measurement


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)

บรรยายพิเศษเนื่องในโอกาสครบรอบ ๔๘ ปี วันสถาปนาคณะเศรษฐศาสตร์ มหาวิทยาลัยเชียงใหม่


ขอเชิญร่วมฟังบรรยายพิเศษเนื่องในโอกาสครบรอบ ๔๘ ปี วันสถาปนา
คณะเศรษฐศาสตร์ มหาวิทยาลัยเชียงใหม่
**พร้อมรับของที่ระลึกสำหรับผู้ลงทะเบียนเข้าฟัง!!

หน่วยบริการวิชาการ ขอเชิญท่านร่วมฟังบรรยายพิเศษเนื่องในโอกาสครบรอบ ๔๘ ปี วันสถาปนาคณะเศรษฐศาสตร์ มหาวิทยาลัยเชียงใหม่

วันอาทิตย์ที่ ๒๘ สิงหาคม ๒๕๕๔

ณ ห้องประชุมใหญ่ คณะเศรษฐศาสตร์ มหาวิทยาลัยเชียงใหม่

กำหนดการ

—————————————————————–

เวลา ๑๒.๓๐ น.
เริ่มลงทะเบียน พร้อมรับ Handy drive ที่ระลึกงานครบรอบ ๔๘ ปี วันสถาปนาคณะเศรษฐศาสตร์ (ของมีจำนวนจำกัดสำหรับผู้ลงทะเบียนเข้าฟังเท่านั้น!)

เวลา ๑๓.๐๐ น.
พิธีเปิดการบรรยายทางวิชาการ โดยคณบดีคณะเศรษฐศาสตร์ ดร.พิสิฐ ลี้อาธรรม

เวลา ๑๓.๓๐ น.
การบรรยายพิเศษ หัวข้อ “อนาคตของมาบตาพุด” โดย ดร. ศิริ จิระพงษ์พันธ์ ผู้อำนวยการสถาบันปิโตรเลียมแห่งประเทศไทย

 เวลา ๑๔.๓๐ น. 
การบรรยายพิเศษ หัวข้อ “การปรับเปลี่ยนองค์การธุรกิจ” โดย คุณบวร วงศ์สินอุดม ประธานเจ้าหน้าที่บริหารและกรรมการผู้จัดการใหญ่ บริษัท ปตท. อะโรเมติกส์ และการกลั่น จำกัด (มหาชน)

เวลา ๑๕.๓๐ น.
การเสวนาทางวิชาการหัวข้อ “การปรับเปลี่ยนของธนาคารไทย” โดย ดร. พิสิฐ ลี้อาธรรม คณบดีคณะเศรษฐศาสตร์, คุณสรสิทธิ์ สุนทรเกศ รองผู้ว่าการสายกำกับสถาบันการเงิน ธนาคารแห่งประเทศไทย และคุณอุดมศักดิ์ เล่ห์หลีกภัย

 เวลา ๑๖.๓๐ น.
พิธีปิด โดย ดร. พิสิฐ ลี้อาธรรม คณบดีคณะเศรษฐศาสตร์

สำรองที่นั่งและสอบถามรายละเอียดเพิ่มเติมได้ที่
หน่วยบริการวิชาการ 0-5394-2235