0
$\begingroup$
  lm(mpg~hp+wt+am+cyl-1, mtcars)
Call: lm(formula = mpg ~ hp + wt + am + cyl - 1, data = mtcars)
Coefficients:
 hp        wt       am0       am1      cyl6      cyl8  
-0.03211  -2.49683  33.70832  35.51754  -3.03134  -2.16368  





lm(mpg~hp+wt+am+cyl, mtcars)
Call: lm(formula = mpg ~ hp + wt + am + cyl, data = mtcars)
Coefficients:
(Intercept)           hp           wt          am1         cyl6         cyl8 
33.70832         -0.03211     -2.49683      1.80921     -3.03134    -2.16368  

When I excluded the intercept, I am getting a coefficient for am0. And when the intercept is included, I am only getting a coefficient for am1 an not for am0, why is it so??

$\endgroup$
0

1 Answer 1

0
$\begingroup$

Not only do you get an estimate for am0 if you exclude the intercept, but it is identical to the intercept in the usual model. That should be a clue. Also note that the default in R is to use effects coding of categorical variables. So, without the intercept your predicted values for Y are $$ Y = -0.03211*hp -2.49683*wt + 33.70832*am0 + 35.51754*am1 - 3.03134*cyl6 - 2.16368*cyl8 $$ where am0, am1, cyl6 and cyl8 are indicator variables that are 0 or 1.

With the intercept the formula is $$ Y = 33.70832 - 0.03211*hp -2.49683*wt + 35.51754*am1 - 3.03134*cyl6 - 2.16368*cyl8 $$

Note that this means exactly the same thing as the first formula; it gives the same results. R chooses the am variable because you listed it first and chooses am0 since it comes before am1.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.