[R] Error with sem function df = -6

John Fox jfox at mcmaster.ca
Tue Jul 23 15:56:56 CEST 2013


Dear Immanuel,

In the absence of more information, your question is unanswerable, since there's no way of knowing which variables in your model are observed and which are latent. It was my guess that Y1, Z1, and Z2 (along with UNIT) are observed and CF is latent, but this is clearly wrong given the df calculation.

Here, as the posting guide suggests, is a reproducible example, using your model and call to sem(), but clearly defined data:

---- snip ---

> set.seed(12345)
> data <- matrix(rnorm(500*3), 500, 3)
> S2 <- rawMoments(cbind(1, data))
> rownames(S2) <- colnames(S2) <- c("UNIT", "Z1", "Z2", "Y1")
> 
> sem.m1<-sem(model=model.ram1, S=S2, N=500, fixed.x="UNIT", raw=T)
Error in sem.default(ram, S = S, N = N, raw = raw, data = data, pattern.number = pattern.number,  : 
  The model has negative degrees of freedom = -2

---- snip ---

This model is underidentified, but at least it's possible to figure out why: There are 4*5/2 = 10 unique observed moments; your model has 11 parameters and also has to account for the second moment of the fixed exogenous UNIT. Thus 10 - (11 + 1) = -2, and the model is underidentified.

Some additional comments:

(1) Aside from UNIT there are no exogenous variables in this model.

(2) It's usually easier to use specifyEquations() than specifyModel() to define the model.

(3) If CF is really meant to be a latent variable, then there's a missing normalizing constraint, underidentifying the model apart from the gross comparison of moments and parameters.

(4) If, as here, you have the data, you don't have to compute the raw-moment matrix in a separate step, but could call sem() with the data argument.

Best,
 John

On Mon, 22 Jul 2013 18:55:31 -0400
 Immanuel Williams <jamesijw23 at gmail.com> wrote:
> Hello all,
> I have an issue where I am generating data and trying to confirm the
> estimates using a sem.  I keep getting an error about the degree of freedom
> being negative "Error in sem.default(ram, S = S, N = N, raw = raw, data =
> data, pattern.number = pattern.number,  : The model has negative degrees of
> freedom = -6"
> 
> Can someone explain this error or tell me what is wrong with my model?
> Thank you.
> Here is the code:
> 
> 
> 
> 
> model.ram1 <- specifyModel()
> UNIT -> Y1, ty,0.3
> UNIT -> Z1, tz1,-0.1
> UNIT -> Z2, tz2,0.1
> CF -> Y1, lamy,0.5
> CF -> Z1, lamz1,0.85
> CF -> Z2, lamz2,0.2
> UNIT -> CF, k
> Y1 <-> Y1, psi3, NA
> Z1 <-> Z1, psi1, NA
> Z2 <-> Z2, psi2, NA
> CF <-> CF,vCF1,NA
> 
> sem.m1<-sem(model=model.ram1,S=S2,N=500,fixed.x="UNIT",raw=T)
> 
> -- 
> 
> I.J. Williams
> 
> Ph.D. Student in Education Measurement and Statistics
> Statistics MS
> 
> Mathematics BS
> 
> Rutgers University
> 
> 	[[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.

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



More information about the R-help mailing list