0

I think that this post is very similar to what I'm trying to do

Fit a sinusoidal term to data

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)

Figure 1

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.

Ana
  • 71
  • 7
  • 1
    But there obviously is not a peak at 0 hours, strongly indicating this is not a periodic signal with period 6. – whuber Apr 02 '22 at 19:30
  • So it is not possible to fit any sinusoidal model? – Ana Apr 02 '22 at 19:41
  • Sure, you can fit one: but it's bound to be a poor fit. This all suggests considering some other model, but how your proceed ought to depend on what you ultimately want to accomplish with these data. – whuber Apr 03 '22 at 17:50

0 Answers0