R: When Estimating Fixed Effect Interactions, How Can I Specify Which Interactions are Omitted?

StackOverflow https://stackoverflow.com/questions/18905581

  •  29-06-2022
  •  | 
  •  

سؤال

I attempt to estimate:

OLS <- lm(Income ~ Year + State + Year:State, data=MyData)

For issues related to collinearity, lm omits one of the years and one of the states. This is fine, accept ideally, I would like to omit say, the first year to use as a baseline.

Is there anyway to specify which year and which state get omitted?

هل كانت مفيدة؟

المحلول

Yes if Year and State are factors then by default the first level is "omitted" (treated as baseline). You can use relevel to specify another baseline level.

See

?relevel

If your model gets more complicated you may need contrasts.

نصائح أخرى

In addition to my comment , You can use subset parameter of lm :

subset an optional vector specifying a subset of observations to be used in the fitting process.

For example using mtcars data set:

lm(mpg ~ wt, cyl!=6 & wt > 0, data=mtcars)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top