LAB8_report
LAB8_report
ARMA Models
STA - 631
Objectives:
CODE:
library(astsa)
library(tseries)
library(forecast)
##
## Attaching package: 'forecast'
data("lh")
ts_data <- lh
plot(ts_data, main="Time Series Plot of LH Data",
ylab="Hormone Level", xlab="Time", col="blue", type="o")
# Stationarity Analysis Using ADF Test
adf_test_result <- adf.test(ts_data)
print(adf_test_result)
##
## Augmented Dickey-Fuller Test
##
## data: ts_data
## Dickey-Fuller = -3.558, Lag order = 3, p-
value = 0.04624 ## alternative hypothesis:
stationary
#INFERENCE:
##
## Augmented Dickey-Fuller Test
##
## data: diff_ts
## Dickey-Fuller = -4.6042, Lag order = 3, p-
value = 0.01 ## alternative hypothesis:
stationary
#INFERENCE:
## Series: ts_data
## arma(0,0,2) with non-zero mean
##
## Coefficients:
## ma1 ma2 mean
## 0.6732 0.3753 2.4016
## s.e. 0.1326 0.1291 0.1244
##
## sigma^2 = 0.1943: log likelihood = -27.53
## AIC=63.06 AICc=63.99 BIC=70.55
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ## Training set 2.994756e-05
0.426814 0.3267262 -3.358918 14.29451 0.9086468 ## ACF1
## Training set 0.02045045
#INFERENCE:
## The auto.arma() function selected an arma(0,0,2) model:
## - 0 AR terms (no autoregressive component).
## - 0 differencing (model was fitted on original series without differencing).
## - 2 MA terms (relying on past error terms for forecasting).
## Estimated Parameters:
## - MA(1) coefficient = 0.6732 (SE = 0.1326)
## - MA(2) coefficient = 0.3753 (SE = 0.1291)
## - Mean = 2.4016 (SE = 0.1244)
## - AIC = 63.06, BIC = 70.55, indicating a good fit with low complexity.
checkresiduals(auto_fit)
##
## Ljung-Box test
##
## data: Residuals from arma(0,0,2) with non-
zero mean ## Q* = 4.0871, df = 8, p-value =
0.8492
##
## Model df: 2. Total lags used: 10
#INFERENCE:
## Ljung-Box test result:
## - Q-statistic = 4.0871, p-value = 0.8492
## - Residuals do not show significant autocorrelation, confirming that the model captures the
variability adequately.
holt_fit <- holt(ts_data, h=3)
summary(holt_fit)
##
## Forecast method: Holt's method
##
## Model Information:
## Holt's method
##
## Call:
## holt(y = ts_data, h = 3)
##
## Smoothing parameters:
## alpha = 0.9443
## beta = 1e-04
##
## Initial states:
## l = 2.3886
## b = 0.0108
##
## sigma: 0.5192
##
## AIC AICc BIC
## 128.7075 130.1361 138.0635
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ## Training set 7.997787e-05
0.4970503 0.3637899 -2.294006 15.15648 1.011724 ## ACF1
## Training set 0.007337923
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 49 2.917989 2.252669 3.583310 1.900470 3.935509
## 50 2.928745 2.013646 3.843844 1.529221 4.328269
## 51 2.939501 1.829435 4.049567 1.241801 4.637200
#INFERENCE:
## Holt’s smoothing parameters:
## - Alpha (level smoothing) = 0.9443 → Suggests strong responsiveness to recent observations.
## - Beta (trend smoothing) = 0.0001 → Indicates a very weak trend component.
## - Initial Level = 2.3886, Initial Slope = 0.0108
## - AIC = 128.71, significantly higher than arma’s AIC (63.06), meaning it is a worse fit to the
data.
plot(holt_fit, main="Holt's Exponential Smoothing
Forecast")
print(accuracy_holt)
## ME RMSE MAE MPE MAPE MASE ## Training set 7.997787e-05
0.4970503 0.3637899 -2.294006 15.15648 1.011724 ## ACF1
## Training set 0.007337923
#INFERENCE:
Conclusion:
Time series analysis is essential for identifying patterns and making reliable forecasts in
various fields. Ensuring stationarity is a key step, often achieved through differencing and
statistical tests like the ADF test. Forecasting models such as arma and Exponential
Smoothing are widely used,
with arma capturing autocorrelation structures and smoothing methods emphasizing
recent trends. Model performance is evaluated using metrics like RMSE and MAPE,
while residual diagnostics ensure proper model fit. Ultimately, selecting the right
model depends on the data's characteristics, ensuring accurate and meaningful
predictions for informed decision-making.