[R] SEM error

John Fox jfox at mcmaster.ca
Tue Mar 8 14:45:59 CET 2011


Dear Kesinee,

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Kes
> Sent: March-07-11 9:51 PM
> To: r-help at r-project.org
> Subject: [R] SEM error
> 
> Dear All,
> I am new for R and SEM. I try to fit the model with Y (ordinal outcome),
> X
> (4 categorical data), M1-M3 (continuous), and 2 covariates (Age&sex) as
> a diagram.
> library(polycor)
> model.ly <-specify.model()
> 1: x -> m1, gam11, NA
> 2: x -> m2, gam12, NA
> 3: x -> m3, gam13, NA
> 4: age -> m1, gam14, NA
> 5: age -> m2, gam15, NA
> 6: age -> m3, gam16, NA
> 7: sex -> m1, gam17, NA
> 8: sex -> m2, gam18, NA
> 9: sex -> m3, gam19, NA
> 10: x -> y, gam20, NA
> 11: m1 -> y, gam21, NA
> 12: m2 -> y, gam22, NA
> 13: m3 -> y, gam23, NA
> 14: age -> y, gam24, NA
> 15: sex -> y, gam25, NA,
> 16: m1 <->m1, psi11, NA
> 17: m2 <-> m2, psi12, NA
> 18: m3 <-> m3, psi13, NA
> 19: m1 <-> m2, psi21, NA
> 20: m1 <->m3, psi22, NA
> 21: m2 <-> m3, psi23, NA
> 22: Y <-> Y, psi24, NA,
> 
> hcor <-function(ly) hetcor(ly, std.err=FALSE)$correlations R.ly <-
> hcor(ly) sem.ly <- sem(model.ly, R.ly, N=174)
> 
> Error in sem.default(ram=ram, S=S, N=N,…………………………) The model has
> negative degree of freedom = -12
> 
> First, I do not know what the mistake is. Second, is this correctly
> modeling my diagram?  Any suggestions would be appreciated.

First, if x isn't ordinal, you have to create dummy regressors to represent it. Second, your model has no variances or covariances for the exogenous variables (which you could handle compactly with the fixed.x argument to sem). Third, I notice that you use both y and Y in the model. Since Y probably doesn't exist in the input data, sem() treats it as a latent variable. This probably produces the negative df, though I don't know off hand why; had you spelled y correctly, the df should be positive, although, as I've mentioned, the model makes no sense. Finally, this model has a block-recursive structure, and an alternative would be to fit each equation in the model as an appropriate regression model.

I hope this helps,
 John

--------------------------------
John Fox
Senator William McMaster
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox


> 
> Thank you,
> Kesinee
> http://r.789695.n4.nabble.com/file/n3340497/path.gif.png
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/SEM-error-
> tp3340497p3340497.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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