[R-sig-ME] using hglm to fit a gamma GLMM with nested randomeffects?

David Duffy davidD at qimr.edu.au
Thu May 19 04:50:18 CEST 2011


On Wed, 18 May 2011, Benjamin Caldwell wrote:

> Apologies for continuing to ask about this but . .  in my quest to fit a
> gamma GLMM model to my data (see partial copy of thread below), I'm
> exploring using hglm today. The question of the day has to do with the
> errors I'm currently getting from the hglm package. Can hglm handle a model
> with nested random effects?

I would say so, but not using the formula interface ie you would have to 
specify the Z matrix.


> test.gamma<-hglm(fixed=post.f.crwn.length~lg.shigo.av+dbh+leaf.area+
> bark.thick.bh+ht.any, random=~1|site/transect/plot, family=Gamma(link=log),
> data=rws30.BL)
> Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :
>  contrasts can be applied only to factors with 2 or more levels
> In addition: Warning messages:
> 1: In Ops.factor(site, transect) : / not meaningful for factors
> 2: In Ops.factor(site/transect, plot) : / not meaningful for factors

This is coming from model.matrix.default AIUI, which does not understand 
the "/" operator.  But anyway,

#
# mother is nested in community
#
library(mlmRev)
data(guImmun)
hglm(fixed= immun=="Y" ~ kid2p + mom25p + ord, random=~ 1|mom + 1|comm,
      data=guImmun, family=binomial())
Error in hglm.formula(fixed = immun == "Y" ~ kid2p + mom25p + ord, random 
= ~1 |  :
   Currently only one random term is supported.


If I just fit ~1|mom, it runs an awfully long time


>> test.gamma<-hglm(fixed=post.f.crwn.length~lg.shigo.av+dbh+leaf.area+
> bark.thick.bh+ht.any, random=~1|site, family=Gamma(link=log), data=rws30.BL)
> Error in hglm.default(X = X, y = Y, Z = z, family = family, rand.family =
> rand.family,  :
>  Length of X and Z differ.

This should work.  Is there missing data [not being handled correctly]? 
Maybe try data=subset(rws30.BL, complete.cases(post.f.crwn ...


Just 2c, David Duffy.

PS Another alternative, which will definitely work, is to use BUGS.

-- 
| David Duffy (MBBS PhD)                                         ,-_|\
| email: davidD at qimr.edu.au  ph: INT+61+7+3362-0217 fax: -0101  /     *
| Epidemiology Unit, Queensland Institute of Medical Research   \_,-._/
| 300 Herston Rd, Brisbane, Queensland 4029, Australia  GPG 4D0B994A v




More information about the R-sig-mixed-models mailing list