Skip to content

using hglm to fit a gamma GLMM with nested random effects?

2 messages · Benjamin Caldwell, David Duffy

#
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 don't see an example of one of those in the
package documentation. If it can, can anyone tell me what these errors are
trying to tell me?

If no, I promise I'll let this rest and just take B. Boker's advice to go
with a nice safe modified log transform of the data.

Best


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
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.
* Dennis Murphy <djmuser at gmail.com> Tue, May 17, 2011 at 6:18 PM
To: Benjamin Caldwell <btcaldwell at berkeley.edu>
 Hi:

Someone else (Wayne Zhang, CNA) asked a similar question re
hierarchical Gamma models on R-help today and responded to suggestions
as follows:

"Hglm does the work! Thanks!

Also, I find that the developing version of lme4, called lme4a, has
the capability to fit Gamma models. And both lme4a and hglm produce
results consistent with the published ones.

Problems solved!"

Perhaps you might find success following his lead?

Dennis
Ben Bolker <bbolker at gmail.com>
* *Tue, May 17, 2011 at 4:50

PM*
To: Benjamin Caldwell <btcaldwell at berkeley.edu>
Cc: "r-sig-mixed-models at r-project.org" <r-sig-mixed-models at r-project.org>
  [forwarding to r-sig-mixed-models list ...]

 As of today, Gamma models are (still) not feasible in lme4 -- they are
somewhat more numerically challenging than the other families, so Doug
Bates is having to do some re-engineering.
 There is a *possibility* that I can get Gamma fitting to work in the
'alpha'/bleeding-edge development version of glmmADMB, but it will
definitely be bleeding-edge ... if you are interested in trying that,
please contact me off-list.

  In the meantime, my standing advice is to try a LMM on the
log-transformed data (zero values in the response are problematic, but
they would be problematic in a Gamma GLMM in any case if the shape
parameter is ever < 1 ...)

 Ben Bolker
On 11-05-17 07:32 PM, Benjamin Caldwell wrote:
<mailto:btcaldwell at berkeley.edu<https://mail.google.com/mail/?ui=2&ik=938097cb0f&view=pt&search=inbox&msg=130005e6516c0ad7&dsqt=1>>>
wrote:
email
"residuals")
about?
bark.thick.bh
*Ben Caldwell*

PhD Candidate
University of California, Berkeley
-------------- next part --------------
A non-text attachment was scrubbed...
Name: residuals.png
Type: image/png
Size: 9189 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20110518/110df56d/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: transformed response var, and subsets.png
Type: image/png
Size: 10643 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20110518/110df56d/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Distribution response var.png
Type: image/png
Size: 8376 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20110518/110df56d/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qqnorm plot of gaussian hierarchical fit.png
Type: image/png
Size: 7515 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20110518/110df56d/attachment-0003.png>
#
On Wed, 18 May 2011, Benjamin Caldwell wrote:

            
I would say so, but not using the formula interface ie you would have to 
specify the Z matrix.
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
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.