title: “Time series approach”

A: time series data

weeks <- 1:6
values <- c(17,13,15,11,17,14)
time series use to compute mesures forecast accuracy using naive method 

Part A : most recent value

forecasts_a <- values[-length(values)]
actual_a <- values[-1]
mse_a <- mean((actual_a - forecasts_a)^2)
mse_a #result 16.2
## [1] 16.2
forecast_week_7_a <- tail(values, 1)
forecast_week_7_a # result : 14 
## [1] 14
mean squared error using recent value approach 
mean squared error is 16.2
predict weeek 7 value would be 14 

avarge of all data

culmulative_averages <- cumsum(values[-length(values)]) / (1:(length(values) - 1))
culmulative_averages
## [1] 17.0 15.0 15.0 14.0 14.6
forecast_b <- culmulative_averages
actual_b <- values[-1]
mse_b <- mean((actual_b - forecast_b)^2)
mse_b # 8.27
## [1] 8.272
forecast_week_7_b <- mean(values)
forecast_week_7_b
## [1] 14.5
mean squared error using average of all data method 
mean squared error equal 8.27
presict week 7 is 14.5
better_method <- ifelse(mse_a < mse_b, "Most recent value", "Avarage 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] 14.5
## 
## $Better_method
## [1] "Avarage of all data"
Interpretation : The average of all data method more acccurate forecasts for the next period than 
using the most recent observation