[R] NA in dummy regression coefficients

Spencer Graves spencer.graves at pdf.com
Thu Feb 27 18:35:03 CET 2003


Your model must be singular.  Consider the following example:

 > dat0 <- data.frame(x1=1:3, x2=1:3, y=rnorm(3))
 > coef(lm(y~x1+x2, dat0))
(Intercept)          x1          x2
   -3.714515    1.487876          NA

Since x1 = x2, ordinarly least squares cannot produce separate estimates 
for coefficients for x1 and x2.  In such situations, "lm" drops terms 
out of the model until it gets a model that is estimable.

In S-Plus, "lm" will give an error message and no answer to this 
problem, unless you add ""singular.ok=TRUE".  I prefer the R default.

Spencer Graves

Ernesto Jardim wrote:
> Hi
> 
> I'm doing a regression analysis with dummy variables and I'm getting NA 
> for some coefficients. I've inspected residuals, leverage effects and 
> Cook's distance and it seems ok.
> 
> Can someone explains what can cause this problem ?
> 
> Thanks
> 
> EJ
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list