[R-sig-ME] R: Nested random effects in mgcv gam/bam

Voeten, C.C. c@c@voeten @end|ng |rom hum@|e|denun|v@n|
Mon Jun 24 15:37:11 CEST 2019


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. 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.)

Good luck,
Cesko

-----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.

Thanks.
_______________________________________________
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 mailing list