[R-sig-ME] GLMM with mgcv::gam

Gavin Simpson gavin.simpson at ucl.ac.uk
Tue Oct 16 14:49:45 CEST 2012

Apologies for the late response. see in-line.

On Mon, 2012-08-27 at 12:25 +0200, Andreas Böck wrote:
> Dear Mixed-Model Experts,
> my question is about the mgcv::gam function in a recent version (version
> 1.7-19 or 1.7-20).
> Is it true, that gam(y ~ x1+ s(id, bs="re"), method ="REML",
> family=binomial) does the following:
> - setup the model
> - call MASS::glmmPQL where
>     glmmPQL somehow iterates between nlme::lme and glm.fit calls
> - make the results look like a gam object

No. Only `gamm()` in the mgcv package would do what you suggest. The
"re" basis derives from the linear mixed effect representation of the
penalised regression model that underlies the mgcv version of a GAM.
IIRC essentially the penalties on the smooth functions can be
represented as random effects in a LME. Simon's new "re" basis is
essentially exploiting this feature, again IIRC, by setting up a spline
basis that would produce a simple random effect when viewed from the LME
formulation of the model. (I speculate that this means that the "re"
basis is solely represented as a random effect, the other basis
functions in mgcv would be split into both fixed and random effects in
the LME representation).

> The method="REML" argument affects only the lme part in the fitting
> procedure ?

Nope, although it is related. The penalised regression underlying the
gam() can be fitted via ML or REML (amongst other methods). As the
penalties on the splines can be viewed as random effects, REML fitting
might be expected to get the best estimation of their variance. From
what I recall of Simon's papers, there is little to choose between ML
and REML fitting in terms of performance on simulated data exercises,
though REML may have the edge. This was not looked at in terms of "re"
basis smooths however, but in terms of more general s() smooths.

> If the above is true, is it prefarable to use glmer(y~x1 + (1|id),
> family="binomial") or gamm4, as the approach in the lme4 package is more
> reliable as the penalized-quasi-likelihood approach in package MASS,
> especially for binomial families?

If your problem involves a simple random effect then I don't think there
will be any major differences between the various approaches (other than
gamm() using glmmPQL() which you might want to avoid). You won't be able
to use glmer() with the same s() functions used in your gam() can't be
included in the glmer() formula. gamm4 does allow the s() from gam() to
be included (or most of them) so your options are gam() with a "re"
basis or gamm4 (which iterates gam() and glmer() IIRC). Do
read ?smooth.construct.re.smooth.spec from package mgcv which describes
where you might choose gamm4 over the "re" basis terms (essentially for
big problems with large numbers of random effects, the "re" basis in
gam() won't be as efficient as gamm4 because it doesn't exploit the
sparseness of the random effect structure).



> Thank you very much for clarification !
> Best,
> Andi Böck
> (PhD candidate, Munich)
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models

 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk

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