[R] error in model specification for cfa with lavaan-package
yrosseel
yrosseel at gmail.com
Wed Jun 1 15:13:20 CEST 2011
Dear Alain,
As for the first error ("sample covariance can not be inverted"): Mike
is right: with only 10 observations and 16 variables, the ML estimation
of the sample cov produces a covariance matrix that is not positive
definite, and hence the inversion (deliberately) fails.
The lesson for me is that lavaan should simply check for this situation
(p > N), and refuse to proceed (with a gentle and more informative error
message).
As for the second error ("Error in start.idx[i]:end.idx[i] : NA/NaN
Argument"): the first argument of cfa() must be a model syntax, not a
lavaanified object.
The 'lavaanify' function is useful to learn about lavaan, and to export
the model specification to other software packages, but you should not
pass a 'lavaanified' object to the cfa/sem/growth functions directly
(although this may work in the future).
Moreover, to get a 'complete' parameter list, you need to specify a
number of additional arguments:
model <- model <- lavaanify(cfa.model, auto.fix.first = TRUE, auto.var =
TRUE, auto.cov.lv.x = TRUE)
(see the 'Details' section in the man page of cfa() for a complete list).
Hope this helps,
Yves.
On 06/01/2011 12:31 PM, D. Alain wrote:
> Dear R-List,
>
> (I am not sure whether this list is the right place for my
> question...)
>
> I have a dataframe df.cfa
>
> df.cfa<-data.frame(x1=c(5,4,1,5,5,NA,4,NA,NA,5),x2=c(2,3,3,3,NA,1,2,1,2,1),x3=c(5,3,4,1,5,5,5,5,5,5),x4=c(5,3,4,5,5,5,5,5,5,5),x5=c(5,4,3,3,4,4,4,5,NA,5),x6=c(3,5,2,1,4,NA,NA,5,3,4),x7=c(5,4,3,4,4,3,4,NA,NA,4),x8=c(5,5,3,4,5,4,5,4,5,5),x9=c(5,1,1,1,NA,3,3,2,2,3),x10=c(5,5,2,3,4,3,1,3,2,5),x11=c(5,4,4,5,5,4,5,4,5,5),x12=c(5,4,5,5,5,4,5,5,5,5),x13=c(5,4,4,5,5,5,5,5,5,5),x14=c(5,3,3,NA,5,4,5,3,NA,5),x15=c(4,4,4,3,4,5,2,4,5,5),x16=c(5,4,3,3,4,4,3,3,4,5))
>
>
>
>
>
> and I want to carry out a confirmatory factor analysis using the
> "cfa" function (lavaan).
>
> library(lavaan)
>
> then I specify my model
>
> cfa.model<-' f1=~x1+x2+x3+x4+x5 f2=~x6+x7+x8+x9+x10+x11
> f3=~x12+x13+x14+x15+x16 '
>
> and run the cfa routine
>
> fit<-cfa(cfa.model,data=df.cfa,missing="ml")
>
> The output is an error message (here partly in german)
>
> "Error in chol.default(S) : der führende Minor der Ordnung 4 ist
> nicht positiv definit Fehler in Sample(data = data, group = group,
> sample.cov = sample.cov, sample.mean = sample.mean, : sample
> covariance can not be inverted"
>
> Then I tried to "lavaanify" my model specification first
>
> cfa.model<- lavaanify(cfa.model)
>
> id lhs op rhs user group free ustart fixed.x label eq.id
> free.uncon 1 1 f1 =~ x1 1 1 1 NA 0 f1=~x1 0
> 1 2 2 f1 =~ x2 1 1 2 NA 0 f1=~x2 0
> 2 3 3 f1 =~ x3 1 1 3 NA 0 f1=~x3 0
> 3 4 4 f1 =~ x4 1 1 4 NA 0 f1=~x4 0
> 4 5 5 f1 =~ x5 1 1 5 NA 0 f1=~x5 0
> 5 6 6 f2 =~ x6 1 1 6 NA 0 f2=~x6 0
> 6 7 7 f2 =~ x7 1 1 7 NA 0 f2=~x7 0
> 7 8 8 f2 =~ x8 1 1 8 NA 0 f2=~x8 0
> 8 9 9 f2 =~ x9 1 1 9 NA 0 f2=~x9 0
> 9 10 10 f2 =~ x10 1 1 10 NA 0 f2=~x10 0
> 10 11 11 f2 =~ x11 1 1 11 NA 0 f2=~x11 0
> 11 12 12 f3 =~ x12 1 1 12 NA 0 f3=~x12 0
> 12 13 13 f3 =~ x13 1 1 13 NA 0 f3=~x13 0
> 13 14 14 f3 =~ x14 1 1 14 NA 0 f3=~x14 0
> 14 15 15 f3 =~ x15 1 1 15 NA 0 f3=~x15 0
> 15 16 16 f3 =~ x16 1 1 16 NA 0 f3=~x16 0
> 16
>
> I run cfa again
>
> fit<-cfa(cfa.model,data=df.cfa,missing="ml")
>
> And this time I get another error information
>
> "Error in start.idx[i]:end.idx[i] : NA/NaN Argument"
>
> I must admit that I am stuck, can anyone help?
>
> Thanks, Alain [[alternative HTML version deleted]]
>
>
>
>
> ______________________________________________ R-help at r-project.org
> mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
> read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list