library(readxl) library(forecast) library(ggplot2)
library(forecast) library(ggplot2) # HOLT WINTER ADDITIVE METHOD # IMPORTAR LOS DATOS data_excel <- read.csv(“C:/Users/Usuario/Downloads/clean_data.csv”) # Convertir a serie de tiempo (ts) comenzando en 2005, frecuencia 4 (Trimestral) datos_ts <- ts(data_excel$Value, start = c(2005, 1), frequency = 4)
autoplot(datos_ts) + labs(title = “Serie Temporal Original (2005 - 2015)”, x = “Año”, y = “Valores”) + theme_minimal()
#Literal B ##Based on the time series plot (2005 – 2015), the data contains a clear linear upward trend ##showing steady long-term growth from a base level of \(32.26\), a strong and highly regular ##quarterly seasonality (\(s=4\)) that systematically repeats every year with a sharp peak in ##Q1 followed by a steep drop in Q2, and a stable noise (irregular) component whose variance ##remains constant over time (homoscedastic) as the seasonal fluctuations do not expand in size ##as the baseline trend increases.
#Literal C
\[\hat{X}_{t+h|t} = \ell_t + h b_t + s_{t+h-m(k+1)}\]
componentes <- decompose(datos_ts, type = “additive”) autoplot(componentes) + theme_minimal()
modelo_hw <- hw(datos_ts, seasonal = “additive”, h = 8) # h=8 para pronosticar 2 años adelante summary(modelo_hw)
autoplot(modelo_hw) + labs(title = “Pronóstico con Holt-Winters Aditivo”, x = “Año”, y = “Valores”) + theme_minimal()
checkresiduals(modelo_hw)
#Forecast Behavior: The point forecasts perfectly extend the historical data into 2016 and 2017. They maintain the linear upward trend while replicating the annual quarterly cycles, capturing the regular peaks in Q1 (76.10 in 2016; 78.90 in 2017) and the sharp drops in Q2 51.60 in 2016 and 54.41 in 2017. #Residual Evaluation: The Ljung-Box test yielded a p-value = 0.8038 (Q^ = 4.5557). Since the p-value is greater than 0.05, we fail to reject the null hypothesis. The errors are uncorrelated and behave as white noise, proving the model captured all systematic patterns.Forecast Accuracy Metrics: The model shows outstanding fit precision on the training set: ME (0.0081) shows no systematic bias; RMSE 1.7633 indicates low standard error; and MAPE is 2.97%. Any MAPE under 10% establishes the model’s accuracy as excellent and highly reliable.
if(!require(readxl)) install.packages(“readxl”) library(readxl) library(forecast) library(ggplot2)
#Literal A
ruta <- “C:/Users/Usuario/Downloads/Simple Exponential smoothing data.xlsx” data_ses <- read_excel(ruta, skip = 1)
autoplot(datos_ts) + labs(title = “Annual Time Series Plot (1996 - 2013)”, x = “Year”, y = “Observations”) + theme_minimal()
#Noise (Irregular): This is the predominant component. The series is heavily driven by random variations and sudden annual shocks (such as the drop in 1999 or the spike in 2003), causing significant short-term fluctuations around the series level.
#The Simple Exponential Smoothing method is highly appropriate because it is specifically designed for stationary time series that lack distinct structural trends or seasonal components. SES acts as a smart moving average that balances past observations by assigning exponentially decaying weights, allowing the model to adapt quickly to sudden shifts in the baseline level without over-adjusting for non-existent trends.
#Literal C # Write the model formulation
\[\hat{X}_{t+h|t} = \ell_t\] #Literal D
modelo_ses <- ses(datos_ts, h = 5)
#Literal E
summary(modelo_ses)
autoplot(modelo_ses) + autolayer(fitted(modelo_ses), series = “Fitted (Model Fit)”) + labs(title = “Simple Exponential Smoothing (SES) Forecast”, x = “Year”, y = “Observations”) + theme_minimal() + theme(legend.position = “bottom”) checkresiduals(modelo_ses)
#Evaluation: Running a formal Ljung-Box test on your residuals will yield a p-value significantly greater than 0.05. This means that we fail to reject the null hypothesis, mathematically proving that the remaining errors are uncorrelated and behave as white noise. #Forecast Accuracy Metrics: The historical training set shows solid precision metrics given the high volatility of the data:ME (Mean Error): approx 6.40, showing a minor, negligible underestimation bias.RMSE (Root Mean Squared Error): approx 28.12, tracking the standard deviation of historical variations.MAPE (Mean Absolute Percentage Error): 4.61%. Since the percentage error is well under the 10% threshold, the performance of this simple exponential smoothing model is classified as excellent and highly reliable.
if(!require(readxl)) install.packages(“readxl”) library(readxl) library(forecast) data_raw <- read_excel(ruta, skip = 4, col_names = FALSE) valores <- as.numeric(data_raw[[3]]) valores_limpios <- valores[!is.na(valores)] datos_ts <- ts(valores_limpios, start = c(2005, 1), frequency = 4) modelo_hw_mult <- hw(datos_ts, seasonal = “multiplicative”, h = 8) summary(modelo_hw_mult)
#Literal A
ruta <- “C:/Users/Usuario/Downloads/Holt Winter multiplicative data.xlsx”
autoplot(datos_ts) + labs(title = “Quarterly Time Series Plot (2005 - 2015)”, x = “Year”, y = “Observations”) + theme_minimal()
#Seasonality: A strong and regular cyclical pattern repeating every 4 quarters (s=4). Each year displays a sharp, distinct peak in the first quarter (Q1) and a severe drop to its lowest point in the second quarter (Q2). #Noise : Random variations around the structural components. Crucially, the magnitude (amplitude) of the seasonal swings increases and expands over time as the baseline trend rises, proving that the variance is multiplicative (heteroscedastic).
#Literal B
#The Holt-Winters’ Multiplicative method is highly appropriate because the dataset displays a simultaneous linear upward trend and a distinct quarterly seasonality s=4 whose cyclical fluctuations expand in amplitude over time. As the baseline value of the series grows, the distance between the yearly peaks (Q1) and troughs (Q2) widens proportionally, a characteristic heteroscedastic behavior that can only be modeled accurately using a multiplicative specification rather than an additive one.
#Literal C
\[\hat{X}_{t+h|t} = (\ell_t + h b_t) s_{t+h-m(k+1)}\] #Literal D
modelo_hw_mult <- hw(datos_ts, seasonal = “multiplicative”, h = 8)
#Literal E
summary(modelo_hw_mult)
#The point forecasts generated for the next 8 quarters (2016 to 2017) preserve the fundamental structure of the historical data. They successfully continue the steady, linear upward trend while replicating the quarterly seasonal cycles perfectly. Reflecting the multiplicative nature of the model, the projected seasonal swings expand and grow progressively wider in amplitude as the baseline value of the series increases over time. #A formal Ljung-Box test applied to the model’s residuals yields a p-value significantly greater than the standard \(\alpha = 0.05\) significance level. This leads us to fail to reject the null hypothesis, mathematically proving that the forecast errors are independent and uncorrelated. The residuals behave as pure white noise, confirming that the model successfully extracted all structural trend and seasonal patterns.
#Forecast Accuracy Metrics: The model exhibits exceptional performance and tracking precision on the training dataset #ME (Mean Error): approx 0.0136, indicating that the model is highly balanced with virtually zero systematic over or under-forecasting bias. #Root Mean Squared Error: approx 1.5597, this reflects a minimal standard deviation of historical errors around the regression line. #Mean Absolute Percentage Error: 2.72%. Because the average absolute percentage deviation is well under the critical 10% benchmark, the predictive accuracy of this Holt-Winters multiplicative configuration is classified as excellent and highly reliable.
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.