I am a medical doctor and recently I have processed and cleaned a data for the aim of application of a negative binomial regression.
First, I tried to use the function glm.nb
of package MASS in R and I had a problem with ensuring that the model will realize the data are for one unique participant (possible correlations in a group of observations).
Then, I realized that I can use glmmPQL
of package MASS or glmer
of package lme4 and use the family negative binomial in it’s family link.
The question is I would like to know in which part of the model I can embed the offset (logarithm of the number of days of treatment) also how should I insert the time-constant observations for an id (such as gender and baseline age in the df)?
My latest attempt was:
(glmmPQL (event ~ treatment + offset (log(person.time)) ,
random= list (id=~1, gender=~1, baseline.age=~1),
family= negative.binomial (theta=1.75), data=df ))
which faced with a memory-related error (probably because of the wrong code). data example:
df<-data.frame(id=rep(1:3,each=4),treatment=sample(c(0,1),12,replace = T),
event=sample(c(0,1),12,replace = T),
person.time=sample(c(15,31,30),12,replace = T),
age=rep(c(65,58,74),each=4),gender=rep(c("m","f","m"),each=4))