2

I have the following gamm4 output:

plot

This is longitudinal data modeled as:

gamm4(Mean_DTI ~ s(Age) + Sex + Timepoint_yrs,
                     random = ~ (1 + Timepoint_yrs | ID),
                     data = DF)

I choose gamm because the data is nonlinear across age in a cross-sectional sample. However, the results show edf is 1 and the plots are linear. This isn't too surprising because the data set is within young adults as opposed to across the lifespan.

My question is: should I be testing a different model instead like: lmer(Mean_DTI ~ Age + Sex + Timepoint_yrs + (1 + Timepoint_yrs|ID), data = DF) and then compare AIC? Or can I report my gamm4 results and simply state the effect of age is linear?

data sample:

structure(list(ID = c(33714L, 35377L, 40556L, 40798L, 40800L, 
40815L, 50848L, 52183L, 52461L, 53320L, 53873L, 54206L, 54581L, 
55122L, 55267L, 55462L, 55612L, 55920L, 56022L, 56307L, 56420L, 
56679L, 57405L, 57480L, 57725L, 57809L, 58004L, 58215L, 58229L, 
59326L, 59327L, 59865L, 60099L, 60100L, 60280L, 60384L, 60429L, 
60493L, 60503L, 60603L, 60664L, 60846L, 61415L, 61749L, 61883L, 
62081L, 62983L, 63327L, 63329L, 64418L, 64507L, 64596L, 65178L, 
65250L, 65802L, 65975L, 65978L, 66396L, 66572L, 66589L, 74034L, 
74427L, 74607L, 74952L, 75732L, 76574L, 76595L, 76755L, 76759L, 
77203L, 77453L, 77668L, 81064L, 81065L, 33714L, 35377L, 40556L, 
40798L, 40800L, 40815L, 50848L, 52183L, 52461L, 53320L, 53873L, 
54206L, 54581L, 55122L, 55267L, 55462L, 55612L, 55920L, 56022L, 
56307L, 56420L, 56679L, 57405L, 57480L, 57725L, 57809L, 58004L, 
58215L, 58229L, 59326L, 59327L, 59865L, 60099L, 60100L, 60280L, 
60384L, 60429L, 60493L, 60503L, 60603L, 60664L, 60846L, 61415L, 
61749L, 61883L, 62081L, 62983L, 63327L, 63329L, 64418L, 64507L, 
64596L, 65178L, 65250L, 65802L, 65975L, 65978L, 66396L, 66572L, 
66589L, 74034L, 74427L, 74607L, 74952L, 75732L, 76574L, 76595L, 
76755L, 76759L, 77203L, 77453L, 77668L, 81064L, 81065L, 33714L, 
35377L, 40556L, 40798L, 40800L, 40815L, 50848L, 52183L, 52461L, 
53320L, 53873L, 54206L, 54581L, 55122L, 55267L, 55462L, 55612L, 
55920L, 56022L, 56307L, 56420L, 56679L, 57405L, 57480L, 57725L, 
57809L, 58004L, 58215L, 58229L, 59326L, 59327L, 59865L, 60099L, 
60100L, 60280L, 60384L, 60429L, 60493L, 60503L, 60603L, 60664L, 
60846L, 61415L, 61749L, 61883L, 62081L, 62983L, 63327L, 63329L, 
64418L, 64507L, 64596L, 65178L, 65250L, 65802L, 65975L, 65978L, 
66396L, 66572L, 66589L, 74034L, 74427L, 74607L, 74952L, 75732L, 
76574L, 76595L, 76755L, 76759L, 77203L, 77453L, 77668L, 81064L, 
81065L), Sex = structure(c(1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 
2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 
2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 
2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 
2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 
2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 
2L, 1L, 2L, 1L, 1L), .Label = c("Male", "Female"), class = "factor"), 
    Age = c(15L, 15L, 9L, 11L, 16L, 9L, 16L, 16L, 14L, 8L, 6L, 
    14L, 10L, 15L, 13L, 15L, 8L, 9L, 9L, 8L, 9L, 9L, 13L, 10L, 
    7L, 8L, 8L, 6L, 15L, 8L, 11L, 14L, 12L, 10L, 16L, 12L, 10L, 
    6L, 13L, 11L, 12L, 13L, 10L, 13L, 14L, 12L, 17L, 9L, 12L, 
    11L, 10L, 12L, 10L, 10L, 14L, 16L, 15L, 14L, 14L, 13L, 10L, 
    12L, 9L, 9L, 16L, 10L, 14L, 15L, 13L, 15L, 13L, 13L, 8L, 
    11L, 16L, 16L, 11L, 13L, 18L, 10L, 18L, 18L, 15L, 10L, 8L, 
    15L, 12L, 16L, 14L, 16L, 9L, 11L, 11L, 10L, 10L, 11L, 14L, 
    12L, 8L, 9L, 9L, 8L, 16L, 9L, 13L, 16L, 13L, 12L, 18L, 13L, 
    11L, 8L, 14L, 12L, 13L, 14L, 11L, 14L, 15L, 14L, 18L, 11L, 
    14L, 12L, 12L, 13L, 11L, 11L, 15L, 17L, 16L, 15L, 15L, 14L, 
    11L, 13L, 10L, 11L, 18L, 11L, 15L, 16L, 14L, 17L, 14L, 14L, 
    9L, 12L, 18L, 18L, 12L, 14L, 19L, 11L, 19L, 19L, 16L, 11L, 
    9L, 17L, 13L, 18L, 16L, 18L, 11L, 12L, 12L, 11L, 11L, 12L, 
    16L, 13L, 9L, 11L, 10L, 9L, 17L, 11L, 14L, 17L, 14L, 13L, 
    19L, 15L, 12L, 9L, 15L, 14L, 14L, 15L, 12L, 16L, 17L, 15L, 
    20L, 12L, 15L, 13L, 13L, 14L, 12L, 12L, 16L, 19L, 18L, 16L, 
    16L, 15L, 12L, 14L, 11L, 11L, 19L, 12L, 16L, 17L, 15L, 18L, 
    15L, 15L, 10L, 13L), Timepoint_yrs = c(0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 2L, 2L, 2L, 1L, 
    2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 
    2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 
    1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 
    1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 
    3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 
    3L, 3L, 2L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 2L, 
    3L, 2L, 3L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 2L, 
    2L, 2L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 
    2L, 2L, 3L, 2L, 2L, 2L, 2L), Mean_DTI = c(-1.29114475134035, 
    -0.602946528016743, 1.41024744477638, 0.666624732324295, 
    -0.892919147953548, 0.6407945839951, 0.205705854349546, 0.402741860197385, 
    -1.07334078703688, 1.08029650481248, 0.350172965356561, -2.54347860616321, 
    0.413255639165549, -0.3523032294053, -0.760004213837485, 
    -0.370085793832933, 0.541108383408053, 0.103423658955543, 
    2.07157712184801, -0.313622906781678, 0.365099935496544, 
    0.880404904676991, -0.584385165147017, 0.12808560962161, 
    -1.30879751602764, 0.897408670662543, -0.553700506528817, 
    1.90361625783806, -1.00532572309467, 0.210378645002065, -0.759874414097138, 
    -0.977159179439218, -0.483530766896841, 0.0460521737218543, 
    0.816803031906609, 0.313569438578502, 0.416370832933893, 
    -0.675893982092161, 0.339788986128743, 0.361465542766807, 
    -0.473536186890064, -0.0725847889559601, -1.60084693181001, 
    0.52306621949972, 0.946083573292935, 0.725034615480771, -1.17328658710462, 
    -1.00844091686302, -1.8176124981907, 0.124970415853266, 0.408323249032337, 
    -0.794920343991022, 0.378079909531318, -0.484179765598582, 
    1.21152404230402, -0.167727998630842, -0.863195007413922, 
    -1.32982507396397, -0.126711280680964, 1.19361167813603, 
    -1.5114408706585, 0.225175815401707, -1.95151391033341, 0.437398390870228, 
    0.222839420075445, -0.580750772417285, -0.449523234925738, 
    -0.389555754885093, 1.32535841458897, -0.79258394866476, 
    1.44178878168087, 0.108875248050149, -0.94159405058394, 0.200643664475987, 
    -0.592692348529272, -1.78438376466168, 0.605618854360869, 
    1.30433085665264, -0.973265187228787, -0.0480526380302461, 
    0.505153855331735, 0.12237442104631, -0.716780900301692, 
    1.23748399037357, 1.94008998487577, -0.604763724381611, 0.165078535620709, 
    -0.361648810710331, -0.738068057718721, -0.278966376108835, 
    1.18712169111865, 0.737754990034845, 0.729967005613983, 0.335375794956919, 
    0.671557122457513, -0.149556034982162, -0.980923371909302, 
    0.818879827752172, 0.716987031579215, 0.818230829050431, 
    0.584980695645581, 2.19930006635016, -0.722621888617338, 
    0.440902983859612, -0.859950013905226, -0.346332441349301, 
    0.471146323360632, -0.421097091789588, 0.281508902712614, 
    -0.0929633481905548, 0.37950770667514, 0.618339228914943, 
    0.129902805986478, 0.505153855331735, -0.145142843810338, 
    -1.05906281559863, -0.493784946384312, 0.584980695645581, 
    1.084969295465, 0.281119503491573, -0.607100119707868, -0.901615730556844, 
    -0.289090755855959, 0.401573662534256, -0.257809018432158, 
    -0.875136583525909, 0.36704693160176, 0.8515893623198, 1.01241124061062, 
    -1.21009779346724, -1.73378782587414, -1.76114961113944, 
    0.477506510637671, 0.993979677481246, -0.915893701995093, 
    -0.514033705878554, -0.0955593429975106, 0.0897946862190348, 
    -0.234445065169567, 0.208301849156502, -1.14135585097908, 
    0.198956267851466, 0.484126297395405, -1.70196092954088, 
    1.25500695532051, 0.0929098799873784, -0.172919988244748, 
    0.135743794302125, -0.517797898348638, -0.384623364751881, 
    -0.800371933085622, 0.599388466824176, -0.594769144374834, 
    -0.352692628626341, 0.250746364250208, -0.157733418624065, 
    -0.509101315745342, 0.874563916361345, -0.626310481279334, 
    -0.748452036946539, 0.257366151007941, 0.28124930323192, 
    -1.6865147604395, -0.437192259592705, 0.967240930969617, 
    0.740610584322495, 0.144310577165074, -1.58890535569802, 
    0.269048127639234, 0.942708780043898, -0.76130221124096, 
    0.00269906044571462, 0.455959753739949, -0.0895885549415116, 
    1.1614213425298, 1.50019866483735, -0.545315443302354, 0.908571448332448, 
    -1.23792685779779, -2.28229556863553, -0.105943322225328, 
    0.146257573270289, -0.10737111936915, -1.3652604030789, -0.534931464074537, 
    -1.41458430441103, 0.0974528708995497, -0.695623542625015, 
    0.703747458063747, -0.255862022326943, -0.462243609479818, 
    0.53163300236267, 1.06446093649006, -0.482362569233713, -1.10618012134485, 
    -0.616056301791863, -0.504039125871783, -0.0945209450747294, 
    -0.290907952220827, -0.4630224079219, -0.342827848359916, 
    0.887414090655766, 1.50759725003717, -0.60712607965594, -1.37935665488066, 
    -0.524677284587066, 0.496327472988091, 1.01500723541758, 
    -1.21508210349659, 0.0894052869979883, -0.0519466302406771, 
    0.701930261698879, -1.13286694796034, -0.657332619222435, 
    -1.27816477730558, -0.300642932746905, -0.284807364424481, 
    -1.31884401593055, 0.958544348366316, -0.492357149240484, 
    -0.356586620836772, 0.554477756663868)), row.names = c(NA, 
-222L), class = c("tbl_df", "tbl", "data.frame"))
COOLSerdash
  • 25,317
  • 8
  • 73
  • 123
CanyonView
  • 239
  • 2
  • 9

1 Answers1

2

I wouldn't use AIC for {gamm4} models - or rather I'd want to check very closely that an AIC that was corrected for the extra uncertainty due to smoothness selection was implemented for gamm4::gamm4(). If it isn't, then AIC is likely to accept the more complex model.

Also, you have to be careful that the same constants are being included in the likelihoods; I supposed if you did AIC(lmer_model, gamm4_model$lmer) this should be true.

As it happens your model has estimated a linear effect of Age. I would simply report that the estimated effect of Age is linear. At the very least by keeping the gamm4 code you are being up front that you thought the effect of Age may be nonlinear.

Gavin Simpson
  • 37,567
  • 5
  • 110
  • 153
  • Could you get an estimate of the slope of the linear effect for `Age` out of `gamm4` or would you recommend refitting the model with `Age` as purely linear effect for that? – COOLSerdash Feb 22 '22 at 14:43
  • 1
    @COOLSerdash for the default basis you could probably get the slope from the coef associated with the basis function that is linear, although I haven't tried that. If you need the slope, you could also just grab it from the `$lmer` component, *I think*. I'll check – Gavin Simpson Feb 22 '22 at 18:38