3 Sinusoidal Model

1 Sinusoidal Model

Goal: to fit a simple sinusoidal[1] model to the sunspots data.

Let's consider the expression of sinusoidal model: s(t)=Acos⁡(2πft)+Bsin⁡(2πft),A=Rcos⁡ϕ,B=−Rsin⁡ϕ.
For us, usually t=1,2,⋯,n. In this case, we can restrict the frequency f∈[0,12].[2]

Based on the remark,

Fact

For every f,ϕ, there exists f0∈[0,12],ϕ0, s.t. s(t;f,ϕ)=s(t,f0,ϕ0), ∀t∈N∗.

When f=0, s(t) is constant; when f=12, s(t)=Rcos⁡(πt+ϕ)=(−1)tRcos⁡(ϕ).

Sinusoidal Model

yt=β0+β1cos⁡2πft+β2sin⁡2πft+εt,εt∼i.i.dN(0,σ2).
The parameters here are β0,β1,β2,σ,f.

If f is known, it's a linear model. Otherwise it's a nonlinear regression model.

2 Frequentist Inference

Like in linear models, frequentist calculate the MLE: ∏i=1n12πσexp⁡[−(yt−β0−β1cos⁡2πft−β2sin⁡2πft)22σ2]∝σ−nexp⁡[−12σ2∑t=1n(yt−β0−β1cos⁡2πft−β2sin⁡2πft)2]=σ−nexp⁡[−12σ2S(β0,β1,β2,f)].
So the problem is to find (β^0,β^1,β^2,f^) that minimizes S(β0,β1,β2,f)=∑t=1n(yt−β0−β1cos⁡2πft−β2sin⁡2πft)2(2.1)=||y−Xfβ||2. We first fix f, so this is just a linear regression. We have β^(f)=(XfTXf)−1XfTy,Xf=[1cos⁡2πf(1)sin⁡2πf(1)⋮⋮⋮1cos⁡2πf(n)sin⁡2πf(n)]. Then f^=arg⁡minfS(β^(f),f),β=(β0,β1,β2)T.

3 Bayesian Inference

The posterior is σ−nexp⁡[−S(β,f)2σ2]1{0≤f≤12}, and assume prior β0,β1,β2,log⁡σ∼i.i.dUniform[−C,C], f∼Uniform[0,12].
Then[3] fβ,σ,f|data=σ−n−1exp⁡[−S(β,f)2σ2]1{0≤f≤12}1{−C<β0,β1,β2,log⁡σ<C}, then the posterior density of f ∝∬σ−n−1exp⁡[−S(β,f)2σ2]dβdσ.

By Pythagorean identity, S(β,f)=||y−Xfβ||2=S(β^f,f)+(β−β^f)TXfTXf(β−β^f).
So further on ∝∬σ−n−1exp⁡(−S(β^f,f)2σ2)[−(β−β^f)TXfTXf(β−β^f)2σ2]dβdσ=∫σ−n−1exp⁡(−S(β^f,f)2σ2)(2π)p2det(σ2(XfTXf)−1)∝∫σ−n−1exp⁡(−S(β^f,f)2σ2)σp|XfTXf|−12dσ=|XfTXf|−12∫σ−n+p−1exp⁡(−S(β^f,f)2σ2)dσ=∫0∞t−n+p−1(S(β^f,f))−n−p2exp⁡(−12t2)dt∝(S(β^f,f))−n−p2|XfTXf|−12.
Compare with linear regression: Posterior∝(S(β))−n2.

4 Fourier Frequency

RSS(f) (S above measures how well the sinusoid at frequency f fits the data). So we should take a grid of values for f, and then compute RSS(f) for each grid point.

Common Choice of Grid for f: (notate as G)

Note that n is the size of data.

Fourier Frequency

Fourier frequency is frequency f s.t. nf is an integer.

So our common choice inside G are all Fourier frequencies lying in [0,12].

When f∈G, plug in β^f=(XfTXf)−1XtTy, RSS(f)=||y−Xfβ^f||2=(y−Xfβ^f)T(y−Xfβ^f)=yTy−β^fTXfTy−yTXfβ^f+β^fTXfTXfβ^f=yTy−yT(XfTXf)−1XfTy−yTXf(XfTXf)−1XfTy+yTXf(XfTXf)−1XfTXf(XfTXf)−1XfTy=yTy−yTXf(XfTXf)−1XfTy.
And XfTXf=[1⋯1cos⁡2πf⋅1⋯cos⁡2πf⋅nsin⁡2πf⋅1⋯sin⁡2πf⋅n][1cos⁡2πf⋅1sin⁡2πf⋅1⋮⋮⋮1cos⁡2πf⋅nsin⁡2πf⋅n]=[n∑t=1ncos⁡(2πft)∑t=1nsin⁡(2πft)∗∑t=1ncos2⁡(2πft)∑t=1ncos⁡(2πft)sin⁡(2πft)∗∗∑t=1nsin2⁡2πft]. Next let r=e2πift, [4]∑t=1ncos⁡(2πft)=∑t=1ne2πift+e−2πift2=r=e2πif12∑t=1nrt+12∑t=1nr−t=12e2πife2πif−1(e2πif−1)+12e−2πife−2πif−1(e−2πif−1)=0.

Next similarly ∑t=1ncos2⁡(2πft)=∑t=1n1+cos⁡(4πft)2=n2,∑t=1ncos⁡(2πft)sin⁡(2πft)=12∑t=1nsin⁡(4πft)=0.

One more fact

f1,f2 are two distinct Fourier frequencies. Then ∑t=0n−1cos⁡(2πf1t)sin⁡(2πf2t)=0,∑t=0n−1sin⁡(2πf1t)sin⁡(2πf2t)=0,∑t=0n−1sin⁡(2πf1t)cos⁡(2πf2t)=0.

So XfTXf=[n000n2000n2],(XfTXf)−1=[1n0002n0002n]. Then RSS(f)=yTy−(∑t=1nyt∑t=1nytcos⁡2πft∑t=1nytsin⁡2πft)[1n0002n0002n](∑t=1nyt∑t=1nytcos⁡2πft∑t=1nytsin⁡2πft)=yTy−1n(∑t=1nyt)2−2n(∑t=1nytcos⁡2πft)2−2n(∑t=1nytsin⁡2πft)2=∑t=1n(yt−y―)2−2n(∑t=1nytcos⁡2πft)2−2n(∑t=1nytsin⁡2πft)2. Note again that this is only true when f∈[0,12] and f is Fourier frequency.

Periodogram

Define periodogram as I(f)=1n[(∑t=1nytcos⁡2πft)2+(∑t=1nytsin⁡2πft)2].

So RSS(f)=∑t=1n(yt−y―)2−2I(f).


We can also rewrite I(f)=1n|∑t=1nyt(cos⁡2πft+isin⁡2πft)|2=1n|∑t=1nyte−2πift|2. This is exactly a Fourier transformation.

5 Some Other Nonlinear Regression Models

  1. yt=β0+β1t+β2cos⁡(2πft)+β3sin⁡(2πft)+εt. RSS(f)=∑t=1n(yt−β0−β1t−β2cos⁡(2πft)−β3sin⁡(2πft))2.
  2. (Broken stick / change of slope) yt=β0+β1t+β2(t−s)++εt, here (t−s)+=max{t−s,0}.

  1. (正弦曲线的) s(t)=Rcos⁡(2πft+ϕ). Here R is called the amplitude (振幅), ϕ is called phase (相位), f is the frequency (频率). The period here is 1f, and 2πf is angular frequencing ↩︎

  2. Because t is an integer, and we are looking at s(t)=Rcos⁡(2πft+ϕ). If say f=−3.5, then s(t)=Rcos⁡(2π(3.5)t−ϕ)=Rcos⁡(6πt+2π(0.5)t−ϕ)=Rcos⁡(2π(0.5)t−ϕ). ↩︎

  3. Here the first f means the likelihood function, and the subscripted f means frequency ↩︎

  4. Last equation 0 is because f is a Fourier frequency, then nf∈Z. ↩︎