[R-sig-ME] Nested random effects in mgcv gam/bam
mrgu|||oy|e @end|ng |rom gm@||@com
Mon Jun 24 18:07:52 CEST 2019
Cesko, thanks for the reply.
> If the subjects are each in one group only, the 'by=G' in the two re smooths in m2b is redundant, and therefore m2a is correct.
Does the addition of a by-factor argument not allow different variance in the random effects for each group? (Incidentally each subject is in one group only)
> Note that this is not entirely equivalent to your gamm model, for two reasons. One is, as you note correctly, that gamm includes correlations between intercept and A which bam doesn't. The second reason is that nlme interprets subsequent grouping factors as nested, meaning that your model actually has random effects for G and G %in% ID, not for G and ID separately. (This could be overcome with a complicated pdBlocked() argument, or by using gamm4 instead of gamm.)
So does this imply that the random effects on intercept and slope will necessarily be uncorrelated in gam/bam, i.e. equivalent to a pdDiag() argument in lme/gamm?
Secondly, does a random effect smooth with two factors [e.g. s(G, ID, A, bs=‘re’)] not create a nested structure? - the mgcv random.effects documentation page implies that the random effect applies to the interaction of the two factors?
> Good luck,
> -----Messaggio originale-----
> Da: R-sig-mixed-models <r-sig-mixed-models-bounces using r-project.org> Per conto di Mathew Guilfoyle
> Inviato: maandag 24 juni 2019 14:34
> A: r-sig-mixed-models using r-project.org
> Oggetto: [R-sig-ME] Nested random effects in mgcv gam/bam
> I have a dataset comprising of subjects with a unique identifier ‘ID’ who are each in one of two groups ‘G’ . I am looking to find the smooth relationship between numerical variables A and B that are both evaluated at multiple times in each subject.
> Ignoring the grouping for the moment, a GAM formula including random intercept and ’slope’ for each subject would be:
> m1 = bam(B ~ s(A, bs=‘cr’, k=10) + s(ID, bs=‘re’) + s(ID, A, bs=‘re’))
> Now, I believe the smooth is different in each group therefore I want to obtain separate smooths based on G, and also include random intercepts and ‘slope’ for each subject but nested within each group.
> Which of the following constructions is correct? (G is a factor)?:
> m2a = bam(B ~ G + s(A, bs=‘cr’, k=10, by=G) + s(G, ID, bs=‘re’) + s(G, ID, A, bs=‘re’))
> m2b = bam(B ~ G + s(A, bs=‘cr’, k=10, by=G) + s(ID, bs=‘re’, by=G) + s(ID, A, bs=‘re’, by=G))
> I have tried do this more explicitly using gamm:
> m3 = gamm(B ~ G + s(A, bs=‘cr’, k=10, by=G), random = list(G=~1+A, ID=~1+A))
> but this takes a lot longer (hours) to run given the size of the dataset and as I don’t need/want to specify the correlation structure of the random effects I hoped that one of the bam calls above was equivalent. I have tried the various models on a subset of the data and model m2a gives qualitatively very similar smooths to model m3.
> R-sig-mixed-models using r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
More information about the R-sig-mixed-models