Dear responders,
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))
Thank you for your time and considerations,
Amir
De informatie in dit bericht is uitsluitend bestemd voor de geadresseerde. Aan dit bericht en de bijlagen kunnen geen rechten worden ontleend. Heeft u deze e-mail onbedoeld ontvangen? Dan verzoeken wij u het te vernietigen en de afzender te informeren. Openbaar maken, kopi?ren en verspreiden van deze e-mail of informatie uit deze e-mail is alleen toegestaan met voorafgaande schriftelijke toestemming van de afzender. Het Radboudumc staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 80262783.
The content of this message is intended solely for the addressee. No rights can be derived from this message or its attachments. If you are not the intended recipient, we kindly request you to delete the message and inform the sender. It is strictly prohibited to disclose, copy or distribute this email or the information inside it, without a written consent from the sender. Radboud university medical center is registered with the Dutch Chamber of Commerce trade register with number 80262783.
Time-dependent Negative binomial regression
3 messages · Amirhossei@@Amirhossei@T@iebi m@iii@g oii r@dboudumc@@i, Thierry Onkelinx, Ben Bolker
Dear Amir, Have a look at the lme4, glmmTMB or INLA packages. Note that if you need on the fly transformations in the model you need to code them as I(log(person.time)) instead of log(person.time). Personally, I prefer to create a new variable in the data.frame and use that new variable in the model. Another thing is that you shouldn't use gender and baseline.age as random effects. Either don't use them (as their effect is handled by the id random effect) or add them as fixed effects. library(lme4) glmer.nb(event ~ offset(log_time) + treatment + gender + baseline.age + (1|id), data = df) Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance thierry.onkelinx at inbo.be Havenlaan 88 bus 73, 1000 Brussel www.inbo.be /////////////////////////////////////////////////////////////////////////////////////////// To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey /////////////////////////////////////////////////////////////////////////////////////////// <https://www.inbo.be> Op do 8 jul. 2021 om 08:59 schreef < Amirhossein.AmirhosseinTalebi at radboudumc.nl>:
Dear responders,
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))
Thank you for your time and considerations,
Amir
De informatie in dit bericht is uitsluitend bestemd voor de geadresseerde.
Aan dit bericht en de bijlagen kunnen geen rechten worden ontleend. Heeft u
deze e-mail onbedoeld ontvangen? Dan verzoeken wij u het te vernietigen en
de afzender te informeren. Openbaar maken, kopi?ren en verspreiden van deze
e-mail of informatie uit deze e-mail is alleen toegestaan met voorafgaande
schriftelijke toestemming van de afzender. Het Radboudumc staat
geregistreerd bij de Kamer van Koophandel in het handelsregister onder
nummer 80262783.
The content of this message is intended solely for the addressee. No
rights can be derived from this message or its attachments. If you are not
the intended recipient, we kindly request you to delete the message and
inform the sender. It is strictly prohibited to disclose, copy or
distribute this email or the information inside it, without a written
consent from the sender. Radboud university medical center is registered
with the Dutch Chamber of Commerce trade register with number 80262783.
[[alternative HTML version deleted]]
_______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
I think log(person.time) will actually work fine, although I() doesn't hurt (it's only transformations that involve operators that are also used by R's formula syntax (*, +, :, /, ^) that need to be protected by I().
On 7/8/21 5:06 AM, Thierry Onkelinx via R-sig-mixed-models wrote:
Dear Amir, Have a look at the lme4, glmmTMB or INLA packages. Note that if you need on the fly transformations in the model you need to code them as I(log(person.time)) instead of log(person.time). Personally, I prefer to create a new variable in the data.frame and use that new variable in the model. Another thing is that you shouldn't use gender and baseline.age as random effects. Either don't use them (as their effect is handled by the id random effect) or add them as fixed effects. library(lme4) glmer.nb(event ~ offset(log_time) + treatment + gender + baseline.age + (1|id), data = df) Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance thierry.onkelinx at inbo.be Havenlaan 88 bus 73, 1000 Brussel www.inbo.be /////////////////////////////////////////////////////////////////////////////////////////// To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey /////////////////////////////////////////////////////////////////////////////////////////// <https://www.inbo.be> Op do 8 jul. 2021 om 08:59 schreef < Amirhossein.AmirhosseinTalebi at radboudumc.nl>:
Dear responders,
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))
Thank you for your time and considerations,
Amir
De informatie in dit bericht is uitsluitend bestemd voor de geadresseerde.
Aan dit bericht en de bijlagen kunnen geen rechten worden ontleend. Heeft u
deze e-mail onbedoeld ontvangen? Dan verzoeken wij u het te vernietigen en
de afzender te informeren. Openbaar maken, kopi?ren en verspreiden van deze
e-mail of informatie uit deze e-mail is alleen toegestaan met voorafgaande
schriftelijke toestemming van de afzender. Het Radboudumc staat
geregistreerd bij de Kamer van Koophandel in het handelsregister onder
nummer 80262783.
The content of this message is intended solely for the addressee. No
rights can be derived from this message or its attachments. If you are not
the intended recipient, we kindly request you to delete the message and
inform the sender. It is strictly prohibited to disclose, copy or
distribute this email or the information inside it, without a written
consent from the sender. Radboud university medical center is registered
with the Dutch Chamber of Commerce trade register with number 80262783.
[[alternative HTML version deleted]]
_______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
[[alternative HTML version deleted]]
_______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
Dr. Benjamin Bolker Professor, Mathematics & Statistics and Biology, McMaster University Director, School of Computational Science and Engineering Graduate chair, Mathematics & Statistics