I am struggling with interpreting coefficients from a multiple regression analysis with multiple categorical (dummy) variables. I am running a linear mixed model with biodiversity (LnS_Add1) as independent variable, and several continuous and categorical dependent variables.

With a single categorical/dummy variable (e.g. LnS_Add1 ~ AREA_AM_2.5 + System_Type3; where AREA_AM_2.5 is continuous and System_Type3 is categorical with 3 levels, i.e. Arable, Grassland and Orchard) this is pretty straightforward. In this case the intercept represents the mean of the reference dummy variable (e.g. Arable) and the mean of the 2nd and 3rd levels Grassland and Orchard can be calculated manually by adding intercept to the slope coefficient.

globmod1 <- lmer(LnS_Add1 ~ AREA_AM_2.5 + System_Type3 + 
     (1|Study_Code/Pair_Code), data1_plant)

Which returns

Fixed effects:
                        Estimate Std. Error t value
(Intercept)            0.3585534  0.1238470   2.895
AREA_AM_2.5            0.0004256  0.0001371   3.104
System_Type3Grassland -0.5227684  0.0915722  -5.709
System_Type3Orchard   -0.4057969  0.5477567  -0.741

To get a summary output that shows the means of both Arable, Grassland and Orchard in R I suppress the intercept by adding a -1 (or +0) to the model.

globmod1.coef <- lmer(LnS_Add1 ~ AREA_AM_2.5 + System_Type3 -1 +
                   (1|Study_Code/Pair_Code), data1_plant)

Which returns:

Fixed effects:
                        Estimate Std. Error t value
AREA_AM_2.5            0.0004256  0.0001371   3.104
System_Type3Arable     0.3585534  0.1238470   2.895
System_Type3Grassland -0.1642149  0.1341851  -1.224
System_Type3Orchard   -0.0472434  0.5457304  -0.087

But what do I do if I have multiple categorical variables (e.g. LnS_Add1 ~ AREA_AM_2.5 + System_Type3 + Habitat2; where Habitat2 is a categorical variable with 3 levels, i.e. Farm aggregated, Outside field, and Within field)?. Now the intercept represents the mean of the reference level of a combination of System_Type3 and Habitat2 (e.g. all data in arable systems and measured at farm aggregate level). But what I am interested in are the means for the different levels of each of my 2 categorical variables, holding everything else constant.

How do I create a summary table that contains means of all levels of all categorical variables in my model? The -1 command doesnt help me anymore, as it removes the intercept but the intercept now represents a mean of 2 reference dummy variables. I am only interested here in the fixed effect estimates, not in any hypothesis testing.

  • 2
    $\begingroup$ This question isn't really about how to code in R. It is about understanding how multiple categorical variables are represented in regression models. IMO, it should be considered on-topic here. $\endgroup$ – gung - Reinstate Monica Jun 1 '15 at 21:00
  • 2
    $\begingroup$ I believe lsmeans in package lmerTest could be what you are after. $\endgroup$ – Roland Jun 2 '15 at 8:14
  • $\begingroup$ @Roland - thanks for the suggestion. I tried lsmeans out but when used on an lmer object it always gives the error message: Error in as.data.frame.default(VarCorr(model)) : cannot coerce class ""VarCorr.merMod"" to a data.frame. And I couldn't find help on this error online. In addition to the question of how to do this in R, as @gung pointed out, this is not just an R question, as I am also just generally interested in how to interpret multiple categorical variables in regressions... $\endgroup$ – Verena Foveolatus Jun 11 '15 at 0:06
  • $\begingroup$ lsmeans from package lsmeans works with an lmer object. And the documentation for the lsmeans package does a good job at explaining what it is doing. $\endgroup$ – Verena Foveolatus Jun 11 '15 at 2:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.