Spectral analysis of sunspot data I consider a model of the form St

Spectral analysis of sunspot data
I consider a model of the form
St = µ+
k n
X
o
aj cos(2πωj t) + bj sin(2πωj t) +Wt
j=1
where W is some ARMA(p, q).
Spectrum has several peaks located using
bump <- function(xx,a,b, n=1000){
f <- seq(a, b, length = n)
x <- unlist(c(xx))
# To make the following code work must
# remove time series attributes of xx
nn <- 1:length(x)
args <- outer(f, nn, "*") * 2 * pi
cosines <- t(cos(t(args)) * x)
sines <- t(sin(t(args)) * x)
one <- rep(1, length(x))
per <- ((cosines %*% one)^2
+ (sines %*% one)^2)/length(x)
top <- max(per)
f[per == top]
}
299
Output from R:
f <- bump(x,1/135,1/130,n=2000)
#
#
f
#
#
> f
[1] 0.007536817
<- bump(x,0.00753, 0.00755,n=2000)
> f
[1] 0.007536783
n <- length(x)
xr <- cbind(cos(2*pi*(1:n)*f),sin(2*pi*(1:n)*f))
lm(x~xr)
#
# Call:
# lm(formula = x ~ xr)
#
# Coefficients:
# (Intercept)
xr1
xr2
#
50.98
27.67
10.57
#
xres <- residuals(.Last.value)
300
Compare spectra with and without cosine term.
6e+05
4e+05
2e+05
0e+00
Estimated Spectral Density
Sunspots, mean removed
0.000
0.002
0.004
0.006
0.008
0.010
0.012
Frequency
2e+05
0e+00
Estimated Spectral Density
Sunspots, mean, leading cosine removed
0.000
0.002
0.004
0.006
0.008
0.010
0.012
Frequency
301
One bump removed, one exposed. Remove 5
more
> f <- c(f,bump(xres,0.0077,0.008,n=2000))
> f <- c(f,bump(xres,0.008,0.009,n=2000))
> f <- c(f,bump(xres,0,0.0006,n=2000))
> f <- c(f,bump(xres,0.0006,0.0012,n=2000))
> f <- c(f,bump(xres,0.0012,0.0016,n=2000))
> round(1/(12*f),3)
[1] 11.057 10.632
9.982 275.162 96.738 59.913
> xra <- cbind(xr,cos(2*pi*(1:n)*f[2]),sin(2*pi*(1:n)*f[2]))
...
> xra <- cbind(xra,cos(2*pi*(1:n)*f[6]),sin(2*pi*(1:n)*f[6]))
> lm(x~xra)
> xres2 <- residuals(.Last.value)
> ar(xres2,method="mle")
order selected 9 sigma^2 estimated as 233.7
> arima.fit <- arima(sunspots,order=c(9,0,0),xreg=xra)
> arima.res <- residuals(arima.fit)
302
Diagnostic plot tsdiag:
−4
−2
0
2
4
6
Standardized Residuals
1750
1800
1850
1900
1950
Time
0.0 0.2 0.4 0.6 0.8 1.0
ACF
ACF of Residuals
0.0
0.5
1.0
1.5
2.0
2.5
Lag
0.6
0.4
0.2
0.0
p value
0.8
1.0
p values for Ljung−Box statistic
2
4
6
8
10
lag
303
Notice waves: autocorrelated sizes?
Try ACF of Residuals squared
0.0 0.2 0.4 0.6 0.8 1.0
ACF
ACF for squared Residuals from AR(9)
0.0
0.5
1.0
1.5
2.0
2.5
Lag
0.10
0.05
0.00
Partial ACF
PACF for squared Residuals from AR(9)
0.0
0.5
1.0
1.5
2.0
2.5
Lag
304
Plot all spectra together
6e+05
4e+05
2e+05
0e+00
Estimated Spectral Density
Sunspots, mean removed
0.000
0.002
0.004
0.006
0.008
0.010
0.012
0.010
0.012
0.010
0.012
Frequency
2e+05
0e+00
Estimated Spectral Density
Sunspots, mean, leading cosine removed
0.000
0.002
0.004
0.006
0.008
Frequency
3000
2000
1000
0
Estimated Spectral Density
Sunspots, mean, 6 cosines removed
0.000
0.002
0.004
0.006
0.008
Frequency
305
All spectra together on same plot
4e+05
3e+05
2e+05
1e+05
0e+00
Estimated Spectral Density
5e+05
6e+05
Sunspots
Sunspots minus 1 cosine
Sunspots minus 6 cosines
Arima Residuals
0.000
0.002
0.004
0.006
0.008
0.010
0.012
Frequency
306
Table of estimates and SEs
Parameter Estimate
a1
a2
a3
a4
a5
a6
a7
a8
a9
σ
0.5299
0.0937
0.0743
0.0800
0.0309
0.0441
-0.0083
0.0002
0.0835
233.7
SE
0.0188
0.0213
0.0213
0.0214
0.0214
0.0214
0.0213
0.0213
0.0188
307
Parameter Estimate SE
µ
50.33 4.22
β1
18.36 2.80
γ1
4.68 2.80
β2
1.76 2.95
γ2
-16.27 2.96
β3
27.27 2.99
γ3
9.85 2.99
β4
-8.96 5.46
γ4
-5.17 5.58
β5
8.81 5.78
γ5
12.31 6.03
β6
4.71 6.34
γ6
-7.78 5.58
Period (yr)
9.982
10.632
11.057
59.913
96.738
275.162
308
Repeat calculation on square root of sunspots.
Fitted model is AR(11).
−2
0
2
4
Standardized Residuals
0
500
1000
1500
2000
2500
Time
0.0 0.2 0.4 0.6 0.8 1.0
ACF
ACF of Residuals
0
5
10
15
20
25
30
35
Lag
0.6
0.4
0.2
0.0
p value
0.8
1.0
p values for Ljung−Box statistic
0
10
20
30
40
lag
309
0
5
sqrt(sunspots)
10
15
Plot of fitted values superimposed on square
root of sunspot numbers.
1750
1800
1850
1900
1950
Time
310