Re: [R] negative binomial lmer

2006-07-29 Thread Douglas Bates
On 7/28/06, Gregor Gorjanc <[EMAIL PROTECTED]> wrote:
> Ben Bolker  ufl.edu> writes:
>
> ...
> >  I haven't tried it, but you could also consider using
> > a Poisson-lognormal (rather than neg binomial, which is Poisson-gamma)
> > distribution, which might make this all work rather well
> > in lmer:
> >
> > www.cefe.cnrs.fr/esp/TBElston_Parasitology2001.pdf
>
> Actually it is very simple
>
> lmer(y ~ effA + (1 | effB), family=quasipoisson)
>
> i.e. this fits the following model
>
> y_ijk ~ Poisson(\lambda_ijk)
> log(lambda_ijk) = \mu + effaA_i + effB_ij + e_ijk
> effB_i ~ Normal(0, \sigma^2_b)
> e_ijk ~ Normal(0, \sigma^2_e)
>
> Gregor

I would advise checking the results from lmer against those from
another way of fitting this model or the negative binomial model.
There may be a problem in the way that lmer handles the scale
parameter.  I haven't checked  generalized linear mixed models with a
scale parameter as extensively as I have checked those without a
separate scale parameter (the binomial and Poisson families).  If
anyone can provide me with an example of such a model and sample data
(preferably off-list) I would appreciate it.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] negative binomial lmer

2006-07-28 Thread Gregor Gorjanc
Ben Bolker  ufl.edu> writes:

...
>  I haven't tried it, but you could also consider using
> a Poisson-lognormal (rather than neg binomial, which is Poisson-gamma)
> distribution, which might make this all work rather well
> in lmer:
> 
> www.cefe.cnrs.fr/esp/TBElston_Parasitology2001.pdf

Actually it is very simple

lmer(y ~ effA + (1 | effB), family=quasipoisson)

i.e. this fits the following model

y_ijk ~ Poisson(\lambda_ijk)
log(lambda_ijk) = \mu + effaA_i + effB_ij + e_ijk
effB_i ~ Normal(0, \sigma^2_b)
e_ijk ~ Normal(0, \sigma^2_e)

Gregor

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] negative binomial lmer

2006-07-28 Thread Ben Bolker
Tracy Feldman  yahoo.com> writes:

> 
> To whom it may concern:
> 
>   I have a question about how to appropriately conduct an lmer analysis for
negative binomially distributed
> data.  I am using R 2.2.1 on a windows machine. 
> 
>   I am trying to conduct an analysis using lmer (for non-normally distributed
data and both random and fixed
> effects) for negative binomially distributed data.  To do this, I have been
using maximum likelihood,
> comparing the full model to reduced models (containing all but one effect, for
all effects).  However, for
> negative binomially distributed data, I need to estimate the parameter theta.
 I have been doing this by
> using a negative binomial glm of the same model (except that all the effects
are fixed), and estimating mu
> as the fitted model like so:
>\

 I haven't tried it, but you could also consider using
a Poisson-lognormal (rather than neg binomial, which is Poisson-gamma)
distribution, which might make this all work rather well
in lmer:

www.cefe.cnrs.fr/esp/TBElston_Parasitology2001.pdf

  cheers
Ben Bolker

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] negative binomial lmer

2006-07-28 Thread ronggui

I think you should use glmm.admb.

library(glmmADMB)
?glmm.admb


glmm.admb  package:glmmADMB  R Documentation

Generalized Linear Mixed Models using AD Model Builder

Description:

Fits mixed-effects models to count data using Binomial, Poisson or
negative binomial response distributions. Zero-inflated versions
of  Poisson and negative binomial distributions are available.



2006/7/28, Tracy Feldman <[EMAIL PROTECTED]>:

To whom it may concern:

  I have a question about how to appropriately conduct an lmer analysis for 
negative binomially distributed data.  I am using R 2.2.1 on a windows machine.

  I am trying to conduct an analysis using lmer (for non-normally distributed 
data and both random and fixed effects) for negative binomially distributed 
data.  To do this, I have been using maximum likelihood, comparing the full 
model to reduced models (containing all but one effect, for all effects).  
However, for negative binomially distributed data, I need to estimate the 
parameter theta.  I have been doing this by using a negative binomial glm of 
the same model (except that all the effects are fixed), and estimating mu as 
the fitted model like so:

  model_1 <-glm.nb(y~x1+x2+x3, data = datafilename)
  mu_1 <- fitted(model_1)
  theta_1 <- theta.ml(y, mu_1, length(data), limit = 10, eps  = 
.Machine$double.eps^0.25, trace = FALSE)

  Then, I conduct the lmer, using the estimated theta:

  model_11 <-lmer(y~x1+x2+(1|x3), family = negative.binomial(theta = theta_1, link = 
"log"), method = "Laplace")

  First, I wondered if this sounds like a reasonable method to accomplish my 
goals.

  Second, I wondered if the theta I use for reduced models (nested within 
model_11) should be estimated using a glm.nb with the same combination of 
variables.  For example, should a glm.nb with x1 and x3 only be used to 
estimate theta for an lmer using x1 and x3?

  Third, I wish to test for random effects of one categorical variable with 122 
categories (effects of individual).  For this variable, the glm.nb (for 
estimating theta) does not work--it gives this error message:
  Error in get(ctr, mode = "function", envir = parent.frame())(levels(x),  :
orthogonal polynomials cannot be represented accurately enough for 122 
degrees of freedom
  Is there any way that will allow me to accurately estimate theta using this 
particular variable (or without it)?  Or should I be using a Poisson 
distribution (lognormal?) instead, given these difficulties?

  If anyone has advice on how to properly conduct this test (or any references 
that might tell me in a clear way), I would be very grateful.  Also, please let 
me know if I should provide additional information to make my question clearer.

  Please respond to me directly, as I am not subscribed to this list.

  Thank you very much,

  Tracy S. Feldman

  Postdoctoral Associate, the Noble Foundation, Ardmore, OK.

 __



[[alternative HTML version deleted]]



__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.






--
黄荣贵
Department of Sociology
Fudan University

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] negative binomial lmer

2006-07-27 Thread Tracy Feldman
To whom it may concern:
   
  I have a question about how to appropriately conduct an lmer analysis for 
negative binomially distributed data.  I am using R 2.2.1 on a windows machine. 
   
  I am trying to conduct an analysis using lmer (for non-normally distributed 
data and both random and fixed effects) for negative binomially distributed 
data.  To do this, I have been using maximum likelihood, comparing the full 
model to reduced models (containing all but one effect, for all effects).  
However, for negative binomially distributed data, I need to estimate the 
parameter theta.  I have been doing this by using a negative binomial glm of 
the same model (except that all the effects are fixed), and estimating mu as 
the fitted model like so:
   
  model_1 <-glm.nb(y~x1+x2+x3, data = datafilename)
  mu_1 <- fitted(model_1)
  theta_1 <- theta.ml(y, mu_1, length(data), limit = 10, eps  = 
.Machine$double.eps^0.25, trace = FALSE)
   
  Then, I conduct the lmer, using the estimated theta:
   
  model_11 <-lmer(y~x1+x2+(1|x3), family = negative.binomial(theta = theta_1, 
link = “log”), method = “Laplace”)
   
  First, I wondered if this sounds like a reasonable method to accomplish my 
goals.  
   
  Second, I wondered if the theta I use for reduced models (nested within 
model_11) should be estimated using a glm.nb with the same combination of 
variables.  For example, should a glm.nb with x1 and x3 only be used to 
estimate theta for an lmer using x1 and x3?  
   
  Third, I wish to test for random effects of one categorical variable with 122 
categories (effects of individual).  For this variable, the glm.nb (for 
estimating theta) does not work--it gives this error message:
  Error in get(ctr, mode = "function", envir = parent.frame())(levels(x),  : 
orthogonal polynomials cannot be represented accurately enough for 122 
degrees of freedom
  Is there any way that will allow me to accurately estimate theta using this 
particular variable (or without it)?  Or should I be using a Poisson 
distribution (lognormal?) instead, given these difficulties?
   
  If anyone has advice on how to properly conduct this test (or any references 
that might tell me in a clear way), I would be very grateful.  Also, please let 
me know if I should provide additional information to make my question clearer. 
 
   
  Please respond to me directly, as I am not subscribed to this list.  
   
  Thank you very much,
   
  Tracy S. Feldman
   
  Postdoctoral Associate, the Noble Foundation, Ardmore, OK.

 __



[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.