Ejercicio 1.3

\[x_{t} = -.9x_{t-2}+w_{t}\]

w = rnorm(100,0,1)
x = filter(w, filter=c(0,-.9), method="recursive")[-(1:50)]

# Moving average filter
v = filter(x,rep(1/4, 4), sides = 1) 

par(mfrow=c(1,1))
plot(x, xlab = "Time", ylab = "Series", type="l")
lines(v, pch = 18, col = "red", type = "l")
lines(w, pch = 18, col = "green", type = "l")
legend("bottomleft", legend = c("Autoregression", "Moving average","White noise"),
       col = c("black", "red","green"), lty = 1:2, cex = 0.7)

\[ x_{t} = cos(\frac{2t\pi}{4})\]

x <- c(cos(2*pi*1:100/4))

# Moving average filter
v = filter(x, rep(1/4, 4), sides = 1)

# Plot
par(mfrow=c(1,1))
plot(x, type="l")
lines(v, pch = 18, col = "red", type = "l")
legend("bottomleft", legend = c("Serie", "Moving average"),
       col = c("black", "red"), lty = 1:2, cex = 0.7)

\[ x_{t} = cos(\frac{2t\pi}{4}) + w_t\]

w = rnorm(100,0,1) 
x <- c(cos(2*pi*1:100/4)) + w

# Moving average filter
v = filter(x, rep(1/4, 4), sides = 1)

# Plot
par(mfrow=c(1,1))
plot(x, type="l")
lines(v, pch = 18, col = "red", type = "l")
legend("bottomleft", legend = c("Serie", "Moving average"),
       col = c("black", "red"), lty = 1:2, cex = 0.7)

Ejercicio 1.7

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

Plot the ACF as a function of \(h\).

w = rnorm(500) #generate random
x = filter(w, filter=c(1,2,1)) [2:499]
print(acf(x, type="correlation"))

## 
## Autocorrelations of series 'x', by lag
## 
##      0      1      2      3      4      5      6      7      8      9     10 
##  1.000  0.648  0.125 -0.025  0.010  0.010 -0.006  0.019  0.073  0.090  0.059 
##     11     12     13     14     15     16     17     18     19     20     21 
##  0.038  0.026  0.014  0.056  0.123  0.137  0.126  0.122  0.095  0.056  0.046 
##     22     23     24     25     26 
##  0.044  0.010 -0.018 -0.011 -0.019

Ejercicio 4

\[ X_{t} = Z_{t} + \theta Z_{t-2} \]

par(mfrow = c(2,1))
plot(arima.sim(list(order=c(0,0,2), ma=c(.1,.8)), n=100), ylab="x",
main=(expression(MA(2)~~~theta==+.8)))
plot(arima.sim(list(order=c(0,0,2), ma=c(.1,.8)), n=100), ylab="x",
main=(expression(MA(2)~~~theta==-.8)))