Question 1
**Given:**
Week | Value
----- | -----
1 | 17
2 | 13
3 | 15
4 | 11
5 | 17
6 | 14
Objective:
Using the naive method (most recent value) as the forecast for the next week, compute the Mean absolute error, Mean squared error, Mean absolute percentage error, and forecast for week 7.
Load the data
week <- 1:6
values <- c(17, 13, 15, 11, 17, 14)
Measures of Forecast Accuracy
forecast <- values[-length(values)]
actual <- values[-1]
me <- mean(abs(actual - forecast))
me
## [1] 3.8
mse <- mean((actual - forecast)^2)
mse
## [1] 16.2
mpe <- mean((abs(actual - forecast))/actual) * 100
mpe
## [1] 27.43778
Interpretation:
Our Mean Absolute error is 3.8
Our Mean Square error is 16.2
Our Mean Absolute Percentage error is 27.44
Forecast for Week 7
forecast_week7 <- tail(values, 1)
forecast_week7
## [1] 14
Interpretation:
Our forcast for week 7 is 14
Question 2
**Given:**
Month | $ in millions
------- | -------------
1 | 240
2 | 352
3 | 230
4 | 260
5 | 280
6 | 322
7 | 220
8 | 310
9 | 240
10 | 310
11 | 240
12 | 230
Objective:
Using the data, construct a time series plot and identify the pattern type, and compare the three-month moving average approach with the exponential smoothing forecast using alpha = 0.2. Which provides more accurate forecasts based on MSE?
Load the data
months <- 1:12
dollars <- c(240, 352, 230, 260, 280, 322, 220, 310, 240, 310, 240, 230)
df <- data.frame(months,dollars)
Create the time series plot
p <- ggplot(df, aes(x=months, y=dollars)) +
geom_line()
p

Interpretation:
Our time series plot has a horizontal pattern fluctuating around a constant mean.
Three-month moving average approach
forecast2 <- dollars[-length(months)]
actual2 <- dollars[-3]
mpe2 <- mean((abs(actual2 - forecast2))/actual2) * 100
mpe2
## [1] 17.48932
Exponential smoothing forecast approach
alpha <- 0.2
exp_smooth <- rep(NA, length(dollars))