R08 Confirmatory Factor Analysis # Psychological Test Results Data (from book) data(Harman74.cor) test.cor <- Harman74.cor$cov[c(6, 7, 9, 10, 12),c(6, 7, 9, 10, 12)] colnames(test.cor) <- c("PARA","SENT","WORD","ADD","COUNT") rownames(test.cor) <- colnames(test.cor) test.cor library(sem) # CFA - A subset of Structural Equation Models # Requires installation of sem package model2.test <- specify.model() # Set up your model F1 -> PARA, lam11, NA # Common Factor loadings F1 -> SENT, lam21, NA F1 -> WORD, lam31, NA F2 -> ADD, lam42, NA F2 -> COUNT, lam52, NA PARA <-> PARA, th1, NA # Specific Factor Variances SENT <-> SENT, th2, NA WORD <-> WORD, th3, NA ADD <-> ADD, th4, NA COUNT <-> COUNT, th5, NA F1 <-> F2, ph12, NA # Common Factor Covariance(s) F1 <-> F1, NA, 1 # Common Factor Variances (fixed to 1) F2 <-> F2, NA, 1 # Blank line to end input model2.test cfa2.test <- sem(model2.test, test.cor, 145) cfa2.test summary(cfa2.test) model1.test <- specify.model() # Change to 1-factor model F1 -> PARA, lam11, NA F1 -> SENT, lam21, NA F1 -> WORD, lam31, NA F2 -> ADD, lam42, NA F2 -> COUNT, lam52, NA PARA <-> PARA, th1, NA SENT <-> SENT, th2, NA WORD <-> WORD, th3, NA ADD <-> ADD, th4, NA COUNT <-> COUNT, th5, NA F1 <-> F2, NA, 1 # Fix correlation as 1 F1 <-> F1, NA, 1 # (forces factors to be the same) F2 <-> F2, NA, 1 cfa1.test <- sem(model1.test, test.cor, 145) summary(cfa1.test) # Note changes to chi-square, GFI, AGFI # Likelihood ratio test comparing the two pchisq(59.473 - 2.9306, 5 - 4, lower.tail=F) # Expert Ratings of Wine-Growing Area's statuses wine <- read.table("H:/S5600/Data sets/ASCII/Ch06/WINE_STATUS.txt") wine wine.cor <- cor(wine) wine.cor model1.wine <- specify.model() # Single factor model STATUS -> V1, lam1, NA STATUS -> V2, lam2, NA STATUS -> V3, lam3, NA STATUS -> V4, lam4, NA STATUS -> V5, lam5, NA V1 <-> V1, th1, NA V2 <-> V2, th2, NA V3 <-> V3, th3, NA V4 <-> V4, th4, NA V5 <-> V5, th5, NA STATUS <-> STATUS, NA, 1 cfa1.wine <- sem(model1.wine, wine.cor, 59) summary(cfa1.wine) # Restrict to a common loading, and # specific factor variance on the experts model1r.wine <- specify.model() STATUS -> V1, lam1, NA # Note all loadings have the STATUS -> V2, lam1, NA # same name now STATUS -> V3, lam1, NA STATUS -> V4, lam1, NA STATUS -> V5, lam1, NA V1 <-> V1, th1, NA # As do all the variances V2 <-> V2, th1, NA V3 <-> V3, th1, NA V4 <-> V4, th1, NA V5 <-> V5, th1, NA STATUS <-> STATUS, NA, 1 cfa1r.wine <- sem(model1r.wine, wine.cor, 59) summary(cfa1r.wine) # Likelihood ratio test comparing the two pchisq(15.618 - 6.755, 13 - 5, lower.tail=F)