# input correlation matrix of perfect two-factor model
# Factor Pattern of the 3 items for each Factor: 0.8, 0.6, 0.4
# Factor-Factor correlation: 0.3
mycor <- matrix(nrow=6, ncol=6, byrow=TRUE,
c(1.000,0.480,0.320,0.192,0.144,0.096,
0.480,1.000,0.240,0.144,0.108,0.072,
0.320,0.240,1.000,0.096,0.072,0.048,
0.192,0.144,0.096,1.000,0.480,0.320,
0.144,0.108,0.072,0.480,1.000,0.240,
0.096,0.072,0.048,0.320,0.240,1.000))
colnames(mycor) <- c("V1", "V2", "V3", "V4", "V5", "V6")
rownames(mycor) <- colnames(mycor)
# the confirmatory factor analysis
# first three variables with first factor, last three with second
# default correlation matrix is mycor
corCFA(F1=c(1:3), F2=c(4:6))
# abbreviated form
cfa(F1=c(1:3), F2=c(4:6))
# produce a gray scale heat map of the item correlations
# with communalities in the diagonal
# all subsequent graphics are in gray scale until changed
set(colors="gray")
corCFA(F1=c(1:3), F2=c(4:6))
# access the lessR data set called datMach4
data(datMach4)
# select the subset of the data that just contains Mach items
mach <- subset(datMach4, select=c(m01:m20))
# calculate the correlations and store in mycor
cr(mach)
# confirmatory factor analysis of 4-factor solution of Mach IV scale
corCFA(F1=c(6,7,9,10), F2=c(15,2), F3=c(4,11,16), F4=c(1,5,12,13))
# bad model to illustrate indicator diagnostics
mycor <- corReflect(vars=c(20))
corCFA(F1=c(6,9,19), F2=c(7), F3=c(4,11,16), F4=c(20,18,12,15))
Run the code above in your browser using DataLab