I think that this post is very similar to what I'm trying to do
y <- c(7,4,4,7,4,11,41,2,9,27,36,23,43,19,12,30,39,26,55,14,13,10,9,12)
t <- c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23)
As shown in the Figure there is a peak every 6 hours at 6, 12 and 18
ssp <- spectrum(y)
per <- 1/ssp$freq[ssp$spec==max(ssp$spec)]
reslm <- lm(y ~ sin(2*pi/per*t)+cos(2*pi/per*t))
summary(reslm)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 19.042 2.482 7.671 1.61e-07 ***
sin(2 * pi/per * t) -5.803 3.511 -1.653 0.11323
cos(2 * pi/per * t) -11.332 3.511 -3.228 0.00403 **
rg <- diff(range(y))
plot(y~t,ylim=c(min(y)-0.1rg,max(y)+0.1rg))
lines(fitted(reslm)~t,col=4,lty=2) # dashed blue line
But I'm confused about how to use the coefficients of the regression model, how to use the fact that I know that there is a peak every 6 hours and how to use that the cosine term is significant.
