https://rdrr.io/cran/forecast/man/gas.html
Australian monthly gas production: 1956–1995.
library(forecast)
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
library(TTR)
library(tseries)
‘tseries’ version: 0.10-50
‘tseries’ is a package for time series analysis and computational finance.
See ‘library(help="tseries")’ for details.
data(gas, package='forecast')
head(gas)
Jan Feb Mar Apr May Jun
1956 1709 1646 1794 1878 2173 2321
summary(gas)
Min. 1st Qu. Median Mean 3rd Qu. Max.
1646 2675 16788 21415 38628 66600
plot.ts(gas, xlab="Time", ylab="Gas production")
ggseasonplot(gas)
plot.ts(log(gas), xlab="Time", ylab="Gas production")
plot.ts(SMA(log(gas), n = 50), xlab="Time", ylab="Gas production")
plot(decompose(log(gas)))
acf(log(gas))
pacf(log(gas))
hw1 <- HoltWinters(log(gas))
hw1
Holt-Winters exponential smoothing with trend and additive seasonal component.
Call:
HoltWinters(x = log(gas))
Smoothing parameters:
alpha: 0.6640584
beta : 0.01627736
gamma: 0.2511116
Coefficients:
[,1]
a 10.817740200
b 0.002421792
s1 0.081519909
s2 0.005080236
s3 -0.074841438
s4 -0.175083641
s5 -0.205117401
s6 -0.188208891
s7 -0.106375501
s8 -0.063333907
s9 0.101100492
s10 0.178808443
s11 0.241557419
s12 0.203283289
plot(hw1)
hw2 <- forecast:::forecast.HoltWinters(hw1, h = 50)
plot(hw2)
adf.test(log(gas))
Augmented Dickey-Fuller Test
data: log(gas)
Dickey-Fuller = -0.515, Lag order = 7, p-value = 0.9811
alternative hypothesis: stationary
plot(diff(log(gas)))
plot(diff(diff(log(gas))))
fit <- auto.arima(log(gas), stationary = FALSE)
autoplot(forecast(fit, level = c(95), h = 50))
acf(fit$residuals)
Box.test(fit$residuals, type="Ljung-Box")
Box-Ljung test
data: fit$residuals
X-squared = 0.0048639, df = 1, p-value = 0.9444
checkresiduals(fit, test=FALSE)