1.

To compare the earthquake and explosion signals, plot the data displayed in Figure 1.7 on the same graph using different colors or different line types and comment on the results.


Solution

library(ggplot2)
library(astsa)
plot.ts(EQ5, col = "#CC6666")
lines(EXP6, col = "#66CC99")

From the plot we can see that the earthquake time series has a much slower decay once the movement becomes eratic. On the other hand looking at the the explosion time series we see the opposite, we see the initial eratic movement, but then a much (much) faster decent to initial state.

2.

Consider a signal-plus-noise model of the general form \(x_t = s_t + w_t\) , where \(w_t\) is Guassian white noise with \(\sigma_w^2 = 1\). Simulate and plot \(n = 200\) observations from each of the following two models.

Solution


a.

Directly from the book we have:

s = c(rep(0,100), 10*exp(-(1:100)/20)*cos(2*pi*1:100/4))
x = ts(s + rnorm(200, 0, 1))
plot(x, col = "#CC6666")

b.

s1 <- c(rep(0, 100), 10*exp(-(1:100)/200)*cos(2*pi*1:100/4))
x1 <- ts(s1 + rnorm(200, 0, 1))
plot(x1, col="#66CC99")

c

They appear to have very similar comparisons. The plot in part (a) has a similar shape to that shown by the explosion, and the plot in part (b) has the the same shape as that of the earthquake.

Signal Modulators

a <- exp(-(1:100)/20)
b <- exp(-(1:100)/200)
qplot(1:length(a), a, geom = "line") + geom_line(aes(1:length(b), b), color = "blue")

From the signal modulators we can see how the time series from part (a) (black line) decays way faster than that of part (b) (blue line).

4.

Show that the autocovariance function can be written as:

\[\gamma(s,t) = E\left[ (x_s - \mu_s)(x_t - \mu_t) \right] = E(x_s,x_t) - \mu_x\mu_t\]

Solution


\[\gamma(s,t) = E\left[ (x_s - \mu_s)(x_t - \mu_t) \right] = \\ E\left[ x_sx_t - x_s\mu_t - \mu_sx_t + \mu_s\mu_t \right] = \\ E(x_sx_t) - \mu_tE(x_s) - \mu_sE(x_t) + \mu_s\mu_t\]

and by assumption that \(E(x_t) = \mu_t\) we have,

\[E(x_sx_t) - \mu_t\mu_s - \mu_s\mu_t + \mu_s\mu_t \\ E(x_sx_t) - \mu_t\mu_s\]

7

For a moving average process of the form,

\[x_t = w_{t-1} + 2w_t + w_{t+1}\]

where \(w_t\) are independent with zero mean and variance \(\sigma_w^2\), determine the autocovariance and aurocorrelation functions as a function of lag \(h = s - t\) and plot the ACF as a function of \(h\).

Solution


Clearly if the lag is larger than or equal to 3 then we have a autocovariance of 0, I now show the cases of \(h = 0, 1, 2\) (we will make use of the formulation from problem #4).

When \(h = 0\)

\[\gamma(t, t) = E\left( w_{t-1} + 2w_t + w_{t+1}\right)^2\]

The resulting terms will yield products of independent \(w_t\) which taking their expectation yields 0. Resulting in only,

\[E\left[ w_{t-1}^2 \right] + 4E\left[ w_t^2 \right] + E\left[ w_{t+1}^2 \right] = 6\sigma_w^2\]

When \(h = 1\)

Similar as above, after taking product of we have only

\[\gamma(t, t + 1) = 2E(w_t^2) + 2E(w_{t+1}^2) = 4\sigma_w^2\]

When \(h = 2\)

\[\gamma(t, t + 2) = E\left[( w_{t-1} + 2w_t + w_{t+1})( w_{t+1} + 2w_{t+2} + w_{t+3})\right]\] \[ = E(w_{t+1}^2) = \sigma_w^2\]

When use the above to formulate the autocorrelation function

\[\rho(h) = \frac{\gamma(t, t+h)}{\gamma(t, t)}\]

When \(h = 0 \Rightarrow \rho(h) = 1\)

When \(h = 1 \Rightarrow \rho(h) = 2/3\)

When \(h = 2 \Rightarrow \rho(h) = 1/6\)

# i am not sure how to simualte x in this case but I think this works
x_ma <- numeric(499-2)
w <- rnorm(500)
for (i in 2:499) {x_ma[i] = w[i-1] + 2*w[i] + w[i+1]}
x_ma <- x_ma[25:length(x_ma)] # eliminate the cold start (i think)
acf(x_ma)

19.

Suppose \(x_t = \mu + w_t + \theta w_{t-1}\), where \(w_t = wn(0, \sigma_w^2)\)

Solution


a.

\[E(x_t) = E\left( \mu + w_t + \theta w_{t+1} \right) \\ = \mu + E(w_t) + \theta E(w_{t+1}) = \mu \]

b.

Once again by properties of white noise only the square terms dont get mapped to zero by the expectation. So we are left with

\[\gamma(t,t) = E(w_t^2) + E(\theta^2 w_{t+1}^2) = \sigma_w^2 + \theta^2\sigma_w^2 = \sigma_w^2(1 + \theta^2)\]

\[\gamma(t, \pm 1) = E(\theta^2 w_{t+1}^2) = \theta\sigma_w^2\]

c.

To show stationary we show that neither the mean or autocovariance depend on time, but only lag. In part (a) above we showed that \(E(x_t) = \mu\) this clearly does not depend on the value of \(t\) or even \(\theta\) so we are good so far. In part (b) above we showed that the autocovariance follows this same trend, namely autocovariance is a function that does not depend on \(t\) for all \(\theta \in \mathbb{R}\).

d.

For this part we note that from part (b) only when \(h = 0, 1, -1\) does the autocovariance term take on a value other than 0. So we have that:

\[var(\bar{x}) = \frac{1}{n}\left[ \left(1 - \frac{1}{n}\right)\sigma_w^2\theta + \sigma_w^2(1 + \theta^2) + \left(1 - \frac{1}{n}\right)\sigma_w^2\theta\right]\]

Now we consider the indivual \(\theta\) value cases.

When \(\theta = 1\)

\[var(\bar{x}) = \frac{1}{n}\left[ (1 - 1/n)\sigma_w^2 + 2\sigma_w^2 + (1 - 1/n)\sigma_w^2 \right]\] \[ = \frac{\sigma_w^2}{n}\left[ 4 - 2/n \right]\]

When \(\theta = 0\)

\[var(\bar{x}) = \sigma_w^2/n\]

When \(\theta = -1\)

22.

The ACF

acf(x, lag.max = 100)

From the ACF plot we can see that although the Time Series is not stationary the autocovariance appears to be completely determined by lag.

23.

The model described in the example is:

\[x_t = 2\cos\left( 2\pi \frac{t + 15}{50} \right) + w_t\]

s2 <- 2*cos(2*pi*((1:500 + 15)/(50))) 
x2 <- ts(s2 + rnorm(500))
acf(x2, lag.max = 100, type = "covariance")

From the ACF we can see that the autocovariance has a very strict pattern, namely from just looking a the model it will cycle.