[R-sig-ME] Adjusting for random recording intervals in glmer/poisson

Dieter Menne dieter.menne at menne-biomed.de
Thu Jul 5 08:39:38 CEST 2012


Joshua Wiley wrote:

>> Also, I thought offset was an argument, not a function in glmer, but I
could be
> wrong (I know offset is used as you shown it in things like glm). 

I first simply tried it the glm way, then only noted that it is different in

glmer, but both methods give the same result.

library(lme4)
nsubj = 10
nvisit = 5
set.seed(100)
d = data.frame(
  subj = as.factor(1:nsubj),
  duration = runif(nsubj*nvisit,30,60),# in minutes
  predictor = rnorm(nsubj*nvisit,50,10))
d$nevent = with(d,rpois(nsubj*nvisit,predictor*duration/500))

# The glm way to use offset seems to work ok
glmer(nevent~predictor+offset(log(duration)) + (1|subj), data=d, 
      family=poisson)

# The lme4 documented way
glmer(nevent~predictor+ (1|subj), data=d, 
      offset= log(duration),family=poisson)



More information about the R-sig-mixed-models mailing list