I. Clean the enviroment and install required packages
rm(list = ls())
cat("\f")
packages <- c("fpp2", "seasonal", "urca", "tseries", "Quandl")
for (i in 1:length(packages)){
if(!packages[i] %in% installed.packages()){
install.packages(packages[i])
}
library(packages[i], character.only = T)
}
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## -- Attaching packages ---------------------------------------------- fpp2 2.4 --
## v ggplot2 3.3.5 v fma 2.4
## v forecast 8.15 v expsmooth 2.3
##
## 载入需要的程辑包:xts
## 载入需要的程辑包:zoo
##
## 载入程辑包:'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
rm(packages)
setwd("C:/Users/admin/Desktop/study/HW2")
pigs_ses <- ses(pigs)
summary(pigs_ses)
##
## Forecast method: Simple exponential smoothing
##
## Model Information:
## Simple exponential smoothing
##
## Call:
## ses(y = pigs)
##
## Smoothing parameters:
## alpha = 0.2971
##
## Initial states:
## l = 77260.0561
##
## sigma: 10308.58
##
## AIC AICc BIC
## 4462.955 4463.086 4472.665
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 385.8721 10253.6 7961.383 -0.922652 9.274016 0.7966249 0.01282239
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Sep 1995 98816.41 85605.43 112027.4 78611.97 119020.8
## Oct 1995 98816.41 85034.52 112598.3 77738.83 119894.0
## Nov 1995 98816.41 84486.34 113146.5 76900.46 120732.4
## Dec 1995 98816.41 83958.37 113674.4 76092.99 121539.8
## Jan 1996 98816.41 83448.52 114184.3 75313.25 122319.6
## Feb 1996 98816.41 82955.06 114677.8 74558.56 123074.2
## Mar 1996 98816.41 82476.49 115156.3 73826.66 123806.2
## Apr 1996 98816.41 82011.54 115621.3 73115.58 124517.2
## May 1996 98816.41 81559.12 116073.7 72423.66 125209.2
## Jun 1996 98816.41 81118.26 116514.6 71749.42 125883.4
fpigs <- forecast(pigs_ses, h = 4)
pigs %>%
autoplot() +
autolayer(fpigs) +
ylab("number of pigs slaughtered") +
ggtitle("Pigs Slaughter Forecast")
manual_upper <- fpigs$mean + sd(pigs_ses$residuals)*1.96
manual_lower <- fpigs$mean - sd(pigs_ses$residuals)*1.96
data.frame(manual_upper = manual_upper
, R_upper = fpigs$upper[,2]
, manual_lower = manual_lower
, R_lower = fpigs$lower[,2])
## manual_upper R_upper manual_lower R_lower
## 1 118952.8 119020.8 78679.97 78611.97
## 2 118952.8 119894.0 78679.97 77738.83
## 3 118952.8 120732.4 78679.97 76900.46
## 4 118952.8 121539.8 78679.97 76092.99
pig_alpha <- fpigs$model$par[1]
pig_init <- fpigs$model$par[2]
fses <- function(ts, par = c(alpha, initial)) {
t = length(ts)
alpha = par[1]
yhat = par[2]
for(i in 1 : t) {
yhat = alpha * ts[i] + (1 - alpha) * yhat
}
return(yhat)
}
pig_alpha <- fpigs$model$par[1]
pig_init <- fpigs$model$par[2]
fses(pigs, par = c(pig_alpha, pig_init))
## alpha
## 98816.41
forecast(fpigs, h = 1)$mean
## Sep
## 1995 98816.41
error_ses <- function(ts, par = c(alpha, initial)) {
t = length(ts)
alpha = par[1]
yhat = par[2]
err = 0
sse = 0
for(i in 1 : t) {
err = ts[i] - yhat
sse = sse + err^2
yhat = alpha * ts[i] + (1 - alpha) * yhat
}
return(sse)
}
optim(ts = pigs, par = c(0, pigs[1]), fn=error_ses)
## $par
## [1] 0.297086 77272.075070
##
## $value
## [1] 19765613447
##
## $counts
## function gradient
## 179 NA
##
## $convergence
## [1] 0
##
## $message
## NULL
pig_fun <- function(ts) {
pig_error = function(ts, par = c(alpha, initial)) {
t = length(ts)
alpha = par[1]
yhat = par[2]
err = 0
sse = 0
for(i in 1 : t) {
err = ts[i] - yhat
sse = sse + err^2
yhat = alpha * ts[i] + (1 - alpha) * yhat
}
return(sse)
}
palpha = optim(ts = ts, par = c(0, ts[1]), fn=pig_error)$par[1]
y_hat = ts[1]
for ( j in 1:length(ts)) {
y_hat = palpha * ts[j] + (1-palpha) * y_hat
}
return(y_hat)
}
pig_fun(pigs)
## [1] 98816.47
autoplot(books)
paper_back <- books[,1]
hard_cover <- books[,2]
fp<- ses(paper_back)
fh <- ses(hard_cover)
forecast(fp, h = 4) %>%
autoplot() +
ylab("Paperback Books Sale")
forecast(fh, h = 4) %>%
autoplot() +
ylab("Hardcover Books Sale")
rmse_fun <- function(fit, actual) {
error = 0
for (i in 1:length(actual)) {
error = error + (actual[i] - fit[i])^2
}
return(sqrt(error/length(actual)))
}
rmse_fun(fp$fitted, paper_back)
## [1] 33.63769
rmse_fun(fh$fitted, hard_cover)
## [1] 31.93101
hp <- holt(paper_back, h = 4)
hh <- holt(hard_cover, h = 4)
rmse_fun(hp$fitted, paper_back)
## [1] 31.13692
rmse_fun(hh$fitted, hard_cover)
## [1] 27.19358
fp %>% autoplot(series = "SES") +
autolayer(hp, series="Holt's Linear Method")
fh %>% autoplot(series = "SES") +
autolayer(hh, series="Holt's Linear Method")
pf_holt <- forecast(hp, h = 1)
pf_ses <- forecast(fp, h = 1)
hf_holt <- forecast(hh, h = 1)
hf_ses <- forecast(fh, h = 1)
pf_holt_ci <- c(pf_holt$lower[2], pf_holt$upper[2])
manual_phci <- c(pf_holt$mean[1]-1.96*sd(pf_holt$residuals)
, pf_holt$mean[1]+1.96*sd(pf_holt$residuals))
data.frame(pf_holt_ci, manual_phci)
## pf_holt_ci manual_phci
## 1 143.9130 147.8390
## 2 275.0205 271.0945
pf_ses_ci <- c(pf_ses$lower[2], pf_ses$upper[2])
manual_psci <- c(pf_ses$mean[1]-1.96*sd(pf_ses$residuals)
, pf_ses$mean[1]+1.96*sd(pf_ses$residuals))
data.frame(pf_ses_ci, manual_psci)
## pf_ses_ci manual_psci
## 1 138.8670 141.5964
## 2 275.3523 272.6230
hf_holt_ci <- c(hf_holt$lower[2], hf_holt$upper[2])
manual_hhci <- c(hf_holt$mean[1]-1.96*sd(hf_holt$residuals)
, hf_holt$mean[1]+1.96*sd(hf_holt$residuals))
data.frame(hf_holt_ci, manual_hhci)
## hf_holt_ci manual_hhci
## 1 192.9222 195.9640
## 2 307.4256 304.3838
hf_ses_ci <- c(hf_ses$lower[2], hf_ses$upper[2])
manual_hsci <- c(hf_ses$mean[1]-1.96*sd(hf_ses$residuals)
, hf_ses$mean[1]+1.96*sd(hf_ses$residuals))
data.frame(hf_ses_ci, manual_hsci)
## hf_ses_ci manual_hsci
## 1 174.7799 178.5848
## 2 304.3403 300.5354
autoplot(eggs)
heggs <- holt(eggs, h = 100)
hdeggs <- holt(eggs, damped = T, h = 100)
hbeggs <- holt(eggs, lambda = BoxCox.lambda(eggs), h = 100)
forecast(heggs) %>% autoplot()
forecast(hdeggs) %>% autoplot()
forecast(hbeggs) %>% autoplot()
(h_rmse <- rmse_fun(heggs$fitted, eggs))
## [1] 26.58219
(hd_rmse <- rmse_fun(hdeggs$fitted, eggs))
## [1] 26.54019
(hb_rmse <- rmse_fun(hbeggs$fitted, eggs))
## [1] 26.39376
retaildata <- readxl::read_excel("retail.xlsx", skip=1)
myts <- ts(retaildata[,"A3349873A"],
frequency=12, start=c(1982,4))
autoplot(myts)
seasonplot(myts)
mretail <- holt(myts, seasonal = "multiplicative")
mdretail <- holt(myts, seasonal = "multiplicative", damped = T)
accuracy(mretail)
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 0.2014937 42.81252 26.89987 -2.619164 11.36189 1.420687 0.264695
accuracy(mdretail)
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 3.091964 42.90522 26.01247 -0.8997451 10.72444 1.373819 0.330954
checkresiduals(mretail)
##
## Ljung-Box test
##
## data: Residuals from Holt's method
## Q* = 734.49, df = 20, p-value < 2.2e-16
##
## Model df: 4. Total lags used: 24
ts_train <- window(myts, end=c(2010, 12))
ts_test <- window(myts, start=c(2011,1))
autoplot(myts)+autolayer(ts_train, series="Training")+autolayer(ts_test, series="Test")
myts %>% stlm( s.window = 13
, robust = TRUE
, method = "ets"
, lambda = BoxCox.lambda(myts) ) %>%
forecast( h = 36, lambda = BoxCox.lambda(myts) ) %>%
autoplot()
## Warning in InvBoxCox(fcast$mean, lambda, biasadj, fcast): biasadj information
## not found, defaulting to FALSE.
myts %>% stlm( s.window = 13
, robust = TRUE
, method = "ets" ) %>%
forecast(h = 36) %>%
autoplot()
autoplot(ukcars)
ukcars %>% stl(s.window = 4, robust = TRUE) %>% seasadj() %>% autoplot()
ukcars %>% stlf(h = 8, etsmodel = "AAN", damped = TRUE) %>% autoplot()
ukcars %>% stlf(h = 8, etsmodel = "AAN", damped = TRUE) %>% autoplot()
ukcars %>% ets() %>% forecast(h=8) %>% autoplot()
ukcars %>% stlf(h = 8, etsmodel = "AAN", damped = TRUE) %>% accuracy()
## ME RMSE MAE MPE MAPE MASE
## Training set 1.040088 22.81499 17.73846 -0.1296296 5.821059 0.5780878
## ACF1
## Training set 0.01590553
ukcars %>% stlf(h = 8, etsmodel = "AAN", damped = TRUE) %>% accuracy()
## ME RMSE MAE MPE MAPE MASE
## Training set 1.040088 22.81499 17.73846 -0.1296296 5.821059 0.5780878
## ACF1
## Training set 0.01590553
ukcars %>% ets() %>% forecast(h=8) %>% accuracy()
## ME RMSE MAE MPE MAPE MASE
## Training set 1.313884 25.23244 20.17907 -0.1570979 6.629003 0.6576259
## ACF1
## Training set 0.02573334
ukcars %>% stlf(h = 8, etsmodel = "AAN", damped = TRUE) %>% checkresiduals()
## Warning in checkresiduals(.): The fitted degrees of freedom is based on the
## model used for the seasonally adjusted data.
##
## Ljung-Box test
##
## data: Residuals from STL + ETS(A,Ad,N)
## Q* = 23.825, df = 3, p-value = 2.717e-05
##
## Model df: 5. Total lags used: 8
autoplot(visitors)
ggseasonplot(visitors)
vtrain <- subset(visitors, end = length(visitors) - 24)
vtest <- subset(visitors, start = length(visitors) - 23)
hw(vtrain, h = 24,seasonal = "multiplicative") %>% autoplot()
hw(vtrain, h = 24,seasonal = "multiplicative") %>% accuracy()
## ME RMSE MAE MPE MAPE MASE
## Training set -0.9749466 14.06539 10.35763 -0.5792169 4.223204 0.3970304
## ACF1
## Training set 0.1356528
forecast(ets(vtrain), h = 24) %>% autoplot()
forecast(ets(vtrain), h = 24) %>% accuracy()
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 0.7640074 14.5348 10.57657 0.1048224 3.994788 0.405423 -0.05311217
forecast(ets(vtrain
, lambda = BoxCox.lambda(vtrain)
, additive.only = TRUE)
, h = 24) %>%
autoplot()
forecast(ets(vtrain
, lambda = BoxCox.lambda(vtrain)
, additive.only = TRUE)
, h = 24) %>%
accuracy()
## ME RMSE MAE MPE MAPE MASE
## Training set 1.001363 14.97096 10.82396 0.1609336 3.974215 0.4149057
## ACF1
## Training set -0.02535299
snaive(vtrain, h = 24) %>% autoplot()
snaive(vtrain, h = 24) %>% accuracy()
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 17.29363 31.15613 26.08775 7.192445 10.28596 1 0.6327669
vtrain %>%
stlm(lambda = BoxCox.lambda(vtrain),
s.window = 13,
robust = TRUE,
method = "ets") %>%
forecast(h = 24) %>%
autoplot()
vtrain %>%
stlm(lambda = BoxCox.lambda(vtrain),
s.window = 13,
robust = TRUE,
method = "ets") %>%
forecast(h = 24) %>%
accuracy()
## ME RMSE MAE MPE MAPE MASE
## Training set 0.5803348 13.36431 9.551391 0.08767744 3.5195 0.3661256
## ACF1
## Training set -0.05924203
fets <- function(y, h) {
forecast(ets(y),
h = h)
}
#tsCV(qcement,fets, h = 4)
#tsCV(qcement, snaive, h = 4)
boxcox_brisk <- BoxCox(bricksq, BoxCox.lambda(bricksq))
brick_train <- window(boxcox_brisk, end = c(1991,1))
brick_test <- window(boxcox_brisk, start = c(1991,2))
boxcox_a10 <- BoxCox(a10, BoxCox.lambda(a10))
a10_train <- window(boxcox_a10 , end = c(2005,6))
a10_test <- window(boxcox_a10 , start = c(2005,7))
ausbeer_train <- window(ausbeer, end = c(2007,2))
ausbeer_test <- window(ausbeer, start = c(2007,3))
dole_train <- window(dole, end=c(1989,7))
dole_test <- window(dole, start=c(1989,8))
h02_train <- window(h02, end = c(2005,7))
h02_test <- window(h02, start = c(2005,8))
usmelec_train <- window(usmelec, end = c(2010,6))
usmelec_test <- window(usmelec, start = c(2010,7))
brick_ets <- ets(brick_train)
a10_ets <- ets(a10_train)
ausbeer_ets <- ets(ausbeer_train)
dole_ets <- ets(dole_train)
h02_ets <- ets(h02_train)
usmelec_ets <- ets(usmelec_train)
forecast(brick_ets, h=12)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 1991 Q2 14.39012 14.06821 14.71204 13.89780 14.88245
## 1991 Q3 14.55275 14.09235 15.01316 13.84862 15.25689
## 1991 Q4 14.29232 13.73850 14.84614 13.44532 15.13932
## 1992 Q1 13.82491 13.20629 14.44354 12.87881 14.77102
## 1992 Q2 14.39013 13.67014 15.11011 13.28900 15.49125
## 1992 Q3 14.55275 13.75508 15.35043 13.33281 15.77270
## 1992 Q4 14.29232 13.44609 15.13855 12.99812 15.58652
## 1993 Q1 13.82491 12.94978 14.70005 12.48651 15.16332
## 1993 Q2 14.39013 13.42387 15.35638 12.91237 15.86788
## 1993 Q3 14.55276 13.52265 15.58286 12.97734 16.12817
## 1993 Q4 14.29232 13.23119 15.35345 12.66947 15.91517
## 1994 Q1 13.82491 12.75277 14.89706 12.18521 15.46462
forecast(a10_ets, h=36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2005 3.392676 3.305704 3.479648 3.259664 3.525688
## Aug 2005 3.391047 3.303038 3.479056 3.256449 3.525645
## Sep 2005 3.416806 3.327771 3.505840 3.280639 3.552972
## Oct 2005 3.513518 3.423468 3.603568 3.375798 3.651238
## Nov 2005 3.538857 3.447801 3.629912 3.399599 3.678114
## Dec 2005 3.760049 3.667998 3.852101 3.619268 3.900830
## Jan 2006 3.852071 3.759033 3.945109 3.709782 3.994361
## Feb 2006 3.177780 3.083764 3.271795 3.033995 3.321564
## Mar 2006 3.328305 3.233321 3.423289 3.183040 3.473570
## Apr 2006 3.333654 3.237710 3.429597 3.186920 3.480387
## May 2006 3.435400 3.338504 3.532295 3.287211 3.583588
## Jun 2006 3.429342 3.331503 3.527182 3.279710 3.578974
## Jul 2006 3.544173 3.445397 3.642949 3.393108 3.695238
## Aug 2006 3.542544 3.442840 3.642249 3.390060 3.695029
## Sep 2006 3.568303 3.467678 3.668928 3.414410 3.722196
## Oct 2006 3.665015 3.563476 3.766554 3.509725 3.820305
## Nov 2006 3.690354 3.587909 3.792799 3.533677 3.847031
## Dec 2006 3.911546 3.808201 4.014892 3.753494 4.069599
## Jan 2007 4.003569 3.899330 4.107807 3.844150 4.162987
## Feb 2007 3.329277 3.224152 3.434402 3.168502 3.490052
## Mar 2007 3.479802 3.373797 3.585808 3.317681 3.641924
## Apr 2007 3.485151 3.378271 3.592031 3.321692 3.648609
## May 2007 3.586897 3.479149 3.694645 3.422110 3.751683
## Jun 2007 3.580840 3.472229 3.689450 3.414734 3.746945
## Jul 2007 3.695670 3.586202 3.805139 3.528253 3.863088
## Aug 2007 3.694042 3.583722 3.804361 3.525322 3.862761
## Sep 2007 3.719800 3.608635 3.830966 3.549788 3.889813
## Oct 2007 3.816512 3.704507 3.928518 3.645215 3.987810
## Nov 2007 3.841851 3.729010 3.954692 3.669276 4.014426
## Dec 2007 4.063044 3.949373 4.176715 3.889199 4.236888
## Jan 2008 4.155066 4.040570 4.269562 3.979959 4.330172
## Feb 2008 3.480774 3.365458 3.596090 3.304413 3.657135
## Mar 2008 3.631299 3.515168 3.747431 3.453691 3.808908
## Apr 2008 3.636648 3.519706 3.753591 3.457800 3.815496
## May 2008 3.738394 3.620645 3.856143 3.558313 3.918475
## Jun 2008 3.732337 3.613786 3.850888 3.551029 3.913644
forecast(ausbeer_ets, h=12)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2007 Q3 404.3218 385.3540 423.2895 375.3131 433.3305
## 2007 Q4 484.3093 460.9469 507.6717 448.5796 520.0390
## 2008 Q1 424.9750 403.7708 446.1792 392.5459 457.4040
## 2008 Q2 385.2270 365.2353 405.2187 354.6524 415.8017
## 2008 Q3 403.1265 379.8780 426.3750 367.5710 438.6820
## 2008 Q4 482.8764 453.8000 511.9528 438.4079 527.3449
## 2009 Q1 423.7166 396.9820 450.4513 382.8295 464.6038
## 2009 Q2 384.0855 358.6189 409.5521 345.1376 423.0334
## 2009 Q3 401.9449 372.4788 431.4111 356.8803 447.0095
## 2009 Q4 481.4600 444.4034 518.5166 424.7868 538.1332
## 2010 Q1 422.4728 388.2859 456.6596 370.1885 474.7570
## 2010 Q2 382.9571 350.3454 415.5687 333.0819 432.8323
forecast(dole_ets, h=36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Aug 1989 357550.0 312945.06 402154.9 289332.642 425767.3
## Sep 1989 342308.5 286561.31 398055.7 257050.527 427566.5
## Oct 1989 331606.7 264605.91 398607.6 229137.813 434075.6
## Nov 1989 326881.1 247817.71 405944.6 205964.050 447798.2
## Dec 1989 340124.0 244214.27 436033.7 193442.733 486805.2
## Jan 1990 374863.2 254107.59 495618.9 190183.411 559543.1
## Feb 1990 384381.2 245185.54 523576.9 171499.791 597262.7
## Mar 1990 379612.5 227069.19 532155.7 146317.666 612907.3
## Apr 1990 382797.3 213919.40 551675.2 124520.833 641073.8
## May 1990 386541.1 200981.73 572100.4 102752.547 670329.6
## Jun 1990 379469.8 182734.40 576205.1 78588.990 680350.5
## Jul 1990 365033.3 161951.09 568115.4 54445.888 675620.6
## Aug 1990 343352.8 134570.12 552135.6 24047.226 662658.5
## Sep 1990 330385.0 117585.66 543184.4 4936.488 655833.5
## Oct 1990 321501.8 102954.77 540048.8 -12737.036 655740.6
## Nov 1990 318193.3 90658.21 545728.3 -29791.564 666178.1
## Dec 1990 332265.8 83052.34 581479.3 -48873.310 713405.0
## Jan 1991 367363.1 79110.65 655615.6 -73480.995 808207.2
## Feb 1991 377750.1 68399.23 687101.1 -95361.262 850861.6
## Mar 1991 373994.3 55017.20 692971.5 -113839.088 861827.7
## Apr 1991 377966.1 42875.37 713056.9 -134510.977 890443.3
## May 1991 382410.7 30607.00 734214.3 -155626.608 920447.9
## Jun 1991 376066.7 17631.09 734502.3 -172113.270 924246.7
## Jul 1991 362315.9 5054.39 719577.4 -184068.427 908700.2
## Aug 1991 341464.2 -10319.53 693248.0 -196542.599 879471.1
## Sep 1991 328960.6 -20518.82 678440.0 -205522.031 863443.2
## Oct 1991 320454.4 -30267.22 671175.9 -215928.007 856836.7
## Nov 1991 317453.5 -40145.69 675052.7 -229447.261 864354.2
## Dec 1991 331767.8 -52558.50 716094.2 -256008.572 919544.2
## Jan 1992 367081.1 -69869.52 804031.8 -301177.236 1035339.5
## Feb 1992 377704.7 -83937.83 839347.1 -328316.595 1083725.9
## Mar 1992 374163.4 -95080.06 843406.9 -343482.547 1091809.4
## Apr 1992 378328.5 -108201.75 864858.7 -365755.280 1122412.2
## May 1992 382948.5 -121740.51 887637.6 -388906.744 1154803.8
## Jun 1992 376744.6 -131799.79 885289.0 -401006.938 1154496.2
## Jul 1992 363095.9 -138637.24 864829.1 -404238.730 1130430.6
forecast(h02_ets, h=36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Aug 2005 0.9261277 0.8532823 0.9989732 0.8147203 1.0375352
## Sep 2005 0.9788350 0.8988398 1.0588302 0.8564929 1.1011771
## Oct 2005 1.0390566 0.9510645 1.1270488 0.9044843 1.1736290
## Nov 2005 1.0478122 0.9560802 1.1395442 0.9075202 1.1881041
## Dec 2005 1.2201827 1.1099771 1.3303883 1.0516377 1.3887276
## Jan 2006 1.1511696 1.0440984 1.2582409 0.9874183 1.3149209
## Feb 2006 0.6254695 0.5656567 0.6852824 0.5339937 0.7169454
## Mar 2006 0.7010367 0.6322100 0.7698635 0.5957753 0.8062981
## Apr 2006 0.6925375 0.6228230 0.7622521 0.5859183 0.7991567
## May 2006 0.7414197 0.6649838 0.8178555 0.6245211 0.8583182
## Jun 2006 0.7888606 0.7056609 0.8720603 0.6616176 0.9161036
## Jul 2006 0.9004823 0.8034177 0.9975469 0.7520348 1.0489298
## Aug 2006 0.9296094 0.8272828 1.0319359 0.7731144 1.0861043
## Sep 2006 0.9824397 0.8721057 1.0927738 0.8136983 1.1511811
## Oct 2006 1.0428051 0.9234085 1.1622017 0.8602037 1.2254064
## Nov 2006 1.0515151 0.9288607 1.1741696 0.8639313 1.2390990
## Dec 2006 1.2244069 1.0789989 1.3698148 1.0020246 1.4467892
## Jan 2007 1.1550737 1.0155006 1.2946468 0.9416151 1.3685324
## Feb 2007 0.6275476 0.5504357 0.7046594 0.5096152 0.7454800
## Mar 2007 0.7033184 0.6154814 0.7911554 0.5689833 0.8376535
## Apr 2007 0.6947457 0.6066032 0.7828882 0.5599434 0.8295480
## May 2007 0.7437356 0.6479262 0.8395450 0.5972077 0.8902634
## Jun 2007 0.7912745 0.6878187 0.8947304 0.6330525 0.9494966
## Jul 2007 0.9031818 0.7833808 1.0229827 0.7199621 1.0864015
## Aug 2007 0.9323395 0.8069204 1.0577586 0.7405275 1.1241515
## Sep 2007 0.9852664 0.8509072 1.1196256 0.7797817 1.1907510
## Oct 2007 1.0457445 0.9012304 1.1902585 0.8247293 1.2667596
## Nov 2007 1.0544189 0.9068064 1.2020313 0.8286651 1.2801726
## Dec 2007 1.2277194 1.0536606 1.4017783 0.9615194 1.4939194
## Jan 2008 1.1581352 0.9919042 1.3243662 0.9039069 1.4123636
## Feb 2008 0.6291771 0.5377750 0.7205792 0.4893897 0.7689645
## Mar 2008 0.7051076 0.6014623 0.8087529 0.5465958 0.8636195
## Apr 2008 0.6964772 0.5929158 0.8000387 0.5380936 0.8548608
## May 2008 0.7455516 0.6334383 0.8576649 0.5740892 0.9170141
## Jun 2008 0.7931675 0.6725728 0.9137622 0.6087339 0.9776011
## Jul 2008 0.9052987 0.7661628 1.0444345 0.6925088 1.1180886
forecast(usmelec_ets, h = 36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2010 398.3597 383.9893 412.7301 376.3821 420.3373
## Aug 2010 402.4829 387.5680 417.3977 379.6725 425.2932
## Sep 2010 344.9220 331.8103 358.0336 324.8694 364.9745
## Oct 2010 323.8277 311.2164 336.4390 304.5403 343.1151
## Nov 2010 312.2226 299.7797 324.6654 293.1929 331.2523
## Dec 2010 350.9904 336.6915 365.2893 329.1221 372.8587
## Jan 2011 360.3726 345.3794 375.3658 337.4425 383.3027
## Feb 2011 318.6280 305.1018 332.1543 297.9414 339.3147
## Mar 2011 322.7679 308.7983 336.7375 301.4033 344.1325
## Apr 2011 302.5312 289.1918 315.8706 282.1304 322.9321
## May 2011 333.2581 318.2985 348.2176 310.3794 356.1367
## Jun 2011 373.3013 356.2527 390.3498 347.2278 399.3748
## Jul 2011 404.5701 384.9434 424.1968 374.5537 434.5865
## Aug 2011 408.7495 388.6252 428.8737 377.9721 439.5269
## Sep 2011 350.2854 332.7910 367.7799 323.5299 377.0409
## Oct 2011 328.8567 312.2027 345.5107 303.3866 354.3268
## Nov 2011 317.0651 300.7901 333.3401 292.1746 341.9556
## Dec 2011 356.4273 337.8901 374.9644 328.0772 384.7773
## Jan 2012 365.9476 346.6708 385.2244 336.4663 395.4289
## Feb 2012 323.5509 306.2943 340.8075 297.1592 349.9426
## Mar 2012 327.7484 310.0550 345.4418 300.6887 354.8081
## Apr 2012 307.1935 290.4128 323.9741 281.5297 332.8573
## May 2012 338.3873 319.6886 357.0859 309.7901 366.9844
## Jun 2012 379.0395 357.8578 400.2212 346.6449 411.4341
## Jul 2012 410.7809 386.8705 434.6912 374.2132 447.3486
## Aug 2012 415.0164 390.6141 439.4187 377.6963 452.3365
## Sep 2012 355.6492 334.5297 376.7687 323.3497 387.9487
## Oct 2012 333.8859 313.8658 353.9061 303.2677 364.5041
## Nov 2012 321.9079 302.4219 341.3938 292.1067 351.7091
## Dec 2012 361.8644 339.7551 383.9736 328.0512 395.6775
## Jan 2013 371.5229 348.6157 394.4301 336.4894 406.5564
## Feb 2013 328.4741 308.0393 348.9088 297.2219 359.7263
## Mar 2013 332.7291 311.8474 353.6108 300.7933 364.6649
## Apr 2013 311.8560 292.1151 331.5968 281.6650 342.0470
## May 2013 343.5168 321.5873 365.4462 309.9786 377.0550
## Jun 2013 384.7780 360.0100 409.5460 346.8986 422.6574
snaive(brick_train, h= 12)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 1991 Q2 15.43122 14.73297 16.12946 14.36335 16.49909
## 1991 Q3 15.17199 14.47375 15.87023 14.10412 16.23986
## 1991 Q4 14.79913 14.10089 15.49737 13.73126 15.86700
## 1992 Q1 13.82491 13.12667 14.52315 12.75704 14.89278
## 1992 Q2 15.43122 14.44375 16.41868 13.92102 16.94141
## 1992 Q3 15.17199 14.18452 16.15945 13.66179 16.68218
## 1992 Q4 14.79913 13.81167 15.78659 13.28894 16.30932
## 1993 Q1 13.82491 12.83745 14.81237 12.31472 15.33511
## 1993 Q2 15.43122 14.22183 16.64061 13.58161 17.28082
## 1993 Q3 15.17199 13.96260 16.38138 13.32238 17.02159
## 1993 Q4 14.79913 13.58974 16.00852 12.94953 16.64873
## 1994 Q1 13.82491 12.61552 15.03430 11.97531 15.67451
snaive(a10_train, h = 36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2005 3.284117 3.062268 3.505965 2.944828 3.623405
## Aug 2005 3.287069 3.065220 3.508918 2.947780 3.626357
## Sep 2005 3.357387 3.135538 3.579236 3.018098 3.696676
## Oct 2005 3.405230 3.183381 3.627079 3.065941 3.744519
## Nov 2005 3.485739 3.263890 3.707588 3.146451 3.825028
## Dec 2005 3.584657 3.362808 3.806506 3.245368 3.923946
## Jan 2006 3.727330 3.505481 3.949179 3.388041 4.066619
## Feb 2006 2.956087 2.734238 3.177936 2.616798 3.295375
## Mar 2006 3.092632 2.870783 3.314481 2.753343 3.431921
## Apr 2006 3.199894 2.978045 3.421743 2.860605 3.539183
## May 2006 3.232556 3.010707 3.454405 2.893267 3.571845
## Jun 2006 3.317933 3.096085 3.539782 2.978645 3.657222
## Jul 2006 3.284117 2.970375 3.597858 2.804290 3.763943
## Aug 2006 3.287069 2.973327 3.600811 2.807242 3.766895
## Sep 2006 3.357387 3.043645 3.671129 2.877560 3.837214
## Oct 2006 3.405230 3.091488 3.718972 2.925403 3.885057
## Nov 2006 3.485739 3.171998 3.799481 3.005913 3.965566
## Dec 2006 3.584657 3.270915 3.898399 3.104830 4.064484
## Jan 2007 3.727330 3.413588 4.041072 3.247503 4.207157
## Feb 2007 2.956087 2.642345 3.269828 2.476260 3.435913
## Mar 2007 3.092632 2.778890 3.406374 2.612805 3.572459
## Apr 2007 3.199894 2.886152 3.513636 2.720067 3.679721
## May 2007 3.232556 2.918814 3.546298 2.752729 3.712383
## Jun 2007 3.317933 3.004192 3.631675 2.838107 3.797760
## Jul 2007 3.284117 2.899863 3.668370 2.696451 3.871782
## Aug 2007 3.287069 2.902815 3.671322 2.699403 3.874734
## Sep 2007 3.357387 2.973133 3.741641 2.769722 3.945052
## Oct 2007 3.405230 3.020976 3.789484 2.817565 3.992895
## Nov 2007 3.485739 3.101486 3.869993 2.898074 4.073405
## Dec 2007 3.584657 3.200403 3.968911 2.996992 4.172323
## Jan 2008 3.727330 3.343076 4.111584 3.139665 4.314995
## Feb 2008 2.956087 2.571833 3.340340 2.368421 3.543752
## Mar 2008 3.092632 2.708378 3.476886 2.504967 3.680297
## Apr 2008 3.199894 2.815640 3.584148 2.612229 3.787559
## May 2008 3.232556 2.848302 3.616810 2.644891 3.820221
## Jun 2008 3.317933 2.933680 3.702187 2.730268 3.905599
snaive(ausbeer_train, h = 12)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2007 Q3 405 379.7918 430.2082 366.4474 443.5526
## 2007 Q4 491 465.7918 516.2082 452.4474 529.5526
## 2008 Q1 427 401.7918 452.2082 388.4474 465.5526
## 2008 Q2 383 357.7918 408.2082 344.4474 421.5526
## 2008 Q3 405 369.3502 440.6498 350.4784 459.5216
## 2008 Q4 491 455.3502 526.6498 436.4784 545.5216
## 2009 Q1 427 391.3502 462.6498 372.4784 481.5216
## 2009 Q2 383 347.3502 418.6498 328.4784 437.5216
## 2009 Q3 405 361.3381 448.6619 338.2250 471.7750
## 2009 Q4 491 447.3381 534.6619 424.2250 557.7750
## 2010 Q1 427 383.3381 470.6619 360.2250 493.7750
## 2010 Q2 383 339.3381 426.6619 316.2250 449.7750
snaive(dole_train, h= 36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Aug 1989 458767 386507.9 531026.1 348256.3 569277.7
## Sep 1989 441201 368941.9 513460.1 330690.3 551711.7
## Oct 1989 428578 356318.9 500837.1 318067.3 539088.7
## Nov 1989 419052 346792.9 491311.1 308541.3 529562.7
## Dec 1989 420900 348640.9 493159.1 310389.3 531410.7
## Jan 1990 448572 376312.9 520831.1 338061.3 559082.7
## Feb 1990 441100 368840.9 513359.1 330589.3 551610.7
## Mar 1990 409708 337448.9 481967.1 299197.3 520218.7
## Apr 1990 393323 321063.9 465582.1 282812.3 503833.7
## May 1990 391918 319658.9 464177.1 281407.3 502428.7
## Jun 1990 390001 317741.9 462260.1 279490.3 500511.7
## Jul 1990 383839 311579.9 456098.1 273328.3 494349.7
## Aug 1990 458767 356577.2 560956.8 302481.2 615052.8
## Sep 1990 441201 339011.2 543390.8 284915.2 597486.8
## Oct 1990 428578 326388.2 530767.8 272292.2 584863.8
## Nov 1990 419052 316862.2 521241.8 262766.2 575337.8
## Dec 1990 420900 318710.2 523089.8 264614.2 577185.8
## Jan 1991 448572 346382.2 550761.8 292286.2 604857.8
## Feb 1991 441100 338910.2 543289.8 284814.2 597385.8
## Mar 1991 409708 307518.2 511897.8 253422.2 565993.8
## Apr 1991 393323 291133.2 495512.8 237037.2 549608.8
## May 1991 391918 289728.2 494107.8 235632.2 548203.8
## Jun 1991 390001 287811.2 492190.8 233715.2 546286.8
## Jul 1991 383839 281649.2 486028.8 227553.2 540124.8
## Aug 1991 458767 333610.6 583923.4 267356.8 650177.2
## Sep 1991 441201 316044.6 566357.4 249790.8 632611.2
## Oct 1991 428578 303421.6 553734.4 237167.8 619988.2
## Nov 1991 419052 293895.6 544208.4 227641.8 610462.2
## Dec 1991 420900 295743.6 546056.4 229489.8 612310.2
## Jan 1992 448572 323415.6 573728.4 257161.8 639982.2
## Feb 1992 441100 315943.6 566256.4 249689.8 632510.2
## Mar 1992 409708 284551.6 534864.4 218297.8 601118.2
## Apr 1992 393323 268166.6 518479.4 201912.8 584733.2
## May 1992 391918 266761.6 517074.4 200507.8 583328.2
## Jun 1992 390001 264844.6 515157.4 198590.8 581411.2
## Jul 1992 383839 258682.6 508995.4 192428.8 575249.2
snaive(h02_train, h = 36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Aug 2005 0.9948643 0.9029552 1.0867735 0.8543014 1.1354272
## Sep 2005 1.1344320 1.0425228 1.2263412 0.9938691 1.2749949
## Oct 2005 1.1810110 1.0891018 1.2729202 1.0404481 1.3215739
## Nov 2005 1.2160370 1.1241278 1.3079462 1.0754741 1.3565999
## Dec 2005 1.2572380 1.1653288 1.3491472 1.1166751 1.3978009
## Jan 2006 1.1706900 1.0787808 1.2625992 1.0301271 1.3112529
## Feb 2006 0.5976390 0.5057298 0.6895482 0.4570761 0.7382019
## Mar 2006 0.6525900 0.5606808 0.7444992 0.5120271 0.7931529
## Apr 2006 0.6705050 0.5785958 0.7624142 0.5299421 0.8110679
## May 2006 0.6952480 0.6033388 0.7871572 0.5546851 0.8358109
## Jun 2006 0.8422630 0.7503538 0.9341722 0.7017001 0.9828259
## Jul 2006 0.8743360 0.7824268 0.9662452 0.7337731 1.0148989
## Aug 2006 0.9948643 0.8648852 1.1248435 0.7960783 1.1936503
## Sep 2006 1.1344320 1.0044528 1.2644112 0.9356460 1.3332180
## Oct 2006 1.1810110 1.0510318 1.3109902 0.9822250 1.3797970
## Nov 2006 1.2160370 1.0860578 1.3460162 1.0172510 1.4148230
## Dec 2006 1.2572380 1.1272588 1.3872172 1.0584520 1.4560240
## Jan 2007 1.1706900 1.0407108 1.3006692 0.9719040 1.3694760
## Feb 2007 0.5976390 0.4676598 0.7276182 0.3988530 0.7964250
## Mar 2007 0.6525900 0.5226108 0.7825692 0.4538040 0.8513760
## Apr 2007 0.6705050 0.5405258 0.8004842 0.4717190 0.8692910
## May 2007 0.6952480 0.5652688 0.8252272 0.4964620 0.8940340
## Jun 2007 0.8422630 0.7122838 0.9722422 0.6434770 1.0410490
## Jul 2007 0.8743360 0.7443568 1.0043152 0.6755500 1.0731220
## Aug 2007 0.9948643 0.8356730 1.1540556 0.7514022 1.2383264
## Sep 2007 1.1344320 0.9752407 1.2936233 0.8909699 1.3778941
## Oct 2007 1.1810110 1.0218197 1.3402023 0.9375489 1.4244731
## Nov 2007 1.2160370 1.0568457 1.3752283 0.9725749 1.4594991
## Dec 2007 1.2572380 1.0980467 1.4164293 1.0137759 1.5007001
## Jan 2008 1.1706900 1.0114987 1.3298813 0.9272279 1.4141521
## Feb 2008 0.5976390 0.4384477 0.7568303 0.3541769 0.8411011
## Mar 2008 0.6525900 0.4933987 0.8117813 0.4091279 0.8960521
## Apr 2008 0.6705050 0.5113137 0.8296963 0.4270429 0.9139671
## May 2008 0.6952480 0.5360567 0.8544393 0.4517859 0.9387101
## Jun 2008 0.8422630 0.6830717 1.0014543 0.5988009 1.0857251
## Jul 2008 0.8743360 0.7151447 1.0335273 0.6308739 1.1177981
snaive(usmelec_train, h= 36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2010 372.542 357.6945 387.3895 349.8348 395.2492
## Aug 2010 381.221 366.3735 396.0685 358.5138 403.9282
## Sep 2010 327.401 312.5535 342.2485 304.6938 350.1082
## Oct 2010 307.040 292.1925 321.8875 284.3328 329.7472
## Nov 2010 296.635 281.7875 311.4825 273.9278 319.3422
## Dec 2010 350.507 335.6595 365.3545 327.7998 373.2142
## Jan 2011 360.957 346.1095 375.8045 338.2498 383.6642
## Feb 2011 319.735 304.8875 334.5825 297.0278 342.4422
## Mar 2011 312.168 297.3205 327.0155 289.4608 334.8752
## Apr 2011 287.800 272.9525 302.6475 265.0928 310.5072
## May 2011 327.936 313.0885 342.7835 305.2288 350.6432
## Jun 2011 375.759 360.9115 390.6065 353.0518 398.4662
## Jul 2011 372.542 351.5445 393.5395 340.4291 404.6549
## Aug 2011 381.221 360.2235 402.2185 349.1081 413.3339
## Sep 2011 327.401 306.4035 348.3985 295.2881 359.5139
## Oct 2011 307.040 286.0425 328.0375 274.9271 339.1529
## Nov 2011 296.635 275.6375 317.6325 264.5221 328.7479
## Dec 2011 350.507 329.5095 371.5045 318.3941 382.6199
## Jan 2012 360.957 339.9595 381.9545 328.8441 393.0699
## Feb 2012 319.735 298.7375 340.7325 287.6221 351.8479
## Mar 2012 312.168 291.1705 333.1655 280.0551 344.2809
## Apr 2012 287.800 266.8025 308.7975 255.6871 319.9129
## May 2012 327.936 306.9385 348.9335 295.8231 360.0489
## Jun 2012 375.759 354.7615 396.7565 343.6461 407.8719
## Jul 2012 372.542 346.8255 398.2585 333.2119 411.8721
## Aug 2012 381.221 355.5045 406.9375 341.8909 420.5511
## Sep 2012 327.401 301.6845 353.1175 288.0709 366.7311
## Oct 2012 307.040 281.3235 332.7565 267.7099 346.3701
## Nov 2012 296.635 270.9185 322.3515 257.3049 335.9651
## Dec 2012 350.507 324.7905 376.2235 311.1769 389.8371
## Jan 2013 360.957 335.2405 386.6735 321.6269 400.2871
## Feb 2013 319.735 294.0185 345.4515 280.4049 359.0651
## Mar 2013 312.168 286.4515 337.8845 272.8379 351.4981
## Apr 2013 287.800 262.0835 313.5165 248.4699 327.1301
## May 2013 327.936 302.2195 353.6525 288.6059 367.2661
## Jun 2013 375.759 350.0425 401.4755 336.4289 415.0891
stlf(brick_train, h= 12)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 1991 Q2 14.53531 14.24229 14.82832 14.08718 14.98344
## 1991 Q3 14.60765 14.19326 15.02205 13.97390 15.24141
## 1991 Q4 14.29050 13.78295 14.79804 13.51427 15.06672
## 1992 Q1 13.82496 13.23886 14.41106 12.92860 14.72132
## 1992 Q2 14.53531 13.87999 15.19062 13.53309 15.53753
## 1992 Q3 14.60765 13.88975 15.32556 13.50971 15.70560
## 1992 Q4 14.29050 13.51502 15.06597 13.10451 15.47648
## 1993 Q1 13.82496 12.99589 14.65403 12.55701 15.09292
## 1993 Q2 14.53531 13.65589 15.41472 13.19036 15.88026
## 1993 Q3 14.60765 13.68061 15.53470 13.18986 16.02545
## 1993 Q4 14.29050 13.31814 15.26285 12.80341 15.77758
## 1994 Q1 13.82496 12.80931 14.84062 12.27165 15.37827
stlf(a10_train, h = 36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2005 3.415153 3.340177 3.490128 3.300488 3.529818
## Aug 2005 3.395244 3.318998 3.471489 3.278637 3.511851
## Sep 2005 3.418283 3.340787 3.495778 3.299763 3.536802
## Oct 2005 3.533661 3.454933 3.612388 3.413257 3.654064
## Nov 2005 3.547334 3.467392 3.627276 3.425073 3.669594
## Dec 2005 3.704706 3.623567 3.785845 3.580614 3.828797
## Jan 2006 3.855858 3.773538 3.938179 3.729960 3.981757
## Feb 2006 3.139824 3.056338 3.223310 3.012143 3.267505
## Mar 2006 3.315041 3.230404 3.399678 3.185600 3.444482
## Apr 2006 3.324589 3.238815 3.410363 3.193409 3.455768
## May 2006 3.452448 3.365552 3.539345 3.319551 3.585345
## Jun 2006 3.435097 3.347091 3.523104 3.300503 3.569692
## Jul 2006 3.564846 3.475742 3.653950 3.428574 3.701118
## Aug 2006 3.544937 3.454748 3.635126 3.407005 3.682869
## Sep 2006 3.567976 3.476714 3.659238 3.428402 3.707549
## Oct 2006 3.683354 3.591030 3.775678 3.542157 3.824551
## Nov 2006 3.697027 3.603652 3.790402 3.554222 3.839832
## Dec 2006 3.854399 3.759984 3.948814 3.710003 3.998795
## Jan 2007 4.005552 3.910106 4.100997 3.859580 4.151523
## Feb 2007 3.289517 3.193051 3.385983 3.141985 3.437049
## Mar 2007 3.464734 3.367258 3.562211 3.315657 3.613811
## Apr 2007 3.474282 3.375804 3.572760 3.323673 3.624891
## May 2007 3.602141 3.502671 3.701611 3.450015 3.754268
## Jun 2007 3.584791 3.484337 3.685244 3.431160 3.738421
## Jul 2007 3.714539 3.613111 3.815968 3.559418 3.869661
## Aug 2007 3.694630 3.592235 3.797025 3.538030 3.851230
## Sep 2007 3.717669 3.614315 3.821023 3.559602 3.875735
## Oct 2007 3.833047 3.728742 3.937352 3.673526 3.992568
## Nov 2007 3.846720 3.741472 3.951968 3.685756 4.007684
## Dec 2007 4.004092 3.897908 4.110276 3.841697 4.166487
## Jan 2008 4.155245 4.048131 4.262358 3.991429 4.319060
## Feb 2008 3.439210 3.331175 3.547245 3.273985 3.604435
## Mar 2008 3.614427 3.505478 3.723377 3.447803 3.781052
## Apr 2008 3.623975 3.514117 3.733833 3.455961 3.791989
## May 2008 3.751834 3.641075 3.862594 3.582442 3.921227
## Jun 2008 3.734484 3.622828 3.846139 3.563721 3.905246
stlf(ausbeer_train, h = 12)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2007 Q3 406.1670 388.7321 423.6019 379.5027 432.8313
## 2007 Q4 483.2273 464.9265 501.5280 455.2386 511.2159
## 2008 Q1 426.0710 406.7446 445.3974 396.5138 455.6281
## 2008 Q2 385.4522 364.9441 405.9603 354.0877 416.8166
## 2008 Q3 405.2659 383.4262 427.1056 371.8649 438.6668
## 2008 Q4 482.3262 459.0127 505.6396 446.6714 517.9809
## 2009 Q1 425.1699 400.2492 450.0906 387.0569 463.2829
## 2009 Q2 384.5511 357.8979 411.2042 343.7886 425.3135
## 2009 Q3 404.3648 375.8623 432.8673 360.7740 447.9555
## 2009 Q4 481.4251 450.9640 511.8861 434.8389 528.0112
## 2010 Q1 424.2688 391.7468 456.7908 374.5307 474.0069
## 2010 Q2 383.6500 348.9709 418.3290 330.6129 436.6870
stlf(dole_train, h= 36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Aug 1989 374079.4 366021.1 382137.7 361755.4 386403.5
## Sep 1989 365745.7 352329.3 379162.1 345227.1 386264.3
## Oct 1989 354372.2 335660.9 373083.5 325755.8 382988.6
## Nov 1989 348635.7 324621.6 372649.8 311909.2 385362.2
## Dec 1989 372192.6 342887.8 401497.3 327374.7 417010.4
## Jan 1990 416820.5 382266.7 451374.3 363975.1 469665.9
## Feb 1990 416350.0 376614.2 456085.8 355579.3 477120.7
## Mar 1990 390535.4 345703.6 435367.1 321971.1 459099.6
## Apr 1990 378456.7 328628.6 428284.8 302251.2 454662.1
## May 1990 376417.3 321701.6 431132.9 292736.8 460097.7
## Jun 1990 373115.1 313626.0 432604.2 282134.4 464095.8
## Jul 1990 370885.8 306740.3 435031.3 272783.7 468987.9
## Aug 1990 362840.5 294156.3 431524.8 257797.1 467884.0
## Sep 1990 355994.5 282888.4 429100.5 244188.5 467800.5
## Oct 1990 345911.7 268498.9 423324.5 227519.0 464304.3
## Nov 1990 341295.1 259687.8 422902.4 216487.5 466102.6
## Dec 1990 365823.6 280130.9 451516.3 234767.9 496879.3
## Jan 1991 411294.6 321621.8 500967.3 274151.9 548437.2
## Feb 1991 411555.6 318004.2 505106.9 268481.2 554629.9
## Mar 1991 386375.5 289043.2 483707.9 237518.6 535232.5
## Apr 1991 374847.5 273827.6 475867.3 220351.0 529344.0
## May 1991 373285.8 268667.9 477903.6 213286.6 533285.0
## Jun 1991 370398.1 262267.8 478528.5 205027.1 535769.2
## Jul 1991 368528.5 256967.4 480089.5 197910.6 539146.4
## Aug 1991 360795.2 245881.4 475709.0 185049.8 536540.7
## Sep 1991 354219.9 236027.8 472412.0 173460.7 534979.1
## Oct 1991 344372.0 222972.7 465771.4 158707.7 530036.3
## Nov 1991 339959.2 215420.3 464498.1 149493.4 530425.0
## Dec 1991 364664.5 237050.8 492278.3 169496.1 559833.0
## Jan 1992 410288.9 279662.0 540915.9 210512.2 610065.7
## Feb 1992 410683.0 277101.7 544264.4 206388.0 614978.0
## Mar 1992 385618.5 249139.1 522097.9 176891.2 594345.8
## Apr 1992 374190.6 234866.8 513514.5 161113.2 587268.1
## May 1992 372715.9 230598.9 514832.9 155366.8 590065.0
## Jun 1992 369903.7 225042.7 514764.7 148357.9 591449.5
## Jul 1992 368099.5 220541.4 515657.5 142428.9 593770.1
stlf(h02_train, h = 36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Aug 2005 0.9280346 0.8754631 0.9806060 0.8476334 1.0084357
## Sep 2005 0.9985831 0.9427200 1.0544463 0.9131478 1.0840184
## Oct 2005 1.0623864 1.0034134 1.1213595 0.9721949 1.1525779
## Nov 2005 1.0668152 1.0048866 1.1287437 0.9721036 1.1615268
## Dec 2005 1.1502578 1.0855069 1.2150087 1.0512299 1.2492858
## Jan 2006 1.1170493 1.0495927 1.1845060 1.0138833 1.2202154
## Feb 2006 0.6294279 0.5593684 0.6994873 0.5222812 0.7365746
## Mar 2006 0.7108066 0.6382362 0.7833769 0.5998198 0.8217933
## Apr 2006 0.7146153 0.6396168 0.7896138 0.5999150 0.8293156
## May 2006 0.7741045 0.6967528 0.8514563 0.6558052 0.8924039
## Jun 2006 0.8280947 0.7484580 0.9077315 0.7063008 0.9498887
## Jul 2006 0.9443360 0.8624768 1.0261953 0.8191431 1.0695290
## Aug 2006 0.9640223 0.8799982 1.0480465 0.8355185 1.0925262
## Sep 2006 1.0345709 0.9484351 1.1207067 0.9028376 1.1663043
## Oct 2006 1.0983742 1.0101762 1.1865723 0.9634870 1.2332615
## Nov 2006 1.1028029 1.0125887 1.1930172 0.9648321 1.2407737
## Dec 2006 1.1862456 1.0940581 1.2784331 1.0452570 1.3272342
## Jan 2007 1.1530371 1.0589167 1.2471575 1.0090924 1.2969818
## Feb 2007 0.6654157 0.5694003 0.7614311 0.5185728 0.8122586
## Mar 2007 0.7467943 0.6489195 0.8446692 0.5971078 0.8964809
## Apr 2007 0.7506031 0.6509026 0.8503036 0.5981243 0.9030819
## May 2007 0.8100923 0.7085979 0.9115867 0.6548701 0.9653146
## Jun 2007 0.8640825 0.7608245 0.9673406 0.7061630 1.0220021
## Jul 2007 0.9803238 0.8753308 1.0853169 0.8197508 1.1408968
## Aug 2007 1.0000101 0.8933094 1.1067109 0.8368254 1.1631948
## Sep 2007 1.0705587 0.9621762 1.1789412 0.9048020 1.2363154
## Oct 2007 1.1343620 1.0243226 1.2444015 0.9660712 1.3026528
## Nov 2007 1.1387907 1.0271180 1.2504634 0.9680021 1.3095794
## Dec 2007 1.2222334 1.1089501 1.3355167 1.0489815 1.3954853
## Jan 2008 1.1890249 1.0741527 1.3038971 1.0133430 1.3647068
## Feb 2008 0.7014035 0.5849632 0.8178437 0.5233234 0.8794835
## Mar 2008 0.7827821 0.6647938 0.9007705 0.6023345 0.9632298
## Apr 2008 0.7865909 0.6670737 0.9061081 0.6038050 0.9693767
## May 2008 0.8460801 0.7250525 0.9671077 0.6609843 1.0311759
## Jun 2008 0.9000703 0.7775501 1.0225905 0.7126918 1.0874488
## Jul 2008 1.0163116 0.8923160 1.1403073 0.8266766 1.2059466
stlf(usmelec_train, h= 36)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2010 400.5899 390.0856 411.0941 384.5250 416.6548
## Aug 2010 403.9813 392.5917 415.3709 386.5624 421.4002
## Sep 2010 347.7292 335.5157 359.9426 329.0503 366.4080
## Oct 2010 327.0296 314.0421 340.0171 307.1670 346.8922
## Nov 2010 315.6826 301.9625 329.4028 294.6995 336.6658
## Dec 2010 353.0671 338.6493 367.4849 331.0170 375.1172
## Jan 2011 361.6913 346.6061 376.7766 338.6204 384.7622
## Feb 2011 323.6885 307.9622 339.4149 299.6371 347.7399
## Mar 2011 327.5662 311.2220 343.9105 302.5699 352.5626
## Apr 2011 306.9165 289.9750 323.8579 281.0068 332.8262
## May 2011 335.0546 317.5346 352.5747 308.2600 361.8493
## Jun 2011 373.3414 355.2594 391.4233 345.6874 400.9953
## Jul 2011 406.0252 387.3967 424.6537 377.5353 434.5151
## Aug 2011 409.4166 390.2555 428.5778 380.1122 438.7211
## Sep 2011 353.1645 333.4835 372.8455 323.0651 383.2639
## Oct 2011 332.4649 312.2760 352.6539 301.5886 363.3413
## Nov 2011 321.1180 300.4320 341.8040 289.4815 352.7545
## Dec 2011 358.5024 337.3296 379.6753 326.1213 390.8835
## Jan 2012 367.1266 345.4764 388.7769 334.0155 400.2378
## Feb 2012 329.1239 307.0051 351.2426 295.2962 362.9516
## Mar 2012 333.0016 310.4227 355.5805 298.4701 367.5330
## Apr 2012 312.3518 289.3205 335.3831 277.1285 347.5751
## May 2012 340.4900 317.0137 363.9663 304.5861 376.3939
## Jun 2012 378.7767 354.8624 402.6910 342.2029 415.3505
## Jul 2012 411.4605 387.1147 435.8063 374.2268 448.6942
## Aug 2012 414.8520 390.0809 439.6230 376.9679 452.7360
## Sep 2012 358.5998 333.4094 383.7902 320.0744 397.1252
## Oct 2012 337.9003 312.2961 363.5044 298.7421 377.0584
## Nov 2012 326.5533 300.5408 352.5658 286.7706 366.3360
## Dec 2012 363.9378 337.5220 390.3535 323.5383 404.3372
## Jan 2013 372.5620 345.7478 399.3762 331.5532 413.5708
## Feb 2013 334.5592 307.3512 361.7672 292.9482 376.1702
## Mar 2013 338.4369 310.8396 366.0342 296.2305 380.6433
## Apr 2013 317.7871 289.8048 345.7695 274.9919 360.5824
## May 2013 345.9253 317.5620 374.2886 302.5474 389.3032
## Jun 2013 384.2120 355.4717 412.9524 340.2575 428.1666
ets(bicoal) %>% forecast() %>% autoplot
ets(chicken) %>% forecast() %>% autoplot
ets(dole) %>% forecast() %>% autoplot
ets(usdeaths) %>% forecast() %>% autoplot
ets(lynx) %>% forecast() %>% autoplot
ets(ibmclose) %>% forecast() %>% autoplot
ets(eggs) %>% forecast() %>% autoplot
15)
ets(usdeaths,model = "MAM") %>% forecast(h=1)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 1979 8233.107 7883.699 8582.515 7698.734 8767.481
hw(usdeaths, seasonal = 'multiplicative', h=1)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 1979 8217.64 7845.352 8589.928 7648.274 8787.005
When H is 2, a^2(h - 1) is equal to the forecast variance, sigma^2.
ets(pigs, model = "ANN") %>% forecast(h = 1)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Sep 1995 98815.93 85604.96 112026.9 78611.49 119020.4
pigs_ets <- ets(pigs, model = "ANN") %>% forecast(h = 1)
c(pigs_ets$lower[2], pigs_ets$upper[2])
## [1] 78611.49 119020.38
Yes, three series are white noise as the ACF are inside the critical value. The scale of the critical value varies due to each residuals’ variance.
autoplot(ibmclose)
acf(ibmclose)
pacf(ibmclose)
Box.test(usnetelec, lag = 10, type = "Ljung-Box")
##
## Box-Ljung test
##
## data: usnetelec
## X-squared = 329.22, df = 10, p-value < 2.2e-16
usnetelec %>% ur.kpss() -> ur_lec
usnetelec %>% diff() %>% ur.kpss() -> ur_diff_lec
Box.test(usgdp, lag =10, type = 'Ljung-Box')
##
## Box-Ljung test
##
## data: usgdp
## X-squared = 2078.3, df = 10, p-value < 2.2e-16
usgdp %>% ur.kpss() -> ur_gdp
usgdp %>% diff() %>% ur.kpss() -> ur_diff_gdp
Box.test(mcopper, lag =10, type = 'Ljung-Box')
##
## Box-Ljung test
##
## data: mcopper
## X-squared = 3819, df = 10, p-value < 2.2e-16
mcopper %>% ur.kpss() -> ur_cop
mcopper %>% diff() %>% ur.kpss() -> ur_diff_cop
Box.test(enplanements, lag =10, type = 'Ljung-Box')
##
## Box-Ljung test
##
## data: enplanements
## X-squared = 2122.7, df = 10, p-value < 2.2e-16
enplanements %>% ur.kpss() -> ur_pl
enplanements %>% diff() %>% ur.kpss() -> ur_diff_pl
Box.test(visitors, lag =10, type = 'Ljung-Box')
##
## Box-Ljung test
##
## data: visitors
## X-squared = 1522.6, df = 10, p-value < 2.2e-16
visitors %>% ur.kpss() -> ur_vis
visitors %>% diff() %>% ur.kpss() -> ur_diff_vis
summary(ur_lec)
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 3 lags.
##
## Value of test-statistic is: 1.464
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
summary(ur_diff_lec)
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 3 lags.
##
## Value of test-statistic is: 0.1585
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
summary(ur_gdp)
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 4 lags.
##
## Value of test-statistic is: 4.6556
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
summary(ur_diff_gdp)
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 4 lags.
##
## Value of test-statistic is: 1.7909
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
summary(ur_cop)
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 6 lags.
##
## Value of test-statistic is: 5.01
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
summary(ur_diff_cop)
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 6 lags.
##
## Value of test-statistic is: 0.1843
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
summary(ur_pl)
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 5 lags.
##
## Value of test-statistic is: 4.4423
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
summary(ur_diff_pl)
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 5 lags.
##
## Value of test-statistic is: 0.0086
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
summary(ur_vis)
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 4 lags.
##
## Value of test-statistic is: 4.6025
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
summary(ur_diff_vis)
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 4 lags.
##
## Value of test-statistic is: 0.0191
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
(1-B)^5*yhat
Data is stationary.
ggtsdisplay(myts)
myts %>% BoxCox(BoxCox.lambda(myts)) %>% diff(1) %>% diff(12) %>%
ggtsdisplay()
myts %>% BoxCox(BoxCox.lambda(myts))%>%
diff(1) %>% diff(12) %>%
ur.kpss() %>% summary()
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 5 lags.
##
## Value of test-statistic is: 0.0138
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
arima_func <- function(phi){
y = ts(numeric(100))
e <- rnorm(100)
for(i in 2:100)
y[i] <- phi*y[i-1] + e[i]
return(y)
}
dl <- list()
i <- 0
phi_range <- c(0.0000001, 0.0001, 0.1) * 6
for (phi in phi_range){
i <- i + 1
dl[[i]] <- arima_func(phi)
}
gd <- do.call(cbind, dl)
colnames(gd) <- phi_range
autoplot(gd, series = "") + ylab("")
## Warning: Ignoring unknown parameters: series
par(mfrow=c(1,3))
acf(gd[,1])
acf(gd[,2])
acf(gd[,3])
ma_func <- function(theta){
y <- ts(numeric(100))
e <- rnorm(100, sd=1)
e[1] <- 0
for(i in 2:100)
y[i] <- theta*e[i-1] + e[i]
return(y)}
dl2 <- list()
i <- 0
theta_range <- c(0.0000001, 0.0001, 0.1) * 6
for (theta in theta_range){
i <- i + 1
dl2[[i]] <- ma_func(theta)}
gd2 <- do.call(cbind, dl2)
colnames(gd2) <- theta_range
autoplot(gd2)
df1 <- ts(numeric(100))
e <- rnorm(100, sd=1)
for(i in 2:100)
df1[i] <- 0.6*df1[i-1] + 0.6*e[i-1] + e[i]
autoplot(df1)
df2 <- ts(numeric(100))
e <- rnorm(100, sd=1)
for(i in 3:100)
df2[i] <- -0.8*df2[i-1] + 0.3*df2[i-2] + e[i]
autoplot(df2)
ggtsdisplay(wmurders)
wmurders %>% diff(1) %>% diff(1) %>% ggtsdisplay()
wmurders %>% diff(1) %>% diff(1) %>% ur.kpss() %>% summary()
##
## #######################
## # KPSS Unit Root Test #
## #######################
##
## Test is of type: mu with 3 lags.
##
## Value of test-statistic is: 0.0458
##
## Critical value for a significance level of:
## 10pct 5pct 2.5pct 1pct
## critical values 0.347 0.463 0.574 0.739
Arima(wmurders, order=c(1,2,1))
## Series: wmurders
## ARIMA(1,2,1)
##
## Coefficients:
## ar1 ma1
## -0.2434 -0.8261
## s.e. 0.1553 0.1143
##
## sigma^2 estimated as 0.04632: log likelihood=6.44
## AIC=-6.88 AICc=-6.39 BIC=-0.97
Arima(wmurders, order=c(1,2,1)) %>% checkresiduals()
##
## Ljung-Box test
##
## data: Residuals from ARIMA(1,2,1)
## Q* = 12.419, df = 8, p-value = 0.1335
##
## Model df: 2. Total lags used: 10
Arima(wmurders, order=c(1,2,1)) %>% forecast(h = 3) %>% autoplot()
auto.arima(wmurders, seasonal=F, stepwise=F, approximation=F)
## Series: wmurders
## ARIMA(0,2,3)
##
## Coefficients:
## ma1 ma2 ma3
## -1.0154 0.4324 -0.3217
## s.e. 0.1282 0.2278 0.1737
##
## sigma^2 estimated as 0.04475: log likelihood=7.77
## AIC=-7.54 AICc=-6.7 BIC=0.35
auto.arima(wmurders, seasonal=F, stepwise=F, approximation=F) %>%
forecast(h = 3) %>% autoplot()
autoplot(austa)
forecast(auto.arima(austa), h = 10) %>% autoplot()
auto.arima(austa) %>% checkresiduals()
##
## Ljung-Box test
##
## data: Residuals from ARIMA(0,1,1) with drift
## Q* = 2.297, df = 5, p-value = 0.8067
##
## Model df: 2. Total lags used: 7
forecast(Arima(austa, order = c(0, 1, 1)), h = 10) %>% autoplot()
forecast(Arima(austa, order = c(0, 1, 0)), h = 10) %>% autoplot()
farima_213 <- forecast(Arima(austa, order = c(2, 1, 3)
, include.drift = TRUE),h = 10)
autoplot(farima_213)
dausta <- farima_213$model$coef[6]
ndausta <- farima_213$mean - dausta*seq_len(10)
autoplot(farima_213) +
autolayer(ndausta)
forecast(Arima(austa, order = c(0, 0, 1), include.constant = TRUE),h = 10) %>%
autoplot()
forecast(Arima(austa, order = c(0, 0, 0), include.constant = TRUE),h = 10) %>%
autoplot()
forecast(Arima(austa, order = c(0, 2, 1)),h = 10) %>%
autoplot()
autoplot(usgdp)
autoplot(BoxCox(usgdp, BoxCox.lambda(usgdp)))
auto.arima(usgdp,lambda = BoxCox.lambda(usgdp)) %>% autoplot()
ndiffs(BoxCox(usgdp, BoxCox.lambda(usgdp)))
## [1] 1
ggtsdisplay(diff(BoxCox(usgdp, BoxCox.lambda(usgdp))))
Arima(usgdp, lambda = BoxCox.lambda(usgdp), order = c(1, 1, 0))
## Series: usgdp
## ARIMA(1,1,0)
## Box Cox transformation: lambda= 0.366352
##
## Coefficients:
## ar1
## 0.6326
## s.e. 0.0504
##
## sigma^2 estimated as 0.04384: log likelihood=34.39
## AIC=-64.78 AICc=-64.73 BIC=-57.85
Arima(usgdp, lambda = BoxCox.lambda(usgdp), order = c(1, 1, 0))$fitted %>%
autoplot(series = "fit") +
autolayer(usgdp, series = "Original")
Arima(usgdp, lambda = BoxCox.lambda(usgdp), order = c(1, 1, 0),include.drift = TRUE)
## Series: usgdp
## ARIMA(1,1,0) with drift
## Box Cox transformation: lambda= 0.366352
##
## Coefficients:
## ar1 drift
## 0.3180 0.1831
## s.e. 0.0619 0.0179
##
## sigma^2 estimated as 0.03555: log likelihood=59.83
## AIC=-113.66 AICc=-113.56 BIC=-103.27
Arima(usgdp, lambda = BoxCox.lambda(usgdp), order = c(1, 1, 0),include.drift = TRUE)$fitted %>% autoplot(series = "fit") +
autolayer(usgdp, series = "Original")
auto.arima(usgdp,lambda = BoxCox.lambda(usgdp)) %>% accuracy()
## ME RMSE MAE MPE MAPE MASE
## Training set 1.195275 39.2224 29.29521 -0.01363259 0.6863491 0.1655687
## ACF1
## Training set -0.03824844
Arima(usgdp, lambda = BoxCox.lambda(usgdp), order = c(1, 1, 0)) %>%
accuracy()
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 15.45449 45.49569 35.08393 0.3101283 0.7815664 0.198285 -0.3381619
Arima(usgdp, lambda = BoxCox.lambda(usgdp), order = c(1, 1, 0),include.drift = TRUE) %>% accuracy()
## ME RMSE MAE MPE MAPE MASE
## Training set 1.315796 39.90012 29.5802 -0.01678591 0.6834509 0.1671794
## ACF1
## Training set -0.08544569
auto.arima(usgdp,lambda = BoxCox.lambda(usgdp)) %>% checkresiduals()
##
## Ljung-Box test
##
## data: Residuals from ARIMA(2,1,0) with drift
## Q* = 6.5772, df = 5, p-value = 0.254
##
## Model df: 3. Total lags used: 8
auto.arima(usgdp,lambda = BoxCox.lambda(usgdp)) %>% forecast() %>%
autoplot()
forecast(ets(usgdp)) %>% autoplot()
autoplot(austourists)
ggAcf(austourists)
ggPacf(austourists)
ggtsdisplay(diff(austourists, lag = 4))
ggtsdisplay(diff(diff(austourists, lag = 4)))
forecast(auto.arima(austourists)) %>% autoplot()
forecast(auto.arima(austourists)) %>% accuracy()
## ME RMSE MAE MPE MAPE MASE
## Training set 0.02200144 2.149384 1.620917 -0.7072593 4.388288 0.5378929
## ACF1
## Training set -0.06393238
forecast(auto.arima(austourists)) %>% checkresiduals()
##
## Ljung-Box test
##
## data: Residuals from ARIMA(1,0,0)(1,1,0)[4] with drift
## Q* = 4.0937, df = 5, p-value = 0.536
##
## Model df: 3. Total lags used: 8
forecast(auto.arima(austourists))$model
## Series: austourists
## ARIMA(1,0,0)(1,1,0)[4] with drift
##
## Coefficients:
## ar1 sar1 drift
## 0.4705 -0.5305 0.5489
## s.e. 0.1154 0.1122 0.0864
##
## sigma^2 estimated as 5.15: log likelihood=-142.48
## AIC=292.97 AICc=293.65 BIC=301.6
ma(usmelec, order = 12, centre = TRUE) %>%
autoplot(series = "2X12")+
autolayer(usmelec, series = "Original")
BoxCox.lambda(usmelec)
## [1] -0.5738331
ndiffs(usmelec)
## [1] 1
nsdiffs(usmelec)
## [1] 1
ggtsdisplay(diff(BoxCox(usmelec, BoxCox.lambda(usmelec)),lag = 12))
ggtsdisplay(diff(diff(BoxCox(usmelec, BoxCox.lambda(usmelec)),lag = 12)))
Arima(usmelec,lambda = BoxCox.lambda(usmelec)
,order = c(0, 1, 2)
,seasonal = c(0, 1, 1))$aic
## [1] -5081.506
Arima(usmelec,lambda =BoxCox.lambda(usmelec)
,order = c(0, 1, 3)
,seasonal = c(0, 1, 1))$aic
## [1] -5080.441
Arima(usmelec,lambda = BoxCox.lambda(usmelec)
,order = c(0, 1, 2)
,seasonal = c(0, 1, 1)) %>% checkresiduals()
##
## Ljung-Box test
##
## data: Residuals from ARIMA(0,1,2)(0,1,1)[12]
## Q* = 32.525, df = 21, p-value = 0.05176
##
## Model df: 3. Total lags used: 24
auto.arima(usmelec,lambda = BoxCox.lambda(usmelec)) %>% checkresiduals()
##
## Ljung-Box test
##
## data: Residuals from ARIMA(1,1,3)(2,1,1)[12]
## Q* = 25.995, df = 17, p-value = 0.07454
##
## Model df: 7. Total lags used: 24
Arima(usmelec, order=c(2,1,3), seasonal=c(2,1,3)
, lambda=BoxCox.lambda(usmelec)) %>%
forecast(h = 12*15) %>% autoplot()
tsdisplay(BoxCox(mcopper, lambda = BoxCox.lambda(mcopper)))
auto.arima(mcopper, trace = TRUE, ic ="aic", lambda = BoxCox.lambda(mcopper))
##
## Fitting models using approximations to speed things up...
##
## ARIMA(2,1,2)(1,0,1)[12] with drift : -66.32021
## ARIMA(0,1,0) with drift : -13.82248
## ARIMA(1,1,0)(1,0,0)[12] with drift : -62.06849
## ARIMA(0,1,1)(0,0,1)[12] with drift : -82.25982
## ARIMA(0,1,0) : -12.82906
## ARIMA(0,1,1) with drift : -83.13952
## ARIMA(0,1,1)(1,0,0)[12] with drift : -73.91207
## ARIMA(0,1,1)(1,0,1)[12] with drift : -71.92506
## ARIMA(1,1,1) with drift : -80.30584
## ARIMA(0,1,2) with drift : -81.16609
## ARIMA(1,1,0) with drift : -71.41152
## ARIMA(1,1,2) with drift : -78.27629
## ARIMA(0,1,1) : -83.33279
## ARIMA(0,1,1)(1,0,0)[12] : -74.05872
## ARIMA(0,1,1)(0,0,1)[12] : -82.603
## ARIMA(0,1,1)(1,0,1)[12] : -72.07316
## ARIMA(1,1,1) : -80.55931
## ARIMA(0,1,2) : -81.33929
## ARIMA(1,1,0) : -71.94456
## ARIMA(1,1,2) : -80.62448
##
## Now re-fitting the best model(s) without approximations...
##
## ARIMA(0,1,1) : -86.0969
##
## Best model: ARIMA(0,1,1)
## Series: mcopper
## ARIMA(0,1,1)
## Box Cox transformation: lambda= 0.1919047
##
## Coefficients:
## ma1
## 0.3720
## s.e. 0.0388
##
## sigma^2 estimated as 0.04997: log likelihood=45.05
## AIC=-86.1 AICc=-86.08 BIC=-77.43
auto.arima(mcopper, trace = TRUE, ic ="aic", lambda = BoxCox.lambda(mcopper)) %>%
checkresiduals()
##
## Fitting models using approximations to speed things up...
##
## ARIMA(2,1,2)(1,0,1)[12] with drift : -66.32021
## ARIMA(0,1,0) with drift : -13.82248
## ARIMA(1,1,0)(1,0,0)[12] with drift : -62.06849
## ARIMA(0,1,1)(0,0,1)[12] with drift : -82.25982
## ARIMA(0,1,0) : -12.82906
## ARIMA(0,1,1) with drift : -83.13952
## ARIMA(0,1,1)(1,0,0)[12] with drift : -73.91207
## ARIMA(0,1,1)(1,0,1)[12] with drift : -71.92506
## ARIMA(1,1,1) with drift : -80.30584
## ARIMA(0,1,2) with drift : -81.16609
## ARIMA(1,1,0) with drift : -71.41152
## ARIMA(1,1,2) with drift : -78.27629
## ARIMA(0,1,1) : -83.33279
## ARIMA(0,1,1)(1,0,0)[12] : -74.05872
## ARIMA(0,1,1)(0,0,1)[12] : -82.603
## ARIMA(0,1,1)(1,0,1)[12] : -72.07316
## ARIMA(1,1,1) : -80.55931
## ARIMA(0,1,2) : -81.33929
## ARIMA(1,1,0) : -71.94456
## ARIMA(1,1,2) : -80.62448
##
## Now re-fitting the best model(s) without approximations...
##
## ARIMA(0,1,1) : -86.0969
##
## Best model: ARIMA(0,1,1)
##
## Ljung-Box test
##
## data: Residuals from ARIMA(0,1,1)
## Q* = 22.913, df = 23, p-value = 0.4659
##
## Model df: 1. Total lags used: 24
auto.arima(mcopper, trace = TRUE, ic ="aic", lambda = BoxCox.lambda(mcopper)) %>%
accuracy()
##
## Fitting models using approximations to speed things up...
##
## ARIMA(2,1,2)(1,0,1)[12] with drift : -66.32021
## ARIMA(0,1,0) with drift : -13.82248
## ARIMA(1,1,0)(1,0,0)[12] with drift : -62.06849
## ARIMA(0,1,1)(0,0,1)[12] with drift : -82.25982
## ARIMA(0,1,0) : -12.82906
## ARIMA(0,1,1) with drift : -83.13952
## ARIMA(0,1,1)(1,0,0)[12] with drift : -73.91207
## ARIMA(0,1,1)(1,0,1)[12] with drift : -71.92506
## ARIMA(1,1,1) with drift : -80.30584
## ARIMA(0,1,2) with drift : -81.16609
## ARIMA(1,1,0) with drift : -71.41152
## ARIMA(1,1,2) with drift : -78.27629
## ARIMA(0,1,1) : -83.33279
## ARIMA(0,1,1)(1,0,0)[12] : -74.05872
## ARIMA(0,1,1)(0,0,1)[12] : -82.603
## ARIMA(0,1,1)(1,0,1)[12] : -72.07316
## ARIMA(1,1,1) : -80.55931
## ARIMA(0,1,2) : -81.33929
## ARIMA(1,1,0) : -71.94456
## ARIMA(1,1,2) : -80.62448
##
## Now re-fitting the best model(s) without approximations...
##
## ARIMA(0,1,1) : -86.0969
##
## Best model: ARIMA(0,1,1)
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 3.480533 77.27254 44.92858 0.166202 4.303677 0.2021433 -0.08442198
ets(mcopper) %>% checkresiduals()
##
## Ljung-Box test
##
## data: Residuals from ETS(M,Ad,N)
## Q* = 77.585, df = 19, p-value = 4.832e-09
##
## Model df: 5. Total lags used: 24
ets(mcopper) %>% accuracy()
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 2.691483 78.87699 46.76047 0.1883633 4.503026 0.2103854 0.1052005
autoplot(auscafe)
BoxCox.lambda(auscafe)
## [1] 0.109056
nsdiffs(auscafe)
## [1] 1
ndiffs(auscafe)
## [1] 1
kpss.test(diff(auscafe, lag = 4))
## Warning in kpss.test(diff(auscafe, lag = 4)): p-value greater than printed p-
## value
##
## KPSS Test for Level Stationarity
##
## data: diff(auscafe, lag = 4)
## KPSS Level = 0.29812, Truncation lag parameter = 5, p-value = 0.1
ggtsdisplay(diff(BoxCox(auscafe, BoxCox.lambda(auscafe)), lag = 4))
ggtsdisplay(diff(diff(BoxCox(auscafe, BoxCox.lambda(auscafe)), lag = 4)))
auto.arima(auscafe, lambda = BoxCox.lambda(auscafe))
## Series: auscafe
## ARIMA(1,0,1)(2,1,1)[12] with drift
## Box Cox transformation: lambda= 0.109056
##
## Coefficients:
## ar1 ma1 sar1 sar2 sma1 drift
## 0.9718 -0.3190 0.1270 -0.0527 -0.8423 0.0056
## s.e. 0.0131 0.0478 0.0649 0.0585 0.0431 0.0004
##
## sigma^2 estimated as 0.0005754: log likelihood=952.96
## AIC=-1891.92 AICc=-1891.65 BIC=-1863.74
auto.arima(auscafe, lambda = BoxCox.lambda(auscafe)) %>% checkresiduals()
##
## Ljung-Box test
##
## data: Residuals from ARIMA(1,0,1)(2,1,1)[12] with drift
## Q* = 56.069, df = 18, p-value = 8.692e-06
##
## Model df: 6. Total lags used: 24
auto.arima(auscafe, lambda = BoxCox.lambda(auscafe)) %>% forecast(h = 8) %>%
autoplot()
forecast(ets(auscafe), h = 8) %>% autoplot()
stlf(auscafe, lambda = BoxCox.lambda(auscafe),
s.window = 5, robust = TRUE, method = "arima",
h = 8) %>% autoplot()
forecast(ets(auscafe), h = 8) %>% autoplot()
forecast(auto.arima(auscafe), h = 8) %>% autoplot()
forecast(auto.arima(myts), h = 36) %>% autoplot()
snaive(myts, h = 36) %>% autoplot()
forecast(ets(myts, lambda=BoxCox.lambda(myts)), h = 36) %>%
autoplot()
autoplot(sheep)
ggtsdisplay(diff(sheep))
forecast(Arima(sheep, order = c(3, 1, 0)),h = 3) $ mean
## Time Series:
## Start = 1940
## End = 1942
## Frequency = 1
## [1] 1777.996 1718.869 1695.985
autoplot(bicoal)
ggAcf(bicoal, lag.max = 36)
ggPacf(bicoal, lag.max = 36)
forecast(ar(bicoal, 4), h = 3) $ mean
## Time Series:
## Start = 1969
## End = 1971
## Frequency = 1
## [1] 526.2057 514.0658 500.0111
y <- ibmclose
autoplot(y)
checkresiduals(y)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.
auto.arima(y) %>% forecast(h = 4 * 12) %>% autoplot()
ets(y) %>% forecast(h = 4*12) %>% autoplot()
ets(y) %>% checkresiduals()
##
## Ljung-Box test
##
## data: Residuals from ETS(A,N,N)
## Q* = 14.132, df = 8, p-value = 0.07839
##
## Model df: 2. Total lags used: 10