title: Autocorrelation in Generalized Additive Models (GAM)
body: <p>I have a time series dataset for water temperature, air temperature and flow rate in a river. I have created a GAM model to predict water temperature based on air temp and flow. However I have not accounted for the autocorrelation in the datasets. Each data point within the predictors and dependent variable are not independent (i.e air temperature on day 2 is not independent of air temperature on day 1). </p>
  
  <p>Can someone help me with the appropriate code to include some form of Autocorrelation measure (AR1?) within my model. As I understand it, I need to use the <code>gamm()</code> function instead of the <code>gam()</code> function?</p>
  
  <p>My current model looks like this:</p>
  
  <p><code>model &lt;- gam(W.T.Mean ~ s(T.Mean) +s(Discharge), data = Pre_regulation_temp)</code></p>
  
  <p>W.T.Mean is Mean daily water temperature.
  T.Mean is Mean daily air temperature.
  Discharge is Mean daily flow</p>
  
  <p>Thanks in advance</p>