ASSIGNMENT-10-M24MSA068.R: # Load Required Libraries
ASSIGNMENT-10-M24MSA068.R: # Load Required Libraries
R
HP
2025-04-02
# Load required libraries
library(forecast)
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Create the data frame
data <- data.frame(
Month
= c("January", "February", "March", "April", "May", "June
",
# 3. ARIMA Model
arima_model <- auto.arima(train, seasonal = FALSE)
arima_forecast <- forecast(arima_model, h = 12)
arima_accuracy <- accuracy(arima_forecast$mean, test)
arima_mape <- arima_accuracy[5]
arima_rmse <- arima_accuracy[2]
# 3. TBATS Model
tbats_model <- tbats(train)
tbats_forecast <- forecast(tbats_model, h = 12)
tbats_accuracy <- accuracy(tbats_forecast$mean, test)
tbats_mape <- tbats_accuracy[5]
tbats_rmse <- tbats_accuracy[2]
## Model Comparison
model_comparison <- data.frame(
Model = c("SES", "Holt", "ARIMA", "Holt-
Winters", "SARIMA", "TBATS"),
Type = c("Non-seasonal", "Non-seasonal", "Non-
seasonal",
"Seasonal", "Seasonal", "Seasonal"),
MAPE = c(ses_mape, holt_mape, arima_mape, hw_mape,
sarima_mape, tbats_mape),
RMSE = c(ses_rmse, holt_rmse, arima_rmse, hw_rmse,
sarima_rmse, tbats_rmse)
)
## Recommendations
cat("\nRecommendations:\n")
##
## Recommendations:
cat("1. The", best_model$Model, "model performed best
with a MAPE of", round(best_model$MAPE, 2), "% and RMSE
of", round(best_model$RMSE, 2), "\n")
## 1. The Holt model performed best with a MAPE of 12.67
% and RMSE of 649877.7
cat("2. Seasonal
models", ifelse(best_model$Type == "Seasonal", "outperfor
med non-seasonal models, confirming the presence of
seasonality in shampoo sales.",
"did not outperform non-
seasonal models, suggesting limited seasonality in this
dataset."), "\n")
## 2. Seasonal models did not outperform non-seasonal
models, suggesting limited seasonality in this dataset.
cat("3. For improved accuracy, future analyses should
incorporate:\n")
## 3. For improved accuracy, future analyses should
incorporate:
cat(" - Promotion expenditure data\n")
## - Promotion expenditure data
cat(" - Competitor promotion indicators\n")
## - Competitor promotion indicators
cat(" - Additional market factors that may influence
shampoo demand\n")
## - Additional market factors that may influence
shampoo demand
KEY FINDINGS
• Key Insight: Kesh shampoo demand is seasonal, with peaks in summer
consistent year-over-year.
Forecast Accuracy
• MAPE (Mean Absolute Percentage Error):