4.5. Let ct be the cardiovascular mortality series (cmort) discussed in Example 3.5 and let \(x_t = \nabla c_t\) be the differenced data.

e)Assuming the fitted model is the true model, find the forecasts over a fourweek horizon, \(x^n_{n+m}\), for \(m = 1, 2, 3, 4\), and the corresponding 95% prediction intervals; \(n = 500\) here. The easiest way to do this is to use sarima.for from astsa.

#work needed 
library(astsa)
## Warning: package 'astsa' was built under R version 4.1.3
data(cmort) 
c_t <- cmort
x_t <- diff(cmort, lag = 1) 

model <- sarima(xdata = x_t, p = 1, d = 0, q = 0) 
## initial  value 1.908706 
## iter   2 value 1.760342
## iter   3 value 1.760341
## iter   4 value 1.760341
## iter   4 value 1.760341
## iter   4 value 1.760341
## final  value 1.760341 
## converged
## initial  value 1.760656 
## iter   2 value 1.760656
## iter   3 value 1.760656
## iter   3 value 1.760656
## iter   3 value 1.760656
## final  value 1.760656 
## converged

forecast <- sarima.for(x_t, n.ahead=4, 1,0,0)

#CI

lowerB <- forecast$pred - 1.96 * forecast$se
upperB <- forecast$pred + 1.96 * forecast$se

cat("The upper bounds for our forward pred are: ", upperB, "\n")
## The upper bounds for our forward pred are:  13.35206 11.74453 13.58632 12.90407
cat("The lower bounds for our forward pred are: ", lowerB, "\n")
## The lower bounds for our forward pred are:  -9.440977 -13.8043 -12.62253 -13.47137
  1. Show how the values obtained in part (e) were calculated.

Since \(x_{n+1}^n =\phi^m x_n\) the values calculated are multiplied by \(\phi^m\) which works well if m is small.

  1. What is the one-step-ahead forecast of the actual value of cardiovascular mortality; i.e., what is \(c^n_{n+1}\) ?

the one step forecast would simply be \(\phi c_n\). This is something that is explored in greater depth in my answer for question 4.6.

4.8. Generate 10 realizations of length n = 200 each of an ARMA(1,1) process with \(\phi = .9\), \(\theta = .5\) and \(\sigma = 1\). Find the MLEs of the three parameters in each case and compare the estimators to the true values.

n <- 200
phi <- 0.9
theta <- 0.5
sigma2 <- 1

phi_values <- numeric(10)
theta_values <- numeric(10)


for (x in 1:10) {
  ar11<- arima.sim(n = 200, list(ar = phi, ma = theta), sd = sigma2)
  sarimaAR11 <- sarima(ar11, p=1,d =0, q=1, details= FALSE)
  phi_values[x] <- sarimaAR11$fit$coef[1]
  theta_values[x] <- sarimaAR11$fit$coef[2]
}

results <- data.frame(phiReal = phi, phiPred = phi_values,  thetaReal = theta, thetaPred = theta_values)
print(results)
##    phiReal   phiPred thetaReal thetaPred
## 1      0.9 0.8699171       0.5 0.4694735
## 2      0.9 0.8964119       0.5 0.5456281
## 3      0.9 0.8342537       0.5 0.4296931
## 4      0.9 0.9199037       0.5 0.4569385
## 5      0.9 0.8811860       0.5 0.4068224
## 6      0.9 0.8801053       0.5 0.4637625
## 7      0.9 0.8667202       0.5 0.5904199
## 8      0.9 0.9068123       0.5 0.4800318
## 9      0.9 0.8876753       0.5 0.4410993
## 10     0.9 0.8907645       0.5 0.4889703

The predictions do come close to the true value