library(astsa)


?soi
plot(soi)
?rec
plot(rec)
fish <- cbind(soi, rec)
plot(fish)      # actually runs plot.ts()
ts.plot(fish)   # no re-scaling
plot.ts(fish)
ts.plot(fish, col = c(2, 3))
legend('top', legend = c('soi', 'rec'))

?fmri1
plot(fmri1[, 2:9])
ts.plot(fmri1[, 2:9], col = 2:9)

?EQ5
plot(EQ5)  # stationary wave

?EXP6

plot(EXP6)
ts.plot(cbind(EQ5, EXP6), col = 1:2)

w <- rnorm(100, 0, 1)
plot(w)
w_t <- ts(w)
w_t
plot(w_t)
w_t2 <- ts(rnorm(100, 0, 3))
ts.plot(cbind(w_t, w_t2), col = 1:2)

w1 <- ts(w_t, start = 1960, freq = 12)
w2 <- ts(w_t2, start = 1965, freq = 12)
plot(cbind(w1, w2))
ww <- ts.intersect(w1, w1)
plot(ww)

window(ww, 1966, 1967)

v <- numeric(100)
v[2:99] <- 1/3 * (w[1:98] + w[2:99] + w[3:100])
v[1] <- NA
v[100] <- NA
ts.plot(cbind(w_t, v), col = 1:2)

?filter
v <- filter(w_t, c(1, 1, 1) / 3, method = 'conv', 2)
ts.plot(cbind(w_t, v), col = 2:3)

z <- filter(w_t, filter = rep(1 / 7, 7), method = 'conv', 2)
ts.plot(cbind(w_t, v, z), col = 1:3)
legend('bottom', legend = c('w_t', 'v', 'z'),
       col = 1:3, lty = 1)
