I have read the Honesty Code included on Brightspace under My
Learning → Welcome.
I understand and agree to this code.
##Question 1: Series weakly stationary We generate e_t ~ N(0,1) and construct each process.
n <- 200
eps <- rnorm(n)
eps_t <- eps
eps_tm1 <- c(NA, eps[-n])
###(a) Y_t = e_t * e_{t-1}
Ya <- eps_t * eps_tm1
Ya <- Ya[-1] # remove first NA
cat("---- (a) Y_t = e_t * e_{t-1} ----\n")
## ---- (a) Y_t = e_t * e_{t-1} ----
cat("Mean =", mean(Ya), "\n")
## Mean = -0.05650406
cat("Variance =", var(Ya), "\n\n")
## Variance = 0.8196189
par(mfrow = c(1, 2))
plot(Ya, type = "l", main = "(a) Y_t = e_t * e_{t-1}", ylab = "Y_t")
acf(Ya, main = "ACF: (a)")
par(mfrow = c(1, 1))
Conclusion: mean and variance constant, ACF dies quickly ⇒ stationary ### (b) Y_t = e_t(1 + e_{t-1})
Yb <- eps_t + eps_t * eps_tm1
Yb <- Yb[-1]
cat("---- (b) Y_t = e_t(1 + e_{t-1}) ----\n")
## ---- (b) Y_t = e_t(1 + e_{t-1}) ----
cat("Mean =", mean(Yb), "\n")
## Mean = -0.06230111
cat("Variance =", var(Yb), "\n\n")
## Variance = 1.404056
par(mfrow = c(1, 2))
plot(Yb, type = "l", main = "(b) Y_t = e_t(1 + e_{t-1})", ylab = "Y_t")
acf(Yb, main = "ACF: (b)")
par(mfrow = c(1, 1))
Conclusion: mean ≈ 0, variance constant ⇒ stationary ### (c) Y_t = e_1 + e_t
Yc <- eps[1] + eps
cat("---- (c) Y_t = e_1 + e_t ----\n")
## ---- (c) Y_t = e_1 + e_t ----
cat("Mean =", mean(Yc), "\n")
## Mean = -0.5690461
cat("Variance (t ≥ 2) =", var(Yc[-1]), "\n\n")
## Variance (t ≥ 2) = 0.8924971
par(mfrow = c(1, 2))
plot(Yc, type = "l", main = "(c) Y_t = e_1 + e_t", ylab = "Y_t")
acf(Yc[-1], main = "ACF: (c)")
par(mfrow = c(1, 1))
Conclusion: variance changes for t=1 ⇒ not stationary ### d) Y_t = (-1)^t * e_t
signs <- (-1)^(1:n)
Yd <- signs * eps
cat("---- (d) Y_t = (-1)^t * e_t ----\n")
## ---- (d) Y_t = (-1)^t * e_t ----
cat("Mean =", mean(Yd), "\n")
## Mean = -0.01437704
cat("Variance =", var(Yd), "\n\n")
## Variance = 0.8894166
par(mfrow = c(1,2))
plot(Yd, type = "l", main = "(d) Y_t = (-1)^t * e_t", ylab = "Y_t")
acf(Yd, main = "ACF: (d)")
par(mfrow = c(1,1))
Conclusion: mean ≈ 0, variance constant ⇒ stationary ## Question 2 : Consider the following ARIMA (p, d, q) time series \(Yt=0.6Y_{t−1}−0.05Y_{t−2}+e_t\) ### (a) Identify p, d and q.
phi1 <- 0.6
phi2 <- -0.05
cat("AR coefficients:", phi1, phi2, "\n")
## AR coefficients: 0.6 -0.05
cat("=> p =", 2, ", d = 0, q = 0\n\n")
## => p = 2 , d = 0, q = 0
(p,d,q) = (2,0,0), \(Y_{t−1}\) and \(Y_{t−2}\) are autoregressive (p=2) ### (b) Calculate the autocovariance function of the series using the Yule–Walker equations
sigma2 <- 1
rho1 <- phi1 / (1 - phi2)
rho2 <- phi1 * rho1 + phi2
gamma0 <- sigma2 / (1 - phi1 * rho1 - phi2 * rho2)
gamma1 <- rho1 * gamma0
gamma2 <- rho2 * gamma0
cat("γ(0) =", gamma0, "\nγ(1) =", gamma1, "\nγ(2) =", gamma2, "\n\n")
## γ(0) = 1.48857
## γ(1) = 0.8506114
## γ(2) = 0.4359383
poly <- c(1, -phi1, -phi2)
cat("Inverse roots:", 1 / abs(polyroot(poly)), "\n")
## Inverse roots: 0.5 0.1
$Y_t= 1/2Y_{t-1} + 1/2Y_{t-2} - 1/3e_{t-1} + e_t $ ### (a) Identify p, d and q
phi <- c(0.5, 0.5)
theta <- -1/3
cat("AR coefficients:", paste(phi, collapse = ", "), "\n")
## AR coefficients: 0.5, 0.5
cat("MA coefficient:", theta, "\n")
## MA coefficient: -0.3333333
cat("=> p =", length(phi), ", d = 0, q = 1 (ARIMA(2,0,1))\n\n")
## => p = 2 , d = 0, q = 1 (ARIMA(2,0,1))
# AR polynomial: 1 - 0.5 z - 0.5 z^2
ar_poly <- c(1, -phi)
roots <- polyroot(ar_poly)
print(roots)
## [1] 1-2.895132e-23i -2+2.895132e-23i
print(Mod(roots))
## [1] 1 2
# Illustrative nearby stationary version for ACF shape
phi_stationary <- c(0.4, 0.4)
set.seed(123)
y <- arima.sim(model = list(ar = phi_stationary, ma = theta), n = 200)
acf(y, main = "ACF (approx. stationary: phi=0.4,0.4; theta=-1/3)")
Series is not stationary, the AR root is on the unit circle. ACF starts high then tails off
set.seed(123)
y_ar1 <- arima.sim(model = list(ar = -0.8), n = 200)
par(mfrow = c(2,1))
acf(y_ar1, main = "ACF: AR(1) with phi = -0.8")
pacf(y_ar1, main = "PACF: AR(1) with phi = -0.8")
par(mfrow = c(1,1))
ACF → decays gradually and alternates in sign. PACF → cuts off sharply after lag 1
###(b) MA(1) with theta = −0.8.
set.seed(123)
y_ma1 <- arima.sim(model = list(ma = -0.8), n = 200)
par(mfrow = c(2,1))
acf(y_ma1, main = "ACF: MA(1) with theta = -0.8")
pacf(y_ma1, main = "PACF: MA(1) with theta = -0.8")
par(mfrow = c(1,1))
ACF → cuts off after lag 1. PACF → decays gradually