library(astsa)
判斷以下範例為何不是 (weakly) stationary
Example 1.1 (p.2)
plot(jj, type="o", ylab="Quarterly Earnings per Share")
Example 1.2 (p.3)
plot(globtemp, type="o", ylab="Global Temperature Deviations")
Example 1.3 (p.3) Voice record
plot(speech)
Example 1.5 (p.5)
par(mfrow = c(2,1)) # set up the graphics
plot(soi, ylab="", xlab="", main="Southern Oscillation Index\nindex of ocean ccurrent 洋流")
plot(rec, ylab="", xlab="", main="Recruitment\nindex of fish amount")
Example 1.6 (p.5) MRI data
par(mfrow=c(2,1))
ts.plot(fmri1[,2:5], col=1:4, ylab="BOLD", main="Cortex")
ts.plot(fmri1[,6:9], col=1:4, ylab="BOLD", main="Thalamus & Cerebellum")
mtext("Time (1 pt = 2 sec)",side = 1,line = 2)
Example 1.7 (p.6)
par(mfrow=c(2,1))
plot(EQ5, main="Earthquake")
plot(EXP6, main="Explosion")
Example 1.9 (p.10)
set.seed(0921)
w = rnorm(500,0,1) # 500 N(0,1) variates
v = filter(w, sides=2, filter=rep(1/3,3)) # moving average
par(mfrow=c(2,1))
plot.ts(w, main="white noise")
plot.ts(v, ylim=c(-3,3), main="moving average")
\[W_t\sim N(0,1)\]
\[V_t=\frac1 3(W_{t-1}+W_t+W_{t+1})\]
Example 1.10 (p.11)
set.seed(0921)
w = rnorm(550,0,1) # 50 extra to avoid startup problems
x = filter(w, filter=c(1,-.9), method="recursive")[-(1:50)] # remove first 50
plot.ts(x, main="autoregression")
\[W_t\sim N(0,1)\] \(X_t=W_t-0.9W_{t-1}\) (default sides=1)
Example 1.11 (p.11)
set.seed(154) # so you can reproduce the results
w = rnorm(200,0,1); x = cumsum(w) # two commands in one line
wd = w +.2; xd = cumsum(wd)
plot.ts(xd, ylim=c(-5,55), main="random walk")
lines(x, col=2)
lines(.2*1:200,lty="dashed")
legend('topleft', col=c(1,2,1), lty=c(1,1,2),
legend = c(expression(X[d]),expression(X[t]),expression(E(X[t]))))
\(X_t\) is not stationary, \(\because Var(X_t)\) depends on t.
\(X_d\) is not stationary, \(\because E(X_d)\) depends on t.
\(E(aX+b)=aE(X)+b\)
\(Var(aX+b)=a^2Var(X)\)
Example 1.12 (p.12)
cs = 2*cos(2*pi*1:500/50 + .6*pi); w = rnorm(500,0,1)
par(mfrow=c(3,1), mar=c(3,2,2,1), cex.main=1.5) # help(par) for info
plot.ts(cs, main=expression(x[t]==2*cos(2*pi*t/50+.6*pi)))
plot.ts(cs+w, main=expression(x[t]==2*cos(2*pi*t/50+.6*pi) + N(0,1)))
plot.ts(cs+5*w, main=expression(x[t]==2*cos(2*pi*t/50+.6*pi) + N(0,25)))
The periodic behavior became less obvious when the noise is large.
Example 1.24 (p.24) \[y_t=Ax_{t-l}+w_t\]
Assume \(w_t\) is uncorrelated with \(x_t\), the cross-covariance function is \[\gamma_{yx}(h)=cov(y_{t+h},x_t)=cov(Ax_{t+h-l}+w_{t+h},x_t)\\=cov(Ax_{t+h-l},x_t)=A\gamma_x(h-l)\]
When \(h=l\), \(\gamma_{yx}(h)=\gamma_x(0)\)
x = rnorm(100)
y = lag(x, -5) + rnorm(100)
par(mfrow=c(1,1))
ccf <- ccf(y, x, type='covariance',
ylab='CCovF', xlab='lag h', main=expression(paste('l=5 with', hat(gamma)[yx](h))))
Example 1.25 (p.28)
par(mfrow=c(1,2))
r = round(acf(soi, 6, plot=FALSE)$acf[-1], 3)
plot(lag(soi,-1), soi, ylab=expression(X[t]), xlab=expression(X[t-1]))
arrows(-1,-1,1,1, col=2, angle = 15, lwd=5)
legend('topleft', legend=r[1])
plot(lag(soi,-6), soi, ylab=expression(X[t]), xlab=expression(X[t-6]))
arrows(-1,1,1,-1, col=2, angle = 15, lwd=5)
legend('topleft', legend=r[6])