Question 1

months <- 1:6 
values <- c(17,13,15,11,17,14)

A(Most Recent)

# A
forecasts_a <- values[-length(values)]
actual_a <- values[-1]
mse_a <- mean((actual_a -forecasts_a)^2)
mse_a # 16.2
## [1] 16.2
forecast_week_7_a <- tail(values,1)
forecast_week_7_a # 14
## [1] 14
cumulative_averages <- cumsum(values[-length(values)])/ (1:(length(values)-1))
cumulative_averages # 17.0, 15.0, 15.0, 14.0, 14.6
## [1] 17.0 15.0 15.0 14.0 14.6

B(All)

# B
forecasts_b <- cumulative_averages
actual_b <- values[-1]
mse_b <- mean((actual_b- forecasts_b)^2)
mse_b
## [1] 8.272
forecast_week_7_b <- tail(values)
forecast_week_7_b
## [1] 17 13 15 11 17 14

Better Method

#Better Method
better_method <- ifelse(mse_a < mse_b, "Most Recent Value", "Average of all Data")
list( 
  MSE_most_recent_value = mse_a,
  forecast_week_7_most_recent = forecast_week_7_a,
  MSE_average_of_all_data = mse_b,
  forecast_week_7_average = forecast_week_7_b,
  Better_Method = better_method
)
## $MSE_most_recent_value
## [1] 16.2
## 
## $forecast_week_7_most_recent
## [1] 14
## 
## $MSE_average_of_all_data
## [1] 8.272
## 
## $forecast_week_7_average
## [1] 17 13 15 11 17 14
## 
## $Better_Method
## [1] "Average of all Data"