# A simple confirmatory factor-analysis model using polychoric correlations.
# The polycor package is required for the hetcor function.
library(polycor)
# The following function returns correlations computed by hetcor,
# and is used for the bootstrapping.
hcor <- function(data) hetcor(data, std.err=FALSE)$correlations
model.cnes <- specifyModel()
F -> MBSA2, lam1
F -> MBSA7, lam2
F -> MBSA8, lam3
F -> MBSA9, lam4
F <-> F, NA, 1
MBSA2 <-> MBSA2, the1
MBSA7 <-> MBSA7, the2
MBSA8 <-> MBSA8, the3
MBSA9 <-> MBSA9, the4
R.cnes <- hcor(CNES)
sem.cnes <- sem(model.cnes, R.cnes, N=1529)
summary(sem.cnes)
# Note: this can take a couple of minutes:
system.time(boot.cnes <- bootSem(sem.cnes, R=100, cov=hcor, data=CNES))
summary(boot.cnes, type="norm")
# cf., standard errors to those computed by summary(sem.cnes)
Run the code above in your browser using DataLab