##STEP 1
week <- 1:6
values <- c(17, 13, 15, 11, 17, 14)
##STEP 2
forecast_a <- values[-length(values)]
actual_a <- values[-1]
mse_a <- mean((actual_a - forecast_a)^2)
##STEP 3
forecast_week7_a <- tail(values, 1)
cumulative_averages <- cumsum(values[-length(values)]) / (1:(length(values) - 1))
forecast_b <- cumulative_averages
actual_b <- values[-1]
##STEP 4
actual_b <- values[-1]
mse_b <- mean((actual_b - forecast_b)^2)
forecast_week7_b <- mean(values)
##STEP 5
better_method <- ifelse(mse_a < mse_b, "Most Recent Value", "Average of All Data")
##STEP 6
list(
MSE_Most_Recent_Value = mse_a,
Forecast_Week7_Most_Recent = forecast_week7_a,
MSE_Average = mse_b,
Forecast_Week7_Average = forecast_week7_b,
Better_Method = better_method
)
## $MSE_Most_Recent_Value
## [1] 16.2
##
## $Forecast_Week7_Most_Recent
## [1] 14
##
## $MSE_Average
## [1] 8.272
##
## $Forecast_Week7_Average
## [1] 14.5
##
## $Better_Method
## [1] "Average of All Data"
$MSE_Most_Recent_Value [1] 16.2
$Forecast_Week7_Most_Recent [1] 14
$MSE_Average [1] 8.272
$Forecast_Week7_Average [1] 14.5
$Better_Method [1] “Average of All Data” ```