[R-sig-ME] glmer syntax for model with "common" random effects

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Mon May 12 17:41:28 CEST 2014

Dear John Doe,

I think you want something like this (if I understand you question correctly).

PGD_21.df$Norm_Inter <- interaction(PGD_21.df$NormXY, PGD_21.df$Norm_21)
model <- glmer(Sex ~ 1 + Norm_XY + Norm_21 + (1|Pat_ID) + (1|PatID: Proc_ID) + (1|Pat_ID:Norm_Inter) + (1|PatID: Proc_ID:Norm_Inter), data =  PGD_21.df,family = binomial)

However that would yield uncorrelated 'common slopes'

Having correlated random slopes would require something like the code below + a mechanism to set a variance structure. That last part is not available in lme4. It is in nlme, but then you are restricted to the Gaussian distribution.

model <- glmer(Sex ~ 1 + Norm_XY + Norm_21 + (1 + Norm_Inter |Pat_ID) + (1 + Norm_Inter |PatID: Proc_ID), data =  PGD_21.df,family = binomial)

Best regards,


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx op inbo.be

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-sig-mixed-models-bounces op r-project.org [mailto:r-sig-mixed-models-bounces op r-project.org] Namens orzack op freshpond.org
Verzonden: maandag 12 mei 2014 16:11
Aan: r-sig-mixed-models op r-project.org
CC: orzack op freshpond.org
Onderwerp: [R-sig-ME] glmer syntax for model with "common" random effects

 I have a quick question about syntax for a glmer call.

I am fitting models with categorial predictors (Norm_XY and Norm_21)


model <- glmer(Sex ~ 1 + Norm_XY + Norm_21 + (Norm_XY|Pat_ID/Proc_ID)  + (Norm_21|Pat_ID/Proc_ID), data =  PGD_21.df,family = binomial)

this will fit random effects for the intercept and "slope" associated with each predictor

Random effects:
 Groups           Name        Variance  Std.Dev. Corr
 Proc_ID.Pat_ID   (Intercept) 0.0371635 0.19278
                  Norm_21NN   0.0073152 0.08553  -1.00
 Proc_ID.Pat_ID.1 (Intercept) 0.0007932 0.02816
                  Norm_XYNN   0.0390357 0.19757  -0.89
 Pat_ID           (Intercept) 0.0055269 0.07434
                  Norm_21NN   0.0129897 0.11397  0.99
 Pat_ID.1         (Intercept) 0.0781525 0.27956
                  Norm_XYNN   0.0579198 0.24067  -1.00

What I can't figure (and have failed to find an example of) is the syntax for "common" estimates of the random effects (i.e., for both categorical predictors).

The following syntax will generate a common estimate of the random effects for the intercept

model <- glmer(Sex ~ 1 + Norm_XY + Norm_21 + ((Norm_XY + Norm_21)|Pat_ID/Proc_ID), data =  PGD_21.df,family = binomial))

the estimates are

Random effects:
 Groups         Name        Variance Std.Dev. Corr
 Proc_ID:Pat_ID (Intercept) 0.010129 0.10064
                Norm_XYNN   0.035686 0.18891   0.99
                Norm_21NN   0.009532 0.09763  -0.99 -1.00
 Pat_ID         (Intercept) 0.101927 0.31926
                Norm_XYNN   0.070295 0.26513  -0.98
                Norm_21NN   0.019164 0.13843   0.11  0.08

So how does one specify a model that estimates the random effects for the "common" or joint categorical predictor of the "slope"  (i.e. for Norm_XY and Norm_21 combined)?

This model would produce estimates like this

Random effects:
 Groups         Name        Variance Std.Dev. Corr
 Proc_ID:Pat_ID (Intercept) XXX
                           Common "slope" ZZZ     QQQ
 Pat_ID               (Intercept) YYY
                           Common "slope" WWW  RRR

In these applications, the random effects are nuisance parameters, so I don't necessarily need predictor-specific estimates. That said, I do want to account for the random effects and their influence on the estimates of the fixed effects (otherwise I would just use GLM)

The first model above penalizes AIC by 24 (just considering random effects) and the last model would penalize it by 12. this is a big difference.


        [[alternative HTML version deleted]]

R-sig-mixed-models op r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.

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