mixed effects models - negative binomial family?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

mixed effects models - negative binomial family?

Constantinos Antoniou
Hello all,

I would like to fit a mixed effects model, but my response is of the  
negative binomial (or overdispersed poisson) family. The only (?)  
package that looks like it can do this is glmm.ADMB (but it cannot  
run on Mac OS X - please correct me if I am wrong!) [1]

I think that glmmML {glmmML}, lmer {Matrix}, and glmmPQL {MASS} do  
not provide this "family" (i.e. nbinom, or overdispersed poisson). Is  
there any other package that offers this functionality?

Thanking you in advance,

Costas


[1] Yes, I know I can use this on another OS. But it is kind of a  
nuisance, as I have my whole workflow setup on a mac, including emacs
+ess, the data etc etc. It will be non-trivial to start moving/
syncing files between >1 computers, in order to use this package...

--
Constantinos Antoniou, Ph.D.
Department of Transportation Planning and Engineering
National Technical University of Athens
5, Iroon Polytechniou str. GR-15773, Athens, Greece

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: mixed effects models - negative binomial family?

Ben Bolker-2
 
 
Constantinos Antoniou <antoniou <at> central.ntua.gr> writes:

>
> Hello all,
>
> I would like to fit a mixed effects model, but my response is of the  
> negative binomial (or overdispersed poisson) family. The only (?)  
> package that looks like it can do this is glmm.ADMB (but it cannot  
> run on Mac OS X - please correct me if I am wrong!) [1]
>
> I think that glmmML {glmmML}, lmer {Matrix}, and glmmPQL {MASS} do  
> not provide this "family" (i.e. nbinom, or overdispersed poisson). Is  
> there any other package that offers this functionality?

 You'll probably get more complete/informed information
shortly, but ... you may not be able to get a negative
binomial distribution per se, but other versions
of "overdispersed Poisson" are indeed possible.  glmmPQL
will let you use the quasipoisson family, which allows for
overdispersion in a phenomenological way; more mechanistically,
observation-level random effects on the scale of the
linear predictor (log for a GLMM with family=poisson)
lead to a lognormal-Poisson distribution, which has similar
properties to the NB.  I suspect you can do this in lmer
(lme4 package), which does GLMMs if you specify the family
argument.

See:

http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&list_uids=11393830&dopt=Abstract
(analysis done in SAS but probably completely feasible in R at this point)

  Ben

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: mixed effects models - negative binomial family?

Prof Brian Ripley
On Mon, 2 Jan 2006, Ben Bolker wrote:

>
>
> Constantinos Antoniou <antoniou <at> central.ntua.gr> writes:
>
>>
>> Hello all,
>>
>> I would like to fit a mixed effects model, but my response is of the
>> negative binomial (or overdispersed poisson) family. The only (?)
>> package that looks like it can do this is glmm.ADMB (but it cannot
>> run on Mac OS X - please correct me if I am wrong!) [1]
>>
>> I think that glmmML {glmmML}, lmer {Matrix}, and glmmPQL {MASS} do
>> not provide this "family" (i.e. nbinom, or overdispersed poisson). Is
>> there any other package that offers this functionality?
>
> You'll probably get more complete/informed information
> shortly, but ... you may not be able to get a negative
> binomial distribution per se, but other versions
> of "overdispersed Poisson" are indeed possible.  glmmPQL
> will let you use the quasipoisson family, which allows for
> overdispersion in a phenomenological way;

and has worked examples of this in the book it supports.

It also lets you use a negative binomial family, and MASS provides one.

> more mechanistically,
> observation-level random effects on the scale of the
> linear predictor (log for a GLMM with family=poisson)
> lead to a lognormal-Poisson distribution, which has similar
> properties to the NB.  I suspect you can do this in lmer
> (lme4 package), which does GLMMs if you specify the family
> argument.
>
> See:
>
> http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&list_uids=11393830&dopt=Abstract
> (analysis done in SAS but probably completely feasible in R at this point)

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: mixed effects models - negative binomial family?

Elizabeth Lawson-2
In reply to this post by Constantinos Antoniou
Have you tried nlme?
   
  I tried to something similar.
   
  Here is the code that I used for a negative binomial random effects model
   
   
  library(nlme)
  mydata<-read.table("C:\\Plx\\plx.all\\plxall.txt",header=TRUE)
  loglike = function(PLX_NRX,PD4_42D,GAT_34D,VIS_42D,MSL_42D,SPE_ROL,XM2_DUM,THX_DUM,b0,b1,b2,b3,b4,b5,b6,b7,alpha){
  lambda = exp(b0 + b1*GAT_34D+b2*VIS_42D+b3*MSL_42D+b4*PD4_42D+b5*SPE_ROL+b6*XM2_DUM+b7*THX_DUM)
  y=round(PLX_NRX)
  y <- table(y)
   freq <- as.vector(y)
          count <- as.numeric(names(y))
   count <- count[!(freq < 1)]
      freq <- freq[!(freq < 1)]
      n <- length(count)
      df <- n - 1
                         
   
   
   
   df <- df - 2
              xbar <- weighted.mean(count, freq)
              s2 <- var(rep(count, freq))
              p <- xbar/s2
              alpha <- xbar^2/(s2 - xbar)
   
  ( dnbinom(y,alpha,(alpha/(alpha+lambda))) )
    }
   
   
  plx.nlme<-nlme(PLX_NRX~loglike(PLX_NRX,PD4_42D,GAT_34D,VIS_42D,MSL_42D,SPE_ROL,XM2_DUM,THX_DUM,b0,b1,b2,b3,b4,b5,b6,b7,alpha),
  data=mydata,
  fixed=list(b0 + b1+b2+b3+b4+b5+b6+b7+alpha~1),
  random=b0~1|menum,
   
  start=c(b0=0,b1=0,b2=0,b3=0,b4=0,b5=0,b6=0,b7=0,alpha=5)
  )
   
  I am not sure that this is what you are looking for , but I hope this helps!

   
  Elizabeth Lawson
Constantinos Antoniou <[hidden email]> wrote:
  Hello all,

I would like to fit a mixed effects model, but my response is of the
negative binomial (or overdispersed poisson) family. The only (?)
package that looks like it can do this is glmm.ADMB (but it cannot
run on Mac OS X - please correct me if I am wrong!) [1]

I think that glmmML {glmmML}, lmer {Matrix}, and glmmPQL {MASS} do
not provide this "family" (i.e. nbinom, or overdispersed poisson). Is
there any other package that offers this functionality?

Thanking you in advance,

Costas


[1] Yes, I know I can use this on another OS. But it is kind of a
nuisance, as I have my whole workflow setup on a mac, including emacs
+ess, the data etc etc. It will be non-trivial to start moving/
syncing files between >1 computers, in order to use this package...

--
Constantinos Antoniou, Ph.D.
Department of Transportation Planning and Engineering
National Technical University of Athens
5, Iroon Polytechniou str. GR-15773, Athens, Greece

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 


               
---------------------------------

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: mixed effects models - negative binomial family?

Constantinos Antoniou
Elisabeth,

Thank you for the code. I will give it a shot and see how it goes.

I have also seen that glmmPQL {MASS} can use the quasipoisson family  
(which is usually fairly close to the negative binomial (?)). So this  
looks like an "easier" way to accomplish what I want. [I would like  
to thank Ben Bolker for his suggestion to use the quasipoisson. As a  
matter of fact, I have used it for glm models in the past (along with  
negative binomial) and gave similar results. Thank you also for the  
useful reference.]

Thank you also to Prof. Ripley for his response. In the past I had  
used glm.nb, but I have to admit I had not realized that there is  
also a negative.binomial family (to use as an argument for "family")!  
Once again, thank you for the help and the wonderful book (it adds  
some weight to my backpack, but it is worth it!).

In a somewhat related comment, I have stopped receiving emails from R-
help this year, i.e. after Dec 31, 2005 (for some unknown reason... I  
subscribed with a different address, so I am getting the messages  
again today, but I cannot reply to the two emails that Ben Bolker and  
Prof. Ripley sent directly. I am replying above, as I only saw them  
in the archives).

Best regards,

Costas



On Jan 3, 2006, at 11:54 PM, Elizabeth Lawson wrote:

> Have you tried nlme?
>
> I tried to something similar.
>
> Here is the code that I used for a negative binomial random effects  
> model
>
>
> library(nlme)
> mydata<-read.table("C:\\Plx\\plx.all\\plxall.txt",header=TRUE)
> loglike = function
> (PLX_NRX,PD4_42D,GAT_34D,VIS_42D,MSL_42D,SPE_ROL,XM2_DUM,THX_DUM,b0,b1
> ,b2,b3,b4,b5,b6,b7,alpha){
> lambda = exp(b0 + b1*GAT_34D+b2*VIS_42D+b3*MSL_42D+b4*PD4_42D
> +b5*SPE_ROL+b6*XM2_DUM+b7*THX_DUM)
> y=round(PLX_NRX)
> y <- table(y)
>  freq <- as.vector(y)
>         count <- as.numeric(names(y))
>  count <- count[!(freq < 1)]
>     freq <- freq[!(freq < 1)]
>     n <- length(count)
>     df <- n - 1
>                       &nbs! p;
>
>
>
>  df <- df - 2
>             xbar <- weighted.mean(count, freq)
>             s2 <- var(rep(count, freq))
>             p <- xbar/s2
>             alpha <- xbar^2/(s2 - xbar)
>
> ( dnbinom(y,alpha,(alpha/(alpha+lambda))) )
>   }
>
>
> plx.nlme<-nlme(PLX_NRX~loglike
> (PLX_NRX,PD4_42D,GAT_34D,VIS_42D,MSL_42D,SPE_ROL,XM2_DUM,THX_DUM,b0,b1
> ,b2,b3,b4,b5,b6,b7,alpha),
> data=mydata,
> fixed=list(b0 + b1+b2+b3+b4+b5+b6+b7+alpha~1),
> random=b0~1|menum,
>
> start=c(b0=0,b1=0,b2=0,b3=0,b4=0,b5=0,b6=0,b7=0,alpha=5)
> )
>
> I am not sure that this is what you are looking for , but I hope  
> this helps!
>
> Elizabeth Lawson
> Constantinos Antoniou <[hidden email]> wrote:
> Hello all,
>
> I would like to fit a mixed effects model, but my re! sponse is of the
> negative binomial (or overdispersed poisson) family. The only (?)
> package that looks like it can do this is glmm.ADMB (but it cannot
> run on Mac OS X - please correct me if I am wrong!) [1]
>
> I think that glmmML {glmmML}, lmer {Matrix}, and glmmPQL {MASS} do
> not provide this "family" (i.e. nbinom, or overdispersed poisson). Is
> there any other package that offers this functionality?
>
> Thanking you in advance,
>
> Costas
>
>
> [1] Yes, I know I can use this on another OS. But it is kind of a
> nuisance, as I have my whole workflow setup on a mac, including emacs
> +ess, the data etc etc. It will be non-trivial to start moving/
> syncing files between >1 computers, in order to use this package...
>
> --
> Constantinos Antoniou, Ph.D.
> Department of Transportation Planning and Engineering
> National Technical University of Athens
> 5, Iroon Polytechniou str. GR-15773, Athens, Greece
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting- 
> guide.html
>
>
> Yahoo! for Good - Make a difference this year.


--
Constantinos Antoniou, Ph.D.
Department of Transportation Planning and Engineering
National Technical University of Athens
5, Iroon Polytechniou str. GR-15773, Athens, Greece





        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html