3

I have a model with two types of many different fixed effects, and I am only interested in a few regressors and not the fixed effects themselves. I find it easier to include the as.factor variables to have fixed effects (rather than use a within estimator). Is it possible, however, to suppress the output of these factor coefficients?

wolfsatthedoor
  • 7,163
  • 18
  • 46
  • 90
  • 1
    Are you actually calling the fixed effects with `as.factor()`? As in: `lm(y~x+as.factor(f),data=df)`? Or are they already factors and you trust `lm()` to treat them as such? i.e. `lm(y~x+f,data=df)` – CephBirk Dec 11 '14 at 05:12
  • They are already factors and lm is treating them that way. – wolfsatthedoor Dec 11 '14 at 05:13

1 Answers1

1

I believe this should work... If your model is named m then try this:

coef(m)[!names(coef(m)) %in% paste0(rep(names(m$xlevels), times=sapply(m$xlevels, length)), unlist(sapply(names(m$xlevels), function(x) m$xlevels[[x]])))]

It's ugly but the concept is to use the xlevels attribute of the lm object to identify coefficients that are factors and remove them from the coefficients list. The rest is just the best way I could find to get the formatting right.

CephBirk
  • 6,422
  • 5
  • 56
  • 74