# Problems with confirmatory factor analysis in R

#### brittany00

##### New Member
I am trying to teach myself confirmatory factor analysis by working through examples in a textbook. The textbook only contains syntax for LISREL or SAS but I'm trying to learn it with R. When I estimate models without any equality constraints or correlated errors, I get the exact same output as the book. However, as soon as I add an equality constraint, following a book example (i.e., equivalent factor loadings among indicators) or correlated error, the model will not run. I receive a message that the model is under identified even though it is in fact not because the book shows the example and output. This makes me think I'm specifying something incorrectly. Here is an example of my problem:

#First, I estimate the model without equality constraints:
library(sem)
library(matrixcalc)

txt <- "1
.661 1
.630 .643 1
.270 .300 .268 1
.297 .265 .225 .805 1
.290 .287 .248 .796 .779 1"

memory.matrix <- data.matrix( read.table(text=txt, fill=TRUE, col.names=paste("X", 1:6)))
memory.matrix[upper.tri(memory.matrix)] <- t(memory.matrix)[upper.tri(memory.matrix)]
memory.matrix
rownames(memory.matrix)<-c("X.1", "X.2", "X.3", "X.4", "X.5", "X.6")

#verify that matrix is symmetric
isSymmetric(memory.matrix)

#verify that matrix is positive definite
is.positive.definite(memory.matrix, tol=0)

sd<-c(2.61, 2.66, 2.59, 1.94, 2.03, 2.05)
mean<-c(0,0,0,0,0,0)
memory<-cov2raw(memory.matrix, mean, 200, sd)
memory.model<-cfa(reference.indicators=FALSE)
Auditory: X.1, X.2, X.3
Visual: X.4, X.5, X.6
memory.fit <- sem(memory.model, memory, 200)
summary(memory.fit, digits=5, conf.level=.95,
fit.indices=c("GFI", "AGFI", "RMSEA", "NFI", "NNFI", "CFI", "RNI",
"IFI", "SRMR", "AIC", "AICc", "BIC", "CAIC"))
modIndices(memory.fit)
standardizedCoefficients(memory.fit)
#This model produces output and works fine

#respecify the model to test tau equivalence of auditory memory indicators

memory2.model<-cfa(reference.indicators=FALSE)
Auditory:X.1=X.2=X.3
Visual: X.4, X.5, X.6
memory2.fit <- sem(memory2.model, memory, 200)
summary(memory2.fit, digits=5, conf.level=.95,
fit.indices=c("GFI", "AGFI", "RMSEA", "NFI", "NNFI", "CFI", "RNI",
"IFI", "SRMR", "AIC", "AICc", "BIC", "CAIC"))

#This model does not run. It says I have -3 df with the following error message:
#Error in sem.default(ram, S = S, N = N, raw = raw, data = data, pattern.number = #pattern.number, :
# The model has negative degrees of freedom = -3