Loading necessary libraries
if (!require("pacman")) install.packages("pacman")
## Loading required package: pacman
pacman::p_load(dplyr, fpp3, ggplot2, readxl)
gas_price <- read_excel("Gas_Price_2017_18.xlsx")
head(gas_price)
Converting it into Tsibble format
gas_series <- gas_price %>%
mutate(Date = as_date(Date)) %>%
as_tsibble(index = Date)
gas_series %>%
autoplot(`Gas_Price_US$`) +
labs(title = "Gas Price Series 2017-2018",
y = "Gas Price (US$)",
x = "Date")
The line chart for the gas price series does not show a clear, consistent upward or downward trend over the entire period. Instead, it exhibits a mix of seasonal and cyclical patterns. Specifically, I observed price peaks in the late winter (February) and late spring (May), while prices tend to ‘cool down’ or price drops in the summer months (June and July) and late autumn (October and November). These fluctuations suggest that gas prices are influenced by recurring seasonal factors rather than a steady long-term growth trend.
random_walk <- gas_series %>%
model(rw_model = NAIVE(`Gas_Price_US$`))
random_walk %>%
gg_tsresiduals()
While a few spikes in the ACF plot exceed the blue-dashed thresholds, they represent less than 5% of the total lags. Therefore, the residuals can still be considered white noise. However, these small spikes suggest that the Random Walk model might still be missing some minor underlying patterns in the gas price data.
augment(random_walk) %>%
features(.innov, ljung_box, lag = 10, dof=0)
After running the Ljung-Box Test, the p-value (6.17×10 −10) is significantly less than the standard 0.05 alpha level. Because the p-value is less than 0.05, we reject the null hypothesis that the residuals are white noise. This confirms the findings from the ACF plot: there is still significant information (autocorrelation) left in the residuals that the Random Walk model did not capture.