0
$\begingroup$

I have ambient temperature data recorded at 90-minute intervals (16 readings per day) over approximately one year. I’m using GAMs to characterise the daily temperature profile in different seasons but I'm having trouble identifying an appropriate error structure to address temporal autocorrelation which appears to decay sinusoidally (consecutive temperature readings are correlated, as are readings taken at the same time of day on consecutive days).

A model with separate smoothers for the time-of-day effect on temperature in different seasons, a smoother for the long-term trend over the year, and an AR(3) error structure has provided the lowest AIC so far, however, it doesn’t seem adequate as significant autocorrelation persists.

Zuur et al. (2009), on p. 152 of their book “Mixed effects models and extensions in ecology with R”, suggest an error structure that allows for a sinusoidal pattern is possible but they don’t provide an example of how to formulate one. I’d be very grateful if someone here could show me how to do this in order to obtain unbiased parameter estimates and standard errors.

Alternatively, if a GAM is not the best approach to model these data, I’d welcome suggestions or advice regarding other approaches as I'm very new to longitudinal data analysis. R code:

dat <- data.frame(
  Season=c(rep("Spring",502),rep("Summer",1456),rep("Autumn",1472),
           rep("Winter",1472),rep("Spring",779)),
  nDate=c(rep(1,6),rep(2:355,each=16),rep(356,11)),
  TimeOfDayI=c(seq(15,22.5,1.5),rep(seq(0,22.5,1.5),354),seq(0,15,1.5)),
  Temp=c(26,23,21.5,18,17,17.5,14.5,14,13.5,13.5,13.5,16.5,
23.5,27.5,27,27.5,25,21,20.5,18.5,16.5,16,15.5,14,
14,15,14,19.5,23,27,30,34,33,25,20.5,20,18.5,18,
18.5,17,16.5,16.5,16.5,17.5,21.5,27,30,33,31,27,25,
20.5,19.5,19,18.5,18,17,16.5,16.5,17,17.5,18,18,18,
17,19,17,16.5,16.5,16,16,16,16.5,16.5,16.5,17,17.5,
18.5,17.5,17.5,17.5,15.5,15.5,15,15.5,15.5,15.5,15.5,
15.5,15.5,15.5,16,17,17.5,18,19,20.5,20.5,19,18.5,
18.5,18.5,18.5,18,17.5,17.5,17.5,18.5,21.5,25.5,29.5,
22,23,27.5,24,18.5,17.5,17,16.5,15.5,15.5,15,16.5,
20.5,22.5,25.5,26.5,21.5,18.5,16.5,17,16,15.5,16,15.5,
15,14,14,14,16,19,21.5,19,22,22,18.5,18.5,15.5,14.5,
14.5,13,13,11.5,11,11,16.5,21,23.5,25,26,25.5,29.5,
22,18,15.5,14.5,14,13,12,12,12,18.5,23,26.5,29.5,
30.5,29.5,32.5,26,19.5,18.5,18.5,18,18,17.5,17.5,18,
18.5,21,24,24,23.5,21.5,18.5,18,17.5,17,16.5,16,16,
16,15,15,19,20.5,25.5,27.5,26.5,23.5,19.5,21.5,18.5,
17.5,17,17,16.5,16,15,15.5,21.5,25,28,29,30.5,18.5,
18,17,17.5,17,16.5,16,15,15.5,16,16,16.5,17.5,16,
16,17,18.5,17.5,16.5,15,14.5,14.5,14,14,14,13,14,
14.5,18,20.5,20,20,18.5,19,19.5,15,15.5,15.5,15,14,
13,11.5,11,17,19.5,22.5,22,22,23.5,27.5,24,16,14,
13,12.5,11.5,11,10.5,11,19.5,21.5,26,27.5,28.5,27.5,
32,28,20.5,19,17.5,16,15.5,14.5,14.5,15,20.5,27.5,
32,35.5,37,38,42.5,40,22.5,20,19,18.5,17,16,15,15.5,
21.5,25.5,29.5,35.5,37.5,39.5,45.5,43,32.5,26.5,25,
23.5,22,20.5,20,19.5,26.5,29.5,34,40,42.5,43,47,42,
24,22.5,21.5,20,19.5,18.5,18,17.5,20,20.5,20.5,22,
23,21.5,21,19,18,18,18,17,16.5,17,16,15.5,23.5,21,
20,20,21.5,21,22.5,21,19,17,16,17.5,16.5,15.5,15.5,
14.5,23,25,26.5,28,26,24,21,20,18.5,19,18.5,17,17,
16.5,15.5,15,24.5,24.5,29.5,29,28.5,28.5,32,27.5,20.5,
19,18,17,15,15,14.5,14.5,25.5,28,32,35.5,36.5,36.5,
36.5,32,25.5,23,21.5,20,18.5,18,20,21,28.5,33.5,36,
38.5,39.5,38,39.5,18.5,17.5,17,16.5,16.5,15.5,13,12,
12,21.5,21.5,23,25,25,25,21.5,24.5,19,18.5,17.5,18,
17.5,17,16.5,17,20.5,20.5,18.5,22,22,24,22.5,22,20.5,
19.5,19.5,19,19,19,19,19,18.5,20.5,27,24.5,30,29.5,
32,28.5,21.5,20,19.5,18.5,17,17,15,14.5,19,24,27.5,
31,30.5,30,29.5,29,22,20,18.5,17.5,17,16,15,16.5,
27.5,31,35,40,41.5,36,33.5,30.5,26.5,26,27.5,20,18.5,
17.5,17,17,20.5,20.5,22.5,20,20.5,19,19.5,19,16,15,
16,16,16,15.5,15.5,15,16.5,18,20.5,25.5,24,24.5,26.5,
24.5,17,14.5,13.5,12.5,12.5,12.5,11.5,12,21.5,22.5,
24.5,26.5,24.5,26.5,27.5,26.5,18.5,16,15,13.5,12.5,
12,11.5,12,24,25,28,30,31.5,29.5,31,27.5,20,18.5,
17.5,16,15.5,14.5,13.5,14,24.5,26,29,32.5,31.5,31,
31.5,25,20.5,19.5,19,18.5,17.5,16.5,16.5,17,21.5,27.5,
27,29.5,30.5,27.5,26.5,22,21,20.5,20,20,20,20,19,
19.5,20.5,25,24,25.5,27.5,26.5,26.5,23.5,22.5,20.5,
20,20,20.5,20,20,20,22,26,30.5,33,34,38,32.5,32,
22.5,22,19.5,19.5,19,18.5,18,19,21,22,25.5,28.5,31.5,
29.5,31.5,28,22,20.5,19,19,19.5,20,20,19,22,28,33.5,
39,36.5,35.5,34,31.5,25.5,19,18.5,18,17,16.5,15.5,
15,23.5,20.5,25,26.5,23.5,21.5,21.5,19,17.5,17,17,
17,17,16.5,16,16.5,18.5,20.5,24,25,26.5,27,24.5,23.5,
21.5,19.5,17.5,17,16,15.5,15,15,25.5,28.5,31,35.5,
33.5,31.5,33.5,31,22.5,20,18.5,17.5,16.5,17,18.5,19.5,
22,28.5,31,32.5,31,28,24,21.5,21,20.5,20.5,19.5,19.5,
18.5,18.5,19.5,20.5,21,15.5,18.5,15.5,18.5,25.5,24,
20,18,17,16,15,14.5,14.5,15,23,25.5,27,30,27,28.5,
30.5,29,22,20.5,19.5,19,18,16.5,16,16,26,29,31.5,
36,34.5,32.5,35.5,33.5,24.5,21.5,20.5,19.5,19,17.5,
17,17.5,29.5,33.5,37,40,38,36,35.5,33.5,25.5,22,20,
18.5,18,16.5,16,16,26,30,33,38.5,41,37.5,37.5,36.5,
28.5,26.5,25.5,24.5,25,25,22.5,22,25,30,25.5,27.5,
20.5,19,18,17.5,16.5,16,16,16.5,16.5,16,15.5,15.5,
15.5,16.5,17,17,17,17,17,17,16.5,16,16,16,16,16,
16.5,17,18.5,21.5,21.5,22,24.5,23.5,23,23.5,20.5,18,
17,16.5,16.5,14.5,14.5,14,22,20.5,21.5,26,26.5,26.5,
24.5,27,19.5,17.5,16.5,16,15.5,15,14.5,14.5,25.5,26,
21,26,27.5,25,25,24,20.5,19,19,18.5,18.5,18.5,17.5,
17,22.5,25.5,28.5,34.5,29.5,22.5,23,23.5,23,21,20.5,
18.5,15,14,14.5,15,15.5,16.5,21,19.5,22.5,22,23,20.5,
17.5,17,17,17,15.5,16,14,13,13.5,17.5,21,20,17.5,
18.5,20.5,17.5,17.5,17,16.5,16,14.5,13,14.5,13,23.5,
24.5,21.5,27,27,26.5,26.5,24.5,18.5,15.5,14,13,12.5,
12,11,12,24.5,26,26.5,29.5,29,27.5,29,26,20,17,15.5,
15.5,14.5,14.5,14,14,25.5,28.5,29,31.5,31.5,30.5,30,
25.5,21.5,19.5,18,17,16.5,16,14.5,14.5,26,24,29,32.5,
30.5,29.5,29,27.5,20.5,18,17,17,16.5,15.5,15,15,21,
23.5,25,28,27.5,24.5,24,23,20,19,18.5,18,18,17.5,
17.5,18,20.5,21.5,23.5,23,25,22.5,22,21.5,20.5,19.5,
19.5,19,19,18.5,18.5,18.5,17.5,18.5,20,22,20,18.5,
18,18.5,18,17.5,17.5,17,17.5,16.5,16,16.5,16.5,17.5,
17,17.5,17,18,17.5,18,17,17,17,17,16,15.5,16,16.5,
16,16.5,16.5,16.5,17,16.5,16.5,17,16.5,16,15.5,15.5,
15,15.5,15,15,16.5,19.5,21.5,24.5,23.5,21,22,22.5,
19,17,16,15,15,14,14,13.5,22,25.5,28,26.5,28,27.5,
26,25.5,19.5,17.5,18,17.5,17.5,17.5,17.5,16.5,21,25.5,
27.5,28.5,30.5,29.5,28,29.5,22,19.5,18.5,17.5,17,16,
15.5,15.5,20.5,24.5,28.5,32.5,32.5,31.5,30.5,29.5,23,
21,21,20,19,18.5,18,17.5,23.5,30.5,32,38,40,37.5,
32,33,29.5,25,23,23,22,21.5,21,22,26,29.5,33.5,35,
29,27,22.5,24.5,21.5,21,20,20,19,19,18,18.5,23,28,
30,33,32,32.5,32.5,32.5,24.5,23,22.5,21,21,21,20.5,
21.5,26.5,33.5,38,39.5,44.5,28.5,22.5,19.5,18,17,14.5,
14,14,14,13,12,12,12,15,20,20.5,20.5,16,15,14.5,
15,16,16,14,14,14.5,14.5,15.5,16,19,16,16.5,19.5,
21.5,20,18.5,18,16,15,15,14.5,14.5,14.5,18.5,22,24.5,
25.5,22.5,27,23,27,20,17.5,16.5,15.5,15,14.5,14.5,
14,18.5,24,27,29.5,30,32.5,29.5,30.5,23,20.5,19,17.5,
17,16,16,16,21.5,25.5,30,33.5,36.5,39,35,35.5,28.5,
25.5,24,22.5,21,20.5,20,20,25.5,30,35,38.5,40.5,39.5,
40.5,32,25.5,24,23,22.5,22,22,21,21.5,23,27.5,34,
38.5,40,39,31,22,22,22,22,22,21.5,21,21.5,21.5,22,
24.5,27.5,27.5,28.5,25.5,23.5,22.5,21.5,21,21.5,21.5,
21.5,21.5,20.5,19.5,23,25.5,22,22.5,24,24.5,24.5,24,
21.5,21,20.5,20.5,19.5,19,18.5,18.5,19,21,22.5,24,
23,23,23.5,22,21,20.5,20.5,20.5,20,19.5,19.5,19.5,
20.5,21,22,23,24.5,23,22,22,19.5,20,19.5,19.5,18.5,
19,19,19,19.5,20.5,24.5,28.5,28,30,27.5,28,23,21.5,
20.5,20.5,20,19.5,19,18.5,20,23.5,23,23,23.5,25.5,
24,21.5,21,20.5,21,20.5,20.5,20.5,20.5,20.5,21.5,23,
26.5,29.5,30,34,27,32.5,24,22,21.5,21,21,20,19.5,
19.5,22,27,27.5,28.5,23.5,21.5,23.5,27,22,21.5,18,
18,18,17.5,17.5,17.5,21.5,23.5,23.5,27,27.5,28.5,22,
22,21.5,21.5,22.5,21,20,19,18.5,18,21,25,29.5,30,
28.5,33,29.5,26.5,23,21,19.5,19.5,19,19.5,19,19,20.5,
23,22.5,17.5,26,23,29.5,20,19,18,17,16.5,15,14,13.5,
14.5,18,23,26,27,26.5,29.5,27,33,22,19.5,18.5,17.5,
17,16.5,16,15.5,21.5,25.5,28.5,32.5,34,31,28,26,23.5,
23,20.5,19.5,18,19,18,17,17,18,19,22.5,22.5,23,23,
21.5,20,19.5,19.5,18.5,19.5,19.5,19,19,18.5,18.5,22.5,
23.5,25,23.5,22,21.5,20.5,20,20,20,19.5,19.5,18.5,
19.5,20,19,20,19.5,20,23.5,23,26,20.5,19,19,17.5,
17,18,18,18,19,23,25,25.5,27,25,27,30.5,22.5,20,
18.5,18,17,16.5,16.5,16.5,19.5,25,28,30,29.5,29.5,
28,31.5,22.5,20.5,20.5,20,18.5,19,18.5,19,21,22.5,
25,25.5,27,26.5,25.5,29,21.5,20,18.5,18,18,17,16.5,
17,21,24.5,27.5,29.5,32,31.5,30.5,33.5,23.5,21.5,21,
19,18.5,18,17,17,20,25,28,29.5,29,29.5,26,24,23,
22,21.5,21,20,19.5,19,18.5,20.5,25.5,28.5,29,29,30,
29.5,32.5,23.5,22.5,22,21.5,21,19.5,19,18.5,21.5,25.5,
29.5,32,34.5,33,28.5,33.5,24.5,23,22,20.5,20,19,19,
18,22.5,26,32,36,36.5,31.5,27,26.5,23,22,22,21.5,
21.5,21,21,20.5,21.5,24.5,27,31,30,30.5,29.5,30,24,
22.5,22,22.5,21,20,18.5,18,21,24,27.5,26,23.5,24.5,
22,22.5,19.5,18.5,18.5,19,18,17,17,16.5,16.5,20.5,
21,25,25.5,25,24,25.5,19.5,17.5,16,15,15,14.5,15,
15,15,20,26.5,25,25.5,28,28,29,22,20.5,21,19,20,
20,19,19.5,21.5,25.5,29.5,32,34,33.5,31.5,34.5,26.5,
24.5,23,22.5,23,22,21.5,21,22,24,25.5,22,28,26.5,
25.5,22.5,21.5,21,21,21,20.5,19.5,19,19,19.5,19.5,
25.5,27.5,28,28.5,27.5,25,23,21,20,20,19.5,19,18.5,
18,19.5,25,27,29.5,33,33,30,28,24,22.5,21.5,20.5,
20,19.5,18.5,17.5,20,24,28.5,31.5,33,34,31.5,29,24.5,
23,22,20.5,20,19.5,19,18,19.5,24.5,29.5,33,35,35,
33,31,25,23.5,22.5,21,20.5,20,19.5,18.5,20.5,25.5,
31.5,36.5,39.5,42,39,36,30.5,28,26.5,25.5,25.5,22.5,
22.5,22,22.5,25,26.5,27.5,28.5,28,24.5,23.5,22.5,22.5,
22,22,21.5,20.5,20,21,21.5,24,24,27.5,28,25,27.5,
23.5,21,20,20,19,18.5,18.5,18,17.5,18.5,23.5,28.5,
30,30.5,29,27.5,26,22,20.5,19,18.5,18,17.5,17,17,
18,21.5,27.5,25,20.5,21,22,24,20.5,20,19.5,19.5,19.5,
18.5,18.5,19,19.5,22.5,25.5,28,30.5,28.5,28.5,26,23,
21.5,20,19.5,18.5,18,18,18,19.5,24.5,28,30,33,32.5,
29.5,28,24,22.5,22,21,21,20.5,20,19.5,20.5,24.5,29.5,
32,33,31.5,28,26,23.5,22.5,22,20.5,21,20,19.5,19.5,
21,24.5,26.5,32,29.5,28.5,28,26,23,21.5,20.5,20,18.5,
18,17.5,17,18.5,24,28,30.5,32,31.5,29.5,26.5,23,21.5,
21,19.5,18.5,17.5,17,16.5,17.5,24.5,28.5,31.5,30,30,
29,25,23,22,22.5,22.5,21,19.5,19,19,19.5,24.5,29.5,
31.5,33.5,31.5,29,26.5,23.5,22.5,22,21.5,22,21,20,
19.5,20.5,25.5,28.5,29.5,30,30.5,26.5,25,23,23,22.5,
22.5,22.5,22,21.5,20,21,26,29.5,32,35,33.5,32.5,27,
25,24.5,23,22,21.5,21,20.5,20.5,21,25.5,26.5,27,28,
28.5,26,23,21.5,22.5,22.5,21.5,21,21.5,21.5,22,22,
22.5,24.5,29,32,26,27,25.5,24,23,22,21.5,20.5,20,
20,19.5,19.5,25,30.5,33,33,32,30,26.5,24,23,22.5,
22,22,21.5,21,20,20,26,27,29.5,30.5,28.5,27,25,23,
23,22.5,22,21,20.5,20,20,20,23,26.5,31.5,30.5,23,
23,24.5,23,22.5,22,20.5,20.5,20.5,20,20,18,18.5,20,
21.5,24,25.5,25,22,20.5,19.5,19,19,19,18.5,18.5,17.5,
18,19,20.5,23.5,24,26,24.5,21.5,19,18.5,18.5,18.5,
18,18.5,18,18,18,19.5,24,21.5,24.5,24.5,24,23,20.5,
19.5,18.5,18.5,17.5,17.5,17.5,17.5,18.5,23,22.5,20,
22.5,26.5,22.5,22.5,19,16,16.5,15.5,16,15,15,14,14,
18,21,23.5,22,22.5,21,19,17,17.5,17,16,15.5,15.5,
15,15.5,15.5,19,21,23,22.5,20.5,15.5,15,14.5,14.5,
14,14.5,14,14,13.5,14,13.5,15,16.5,18.5,17.5,17.5,
20.5,16.5,15,14.5,15,14,14,13.5,13.5,13.5,13,18.5,
22.5,22.5,22.5,22,20.5,18.5,16,16,15.5,14.5,15,14.5,
14,13.5,14,19,23,26,26.5,27,25.5,21.5,18,17.5,16.5,
16,15.5,15,15,14.5,15.5,21,26,29,31,26.5,25,23,21.5,
21,19.5,19,18,17.5,17.5,17,18,20,21,22.5,22,24.5,
24.5,23,19,18.5,19.5,18.5,18.5,17,16,15.5,15.5,20.5,
27.5,25,28,26.5,26,22.5,20.5,19.5,20.5,19,18,18,18.5,
18.5,18,22.5,23.5,24.5,25,23,23.5,22,20.5,19,19.5,
18.5,18.5,19,19,18.5,18,21.5,22.5,26,24,25,23.5,21.5,
19.5,19,18.5,19,19,19,18.5,18.5,18.5,20.5,22,23.5,
20,19,19.5,19,18,18,18,17.5,17.5,17,16.5,16.5,16.5,
22,24,26,26,27.5,24.5,23,20.5,19,20,18.5,15,15,15,
14,14.5,19,23,23,24,23.5,22.5,20.5,18.5,16.5,15.5,
15,15,15,15.5,16.5,16.5,21.5,24.5,27,28.5,29.5,26.5,
23,21,20,19,18,17,17,16.5,16.5,16,22,26.5,29,30.5,
30.5,28,25,20.5,19,19,20.5,20,19.5,18.5,18,17,19.5,
24,24,23.5,23,22.5,20.5,19,18,17.5,18,18,17,17,17,
17,18,19.5,19,20.5,22.5,22,21,19,19,19,19,18.5,17.5,
17,16.5,16.5,22.5,25,27,29,29,26,24,21.5,21,20,19,
18.5,18,17,16.5,17,23,27,31,34,35,34,31.5,26.5,24,
25,21,20,20,19,17.5,18,18,18,19,20,20,18.5,17.5,
17,17,17,16.5,17,16.5,16,16,16,17,19,18,20,20,18.5,
18,17,17.5,18,17.5,18,16,14.5,14,14.5,20.5,25,22.5,
24.5,24,22.5,19.5,17.5,16.5,15.5,14.5,14,14.5,15,15,
14.5,18.5,22,24,27,30,28.5,22,18.5,17,15.5,16,17,
18,17,16,14.5,19.5,22,26,25.5,23,21.5,20,18.5,18.5,
19,18.5,18.5,17.5,17.5,15.5,15.5,16,17,20,21.5,22,
20,18,16.5,15.5,14.5,15.5,16.5,15,15.5,15,15,21,21.5,
23,23.5,23.5,22,19,16.5,16,15,14.5,14.5,14,14,14,
14,17,19,22.5,22,22.5,22,20,18,17,17,17.5,17.5,16,
14.5,14.5,14.5,20,23.5,26.5,28,28,24.5,21.5,19.5,18.5,
17.5,17,15.5,15,14.5,14,14,20,23,26,28,26.5,23.5,
21,19.5,20,19,19,18,17,17,17,16.5,19.5,20.5,20,22.5,
19,19.5,18,17.5,16.5,16,15.5,15,14.5,14.5,14.5,15.5,
19.5,20,20.5,22.5,16.5,16.5,17,16.5,16.5,16.5,16,16,
16,16,16,15.5,19,23,21,21,22,20.5,19,17.5,17,16.5,
16,16,15.5,15.5,15,14.5,19,22,26,27,26.5,23.5,20,
18.5,18,17,17,16.5,16,15,14.5,15,20.5,24,26.5,28,
28,25.5,22.5,19,18.5,18,17.5,17,16.5,17,17,16.5,21.5,
24,23,25.5,21,19.5,18,17,16,15.5,15.5,15,16,15,15.5,
15.5,16.5,16.5,16,16,14.5,14.5,14,14,14,14,14,13.5,
14,14,14.5,14.5,15,17,18,20,20.5,19.5,17,15,14.5,
13.5,12.5,12,12,12,12,12,16,19,24,23.5,23.5,21.5,
18,15,15,14,13,13,12,12,12.5,12.5,16.5,23,22,25.5,
25,22,19,17,16.5,17,14.5,14,13.5,13,12.5,12,17.5,
22,25,26,27,23,20,18,17,16,15,14.5,15,14.5,14,14,
17,19.5,21,25.5,27,25.5,21,19,18.5,17,16,15,15,14,
13.5,13,17.5,24,23.5,24.5,23.5,22.5,20.5,19.5,18.5,
18,17.5,17.5,18.5,18.5,17,17.5,18.5,20.5,24,25.5,26.5,
27,22,19.5,18.5,17.5,16.5,15.5,15.5,16,15.5,16,16.5,
18,19,22,26,26.5,23.5,21,19.5,18.5,17,15.5,14,12,
9.5,12,15.5,19,21.5,24,22,19.5,16,15.5,14,13,12.5,
11.5,11,11.5,11,9.5,16,19.5,22,25.5,25,24.5,21,17.5,
15,15,14,13.5,12,11.5,11,10,17.5,21.5,23.5,25.5,25.5,
20.5,17.5,16.5,16,15,14,13.5,12,12,12,12,16,20.5,
23,25,25,23.5,18,16,14.5,14,12.5,13,13.5,11.5,11.5,
12.5,19,22,25,28,25,23,18.5,15.5,15,13,12.5,12,11.5,
11,10.5,10.5,15,21,25,27,26,22,18,17.5,16.5,16,16,
16,16,16,16,16,17,18.5,19.5,21,20.5,19.5,18,17,17,
16.5,17,16.5,16.5,16.5,16.5,16.5,17,17.5,18,17.5,18.5,
18.5,18.5,18.5,18,17.5,17,16,16.5,15.5,13.5,12.5,18.5,
21.5,23,25,24,22.5,19.5,18,17,16.5,13,13.5,12.5,10,
9.5,7.5,13.5,17,20.5,21.5,21,17.5,15.5,15,14.5,14,
13.5,12.5,12,11.5,10.5,11,16.5,20,21.5,23,22.5,20.5,
17.5,16,16,16.5,16,16,16,15,12,11.5,16.5,21,23.5,
25.5,24.5,24,19.5,16.5,16,14,15.5,15.5,12,13,11.5,
12,15.5,20.5,24,29,28,26,19,16,13.5,12.5,12,10.5,
12,12.5,13,12,17,17.5,21,21.5,21,19.5,17.5,19.5,17.5,
16.5,15.5,14,14,14.5,13.5,13,16,22.5,25,27.5,25.5,
22.5,19.5,17,15.5,15.5,15,14.5,14.5,13.5,13,11.5,14.5,
20.5,25,29,27.5,25.5,22,19,18.5,17,16.5,14,12.5,12.5,
12.5,12.5,14,16.5,19,21.5,21,19,15,13.5,13.5,14.5,
12,12,12.5,13,12.5,10.5,13.5,17.5,20.5,24.5,22,20.5,
17.5,15.5,15,14.5,12,11,11,11,11,10,17,19,21.5,26,
24,19.5,15.5,13.5,13,12.5,12,12,13,12,13,13.5,15,
19.5,22,21,22.5,19,16,16,15,14,13.5,13.5,13,12.5,
12.5,12.5,16.5,20,23,27.5,25,22.5,18.5,16.5,16,14.5,
14.5,13.5,12.5,11.5,11.5,12.5,15,22,25,23,22.5,20.5,
17,15.5,14,13,12.5,12,11.5,11.5,11.5,10,13.5,16,18.5,
22.5,21.5,19,16,14.5,12,12.5,12,10.5,9.5,9.5,8.5,
8.5,11.5,15.5,18.5,24.5,21.5,19.5,13.5,12.5,12.5,12,
11.5,12.5,12,10,10,10,10.5,13.5,13.5,19,20.5,18,16,
13,13,12.5,13,13.5,12.5,11.5,12,11,12.5,16,17.5,19,
17.5,15.5,13.5,12.5,12,10.5,10,9.5,9.5,7.5,6.5,7,
10,9,9.5,9.5,12,11.5,12,11,11,10.5,10.5,9,9.5,8.5,
8.5,9,11,13,16,20,19,17.5,13,11.5,10,9,8.5,8,7,
6.5,6.5,5.5,8.5,14.5,18,23,19,16.5,12.5,11,10.5,10,
9.5,9,8,8.5,10,11.5,11.5,14,14,13.5,14.5,13.5,12.5,
12,12,11.5,11.5,11,11,11,11,11.5,11.5,12.5,13.5,15.5,
14.5,14,13,12.5,12,11,11,10.5,10.5,10.5,10.5,10.5,
12,16.5,18,22.5,17.5,16,13.5,12.5,12,12,12,11.5,11,
11.5,10.5,11.5,12.5,17,17.5,17.5,16.5,16,15,14.5,15,
14,14,14,14,14.5,15,14.5,14.5,15,15.5,17,16,16,15.5,
15,15.5,15,15.5,14.5,15,17,16.5,17,17.5,17,17,16.5,
17,17.5,17,17.5,14,13,12.5,12.5,12,13,13.5,13,13.5,
14,15,18,15.5,16.5,14,13,12.5,11.5,11.5,12,11.5,10.5,
10,9.5,11,14,20,22.5,17,15,13.5,11.5,10.5,8.5,8.5,
9,11,11,10.5,12,15.5,17,19,23.5,20.5,18.5,14.5,12.5,
12.5,12.5,13,12.5,12.5,13.5,14,14.5,15,16.5,21.5,24.5,
23,20.5,17,16,15.5,13.5,15,14.5,13.5,10.5,10,10.5,
16,17,19.5,22,20,19,15,14.5,13,13,12,11,11,10.5,
10,10.5,15.5,16,18.5,20.5,19.5,17.5,13.5,13,11.5,10.5,
10,9,8,8,8,7,11,13.5,17,20.5,18,16.5,11,9,8.5,
7,7,6.5,6,7,7,7.5,9.5,15,18.5,22.5,21,18,13.5,12.5,
11.5,10.5,9,8.5,8,8,6.5,7,14.5,15.5,19,23,21.5,20,
14,13.5,12.5,11,10,9,9,9,8.5,9,13.5,16,19.5,18.5,
21,18.5,13,12,10.5,10,8.5,7.5,7.5,7.5,7,6.5,13.5,
15.5,19,22.5,21,19.5,14,12.5,11,10.5,10,9,9,8.5,
8.5,8,12,12.5,13.5,16.5,18,18,15,14.5,14.5,14,13.5,
12.5,13.5,12.5,12.5,13,13.5,14.5,16.5,19,17.5,17,15,
13.5,14,14,14,12.5,12.5,13.5,13,13,14,15,14.5,14.5,
15.5,14.5,15,16,17,17,16.5,15,14.5,14,13.5,12.5,14,
16.5,16.5,16,19,15.5,13,13.5,12.5,13.5,13,12.5,13.5,
13,13.5,13,13.5,14.5,17,16,18,16,12.5,11,9,9.5,9.5,
10,9.5,9,9,9,15.5,17.5,16.5,20.5,18,17,13.5,11,11,
10,10.5,10,9.5,7.5,8,7,12,13.5,17.5,15.5,17,15,13,
11.5,12,11,11.5,11,9.5,11,11.5,11.5,15,13,14,17,
13,11,8.5,7.5,8,7.5,8,6.5,7,6.5,6,5.5,7.5,10,12.5,
18,14,13,10,8.5,7.5,7,6.5,6,5.5,4.5,4.5,4.5,7,11.5,
16.5,19,15.5,13,10,9,8,8.5,8,7.5,7.5,8.5,8,7.5,
7.5,7,7.5,9.5,10.5,9.5,8.5,9,8.5,8.5,8.5,7.5,7,7.5,
7.5,7,9.5,11,14.5,19,16.5,15,10,8,8.5,9,8.5,8,7.5,
7,6.5,6,10,14,18,24,20,17.5,11.5,9.5,8.5,7,6.5,
5,4,4,2.5,2.5,8.5,11,16,18,13,11.5,11.5,10,8.5,
9,8,7.5,8.5,9,8,7,7.5,10.5,13.5,16.5,15.5,15,12.5,
11,10,9.5,9,9,9,9.5,9,8.5,10.5,12.5,16,18,17.5,
16,13,12,11,9,9.5,9,8.5,8,7,6.5,9,12.5,17,18,18.5,
17,11,9,7,8.5,8,7,6.5,5,3,2.5,6.5,10,14,16,15,
15,10.5,9.5,9,8,7,6,6.5,7.5,8.5,8.5,9,10,12.5,17,
17,15,12.5,11.5,10,9,8,7.5,7.5,8,7.5,7.5,10,14,
15.5,17.5,16.5,14,13,13,12,11.5,12,12.5,12.5,12.5,
12.5,12.5,13,13.5,13.5,14,13.5,13,12.5,12,12,12.5,
12,12,11.5,11.5,12,11.5,12,13,13.5,13,13,13,12,12,
11,10,9,9,8.5,8,8,7.5,9,12.5,15.5,16,17.5,16,13,
12,11.5,11.5,10,11,10.5,10,10,10,10.5,13,19,18.5,
17,15.5,13.5,12.5,12,12.5,11.5,11.5,11.5,11.5,11.5,
11.5,11.5,13,14.5,14.5,15,16.5,15,14,13.5,14,13.5,
13.5,11.5,13,13.5,13,14,15,18,20.5,19.5,17.5,14.5,
12.5,11.5,12,9.5,9.5,8.5,8,7.5,7.5,9,10.5,11.5,13,
13,11,8.5,8,7.5,7,6.5,7,6,6.5,6.5,6,9,12.5,13.5,
16,17,15.5,11.5,9.5,8,7,7.5,8,7.5,7,6.5,7,9,12.5,
15,19,18,16,12,9.5,8,7,7,7,7.5,6.5,7,6.5,9.5,14.5,
19,18.5,19,16,14,13.5,13.5,14,13.5,12.5,12.5,12,12,
13,13,13.5,16,18.5,19.5,19.5,17,14.5,13,12,10.5,11.5,
12,10.5,9,7,8.5,13.5,19,22,23.5,22.5,19,17,15,14.5,
15.5,15.5,15,14.5,14.5,13.5,14,18,23.5,22.5,24.5,24,
20,18.5,17,17,16.5,15.5,15.5,15,15,15,15,15,15,15.5,
15.5,15,14.5,14,13.5,12.5,13,13.5,13,13,13,13.5,14,
15,16.5,17.5,16.5,17.5,14.5,14,13,12.5,12.5,13,13,
11,10,10.5,14.5,15.5,18.5,23,25.5,24,21,20.5,19.5,
18.5,15.5,15.5,12.5,14.5,14,12.5,13,14,16,16,16.5,
15,12,11,9.5,7.5,7,5,5.5,4.5,4.5,3.5,5,7.5,9.5,
14,15,13,9,6.5,5.5,4.5,5.5,6,5,5.5,4,4.5,10.5,13.5,
15.5,16,17.5,15.5,12,10,9,8,7,5.5,5,5,5,6,11,15,
18,19.5,20,18,14,11.5,10,9,7.5,7.5,6.5,8.5,9.5,9,
12.5,16.5,17,17.5,18.5,16,13.5,12,10,8.5,8.5,9,9,
8.5,9,7.5,10.5,13.5,18,19.5,21,17.5,13.5,10.5,10,
9,9,8.5,8,6.5,6.5,5.5,9,13,16,18.5,19.5,17,13,11,
10.5,9.5,9,8.5,8,7.5,7.5,6,10,15,18.5,18,18.5,17.5,
13.5,11.5,10.5,9,9,10.5,10.5,9,9,9,11,12,13,17,
21.5,20,15.5,13.5,13,13,12.5,11,10.5,9,9.5,9.5,11.5,
14,14,15.5,15.5,14.5,12,11.5,11,11,10.5,10,9.5,9,
9.5,9.5,10.5,12.5,12.5,12,9.5,9,8.5,9,9.5,9.5,9.5,
9,9,8.5,8.5,9,9.5,11,13.5,12.5,13,10.5,10.5,9.5,
9.5,10,9.5,9,9,9,8.5,8.5,9.5,11,10.5,11,12.5,11,
10,10,10,10,9.5,9.5,9,9,8,9,9.5,11,13.5,13.5,14.5,
15.5,11.5,11,11,10,9,8.5,8,8,8,8.5,9.5,13.5,16,
16.5,16.5,14.5,13,11.5,10.5,9.5,9,8,9,8.5,9,9.5,
11.5,14.5,16.5,16,16,14.5,13,11.5,10,10,9.5,8.5,8,
7,6.5,6.5,9,13.5,16.5,20,17,15,13,10.5,9.5,8,8.5,
7,6.5,6,6,5.5,11.5,16,19.5,20,18,16.5,13.5,13,13,
12.5,12,11.5,11,11.5,11.5,11,13.5,19,23,25,29,24.5,
21,18,17,15.5,13,12,11.5,12.5,8.5,7.5,13.5,16.5,18.5,
19,20.5,18,15,12,10,9.5,8.5,8,7.5,7.5,6,5.5,9.5,
15,17.5,19,21.5,17,14.5,12,10,10.5,9,7.5,7,5,7.5,
8.5,12,15,18.5,20.5,23.5,19.5,16,12.5,11.5,10,10,
11.5,11,11.5,10,10.5,13.5,17,20,18.5,21.5,18.5,15,
11.5,11,9.5,8.5,7.5,7,7,6.5,6.5,12.5,18,21.5,22,
24,21.5,16.5,14,12.5,11.5,10,8.5,8,8,7.5,7.5,14,
19,22,23.5,26,23,18,15.5,14,13,11,10,9,7.5,7.5,
7,14,19.5,22.5,22.5,26,21,17.5,16.5,14,13.5,13.5,
11,10.5,10.5,9.5,9.5,15.5,20,23.5,24.5,26.5,23.5,18,
16,14.5,13.5,11.5,11,10,8,7,6.5,14.5,19.5,22,25,
26,21,19,17,16,15,16,8.5,8.5,8.5,8.5,6.5,12.5,15.5,
16,18.5,17,16,12.5,10.5,9.5,8.5,7,6,4.5,5,5.5,6,
12,16.5,18.5,19,20,20,16,12.5,11.5,10.5,8.5,7,9,
9,8.5,8,9.5,15,17.5,14,11.5,9,9,8.5,7.5,8,7.5,7,
7,6,6,6.5,10,12.5,16,16.5,15.5,14,13,11.5,11.5,11.5,
11.5,11.5,10.5,11,11,11,11,11,12,11,12,11,10,10,
9.5,9,8.5,8,8,7,7,7,9,11.5,14.5,15.5,18.5,14.5,
13.5,10.5,10.5,9.5,8.5,7,6.5,6.5,5.5,5.5,9,15,15.5,
15.5,15.5,14.5,13,12,12,10,8,7.5,7.5,7,7,7,11,16,
18,20.5,21.5,19.5,16,12.5,9.5,9,10,9.5,8.5,7.5,5.5,
5.5,12.5,16.5,19,20.5,20,18.5,15.5,11.5,10,8,9,7,
7,5.5,6,7,12,16,17.5,20.5,18.5,19.5,15.5,12.5,12,
11.5,11,10,10,10,10,9.5,12.5,17,21.5,21.5,22.5,21.5,
18,15.5,15.5,15.5,14,14,13.5,13.5,13.5,13.5,15.5,16.5,
21,24.5,22,21,19.5,17,16,13.5,12.5,11.5,11.5,10.5,
10,11.5,17,21,21,22,25,19,17.5,16,15.5,15,13.5,13.5,
13.5,13,13,13,13.5,13.5,14.5,15,14,14,13.5,13.5,14,
15,15,14.5,14,13.5,13,13,13.5,17.5,17.5,18.5,17.5,
18,15,13.5,13,13,11.5,10,10.5,7.5,8.5,8,15,17,18.5,
20.5,20.5,20.5,16.5,13,11.5,11,10.5,10,9,8,7,7,13.5,
19,20.5,22.5,24,22,16.5,14.5,12.5,11.5,10,9.5,9,8.5,
8,8,16,20.5,23.5,25,25,22.5,18.5,15,14.5,13,14,14,
14,13.5,14,13.5,18.5,18.5,21.5,22,22,19.5,18,17,16,
16,15.5,15,14.5,14,14,14.5,16,18.5,22,24.5,23,21.5,
18.5,16.5,16.5,15.5,14,13.5,13,12.5,12,11.5,17,22,
24.5,27,24,21,19,18.5,18.5,18,18,17,16.5,13.5,12.5,
12.5,14.5,18,21.5,22,21.5,19.5,17.5,16,14.5,14,13,
12,12.5,10.5,10,11,15.5,19,21.5,19.5,21.5,18.5,16,
13.5,13,11.5,11,9.5,9,8.5,11,12.5,15.5,19.5,22,24,
22.5,20.5,17,15,14.5,15,15,15,14.5,14,14,14,16.5,
17,20.5,19.5,20.5,18.5,16.5,15.5,14.5,14.5,14,13.5,
14,14.5,14.5,15,15.5,17.5,19.5,25,23.5,24.5,21.5,19.5,
18,17.5,16,14.5,14.5,13.5,12,13,17,19.5,21.5,23,21,
20,17,15,14.5,14,13,13,12,12.5,12,12.5,14,18,21.5,
22.5,21.5,21,18,16,14.5,13,11.5,10.5,9,9,7.5,9,17.5,
21.5,22,24,24.5,20,17.5,16,15,14,12.5,12,11.5,11,
11.5,11.5,12.5,15.5,15,14.5,14,13,13,12.5,12,12,11.5,
11,11.5,10.5,11.5,11.5,15.5,17.5,19,20.5,20.5,20,17.5,
14.5,12,11,11.5,10,11,8.5,8,9.5,15,18.5,21,23.5,
22.5,18.5,17,14.5,14,13,12.5,12.5,12.5,12,11.5,12,
14.5,22.5,23,17.5,17,16,15,13.5,13,11.5,11,11.5,11,
11.5,10.5,11.5,16.5,18.5,17,17.5,16,15.5,16.5,15.5,
14.5,14.5,14.5,14.5,14,14,13,13.5,16.5,19.5,21.5,21,
22,20,17,15,14.5,14,13.5,13,10.5,10,10,12,17.5,22,
22,22.5,24.5,22,18.5,17,16.5,15.5,15,14,14.5,14,13.5,
12.5,13.5,14.5,17,20.5,17.5,18,15.5,13,13.5,12.5,12.5,
11.5,10.5,10,9,11,14.5,18,20,22,19.5,17.5,15,14.5,
13,11,10.5,11,9.5,7,7.5,7.5,15,21,22,22,21,19,16,
14,12.5,10.5,11,11,9.5,9,9,10,15,19.5,22,20,20.5,
19.5,16.5,14,12.5,11,9.5,9.5,9.5,10,11.5,11.5,11,
12,13,15.5,20.5,21,18.5,15,13.5,12.5,11.5,11,10.5,
10,9.5,11.5,18,18,18,17.5,17.5,18,15,11.5,12,11,
11.5,10,8.5,7.5,8,11.5,18,19.5,21.5,21,21.5,21,18,
15.5,14.5,12,12,9.5,9,7.5,7.5,11,17.5,22.5,24.5,27,
28.5,27.5,22.5,18.5,19,18.5,17,17,17,16.5,18,18.5,
21,24.5,27,28,24,21.5,18.5,15.5,14.5,14.5,15,14.5,
13,11,13,14,18.5,20.5,22,24,24.5,21,20,18.5,13,12,
12,12,11.5,10.5,9.5,11,15,19,21,22.5,23,20,18.5,
16.5,15.5,14.5,13.5,12.5,12,11,9.5,14,19.5,22,26,
27,29,28,25,21,18.5,16.5,15,16,15,13.5,13.5,16,22.5,
27.5,29.5,31,31,29,26,23,22,20.5,20,20,19.5,17.5,
17,18,19.5,20,20,19.5,17.5,15,14.5,14.5,14.5,14,14,
14,12.5,10.5,9.5,12,17.5,22,23.5,24,22.5,20,18.5,
17.5,16.5,16,15.5,15.5,14.5,13,13,16.5,19,30,33,32,
30,26.5,24,21,19.5,18,16,13.5,12.5,12,11,12,15,18,
19.5,20.5,19,19.5,16.5,13.5,12,11.5,10.5,10,9.5,9,
8,10.5,15,20,22.5,24.5,21.5,19,17.5,15.5,14.5,13.5,
12,12.5,10.5,10,10.5,11.5,14.5,16.5,18,18.5,19.5,16.5,
14.5,12.5,11.5,10,9.5,11,8,8.5,8,12.5,17,20,19.5,
23.5,23,21,18,14.5,12.5,10,10,9.5,8.5,8.5,8,12.5,
19,23.5,26.5,29,32,27,22.5,18,16.5,14.5,13.5,13,13,
12.5,12,15.5,22,27,30.5,32.5,34.5,33,24,21.5,21.5,
22,21.5,21.5,21.5,21,21,20.5,17,16,14.5,14,14.5,19,
17.5,15,15,12.5,12,11.5,10.5,8.5,7.5,12,17.5,20.5,
24.5,27.5,28,26,22.5,19,17.5,16,15,12.5,14.5,13.5,
12.5,14,18.5,20,22,23.5,24.5))

## Visualise data
dat$DateTime <- dat$nDate + dat$TimeOfDayI/24
plot(Temp~DateTime,data=dat,type="l",xlab="Day")

## Examine autocorrelation
par(mfrow=c(1,2))
acf(dat$Temp)
pacf(dat$Temp)

## Apply a GAM
library(mgcv)

ctrl<-list(niterEM=0,msVerbose=TRUE,optimMethod="L-BFGS-B")

M1 <-gamm(Temp~s(TimeOfDayI,bs="cr",k=16,by=Season)+s(nDate,k=20)+Season,
         correlation=corARMA(form=~1|nDate,p=3),
         family=Gamma(link="log"),control=ctrl,data=dat)

## Diagnostic plots
par(mfrow=c(2,2))
E <- residuals(M1$lme,type="normalized")
plot(E~predict(M1$lme,type="link"))
abline(h=0,lty=2)
plot(E~dat$TimeOfDayI)
abline(h=0,lty=2)
acf(E)
pacf(E)

## Significant autocorrelation persists ...
$\endgroup$
0
$\begingroup$

what don't you try to estimate the model with a Bayesian approach, using INLA. Maybe this example can help you to fit your model. https://dahtah.wordpress.com/2012/01/13/functional-anova-using-inla/ and the corrected R code associated in the example!https://dahtah.wordpress.com/2012/02/29/functional-anova-using-inla-update/

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.