jiblerize22 at yahoo.com
2009-Mar-30 07:34 UTC
[R] interpreting "not defined because of singularities" in lm
I run lm to fit an OLS model where one of the covariates is a factor with 30 levels. I use contr.treatment() to set the base level of the factor, so when I run lm() no coefficients are estimated for that level. But in addition (and regardless of which level I choose to be the base), lm also gives a vector of NA coefficients for another level of my factor. The output says that these coefficients were "not defined because of singularities", suggesting maybe that the 28 estimated coefficients are sufficient to pin down the 29th... but why is this the case? Why am I going from 30 levels to 28 coefficients? Am I misunderstanding the way factors/levels are supposed to work? Thanks for any suggestions. [[alternative HTML version deleted]]
Duncan Murdoch
2009-Mar-30 10:40 UTC
[R] interpreting "not defined because of singularities" in lm
jiblerize22 at yahoo.com wrote:> I run lm to fit an OLS model where one of the covariates is a factor with 30 levels. I use contr.treatment() to set the base level of the factor, so when I run lm() no coefficients are estimated for that level. But in addition (and regardless of which level I choose to be the base), lm also gives a vector of NA coefficients for another level of my factor. > > The output says that these coefficients were "not defined because of singularities", suggesting maybe that the 28 estimated coefficients are sufficient to pin down the 29th... but why is this the case? Why am I going from 30 levels to 28 coefficients? Am I misunderstanding the way factors/levels are supposed to work?The usual cause of this is that one of the levels is not present in the data set. Another possibility is collinearity with some other covariate in your model. Duncan Murdoch
Possibly Parallel Threads
- Coefficients: (20 not defined because of singularities)
- lm, coefficient 'not defined because of singularities'? What does this mean?
- glm prb (Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : )
- Summary coefficients give NA values because of singularities
- Interpreting model matrix columns when using contr.sum