# [R-sig-ME] Setting average as baseline rather than a dummy variable in a negative binomial glm

Aitor Gastón aitor.gaston at upm.es
Fri Aug 5 21:29:40 CEST 2016

```You can change the contrasts type using contrasts.

I always use the default contrast in R (treatment), but I guess that you are
looking for sum contrast, running

options(contrasts=c("contr.sum","contr.poly"))

before you fit the model will change to sum contrasts, i.e., the intercept
shows the grand mean and the coefficients of each level are the difference
between the grand mean and each level.

Aitor

-----Mensaje original-----
From: Daniel Rubi via R-sig-mixed-models
Sent: Friday, August 05, 2016 6:37 PM
To: R-sig-mixed-models
Subject: [R-sig-ME] Setting average as baseline rather than a dummy variable
in a negative binomial glm

Hi,
I first posted this in cross validated, but thought this forum is better
suited for this question.

I have binomial data (meaning k successes out of n trials) for a set of
conditions. I would like to fit a glm in order to quantify the effect of
each condition on the success.Since the data are overdisperesed I thought of
using a negative binomial glm (glm.nb from the R MASS package does
that).Code snippet (though not really overdisperesed):set.seed(1)
df <- data.frame(k = as.integer(runif(200,1,20)),
n = as.integer(runif(200,100,200)),
cond = rep(LETTERS[1:20],10),
stringsAsFactors = F)
df\$cond <- as.factor(df\$cond)
library(MASS)
fit <- glm.nb(k ~ cond + offset(n), data = df)
Obviously cond A will be set as baseline and all effects will be relative to
it. However, this makes interpretation very difficult for me. Therefore my
question is how do I fit a glm.nb model where the effects are relative to
the mean across all conditions rather than the dummy variable set as
baseline?
Thanks a lot,Dan
[[alternative HTML version deleted]]

_______________________________________________
R-sig-mixed-models at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models

```