[R] Incorrect degrees of freedom in SEM model using lavaan
Mike Cheung
mikewlcheung at gmail.com
Thu Mar 17 16:27:36 CET 2011
Dear Andrew,
The reported df in lavaan is 0 which is correct. It is because this
path model is saturated. "28" is not the df, it is the no. of pieces
of information. The no. of parameter estimates is also 28. Thus, the
df is 0.
However, you are correct that there are only 13, not 28, free
parameters reported by lavaan. It is because "fixed.x=TRUE" was
implicitly used in your example (see ?sem). Since HHincome + Race +
Age + Gender + Stress1 are predictors, they are fixed at their sample
values when "fixed.x=TRUE" was used. And their covariance elements are
not involved in calculating the df.
If you want to mirror the behaviors in other SEM packages, you may try:
fit2 <- sem(model, sample.nobs=161, sample.cov=myCov, fixed.x=FALSE)
inspect(fit2, what="free")
summary(fit2)
Hope it helps.
Mike
--
---------------------------------------------------------------------
Mike W.L. Cheung Phone: (65) 6516-3702
Department of Psychology Fax: (65) 6773-1843
National University of Singapore
http://courses.nus.edu.sg/course/psycwlm/internet/
---------------------------------------------------------------------
On Thu, Mar 17, 2011 at 8:50 PM, Andrew Miles <rstuff.miles at gmail.com> wrote:
> I have been trying to use lavaan (version 0.4-7) for a simple path model,
> but the program seems to be computing far less degrees of freedom for my
> model then it should have. I have 7 variables, which should give (7)(8)/2 =
> 28 covariances, and hence 28 DF. The model seems to only think I have 13
> DF. The code to reproduce the problem is below. Have I done something
> wrong, or is this something I should take to the developer?
>
>
> library(lavaan)
>
> myCov = matrix(c(24.40, 0, 0, 0, 0, 0, 0, .03, .03, 0, 0, 0, 0, 0, 6.75, -
> .08, 519.38, 0, 0, 0, 0, .36, .01, 2.74, .18, 0, 0, 0, .51, .0, -.31, .02,
> .2, .0, 0, -.17, .0, -1.6, -.04, .01, .25, 0, -.1, .02, -.03, .0, -.01, .01
> , .02), nrow=7, byrow=TRUE, dimnames=list(c("Internet", "Stress3",
> "HHincome", "Race", "Age", "Gender", "Stress1"), c("Internet", "Stress3",
> "HHincome", "Race", "Age", "Gender", "Stress1")))
>
>
> model = '
>
> Internet ~ HHincome + Race + Age + Gender + Stress1
>
> Stress3 ~ Internet + HHincome + Race + Age + Gender + Stress1
>
> '
>
>
> fit=sem(model, sample.nobs=161, sample.cov=myCov, mimic.Mplus=FALSE)
>
>
> #check the number of parameters being estimated
>
> inspect(fit, what="free")
>
>
> #Note the DF for the Chi-square is 0, when it should be 28-13 = 15
>
> summary(fit)
>
>
> Andrew Miles
>
> [[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