# Generalized additive mixed model in R - specifying a fit function

The data in question comprise two response groups (no response vs. stress signal), different individuals, repeated measures through time for each individual (period), and a continuous variable for a metabolic marker. The stress signal, if present, was always limited to a single sampling period.

What I'm looking to test is two-fold:

1. is the type of response related to the concentration of the metabolic marker, and
2. do stress signals within individuals significantly correspond to spikes in the metabolic marker relative to the rest of the periods sampled?

I would like to remove individual variation (random effect) and slope variation across periods for each individual (because the metabolic marker naturally changes within individuals as a factor of time, but varies across individuals in this speed of this change). The natural pattern of change across periods is also non-linear (best fit by a second-order polynomial).

This is the model I've built in R using gamm4 to test overall response differences:

> OverallRespModel <- gamm4(response ~ s(marker), random=~ (1|period) +
(period|individual), data=Data, family= gaussian)


The similar model I've built to test within-individual associations between the presence of the stress mark and metabolic marker spikes is:

> PeriodRespModel <- gamm4(response ~ s(marker), random=~ (1+period|individual),
data=Data, family=gaussian)


My concerns are:

1. Whether these two models will address the questions I am asking, respectively.
2. That my additive model is simply fitting a spline to the metabolic marker data (as a factor of period, hopefully), and I'm not sure how to customize this fit to force a second-order polynomial fit.

Should I alternatively use the metabolic marker as the response variable and the presence / absence of stress markers as a binary predictor variable?

• Is the marker in your formulas the "metabolic marker" or the "stress marker"? – gung Dec 20 '14 at 23:53
• It's the metabolic marker. I just edited the original question to distinguish "stress signals" and avoid this confusion. Thanks for pointing this out. – Jeremy Ross Dec 21 '14 at 16:33