[R] Difficulty understanding sem errors / failed confirmatory factor analysis

Adam D. I. Kramer adik at ilovebacon.org
Thu Sep 18 19:01:30 CEST 2008


Hello,

 	I'm trying to fit a pretty simple confirmatory factor analysis using
the sem package. There's a CFA example in the examples, which is helpful,
but the output for my (failing) model is hard to understand. I'd be
interested in any other ways to do a CFA in R, if this proves troublesome.

 	The CFA is replicating a 5 uncorrelated-factor structure (for those
interested, it is a structure of word usage patterns in weblogs) in a
special population. The model looks like model.txt (attached as many people
hate long emails); the correlation matrix cors.txt as well.

 	I'm setting no overlap between factors, no correlation between
factors, and estimating a separate variance for each observed variable
(which should be everything on the right-hand side of the -> arrows), but
setting the factor variances equal to 1...pretty standard. I've ensured that
everything is typed correctly to the best I am able.

 	The problem:

library(sem)
model.kr <- specify.model(file="model.txt") # printing it checks out ok
correl <- read.csv("cors.csv", header=TRUE) # printing it checks out ok
kr.sem <- sem(ram=model.kr,S=correl,N=3034)
...about 10 seconds pass...
Warning message:
In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars,  :
   Could not compute QR decomposition of Hessian.
Optimization probably did not converge.

(running qr on correl works fine; randomly-generated correl matrices fail in
the same way; I do not know how to further troubleshoot this)

...and then the model itself (which is produced, as the above was just a
warning):

summary(kr.sem)
Error in data.frame(object$coeff, se, z, 2 * (1 - pnorm(abs(z))), par.code) :
   arguments imply differing number of rows: 47, 0

...both of these error messages are beyond my ability to troubleshoot. Any
help would be greatly appreciated. Because I am unsure what exactly the
problem with this analysis is, I can't create a simpler example for testing
purposes...but I think my model and correlation matrix are fairly simple.

> unlist(R.Version())
                       platform                           arch
     "x86_64-unknown-linux-gnu"                       "x86_64"
                             os                         system
                    "linux-gnu"            "x86_64, linux-gnu"
                         status                          major
                             ""                            "2"
                          minor                           year
                          "7.2"                         "2008"
                          month                            day
                           "08"                           "25"
                        svn rev                       language
                        "46428"                            "R"
                 version.string 
"R version 2.7.2 (2008-08-25)"

...sem installed via install.packages("sem") which I assume is current.

Cordially,
Adam Kramer



More information about the R-help mailing list