Skip to content
Prev 8537 / 20628 Next

Adjusting for random recording intervals in glmer/poisson

Joshua Wiley wrote:

            
Good to hear that you suggest it to put it into the offset; I wanted to do this, but was not sure what exactly to put into the offset term. Duration or log(duration)?

Dieter


Apologies: I forgot to attach the simulated sample data in the original message

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

# Proposed solution by university statistician: 
# use only the data from the first 30 minutes (not shown here) and do
glmer(nevent~predictor + (1|subj),data=d, family=poisson)
# Result is not correct, because truncated data not used

# Proposed by Joshua
glmer(nevent~predictor+offset(log(duration)) + (1|subj), data=d, family=poisson)