Is it possible to hide the coefficients that are factors in R lm ()?

I have a model with two types of many different fixed effects, and I'm only interested in a few regressors, not fixed effects. I find it easier to include as.factor variables to have fixed effects (rather than being used inside an evaluation). Is it possible, however, to suppress the output of these factor factors?

+3


source to share


1 answer


I believe this should work ... If your model is called m

, 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]])))]

      



This is ugly, but the concept is to use an xlevels

object attribute lm

to define the factors that are factors and remove them from the list of factors. The rest is the best way to find the correct formatting.

+1


source







All Articles