[R] Overdispersed GLM

Ben Bolker bbolker at gmail.com
Sat Aug 27 23:45:48 CEST 2011


Jim Silverton <jim.silverton <at> gmail.com> writes:

> 
> Hi all,
> 
> I have the following  data:
> 
> rep1_treat       rep2_treat         rep1_control      rep2_control
> 2                          3                          4                  5
> 100                     20                         98                  54
> 0                          1                         2                     3
> 23                       32                        27                   28
> 
> Two replicates for the treatment and control groups. I want to simulate from
> the null where the null is:
> Ho:there is no difference between control and treatment groups.
> 
> Can R do a glm to do this?
> Another point is my data is overdispersed, so I would like to fit a negative
> binomial glm for each variable. Each row is a variable.

  Your data look a little weird.  Do you really have (0,2) and
(100,23) as responses for rep1_treat, or are those indices that
got mangled somehow?  In any case, you need to rearrange your
data to long format:

d <- data.frame(rep1_treat=c(2,100,0,23),
                rep2_treat=c(3,20,1,32),
                rep1_control=c(4,98,2,27),
                rep2_control=c(5,54,3,28))


library(reshape)
d2 <- melt(d)
d3 <- data.frame(d2,colsplit(d2$variable,"_",c("rep","ttt")))

library(lattice)
xyplot(value~ttt:rep,data=d3)

library(MASS)
g1 <- glm.nb(value~1,data=d3)
simulate(g1)  ## simulate from null model
g2 <- glm.nb(value~ttt,data=d3)

You may need to consider the possibility that "rep1" and "rep2"
are different.  In principle 'rep' should be treated as a random
effect, but with only two reps that's not really feasible, so
try including it as an interaction instead (i.e. value~rep*ttt)



More information about the R-help mailing list