Today, give a try to Techtonique web app, a tool designed to help you make informed, data-driven decisions using Mathematics, Statistics, Machine Learning, and Data Visualization. Here is a tutorial with audio, video, code, and slides: https://moudiki2.gumroad.com/l/nrhgb
Last week, I presented a new version of ahead
, which includes an extension of the Theta forecasting method to Generalized Linear Models (GLMs), GAMs, GLMBoost, and an attention mechanism (work in progress).
This post demonstrates the performance of the new method on Tourism (1311 series), M1 (1001 series), M3 (3003 series), and M4 Yearly (23000 series) competition data sets. Workhorse models are used to benchmark the new method, including glm.nb
, glm
, rlm
, lqs
, gam
, and glmboost
.
The results are compared to the original Theta method, and are highly competitive, especially on the Tourism and M4 Yearly data sets (MASE, RMSE).
%load_ext rpy2.ipython
1 - R
%%R
options(repos = c(techtonique = "https://r-packages.techtonique.net",
CRAN = "https://cloud.r-project.org"))
install.packages("ahead")
install.packages("remotes")
install.packages("doParallel")
install.packages("quantreg")
install.packages("memoise")
install.packages("Mcomp")
install.packages("Tcomp")
install.packages("gam")
install.packages("mboost")
install.packages("https://github.com/carlanetto/M4comp2018/releases/download/0.2.0/M4comp2018_0.2.0.tar.gz",
repos=NULL)
%%R
install.packages("knitr")
install.packages("kableExtra")
library(knitr)
library(kableExtra)
%%R
install.packages("gt")
library(gt)
%%R
#install.packages("forecast")
library(forecast)
require(Mcomp)
coverage_score <- function(obj, actual){
if (is.null(obj$lower))
{
return(mean((obj$intervals[, 1] <= actual)*(actual <= obj$intervals[, 2]), na.rm=TRUE)*100)
}
return(mean((obj$lower <= actual)*(actual <= obj$upper), na.rm=TRUE)*100)
}
#coverage_score <- memoise::memoise(coverage_score)
winkler_score <- function(obj, actual, level = 95) {
alpha <- 1 - level / 100
lt <- try(obj$lower, silent = TRUE)
ut <- try(obj$upper, silent = TRUE)
actual <- as.numeric(actual)
if (is.null(lt) || is.null(ut))
{
lt <- as.numeric(obj$intervals[, 1])
ut <- as.numeric(obj$intervals[, 2])
}
n_points <- length(actual)
stopifnot((n_points == length(lt)) && (n_points == length(ut)))
diff_lt <- lt - actual
diff_bounds <- ut - lt
diff_ut <- actual - ut
score <- diff_bounds
score <- score + (2 / alpha) * (pmax(diff_lt, 0) + pmax(diff_ut, 0))
return(mean(score, na.rm=TRUE))
}
#winkler_score <- memoise::memoise(winkler_score)
accuracy <- function(obj, actual, level = 95)
{
actual <- as.numeric(actual)
mean_prediction <- as.numeric(obj$mean)
me <- mean(mean_prediction - actual)
rmse <- sqrt(mean((mean_prediction - actual)**2, na.rm=TRUE))
mae <- mean(abs(mean_prediction - actual), na.rm=TRUE)
mpe <- mean(mean_prediction/actual-1, na.rm=TRUE)
mape <- mean(abs(mean_prediction/actual-1), na.rm=TRUE)
m <- frequency(obj$x) # e.g., 12 for monthly data
# Compute scaling factor (MAE of in-sample seasonal naive forecasts)
if (m > 1) {
scale <- mean(abs(diff(obj$x, lag = m)), na.rm=TRUE)
} else {
scale <- mean(abs(diff(obj$x, lag = 1)), na.rm=TRUE)
}
# MASE = mean(|test - forecast|) / scale
mase <- mean(abs(actual - obj$mean), na.rm=TRUE) / max(scale, 1e-6)
coverage <- as.numeric(coverage_score(obj, actual))
winkler <- winkler_score(obj, actual, level = level)
res <- c(me, rmse, mae, mpe,
mape, mase, coverage, winkler)
names(res) <- c("me", "rmse", "mae", "mpe",
"mape", "mase", "coverage", "winkler")
return(res)
}
#accuracy <- memoise::memoise(accuracy)
thetaf <- memoise::memoise(forecast::thetaf)
glmthetaf <- memoise::memoise(ahead::glmthetaf)
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Loading required package: Mcomp
1 - 1 Tcomp
%%R
# Load necessary libraries
library(doSNOW)
library(tcltk)
# Tcomp series -----
(nseries <- length(Tcomp::tourism))
# Set up parallel backend
cl <- makeSOCKcluster(parallel::detectCores()) # Use 2 cores (adjust as needed)
registerDoSNOW(cl)
# Define progress bar
pb <- txtProgressBar(min = 0, max = nseries, style = 3)
# Progress function
progress <- function(n) setTxtProgressBar(pb, n)
# Options for progress tracking
opts <- list(progress = progress)
# Parallel loop with progress bar
results <- foreach(i = 1:nseries, .combine = rbind,
.errorhandling = "remove",
.export=c("accuracy", "coverage_score", "winkler_score"),
.options.snow = opts) %dopar% {
x <- Tcomp::tourism[[i]]$x
xx <- Tcomp::tourism[[i]]$xx
h <- length(xx)
# thetaf
obj <- try(suppressWarnings(thetaf(x, h = h, level=95)),
silent=TRUE)
res1 <- accuracy(obj, xx)
# glmthetaf with MASS::glm.nb
obj <- try(suppressWarnings(glmthetaf(x, h = h,
fit_func = MASS::glm.nb,
attention = TRUE)),
silent=TRUE)
if (inherits(obj, "try-error"))
{
obj <- forecast:::snaive(time_series, h = forecast_horizon)
}
res2 <- accuracy(obj, xx)
# glmthetaf with stats::glm
obj <- try(suppressWarnings(glmthetaf(x, h = h,
fit_func = stats::glm,
attention = TRUE)),
silent=TRUE)
if (inherits(obj, "try-error"))
{
obj <- forecast:::snaive(time_series, h = forecast_horizon)
}
res3 <- accuracy(obj, xx)
# glmthetaf with MASS::rlm
obj <- try(suppressWarnings(glmthetaf(x, h = h,
fit_func = MASS::rlm,
attention = TRUE)),
silent=TRUE)
if (inherits(obj, "try-error"))
{
obj <- forecast:::snaive(time_series, h = forecast_horizon)
}
res4 <- accuracy(obj, xx)
# glmthetaf with MASS::lqs
obj <- try(suppressWarnings(glmthetaf(x, h = h,
fit_func = MASS::lqs,
attention = TRUE)),
silent=TRUE)
if (inherits(obj, "try-error"))
{
obj <- forecast:::snaive(time_series, h = forecast_horizon)
}
res5 <- accuracy(obj, xx)
# glmthetaf with gam::gam
obj <- try(suppressWarnings(glmthetaf(x, h = h,
fit_func = gam::gam,
attention = TRUE)),
silent=TRUE)
if (inherits(obj, "try-error"))
{
obj <- forecast:::snaive(time_series, h = forecast_horizon)
}
res6 <- accuracy(obj, xx)
# glmthetaf with quantreg::rq
obj <- try(suppressWarnings(glmthetaf(x, h = h,
fit_func = quantreg::rq,
attention = TRUE)),
silent=TRUE)
if (inherits(obj, "try-error"))
{
obj <- forecast:::snaive(time_series, h = forecast_horizon)
}
res7 <- accuracy(obj, xx)
# glmthetaf with quantreg::rq
obj <- try(suppressWarnings(glmthetaf(x, h = h,
fit_func = mboost::glmboost,
attention = TRUE)),
silent=TRUE)
if (inherits(obj, "try-error"))
{
obj <- forecast:::snaive(time_series, h = forecast_horizon)
}
res8 <- accuracy(obj, xx)
# Determine period
period <- switch(Tcomp::tourism[[i]]$period,
"YEARLY" = 1,
"QUARTERLY" = 4,
"MONTHLY" = 12)
# Combine results
res <- cbind(i, period,
res1, res2,
res3, res4,
res5, res6,
res7, res8)
colnames(res) <- c("series", "period", "theta", "glmnbtheta",
"glmtheta", "rlmtheta", "lqstheta",
"gamtheta", "quantregtheta", "glmboosttheta")
res
}
# Stop cluster
stopCluster(cl)
# Close progress bar
close(pb)
# Convert results to data frame
results <- data.frame(results)
base::saveRDS(results, "results_Tcomp.rds")
%%R
print(head(results))
print(tail(results))
print(dim(results))
from IPython.display import FileLink
# Create a download link for the file
FileLink('results_Tcomp.rds')
%%R
results_Tcomp <- readRDS("results_Tcomp.rds")
cat("\n\n MASE - YEARLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("mase", rownames(results_Tcomp)), ], period==1)))
cat("\n\n MASE - QUARTERLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("mase", rownames(results_Tcomp)), ], period==4)))
cat("\n\n MASE - MONTHLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("mase", rownames(results_Tcomp)), ], period==12)))
cat("\n\n RMSE - YEARLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("rmse", rownames(results_Tcomp)), ], period==1)))
cat("\n\n RMSE - QUARTERLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("rmse", rownames(results_Tcomp)), ], period==4)))
cat("\n\n RMSE - MONTHLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("rmse", rownames(results_Tcomp)), ], period==12)))
cat("\n\n COVERAGE - YEARLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("coverage", rownames(results_Tcomp)), ], period==1)))
cat("\n\n COVERAGE - QUARTERLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("coverage", rownames(results_Tcomp)), ], period==4)))
cat("\n\n COVERAGE - MONTHLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("coverage", rownames(results_Tcomp)), ], period==12)))
cat("\n\n WINKLER - YEARLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("winkler", rownames(results_Tcomp)), ], period==1)))
cat("\n\n WINKLER - QUARTERLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("winkler", rownames(results_Tcomp)), ], period==4)))
cat("\n\n WINKLER - MONTHLY ----- \n\n")
print(summary(subset(results_Tcomp[grep("winkler", rownames(results_Tcomp)), ], period==12)))
MASE - YEARLY -----
series period theta glmnbtheta
Min. : 794 Min. :1 Min. : 0.1659 Min. : 0.05748
1st Qu.: 923 1st Qu.:1 1st Qu.: 1.1639 1st Qu.: 1.35532
Median :1053 Median :1 Median : 2.0521 Median : 2.36326
Mean :1053 Mean :1 Mean : 2.7308 Mean : 3.02522
3rd Qu.:1182 3rd Qu.:1 3rd Qu.: 3.4393 3rd Qu.: 4.01984
Max. :1311 Max. :1 Max. :12.6591 Max. :13.42235
glmtheta rlmtheta lqstheta gamtheta
Min. : 0.2033 Min. : 0.2137 Min. : 0.1668 Min. : 0.2033
1st Qu.: 1.1759 1st Qu.: 1.1730 1st Qu.: 1.2353 1st Qu.: 1.1759
Median : 2.0773 Median : 2.0348 Median : 2.1894 Median : 2.0773
Mean : 2.7258 Mean : 2.7045 Mean : 2.8242 Mean : 2.7258
3rd Qu.: 3.4659 3rd Qu.: 3.4703 3rd Qu.: 3.8215 3rd Qu.: 3.4659
Max. :12.7243 Max. :12.2952 Max. :14.8614 Max. :12.7243
quantregtheta glmboosttheta
Min. : 0.1855 Min. : 0.2033
1st Qu.: 1.2333 1st Qu.: 1.1759
Median : 2.1000 Median : 2.0774
Mean : 2.7308 Mean : 2.7258
3rd Qu.: 3.5459 3rd Qu.: 3.4658
Max. :12.6997 Max. :12.7241
MASE - QUARTERLY -----
series period theta glmnbtheta glmtheta
Min. :367.0 Min. :4 Min. :0.1435 Min. :0.2547 Min. :0.3146
1st Qu.:473.5 1st Qu.:4 1st Qu.:0.9411 1st Qu.:0.9345 1st Qu.:0.9216
Median :580.0 Median :4 Median :1.3482 Median :1.3963 Median :1.3393
Mean :580.0 Mean :4 Mean :1.6613 Mean :1.6622 Mean :1.5744
3rd Qu.:686.5 3rd Qu.:4 3rd Qu.:2.0063 3rd Qu.:1.9796 3rd Qu.:1.9217
Max. :793.0 Max. :4 Max. :6.5581 Max. :7.1608 Max. :7.5383
rlmtheta lqstheta gamtheta quantregtheta
Min. :0.3075 Min. :0.2563 Min. :0.3146 Min. :0.2485
1st Qu.:0.9121 1st Qu.:0.8884 1st Qu.:0.9216 1st Qu.:0.9178
Median :1.3063 Median :1.3483 Median :1.3393 Median :1.3200
Mean :1.5657 Mean :1.6053 Mean :1.5744 Mean :1.5725
3rd Qu.:1.8925 3rd Qu.:1.9778 3rd Qu.:1.9217 3rd Qu.:1.9146
Max. :7.5300 Max. :7.4773 Max. :7.5383 Max. :7.5101
glmboosttheta
Min. :0.3146
1st Qu.:0.9216
Median :1.3393
Mean :1.5744
3rd Qu.:1.9217
Max. :7.5382
MASE - MONTHLY -----
series period theta glmnbtheta
Min. : 1.00 Min. :12 Min. :0.2306 Min. :0.3772
1st Qu.: 92.25 1st Qu.:12 1st Qu.:1.0318 1st Qu.:1.0078
Median :183.50 Median :12 Median :1.3823 Median :1.3077
Mean :183.50 Mean :12 Mean :1.6488 Mean :1.5406
3rd Qu.:274.75 3rd Qu.:12 3rd Qu.:1.9223 3rd Qu.:1.7017
Max. :366.00 Max. :12 Max. :6.5851 Max. :6.3361
glmtheta rlmtheta lqstheta gamtheta
Min. :0.3479 Min. :0.3458 Min. :0.3703 Min. :0.3479
1st Qu.:0.9531 1st Qu.:0.9477 1st Qu.:0.9981 1st Qu.:0.9531
Median :1.2789 Median :1.2788 Median :1.3063 Median :1.2789
Mean :1.5083 Mean :1.5005 Mean :1.5058 Mean :1.5083
3rd Qu.:1.7390 3rd Qu.:1.7282 3rd Qu.:1.7290 3rd Qu.:1.7390
Max. :6.2486 Max. :6.0757 Max. :5.9378 Max. :6.2486
quantregtheta glmboosttheta
Min. :0.3468 Min. :0.3479
1st Qu.:0.9544 1st Qu.:0.9531
Median :1.2783 Median :1.2789
Mean :1.5001 Mean :1.5083
3rd Qu.:1.7180 3rd Qu.:1.7390
Max. :6.0329 Max. :6.2486
RMSE - YEARLY -----
series period theta glmnbtheta
Min. : 794 Min. :1 Min. : 0 Min. : 0
1st Qu.: 923 1st Qu.:1 1st Qu.: 523 1st Qu.: 621
Median :1053 Median :1 Median : 3469 Median : 3866
Mean :1053 Mean :1 Mean : 92401 Mean : 97418
3rd Qu.:1182 3rd Qu.:1 3rd Qu.: 16640 3rd Qu.: 17956
Max. :1311 Max. :1 Max. :9308127 Max. :7103768
glmtheta rlmtheta lqstheta gamtheta
Min. : 0 Min. : 0 Min. : 0 Min. : 0
1st Qu.: 570 1st Qu.: 570 1st Qu.: 621 1st Qu.: 570
Median : 3086 Median : 3043 Median : 3036 Median : 3086
Mean : 104771 Mean : 105078 Mean : 153605 Mean : 104771
3rd Qu.: 17828 3rd Qu.: 18013 3rd Qu.: 16787 3rd Qu.: 17828
Max. :17859424 Max. :17859424 Max. :22096361 Max. :17859424
quantregtheta glmboosttheta
Min. : 0 Min. : 0
1st Qu.: 601 1st Qu.: 570
Median : 3172 Median : 3086
Mean : 96344 Mean : 104770
3rd Qu.: 17791 3rd Qu.: 17828
Max. :14863748 Max. :17859129
RMSE - QUARTERLY -----
series period theta glmnbtheta
Min. :367.0 Min. :4 Min. : 14.3 Min. : 9.8
1st Qu.:473.5 1st Qu.:4 1st Qu.: 437.0 1st Qu.: 458.4
Median :580.0 Median :4 Median : 1392.9 Median : 1261.3
Mean :580.0 Mean :4 Mean : 9254.6 Mean : 11103.8
3rd Qu.:686.5 3rd Qu.:4 3rd Qu.: 4819.2 3rd Qu.: 4682.0
Max. :793.0 Max. :4 Max. :1010121.0 Max. :1491237.3
glmtheta rlmtheta lqstheta gamtheta
Min. : 12.2 Min. : 12.3 Min. : 9.2 Min. : 12.2
1st Qu.: 426.0 1st Qu.: 429.8 1st Qu.: 428.4 1st Qu.: 426.0
Median : 1262.9 Median : 1245.3 Median : 1263.3 Median : 1262.9
Mean : 8026.0 Mean : 7892.1 Mean : 7993.1 Mean : 8026.0
3rd Qu.: 4202.2 3rd Qu.: 4162.0 3rd Qu.: 4570.7 3rd Qu.: 4202.2
Max. :429038.8 Max. :427515.5 Max. :466923.3 Max. :429038.8
quantregtheta glmboosttheta
Min. : 12.3 Min. : 12.2
1st Qu.: 428.2 1st Qu.: 426.0
Median : 1242.5 Median : 1262.8
Mean : 7714.7 Mean : 8026.0
3rd Qu.: 4225.0 3rd Qu.: 4202.2
Max. :439185.7 Max. :429043.0
RMSE - MONTHLY -----
series period theta glmnbtheta
Min. : 1.00 Min. :12 Min. : 40.19 Min. : 35.52
1st Qu.: 92.25 1st Qu.:12 1st Qu.: 267.63 1st Qu.: 256.08
Median :183.50 Median :12 Median : 675.10 Median : 586.62
Mean :183.50 Mean :12 Mean : 2701.96 Mean : 2571.03
3rd Qu.:274.75 3rd Qu.:12 3rd Qu.: 2181.65 3rd Qu.: 2042.95
Max. :366.00 Max. :12 Max. :107131.65 Max. :101604.31
glmtheta rlmtheta lqstheta gamtheta
Min. : 35.58 Min. : 35.69 Min. : 38.55 Min. : 35.58
1st Qu.: 239.40 1st Qu.: 239.10 1st Qu.: 244.94 1st Qu.: 239.40
Median : 593.21 Median : 590.25 Median : 575.99 Median : 593.21
Mean : 2404.19 Mean : 2379.51 Mean : 2350.07 Mean : 2404.19
3rd Qu.: 1945.45 3rd Qu.: 1917.55 3rd Qu.: 1945.51 3rd Qu.: 1945.45
Max. :83410.95 Max. :81413.31 Max. :81483.87 Max. :83410.95
quantregtheta glmboosttheta
Min. : 35.77 Min. : 35.58
1st Qu.: 241.63 1st Qu.: 239.40
Median : 582.61 Median : 593.22
Mean : 2345.52 Mean : 2404.19
3rd Qu.: 1881.51 3rd Qu.: 1945.45
Max. :70072.82 Max. :83409.12
COVERAGE - YEARLY -----
series period theta glmnbtheta glmtheta
Min. : 794 Min. :1 Min. : 0.00 Min. : 0.00 Min. : 0.00
1st Qu.: 923 1st Qu.:1 1st Qu.: 50.00 1st Qu.: 50.00 1st Qu.: 50.00
Median :1053 Median :1 Median :100.00 Median :100.00 Median : 75.00
Mean :1053 Mean :1 Mean : 77.56 Mean : 72.68 Mean : 71.23
3rd Qu.:1182 3rd Qu.:1 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :1311 Max. :1 Max. :100.00 Max. :100.00 Max. :100.00
rlmtheta lqstheta gamtheta quantregtheta
Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.00
1st Qu.: 50.00 1st Qu.: 50.00 1st Qu.: 50.00 1st Qu.: 50.00
Median :100.00 Median :100.00 Median : 75.00 Median : 75.00
Mean : 71.37 Mean : 71.62 Mean : 71.23 Mean : 71.08
3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :100.00 Max. :100.00 Max. :100.00 Max. :100.00
glmboosttheta
Min. : 0.00
1st Qu.: 50.00
Median : 75.00
Mean : 71.23
3rd Qu.:100.00
Max. :100.00
COVERAGE - QUARTERLY -----
series period theta glmnbtheta glmtheta
Min. :367.0 Min. :4 Min. : 0.00 Min. : 0.00 Min. : 0.00
1st Qu.:473.5 1st Qu.:4 1st Qu.: 75.00 1st Qu.: 87.50 1st Qu.: 87.50
Median :580.0 Median :4 Median : 87.50 Median :100.00 Median :100.00
Mean :580.0 Mean :4 Mean : 83.37 Mean : 92.71 Mean : 91.39
3rd Qu.:686.5 3rd Qu.:4 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :793.0 Max. :4 Max. :100.00 Max. :100.00 Max. :100.00
rlmtheta lqstheta gamtheta quantregtheta
Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.00
1st Qu.: 87.50 1st Qu.: 87.50 1st Qu.: 87.50 1st Qu.: 87.50
Median :100.00 Median :100.00 Median :100.00 Median :100.00
Mean : 91.66 Mean : 91.57 Mean : 91.39 Mean : 91.66
3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :100.00 Max. :100.00 Max. :100.00 Max. :100.00
glmboosttheta
Min. : 0.00
1st Qu.: 87.50
Median :100.00
Mean : 91.39
3rd Qu.:100.00
Max. :100.00
COVERAGE - MONTHLY -----
series period theta glmnbtheta
Min. : 1.00 Min. :12 Min. : 12.50 Min. : 16.67
1st Qu.: 92.25 1st Qu.:12 1st Qu.: 79.17 1st Qu.: 91.67
Median :183.50 Median :12 Median : 87.50 Median :100.00
Mean :183.50 Mean :12 Mean : 84.41 Mean : 94.40
3rd Qu.:274.75 3rd Qu.:12 3rd Qu.: 95.83 3rd Qu.:100.00
Max. :366.00 Max. :12 Max. :100.00 Max. :100.00
glmtheta rlmtheta lqstheta gamtheta
Min. : 29.17 Min. : 29.17 Min. : 20.83 Min. : 29.17
1st Qu.: 91.67 1st Qu.: 91.67 1st Qu.: 91.67 1st Qu.: 91.67
Median : 95.83 Median : 95.83 Median : 95.83 Median : 95.83
Mean : 93.56 Mean : 93.64 Mean : 93.74 Mean : 93.56
3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :100.00 Max. :100.00 Max. :100.00 Max. :100.00
quantregtheta glmboosttheta
Min. : 25.00 Min. : 29.17
1st Qu.: 91.67 1st Qu.: 91.67
Median : 95.83 Median : 95.83
Mean : 93.64 Mean : 93.56
3rd Qu.:100.00 3rd Qu.:100.00
Max. :100.00 Max. :100.00
WINKLER - YEARLY -----
series period theta glmnbtheta
Min. : 794 Min. :1 Min. : 0 Min. : 0
1st Qu.: 923 1st Qu.:1 1st Qu.: 3353 1st Qu.: 4395
Median :1053 Median :1 Median : 19179 Median : 27045
Mean :1053 Mean :1 Mean : 991140 Mean : 1354242
3rd Qu.:1182 3rd Qu.:1 3rd Qu.: 121725 3rd Qu.: 152326
Max. :1311 Max. :1 Max. :131631759 Max. :139207678
glmtheta rlmtheta lqstheta
Min. : 0 Min. : 0 Min. : 0
1st Qu.: 3987 1st Qu.: 3962 1st Qu.: 4672
Median : 22339 Median : 23038 Median : 23000
Mean : 1428806 Mean : 1430121 Mean : 2640349
3rd Qu.: 152825 3rd Qu.: 152825 3rd Qu.: 140807
Max. :220841357 Max. :220841357 Max. :591435564
gamtheta quantregtheta glmboosttheta
Min. : 0 Min. : 0 Min. : 0
1st Qu.: 3987 1st Qu.: 4321 1st Qu.: 3987
Median : 22339 Median : 23113 Median : 22338
Mean : 1428806 Mean : 1209054 Mean : 1428804
3rd Qu.: 152825 3rd Qu.: 147477 3rd Qu.: 152834
Max. :220841357 Max. :144113476 Max. :220837127
WINKLER - QUARTERLY -----
series period theta glmnbtheta
Min. :367.0 Min. :4 Min. : 119 Min. : 182
1st Qu.:473.5 1st Qu.:4 1st Qu.: 2802 1st Qu.: 2784
Median :580.0 Median :4 Median : 9777 Median : 9358
Mean :580.0 Mean :4 Mean : 65465 Mean : 87156
3rd Qu.:686.5 3rd Qu.:4 3rd Qu.: 35033 3rd Qu.: 34782
Max. :793.0 Max. :4 Max. :4614660 Max. :8044282
glmtheta rlmtheta lqstheta gamtheta
Min. : 160 Min. : 159 Min. : 161 Min. : 160
1st Qu.: 2770 1st Qu.: 2725 1st Qu.: 2665 1st Qu.: 2770
Median : 8187 Median : 7965 Median : 7905 Median : 8187
Mean : 70215 Mean : 68396 Mean : 70960 Mean : 70215
3rd Qu.: 31793 3rd Qu.: 31746 3rd Qu.: 32823 3rd Qu.: 31793
Max. :4942200 Max. :4952162 Max. :4783339 Max. :4942200
quantregtheta glmboosttheta
Min. : 147 Min. : 160
1st Qu.: 2704 1st Qu.: 2770
Median : 7863 Median : 8187
Mean : 68699 Mean : 70216
3rd Qu.: 31788 3rd Qu.: 31793
Max. :4927588 Max. :4942298
WINKLER - MONTHLY -----
series period theta glmnbtheta
Min. : 1.00 Min. :12 Min. : 225.7 Min. : 174.9
1st Qu.: 92.25 1st Qu.:12 1st Qu.: 1728.9 1st Qu.: 1493.6
Median :183.50 Median :12 Median : 4769.1 Median : 4016.7
Mean :183.50 Mean :12 Mean : 19385.1 Mean : 20667.8
3rd Qu.:274.75 3rd Qu.:12 3rd Qu.: 14892.4 3rd Qu.: 13917.2
Max. :366.00 Max. :12 Max. :622300.5 Max. :1200917.2
glmtheta rlmtheta lqstheta
Min. : 175.7 Min. : 175.8 Min. : 182.2
1st Qu.: 1339.0 1st Qu.: 1338.2 1st Qu.: 1425.4
Median : 4099.8 Median : 4048.5 Median : 3676.0
Mean : 19029.6 Mean : 18880.7 Mean : 19139.1
3rd Qu.: 12796.5 3rd Qu.: 12717.9 3rd Qu.: 12594.7
Max. :1030204.8 Max. :1035876.3 Max. :1108778.7
gamtheta quantregtheta glmboosttheta
Min. : 175.7 Min. : 175.9 Min. : 175.7
1st Qu.: 1339.0 1st Qu.: 1335.8 1st Qu.: 1339.0
Median : 4099.8 Median : 3987.9 Median : 4099.8
Mean : 19029.6 Mean : 18961.6 Mean : 19029.6
3rd Qu.: 12796.5 3rd Qu.: 12561.8 3rd Qu.: 12796.5
Max. :1030204.8 Max. :1064937.4 Max. :1030209.7
1 - 2 - M3
%%R
# Load necessary libraries
library(doSNOW)
library(tcltk)
require(Mcomp)
nseries <- length(M3)
# Set up parallel backend
cl <- makeSOCKcluster(parallel::detectCores()) # Use 2 cores (adjust as needed)
registerDoSNOW(cl)
# Define progress bar
pb <- txtProgressBar(min = 0, max = nseries, style = 3)
# Progress function
progress <- function(n) setTxtProgressBar(pb, n)
# Options for progress tracking
opts <- list(progress = progress)
pb <- utils::txtProgressBar(min=0, max=nseries, style = 3)
(M3results <- foreach::foreach(i = 1:nseries, .combine = rbind,
.errorhandling = "remove",
.verbose=FALSE,
.options.snow = opts)%dopar%{
x <- Mcomp::M3[[i]]$x
xx <- Mcomp::M3[[i]]$xx
h <- length(xx)
obj <- suppressWarnings(thetaf(x, h=h, level=95))
res1 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=MASS::glm.nb,
attention = TRUE))
res2 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=stats::glm,
attention = TRUE))
res3 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=MASS::rlm,
attention = TRUE))
res4 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=MASS::lqs,
attention = TRUE))
res5 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=gam::gam,
attention = TRUE))
res6 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=quantreg::rq,
attention = TRUE))
res7 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=mboost::glmboost,
attention = TRUE))
res8 <- accuracy(obj, xx)
period <- switch (Mcomp::M3[[i]]$period,
"YEARLY" = 1,
"QUARTERLY" = 4,
"MONTHLY" = 12,
"OTHER" = 99
)
utils::setTxtProgressBar(pb, i)
res <- cbind(i, period,
res1, res2,
res3, res4,
res5, res6,
res7, res8)
colnames(res) <- c("series", "period", "theta", "glmnbtheta",
"glmtheta", "rlmtheta", "lqstheta",
"gamtheta", "quantregtheta", "glmboosttheta")
res
})
close(pb)
M3results <- data.frame(M3results)
print(head(M3results))
print(tail(M3results))
print(dim(M3results))
base::saveRDS(M3results, "results_M3.rds")
print(summary(subset(M3results[grep("mase", rownames(M3results)), ], period==1)))
print(summary(subset(M3results[grep("mase", rownames(M3results)), ], period==4)))
print(summary(subset(M3results[grep("mase", rownames(M3results)), ], period==12)))
print(summary(subset(M3results[grep("mase", rownames(M3results)), ], period==99)))
print(summary(subset(M3results[grep("mae", rownames(M3results)), ], period==1)))
print(summary(subset(M3results[grep("mae", rownames(M3results)), ], period==4)))
print(summary(subset(M3results[grep("mae", rownames(M3results)), ], period==12)))
print(summary(subset(M3results[grep("mae", rownames(M3results)), ], period==99)))
print(summary(subset(M3results[grep("rmse", rownames(M3results)), ], period==1)))
print(summary(subset(M3results[grep("rmse", rownames(M3results)), ], period==4)))
print(summary(subset(M3results[grep("rmse", rownames(M3results)), ], period==12)))
print(summary(subset(M3results[grep("rmse", rownames(M3results)), ], period==99)))
from IPython.display import FileLink
# Create a download link for the file
FileLink('results_M3.rds')
%%R
results_M3 <- readRDS("results_M3.rds")
cat("\n\n MASE - YEARLY ----- \n\n")
print(summary(subset(results_M3[grep("mase", rownames(results_M3)), ], period==1)))
cat("\n\n MASE - QUARTERLY ----- \n\n")
print(summary(subset(results_M3[grep("mase", rownames(results_M3)), ], period==4)))
cat("\n\n MASE - MONTHLY ----- \n\n")
print(summary(subset(results_M3[grep("mase", rownames(results_M3)), ], period==12)))
cat("\n\n MASE - OTHER ----- \n\n")
print(summary(subset(results_M3[grep("mase", rownames(results_M3)), ], period==99)))
cat("\n\n RMSE - YEARLY ----- \n\n")
print(summary(subset(results_M3[grep("rmse", rownames(results_M3)), ], period==1)))
cat("\n\n RMSE - QUARTERLY ----- \n\n")
print(summary(subset(results_M3[grep("rmse", rownames(results_M3)), ], period==4)))
cat("\n\n RMSE - MONTHLY ----- \n\n")
print(summary(subset(results_M3[grep("rmse", rownames(results_M3)), ], period==12)))
cat("\n\n RMSE - OTHER ----- \n\n")
print(summary(subset(results_M3[grep("rmse", rownames(results_M3)), ], period==99)))
cat("\n\n COVERAGE - YEARLY ----- \n\n")
print(summary(subset(results_M3[grep("coverage", rownames(results_M3)), ], period==1)))
cat("\n\n COVERAGE - QUARTERLY ----- \n\n")
print(summary(subset(results_M3[grep("coverage", rownames(results_M3)), ], period==4)))
cat("\n\n COVERAGE - MONTHLY ----- \n\n")
print(summary(subset(results_M3[grep("coverage", rownames(results_M3)), ], period==12)))
cat("\n\n COVERAGE - OTHER ----- \n\n")
print(summary(subset(results_M3[grep("coverage", rownames(results_M3)), ], period==99)))
cat("\n\n WINKLER - YEARLY ----- \n\n")
print(summary(subset(results_M3[grep("winkler", rownames(results_M3)), ], period==1)))
cat("\n\n WINKLER - QUARTERLY ----- \n\n")
print(summary(subset(results_M3[grep("winkler", rownames(results_M3)), ], period==4)))
cat("\n\n WINKLER - MONTHLY ----- \n\n")
print(summary(subset(results_M3[grep("winkler", rownames(results_M3)), ], period==12)))
cat("\n\n WINKLER - OTHER ----- \n\n")
print(summary(subset(results_M3[grep("winkler", rownames(results_M3)), ], period==99)))
MASE - YEARLY -----
series period theta glmnbtheta
Min. : 1.0 Min. :1 Min. : 0.03876 Min. : 0.06781
1st Qu.:161.5 1st Qu.:1 1st Qu.: 1.13652 1st Qu.: 1.23557
Median :322.0 Median :1 Median : 1.98470 Median : 2.26387
Mean :322.5 Mean :1 Mean : 2.76912 Mean : 3.19215
3rd Qu.:484.5 3rd Qu.:1 3rd Qu.: 3.35399 3rd Qu.: 4.25194
Max. :645.0 Max. :1 Max. :18.39875 Max. :19.71222
glmtheta rlmtheta lqstheta gamtheta
Min. : 0.04206 Min. : 0.08489 Min. : 0.03962 Min. : 0.04206
1st Qu.: 1.11360 1st Qu.: 1.11360 1st Qu.: 1.21102 1st Qu.: 1.11360
Median : 2.14429 Median : 2.09826 Median : 2.30911 Median : 2.14429
Mean : 2.88090 Mean : 2.88413 Mean : 3.13534 Mean : 2.88090
3rd Qu.: 3.73801 3rd Qu.: 3.72109 3rd Qu.: 4.01386 3rd Qu.: 3.73801
Max. :21.90144 Max. :21.77296 Max. :19.66367 Max. :21.90144
quantregtheta glmboosttheta
Min. : 0.06057 Min. : 0.04204
1st Qu.: 1.11884 1st Qu.: 1.11358
Median : 2.15137 Median : 2.14420
Mean : 2.92007 Mean : 2.88088
3rd Qu.: 3.75612 3rd Qu.: 3.73791
Max. :21.50529 Max. :21.90127
MASE - QUARTERLY -----
series period theta glmnbtheta
Min. : 646.0 Min. :4 Min. :0.04948 Min. :0.0643
1st Qu.: 834.5 1st Qu.:4 1st Qu.:0.50591 1st Qu.:0.6007
Median :1023.0 Median :4 Median :0.83113 Median :1.0169
Mean :1023.1 Mean :4 Mean :1.11726 Mean :1.2849
3rd Qu.:1211.5 3rd Qu.:4 3rd Qu.:1.36553 3rd Qu.:1.6517
Max. :1401.0 Max. :4 Max. :8.95676 Max. :9.1094
glmtheta rlmtheta lqstheta gamtheta
Min. :0.09065 Min. :0.08851 Min. : 0.08128 Min. :0.09065
1st Qu.:0.61515 1st Qu.:0.61881 1st Qu.: 0.68118 1st Qu.:0.61515
Median :1.01690 Median :1.05730 Median : 1.17732 Median :1.01690
Mean :1.38350 Mean :1.38570 Mean : 1.50226 Mean :1.38350
3rd Qu.:1.76938 3rd Qu.:1.75291 3rd Qu.: 1.95377 3rd Qu.:1.76938
Max. :8.38250 Max. :8.39255 Max. :11.13771 Max. :8.38250
quantregtheta glmboosttheta
Min. :0.07944 Min. :0.09066
1st Qu.:0.61232 1st Qu.:0.61516
Median :1.06087 Median :1.01687
Mean :1.42023 Mean :1.38349
3rd Qu.:1.78674 3rd Qu.:1.76936
Max. :8.62425 Max. :8.38252
MASE - MONTHLY -----
series period theta glmnbtheta
Min. :1402 Min. :12 Min. :0.04156 Min. :0.07518
1st Qu.:1758 1st Qu.:12 1st Qu.:0.49464 1st Qu.:0.55326
Median :2115 Median :12 Median :0.72146 Median :0.79654
Mean :2115 Mean :12 Mean :0.86417 Mean :0.98665
3rd Qu.:2472 3rd Qu.:12 3rd Qu.:1.05258 3rd Qu.:1.21279
Max. :2829 Max. :12 Max. :5.05211 Max. :5.57131
glmtheta rlmtheta lqstheta gamtheta
Min. :0.05811 Min. :0.05926 Min. :0.04708 Min. :0.05811
1st Qu.:0.52229 1st Qu.:0.51812 1st Qu.:0.54834 1st Qu.:0.52229
Median :0.82511 Median :0.82046 Median :0.88410 Median :0.82511
Mean :1.00510 Mean :1.00248 Mean :1.08024 Mean :1.00510
3rd Qu.:1.26832 3rd Qu.:1.26736 3rd Qu.:1.40810 3rd Qu.:1.26832
Max. :5.38855 Max. :5.38743 Max. :5.53397 Max. :5.38855
quantregtheta glmboosttheta
Min. :0.0580 Min. :0.0581
1st Qu.:0.5366 1st Qu.:0.5223
Median :0.8469 Median :0.8251
Mean :1.0262 Mean :1.0051
3rd Qu.:1.2965 3rd Qu.:1.2683
Max. :5.2947 Max. :5.3886
MASE - OTHER -----
series period theta glmnbtheta
Min. :2830 Min. :99 Min. : 0.220 Min. : 0.2614
1st Qu.:2873 1st Qu.:99 1st Qu.: 1.024 1st Qu.: 1.5711
Median :2916 Median :99 Median : 1.896 Median : 2.7695
Mean :2916 Mean :99 Mean : 2.271 Mean : 3.0931
3rd Qu.:2960 3rd Qu.:99 3rd Qu.: 2.967 3rd Qu.: 4.2789
Max. :3003 Max. :99 Max. :10.151 Max. :11.0702
glmtheta rlmtheta lqstheta gamtheta
Min. :0.1891 Min. :0.1909 Min. :0.1219 Min. :0.1891
1st Qu.:0.8943 1st Qu.:0.9288 1st Qu.:0.9450 1st Qu.:0.8943
Median :1.6009 Median :1.6086 Median :1.7089 Median :1.6009
Mean :1.9444 Mean :1.9549 Mean :2.0180 Mean :1.9444
3rd Qu.:2.4451 3rd Qu.:2.4248 3rd Qu.:2.4961 3rd Qu.:2.4451
Max. :7.3144 Max. :7.3169 Max. :7.7471 Max. :7.3144
quantregtheta glmboosttheta
Min. :0.2312 Min. :0.1890
1st Qu.:0.9104 1st Qu.:0.8942
Median :1.5795 Median :1.6009
Mean :1.9533 Mean :1.9444
3rd Qu.:2.4042 3rd Qu.:2.4451
Max. :7.3200 Max. :7.3145
RMSE - YEARLY -----
series period theta glmnbtheta
Min. : 1.0 Min. :1 Min. : 8.301 Min. : 14.41
1st Qu.:161.5 1st Qu.:1 1st Qu.: 375.740 1st Qu.: 443.31
Median :322.0 Median :1 Median : 743.996 Median : 803.55
Mean :322.5 Mean :1 Mean : 1108.824 Mean : 1185.30
3rd Qu.:484.5 3rd Qu.:1 3rd Qu.: 1415.724 3rd Qu.: 1591.94
Max. :645.0 Max. :1 Max. :14639.170 Max. :12502.86
glmtheta rlmtheta lqstheta gamtheta
Min. : 1.539 Min. : 23.92 Min. : 11.06 Min. : 1.539
1st Qu.: 342.056 1st Qu.: 358.53 1st Qu.: 380.97 1st Qu.: 342.056
Median : 816.486 Median : 789.31 Median : 898.02 Median : 816.486
Mean : 1310.461 Mean : 1308.33 Mean : 1408.77 Mean : 1310.461
3rd Qu.: 1718.193 3rd Qu.: 1707.00 3rd Qu.: 1777.14 3rd Qu.: 1718.193
Max. :29687.208 Max. :29687.21 Max. :17861.89 Max. :29687.208
quantregtheta glmboosttheta
Min. : 20.97 Min. : 1.539
1st Qu.: 359.88 1st Qu.: 342.067
Median : 818.52 Median : 816.484
Mean : 1320.32 Mean : 1310.448
3rd Qu.: 1758.11 3rd Qu.: 1718.179
Max. :29005.49 Max. :29686.714
RMSE - QUARTERLY -----
series period theta glmnbtheta
Min. : 646.0 Min. :4 Min. : 8.075 Min. : 10.3
1st Qu.: 834.5 1st Qu.:4 1st Qu.: 178.873 1st Qu.: 213.8
Median :1023.0 Median :4 Median : 356.054 Median : 413.5
Mean :1023.1 Mean :4 Mean : 568.246 Mean : 619.8
3rd Qu.:1211.5 3rd Qu.:4 3rd Qu.: 638.098 3rd Qu.: 712.3
Max. :1401.0 Max. :4 Max. :7592.100 Max. :8070.6
glmtheta rlmtheta lqstheta gamtheta
Min. : 20.5 Min. : 20.07 Min. : 14.76 Min. : 20.5
1st Qu.: 214.7 1st Qu.: 214.43 1st Qu.: 226.35 1st Qu.: 214.7
Median : 416.0 Median : 414.46 Median : 456.80 Median : 416.0
Mean : 688.9 Mean : 688.75 Mean : 739.78 Mean : 688.9
3rd Qu.: 832.7 3rd Qu.: 843.02 3rd Qu.: 919.21 3rd Qu.: 832.7
Max. :8620.4 Max. :8763.45 Max. :6697.08 Max. :8620.4
quantregtheta glmboosttheta
Min. : 19.05 Min. : 20.5
1st Qu.: 214.37 1st Qu.: 214.7
Median : 430.28 Median : 416.0
Mean : 703.29 Mean : 688.9
3rd Qu.: 842.21 3rd Qu.: 832.7
Max. :10508.84 Max. :8620.4
RMSE - MONTHLY -----
series period theta glmnbtheta
Min. :1402 Min. :12 Min. : 16.07 Min. : 13.93
1st Qu.:1758 1st Qu.:12 1st Qu.: 255.31 1st Qu.: 283.97
Median :2115 Median :12 Median : 517.13 Median : 565.79
Mean :2115 Mean :12 Mean : 754.26 Mean : 827.42
3rd Qu.:2472 3rd Qu.:12 3rd Qu.: 944.13 3rd Qu.: 1029.99
Max. :2829 Max. :12 Max. :12302.42 Max. :11985.62
glmtheta rlmtheta lqstheta gamtheta
Min. : 17.31 Min. : 17.28 Min. : 14.31 Min. : 17.31
1st Qu.: 265.61 1st Qu.: 263.04 1st Qu.: 280.40 1st Qu.: 265.61
Median : 589.47 Median : 593.14 Median : 594.36 Median : 589.47
Mean : 890.13 Mean : 887.46 Mean : 972.64 Mean : 890.13
3rd Qu.: 1124.05 3rd Qu.: 1110.66 3rd Qu.: 1250.92 3rd Qu.: 1124.05
Max. :13455.93 Max. :13538.13 Max. :11462.02 Max. :13455.93
quantregtheta glmboosttheta
Min. : 15.6 Min. : 17.31
1st Qu.: 269.1 1st Qu.: 265.61
Median : 583.2 Median : 589.47
Mean : 914.6 Mean : 890.13
3rd Qu.: 1161.2 3rd Qu.: 1124.04
Max. :13634.0 Max. :13455.88
RMSE - OTHER -----
series period theta glmnbtheta
Min. :2830 Min. :99 Min. : 8.218 Min. : 9.938
1st Qu.:2873 1st Qu.:99 1st Qu.: 61.988 1st Qu.: 100.167
Median :2916 Median :99 Median : 120.836 Median : 182.118
Mean :2916 Mean :99 Mean : 242.133 Mean : 309.795
3rd Qu.:2960 3rd Qu.:99 3rd Qu.: 279.193 3rd Qu.: 340.758
Max. :3003 Max. :99 Max. :3453.536 Max. :3129.978
glmtheta rlmtheta lqstheta gamtheta
Min. : 6.652 Min. : 6.711 Min. : 4.814 Min. : 6.652
1st Qu.: 51.985 1st Qu.: 55.197 1st Qu.: 54.531 1st Qu.: 51.985
Median : 106.711 Median : 105.570 Median : 102.020 Median : 106.711
Mean : 249.562 Mean : 250.666 Mean : 256.004 Mean : 249.562
3rd Qu.: 223.361 3rd Qu.: 223.213 3rd Qu.: 238.648 3rd Qu.: 223.361
Max. :4079.840 Max. :4065.917 Max. :3765.921 Max. :4079.840
quantregtheta glmboosttheta
Min. : 8.082 Min. : 6.651
1st Qu.: 55.418 1st Qu.: 51.986
Median : 103.246 Median : 106.712
Mean : 253.318 Mean : 249.559
3rd Qu.: 228.469 3rd Qu.: 223.364
Max. :4230.672 Max. :4079.814
COVERAGE - YEARLY -----
series period theta glmnbtheta glmtheta
Min. : 1.0 Min. :1 Min. : 0.00 Min. : 0.00 Min. : 0.00
1st Qu.:161.5 1st Qu.:1 1st Qu.: 83.33 1st Qu.: 33.33 1st Qu.: 33.33
Median :322.0 Median :1 Median :100.00 Median : 83.33 Median : 83.33
Mean :322.5 Mean :1 Mean : 84.32 Mean : 68.56 Mean : 66.95
3rd Qu.:484.5 3rd Qu.:1 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :645.0 Max. :1 Max. :100.00 Max. :100.00 Max. :100.00
rlmtheta lqstheta gamtheta quantregtheta
Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.00
1st Qu.: 33.33 1st Qu.: 33.33 1st Qu.: 33.33 1st Qu.: 33.33
Median : 66.67 Median : 66.67 Median : 83.33 Median : 83.33
Mean : 66.38 Mean : 64.23 Mean : 66.95 Mean : 66.17
3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :100.00 Max. :100.00 Max. :100.00 Max. :100.00
glmboosttheta
Min. : 0.00
1st Qu.: 33.33
Median : 83.33
Mean : 66.95
3rd Qu.:100.00
Max. :100.00
COVERAGE - QUARTERLY -----
series period theta glmnbtheta
Min. : 646.0 Min. :4 Min. : 0.00 Min. : 0.00
1st Qu.: 834.5 1st Qu.:4 1st Qu.: 87.50 1st Qu.: 75.00
Median :1023.0 Median :4 Median :100.00 Median :100.00
Mean :1023.1 Mean :4 Mean : 87.22 Mean : 83.77
3rd Qu.:1211.5 3rd Qu.:4 3rd Qu.:100.00 3rd Qu.:100.00
Max. :1401.0 Max. :4 Max. :100.00 Max. :100.00
glmtheta rlmtheta lqstheta gamtheta
Min. : 0.00 Min. : 0.00 Min. : 0.0 Min. : 0.00
1st Qu.: 56.25 1st Qu.: 50.00 1st Qu.: 50.0 1st Qu.: 56.25
Median : 87.50 Median : 87.50 Median : 87.5 Median : 87.50
Mean : 75.30 Mean : 75.26 Mean : 74.5 Mean : 75.30
3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.0 3rd Qu.:100.00
Max. :100.00 Max. :100.00 Max. :100.0 Max. :100.00
quantregtheta glmboosttheta
Min. : 0.0 Min. : 0.00
1st Qu.: 50.0 1st Qu.: 56.25
Median : 87.5 Median : 87.50
Mean : 74.4 Mean : 75.30
3rd Qu.:100.0 3rd Qu.:100.00
Max. :100.0 Max. :100.00
COVERAGE - MONTHLY -----
series period theta glmnbtheta
Min. :1402 Min. :12 Min. : 0.00 Min. : 5.556
1st Qu.:1758 1st Qu.:12 1st Qu.: 88.89 1st Qu.: 77.778
Median :2115 Median :12 Median :100.00 Median : 94.444
Mean :2115 Mean :12 Mean : 89.84 Mean : 86.101
3rd Qu.:2472 3rd Qu.:12 3rd Qu.:100.00 3rd Qu.:100.000
Max. :2829 Max. :12 Max. :100.00 Max. :100.000
glmtheta rlmtheta lqstheta gamtheta
Min. : 5.556 Min. : 5.556 Min. : 0.00 Min. : 5.556
1st Qu.: 77.778 1st Qu.: 77.778 1st Qu.: 72.22 1st Qu.: 77.778
Median : 94.444 Median : 94.444 Median : 94.44 Median : 94.444
Mean : 86.183 Mean : 86.082 Mean : 83.09 Mean : 86.183
3rd Qu.:100.000 3rd Qu.:100.000 3rd Qu.:100.00 3rd Qu.:100.000
Max. :100.000 Max. :100.000 Max. :100.00 Max. :100.000
quantregtheta glmboosttheta
Min. : 5.556 Min. : 5.556
1st Qu.: 77.778 1st Qu.: 77.778
Median : 94.444 Median : 94.444
Mean : 85.167 Mean : 86.183
3rd Qu.:100.000 3rd Qu.:100.000
Max. :100.000 Max. :100.000
COVERAGE - OTHER -----
series period theta glmnbtheta glmtheta
Min. :2830 Min. :99 Min. : 0.00 Min. : 12.50 Min. : 12.50
1st Qu.:2873 1st Qu.:99 1st Qu.:100.00 1st Qu.:100.00 1st Qu.:100.00
Median :2916 Median :99 Median :100.00 Median :100.00 Median :100.00
Mean :2916 Mean :99 Mean : 93.68 Mean : 95.19 Mean : 91.31
3rd Qu.:2960 3rd Qu.:99 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :3003 Max. :99 Max. :100.00 Max. :100.00 Max. :100.00
rlmtheta lqstheta gamtheta quantregtheta
Min. : 12.50 Min. : 12.50 Min. : 12.50 Min. : 12.50
1st Qu.:100.00 1st Qu.:100.00 1st Qu.:100.00 1st Qu.:100.00
Median :100.00 Median :100.00 Median :100.00 Median :100.00
Mean : 91.24 Mean : 91.24 Mean : 91.31 Mean : 90.73
3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :100.00 Max. :100.00 Max. :100.00 Max. :100.00
glmboosttheta
Min. : 12.50
1st Qu.:100.00
Median :100.00
Mean : 91.31
3rd Qu.:100.00
Max. :100.00
WINKLER - YEARLY -----
series period theta glmnbtheta
Min. : 1.0 Min. :1 Min. : 149.8 Min. : 135.9
1st Qu.:161.5 1st Qu.:1 1st Qu.: 2088.6 1st Qu.: 2836.9
Median :322.0 Median :1 Median : 3965.6 Median : 5667.1
Mean :322.5 Mean :1 Mean : 9461.6 Mean : 14531.6
3rd Qu.:484.5 3rd Qu.:1 3rd Qu.: 8123.2 3rd Qu.: 16657.3
Max. :645.0 Max. :1 Max. :146923.2 Max. :150928.8
glmtheta rlmtheta lqstheta gamtheta
Min. : 142.9 Min. : 148.2 Min. : 161.8 Min. : 142.9
1st Qu.: 2757.0 1st Qu.: 2773.6 1st Qu.: 2996.9 1st Qu.: 2757.0
Median : 6158.4 Median : 6234.4 Median : 7113.8 Median : 6158.4
Mean : 17825.6 Mean : 17968.2 Mean : 21628.9 Mean : 17825.6
3rd Qu.: 19483.3 3rd Qu.: 20031.8 3rd Qu.: 24644.4 3rd Qu.: 19483.3
Max. :652521.2 Max. :652521.2 Max. :319696.8 Max. :652521.2
quantregtheta glmboosttheta
Min. : 147.1 Min. : 142.9
1st Qu.: 2785.1 1st Qu.: 2756.9
Median : 6591.8 Median : 6158.2
Mean : 18437.3 Mean : 17825.4
3rd Qu.: 20114.9 3rd Qu.: 19484.5
Max. :629977.7 Max. :652503.7
WINKLER - QUARTERLY -----
series period theta glmnbtheta
Min. : 646.0 Min. :4 Min. : 181.7 Min. : 201.7
1st Qu.: 834.5 1st Qu.:4 1st Qu.: 1043.9 1st Qu.: 1407.0
Median :1023.0 Median :4 Median : 1901.2 Median : 2517.0
Mean :1023.1 Mean :4 Mean : 4710.3 Mean : 5593.2
3rd Qu.:1211.5 3rd Qu.:4 3rd Qu.: 3829.0 3rd Qu.: 4658.6
Max. :1401.0 Max. :4 Max. :189229.7 Max. :181194.4
glmtheta rlmtheta lqstheta gamtheta
Min. : 150.4 Min. : 150.4 Min. : 141.7 Min. : 150.4
1st Qu.: 1375.3 1st Qu.: 1394.0 1st Qu.: 1433.3 1st Qu.: 1375.3
Median : 2760.6 Median : 2792.3 Median : 2965.4 Median : 2760.6
Mean : 6777.3 Mean : 6814.5 Mean : 7616.0 Mean : 6777.3
3rd Qu.: 6271.5 3rd Qu.: 6441.3 3rd Qu.: 7976.4 3rd Qu.: 6271.5
Max. :170507.1 Max. :171700.5 Max. :162725.5 Max. :170507.1
quantregtheta glmboosttheta
Min. : 142.5 Min. : 150.4
1st Qu.: 1419.5 1st Qu.: 1375.4
Median : 2790.6 Median : 2760.4
Mean : 7105.7 Mean : 6777.1
3rd Qu.: 6900.2 3rd Qu.: 6270.8
Max. :176740.5 Max. :170507.4
WINKLER - MONTHLY -----
series period theta glmnbtheta
Min. :1402 Min. :12 Min. : 123.1 Min. : 193.8
1st Qu.:1758 1st Qu.:12 1st Qu.: 1444.9 1st Qu.: 1650.2
Median :2115 Median :12 Median : 3154.7 Median : 3169.2
Mean :2115 Mean :12 Mean : 5071.6 Mean : 5788.5
3rd Qu.:2472 3rd Qu.:12 3rd Qu.: 5428.2 3rd Qu.: 5978.7
Max. :2829 Max. :12 Max. :129135.8 Max. :160190.5
glmtheta rlmtheta lqstheta gamtheta
Min. : 147.1 Min. : 147.1 Min. : 110.5 Min. : 147.1
1st Qu.: 1637.9 1st Qu.: 1645.1 1st Qu.: 1721.2 1st Qu.: 1637.9
Median : 3455.6 Median : 3458.1 Median : 3610.6 Median : 3455.6
Mean : 6514.0 Mean : 6487.6 Mean : 8153.8 Mean : 6514.0
3rd Qu.: 6644.7 3rd Qu.: 6635.1 3rd Qu.: 7806.3 3rd Qu.: 6644.7
Max. :177738.4 Max. :177797.3 Max. :271625.2 Max. :177738.4
quantregtheta glmboosttheta
Min. : 129.4 Min. : 147.1
1st Qu.: 1653.2 1st Qu.: 1637.9
Median : 3429.8 Median : 3455.6
Mean : 6845.1 Mean : 6513.9
3rd Qu.: 7183.7 3rd Qu.: 6644.5
Max. :172824.8 Max. :177737.8
WINKLER - OTHER -----
series period theta glmnbtheta
Min. :2830 Min. :99 Min. : 215.8 Min. : 193.7
1st Qu.:2873 1st Qu.:99 1st Qu.: 416.6 1st Qu.: 712.6
Median :2916 Median :99 Median : 661.8 Median : 1229.0
Mean :2916 Mean :99 Mean : 1375.9 Mean : 2313.1
3rd Qu.:2960 3rd Qu.:99 3rd Qu.: 1320.4 3rd Qu.: 2185.5
Max. :3003 Max. :99 Max. :13205.7 Max. :29189.4
glmtheta rlmtheta lqstheta gamtheta
Min. : 146.3 Min. : 147.8 Min. : 133.5 Min. : 146.3
1st Qu.: 448.3 1st Qu.: 458.1 1st Qu.: 515.1 1st Qu.: 448.3
Median : 895.8 Median : 885.8 Median : 875.2 Median : 895.8
Mean : 2256.3 Mean : 2261.6 Mean : 2025.5 Mean : 2256.3
3rd Qu.: 1755.3 3rd Qu.: 1888.6 3rd Qu.: 1762.8 3rd Qu.: 1755.3
Max. :33854.7 Max. :33975.6 Max. :38790.9 Max. :33854.7
quantregtheta glmboosttheta
Min. : 149.7 Min. : 146.2
1st Qu.: 461.1 1st Qu.: 448.3
Median : 896.4 Median : 895.8
Mean : 2309.8 Mean : 2256.3
3rd Qu.: 1855.2 3rd Qu.: 1755.3
Max. :33681.9 Max. :33854.8
1 - 3 M1
%%R
# Load necessary libraries
library(doSNOW)
library(tcltk)
require(Mcomp)
nseries <- length(M1)
# Set up parallel backend
cl <- makeSOCKcluster(parallel::detectCores()) # Use 2 cores (adjust as needed)
registerDoSNOW(cl)
# Define progress bar
pb <- txtProgressBar(min = 0, max = nseries, style = 3)
# Progress function
progress <- function(n) setTxtProgressBar(pb, n)
# Options for progress tracking
opts <- list(progress = progress)
pb <- utils::txtProgressBar(min=0, max=nseries, style = 3)
(M1results <- foreach::foreach(i = 1:nseries, .combine = rbind,
.errorhandling = "remove",
.verbose=FALSE,
.options.snow = opts)%dopar%{
x <- Mcomp::M1[[i]]$x
xx <- Mcomp::M1[[i]]$xx
h <- length(xx)
obj <- suppressWarnings(thetaf(x, h=h, level=95))
res1 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=MASS::glm.nb,
attention = TRUE))
res2 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=stats::glm,
attention = TRUE))
res3 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=MASS::rlm,
attention = TRUE))
res4 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=MASS::lqs,
attention = TRUE))
res5 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=gam::gam,
attention = TRUE))
res6 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=quantreg::rq,
attention = TRUE))
res7 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=mboost::glmboost,
attention = TRUE))
res8 <- accuracy(obj, xx)
period <- switch (Mcomp::M1[[i]]$period,
"YEARLY" = 1,
"QUARTERLY" = 4,
"MONTHLY" = 12
)
utils::setTxtProgressBar(pb, i)
res <- cbind(i, period,
res1, res2,
res3, res4,
res5, res6,
res7, res8)
colnames(res) <- c("series", "period", "theta", "glmnbtheta",
"glmtheta", "rlmtheta", "lqstheta",
"gamtheta", "quantregtheta", "glmboosttheta")
res
})
close(pb)
M1results <- data.frame(M1results)
print(head(M1results))
print(tail(M1results))
print(dim(M1results))
base::saveRDS(M1results, "results_M1.rds")
print(summary(subset(M1results[grep("mase", rownames(M1results)), ], period==1)))
print(summary(subset(M1results[grep("mase", rownames(M1results)), ], period==4)))
print(summary(subset(M1results[grep("mase", rownames(M1results)), ], period==12)))
print(summary(subset(M1results[grep("mae", rownames(M1results)), ], period==1)))
print(summary(subset(M1results[grep("mae", rownames(M1results)), ], period==4)))
print(summary(subset(M1results[grep("mae", rownames(M1results)), ], period==12)))
print(summary(subset(M1results[grep("rmse", rownames(M1results)), ], period==1)))
print(summary(subset(M1results[grep("rmse", rownames(M1results)), ], period==4)))
print(summary(subset(M1results[grep("rmse", rownames(M1results)), ], period==12)))
from IPython.display import FileLink
# Create a download link for the file
FileLink('results_M1.rds')
%%R
results_M1 <- readRDS("results_M1.rds")
cat("\n\n MASE - YEARLY ----- \n\n")
print(summary(subset(results_M1[grep("mase", rownames(results_M1)), ], period==1)))
cat("\n\n MASE - QUARTERLY ----- \n\n")
print(summary(subset(results_M1[grep("mase", rownames(results_M1)), ], period==4)))
cat("\n\n MASE - MONTHLY ----- \n\n")
print(summary(subset(results_M1[grep("mase", rownames(results_M1)), ], period==12)))
cat("\n\n RMSE - YEARLY ----- \n\n")
print(summary(subset(results_M1[grep("rmse", rownames(results_M1)), ], period==1)))
cat("\n\n RMSE - QUARTERLY ----- \n\n")
print(summary(subset(results_M1[grep("rmse", rownames(results_M1)), ], period==4)))
cat("\n\n RMSE - MONTHLY ----- \n\n")
print(summary(subset(results_M1[grep("rmse", rownames(results_M1)), ], period==12)))
cat("\n\n COVERAGE - YEARLY ----- \n\n")
print(summary(subset(results_M1[grep("coverage", rownames(results_M1)), ], period==1)))
cat("\n\n COVERAGE - QUARTERLY ----- \n\n")
print(summary(subset(results_M1[grep("coverage", rownames(results_M1)), ], period==4)))
cat("\n\n COVERAGE - MONTHLY ----- \n\n")
print(summary(subset(results_M1[grep("coverage", rownames(results_M1)), ], period==12)))
cat("\n\n WINKLER - YEARLY ----- \n\n")
print(summary(subset(results_M1[grep("winkler", rownames(results_M1)), ], period==1)))
cat("\n\n WINKLER - QUARTERLY ----- \n\n")
print(summary(subset(results_M1[grep("winkler", rownames(results_M1)), ], period==4)))
cat("\n\n WINKLER - MONTHLY ----- \n\n")
print(summary(subset(results_M1[grep("winkler", rownames(results_M1)), ], period==12)))
MASE - YEARLY -----
series period theta glmnbtheta
Min. : 1.00 Min. :1 Min. : 0.339 Min. : 0.2002
1st Qu.: 45.00 1st Qu.:1 1st Qu.: 1.590 1st Qu.: 1.7242
Median : 89.00 Median :1 Median : 3.030 Median : 3.5463
Mean : 89.81 Mean :1 Mean : 4.189 Mean : 4.8790
3rd Qu.:135.00 3rd Qu.:1 3rd Qu.: 5.488 3rd Qu.: 5.9936
Max. :181.00 Max. :1 Max. :53.736 Max. :54.4274
glmtheta rlmtheta lqstheta gamtheta
Min. : 0.2284 Min. : 0.1634 Min. : 0.1689 Min. : 0.2284
1st Qu.: 1.2867 1st Qu.: 1.2723 1st Qu.: 1.1949 1st Qu.: 1.2867
Median : 2.3605 Median : 2.3112 Median : 2.4514 Median : 2.3605
Mean : 3.3171 Mean : 3.3137 Mean : 3.4067 Mean : 3.3171
3rd Qu.: 3.9079 3rd Qu.: 3.7760 3rd Qu.: 3.9569 3rd Qu.: 3.9079
Max. :50.3795 Max. :51.5947 Max. :54.2701 Max. :50.3795
quantregtheta glmboosttheta
Min. : 0.1689 Min. : 0.2283
1st Qu.: 1.2799 1st Qu.: 1.2867
Median : 2.4032 Median : 2.3605
Mean : 3.3675 Mean : 3.3171
3rd Qu.: 3.8951 3rd Qu.: 3.9080
Max. :52.2621 Max. :50.3796
MASE - QUARTERLY -----
series period theta glmnbtheta
Min. :182.0 Min. :4 Min. : 0.06685 Min. : 0.2688
1st Qu.:231.0 1st Qu.:4 1st Qu.: 0.76595 1st Qu.: 0.9400
Median :282.0 Median :4 Median : 1.28289 Median : 1.3712
Mean :281.8 Mean :4 Mean : 1.72391 Mean : 1.8599
3rd Qu.:331.0 3rd Qu.:4 3rd Qu.: 1.89038 3rd Qu.: 2.0453
Max. :384.0 Max. :4 Max. :13.56309 Max. :13.8709
glmtheta rlmtheta lqstheta gamtheta
Min. : 0.1237 Min. : 0.1260 Min. : 0.1906 Min. : 0.1237
1st Qu.: 0.8431 1st Qu.: 0.8498 1st Qu.: 0.8649 1st Qu.: 0.8431
Median : 1.3482 Median : 1.3615 Median : 1.4702 Median : 1.3482
Mean : 1.8028 Mean : 1.8130 Mean : 1.9865 Mean : 1.8028
3rd Qu.: 2.1977 3rd Qu.: 2.2306 3rd Qu.: 2.3770 3rd Qu.: 2.1977
Max. :12.8633 Max. :12.4328 Max. :12.1660 Max. :12.8633
quantregtheta glmboosttheta
Min. : 0.1329 Min. : 0.1237
1st Qu.: 0.8626 1st Qu.: 0.8431
Median : 1.4129 Median : 1.3482
Mean : 1.8693 Mean : 1.8028
3rd Qu.: 2.3317 3rd Qu.: 2.1977
Max. :12.5140 Max. :12.8633
MASE - MONTHLY -----
series period theta glmnbtheta
Min. : 385 Min. :12 Min. :0.08899 Min. :0.03055
1st Qu.: 539 1st Qu.:12 1st Qu.:0.61489 1st Qu.:0.72027
Median : 693 Median :12 Median :0.88503 Median :1.09843
Mean : 693 Mean :12 Mean :1.09097 Mean :1.30865
3rd Qu.: 847 3rd Qu.:12 3rd Qu.:1.31576 3rd Qu.:1.59016
Max. :1001 Max. :12 Max. :5.66195 Max. :6.11137
glmtheta rlmtheta lqstheta gamtheta
Min. :0.07755 Min. :0.06842 Min. :0.007376 Min. :0.07755
1st Qu.:0.74019 1st Qu.:0.73040 1st Qu.:0.768420 1st Qu.:0.74019
Median :1.17541 Median :1.16993 Median :1.230610 Median :1.17541
Mean :1.42698 Mean :1.40937 Mean :1.497829 Mean :1.42698
3rd Qu.:1.81082 3rd Qu.:1.79974 3rd Qu.:1.888202 3rd Qu.:1.81082
Max. :7.22650 Max. :6.92929 Max. :6.583633 Max. :7.22650
quantregtheta glmboosttheta
Min. :0.008536 Min. :0.07755
1st Qu.:0.741870 1st Qu.:0.74019
Median :1.170760 Median :1.17541
Mean :1.427073 Mean :1.42697
3rd Qu.:1.783612 3rd Qu.:1.81080
Max. :6.317748 Max. :7.22647
RMSE - YEARLY -----
series period theta glmnbtheta
Min. : 1.00 Min. :1 Min. : 0 Min. : 0
1st Qu.: 45.00 1st Qu.:1 1st Qu.: 17 1st Qu.: 22
Median : 89.00 Median :1 Median : 347 Median : 416
Mean : 89.81 Mean :1 Mean : 175332 Mean : 197775
3rd Qu.:135.00 3rd Qu.:1 3rd Qu.: 8364 3rd Qu.: 10104
Max. :181.00 Max. :1 Max. :15662440 Max. :16475297
glmtheta rlmtheta lqstheta gamtheta
Min. : 0 Min. : 0 Min. : 0 Min. : 0
1st Qu.: 10 1st Qu.: 12 1st Qu.: 13 1st Qu.: 10
Median : 213 Median : 213 Median : 205 Median : 213
Mean : 157517 Mean : 157542 Mean : 175530 Mean : 157517
3rd Qu.: 7067 3rd Qu.: 7097 3rd Qu.: 7832 3rd Qu.: 7067
Max. :13016053 Max. :12958792 Max. :13326865 Max. :13016053
quantregtheta glmboosttheta
Min. : 0 Min. : 0
1st Qu.: 11 1st Qu.: 10
Median : 212 Median : 213
Mean : 159385 Mean : 157517
3rd Qu.: 6784 3rd Qu.: 7067
Max. :13021534 Max. :13016145
RMSE - QUARTERLY -----
series period theta glmnbtheta
Min. :182.0 Min. :4 Min. : 0.01 Min. : 0.02
1st Qu.:231.0 1st Qu.:4 1st Qu.: 7.38 1st Qu.: 7.50
Median :282.0 Median :4 Median : 24.01 Median : 24.87
Mean :281.8 Mean :4 Mean : 2351.98 Mean : 2584.09
3rd Qu.:331.0 3rd Qu.:4 3rd Qu.: 253.31 3rd Qu.: 252.57
Max. :384.0 Max. :4 Max. :94218.49 Max. :102660.28
glmtheta rlmtheta lqstheta
Min. : 0.02 Min. : 0.02 Min. : 0.01
1st Qu.: 9.86 1st Qu.: 9.38 1st Qu.: 9.39
Median : 29.71 Median : 29.23 Median : 30.34
Mean : 2817.96 Mean : 2845.29 Mean : 3232.61
3rd Qu.: 200.88 3rd Qu.: 208.27 3rd Qu.: 212.49
Max. :129950.26 Max. :127877.25 Max. :201583.89
gamtheta quantregtheta glmboosttheta
Min. : 0.02 Min. : 0.02 Min. : 0.02
1st Qu.: 9.86 1st Qu.: 9.53 1st Qu.: 9.86
Median : 29.71 Median : 28.72 Median : 29.71
Mean : 2817.96 Mean : 2853.71 Mean : 2817.95
3rd Qu.: 200.88 3rd Qu.: 240.04 3rd Qu.: 200.88
Max. :129950.26 Max. :115511.98 Max. :129949.34
RMSE - MONTHLY -----
series period theta glmnbtheta
Min. : 385 Min. :12 Min. : 0.0 Min. : 0.0
1st Qu.: 539 1st Qu.:12 1st Qu.: 7.8 1st Qu.: 8.7
Median : 693 Median :12 Median : 46.4 Median : 50.8
Mean : 693 Mean :12 Mean : 2564.9 Mean : 2532.1
3rd Qu.: 847 3rd Qu.:12 3rd Qu.: 496.2 3rd Qu.: 594.1
Max. :1001 Max. :12 Max. :686105.3 Max. :521915.2
glmtheta rlmtheta lqstheta gamtheta
Min. : 0.0 Min. : 0.0 Min. : 0.0 Min. : 0.0
1st Qu.: 9.5 1st Qu.: 9.7 1st Qu.: 10.5 1st Qu.: 9.5
Median : 52.1 Median : 50.8 Median : 56.8 Median : 52.1
Mean : 3548.7 Mean : 3449.2 Mean : 3953.3 Mean : 3548.7
3rd Qu.: 648.8 3rd Qu.: 641.3 3rd Qu.: 643.8 3rd Qu.: 648.8
Max. :969404.8 Max. :959390.3 Max. :1310439.1 Max. :969404.8
quantregtheta glmboosttheta
Min. : 0.0 Min. : 0.0
1st Qu.: 10.1 1st Qu.: 9.5
Median : 53.6 Median : 52.1
Mean : 3221.8 Mean : 3548.6
3rd Qu.: 623.1 3rd Qu.: 648.8
Max. :854678.2 Max. :969391.4
COVERAGE - YEARLY -----
series period theta glmnbtheta
Min. : 1.00 Min. :1 Min. : 0.00 Min. : 0.00
1st Qu.: 45.00 1st Qu.:1 1st Qu.: 33.33 1st Qu.: 16.67
Median : 89.00 Median :1 Median : 83.33 Median : 50.00
Mean : 89.81 Mean :1 Mean : 69.02 Mean : 51.22
3rd Qu.:135.00 3rd Qu.:1 3rd Qu.:100.00 3rd Qu.: 83.33
Max. :181.00 Max. :1 Max. :100.00 Max. :100.00
glmtheta rlmtheta lqstheta gamtheta
Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.00
1st Qu.: 33.33 1st Qu.: 33.33 1st Qu.: 16.67 1st Qu.: 33.33
Median : 50.00 Median : 50.00 Median : 50.00 Median : 50.00
Mean : 56.40 Mean : 55.18 Mean : 57.06 Mean : 56.40
3rd Qu.: 83.33 3rd Qu.: 83.33 3rd Qu.:100.00 3rd Qu.: 83.33
Max. :100.00 Max. :100.00 Max. :100.00 Max. :100.00
quantregtheta glmboosttheta
Min. : 0.00 Min. : 0.00
1st Qu.: 16.67 1st Qu.: 33.33
Median : 50.00 Median : 50.00
Mean : 54.90 Mean : 56.40
3rd Qu.:100.00 3rd Qu.: 83.33
Max. :100.00 Max. :100.00
COVERAGE - QUARTERLY -----
series period theta glmnbtheta glmtheta
Min. :182.0 Min. :4 Min. : 0.00 Min. : 0.00 Min. : 0.00
1st Qu.:231.0 1st Qu.:4 1st Qu.: 62.50 1st Qu.: 62.50 1st Qu.: 37.50
Median :282.0 Median :4 Median : 87.50 Median : 87.50 Median : 75.00
Mean :281.8 Mean :4 Mean : 74.24 Mean : 77.09 Mean : 67.83
3rd Qu.:331.0 3rd Qu.:4 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :384.0 Max. :4 Max. :100.00 Max. :100.00 Max. :100.00
rlmtheta lqstheta gamtheta quantregtheta
Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.00
1st Qu.: 37.50 1st Qu.: 37.50 1st Qu.: 37.50 1st Qu.: 37.50
Median : 75.00 Median : 75.00 Median : 75.00 Median : 75.00
Mean : 66.94 Mean : 64.97 Mean : 67.83 Mean : 66.31
3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :100.00 Max. :100.00 Max. :100.00 Max. :100.00
glmboosttheta
Min. : 0.00
1st Qu.: 37.50
Median : 75.00
Mean : 67.83
3rd Qu.:100.00
Max. :100.00
COVERAGE - MONTHLY -----
series period theta glmnbtheta
Min. : 385 Min. :12 Min. : 0.00 Min. : 5.556
1st Qu.: 539 1st Qu.:12 1st Qu.: 83.33 1st Qu.: 66.667
Median : 693 Median :12 Median : 94.44 Median : 88.889
Mean : 693 Mean :12 Mean : 86.50 Mean : 80.146
3rd Qu.: 847 3rd Qu.:12 3rd Qu.:100.00 3rd Qu.:100.000
Max. :1001 Max. :12 Max. :100.00 Max. :100.000
glmtheta rlmtheta lqstheta gamtheta
Min. : 5.556 Min. : 0.00 Min. : 0.00 Min. : 5.556
1st Qu.: 61.111 1st Qu.: 61.11 1st Qu.: 61.11 1st Qu.: 61.111
Median : 83.333 Median : 83.33 Median : 83.33 Median : 83.333
Mean : 77.220 Mean : 77.45 Mean : 76.24 Mean : 77.220
3rd Qu.:100.000 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.000
Max. :100.000 Max. :100.00 Max. :100.00 Max. :100.000
quantregtheta glmboosttheta
Min. : 0.00 Min. : 5.556
1st Qu.: 66.67 1st Qu.: 61.111
Median : 88.89 Median : 83.333
Mean : 77.20 Mean : 77.220
3rd Qu.:100.00 3rd Qu.:100.000
Max. :100.00 Max. :100.000
WINKLER - YEARLY -----
series period theta glmnbtheta
Min. : 1.00 Min. :1 Min. : 0 Min. : 0
1st Qu.: 45.00 1st Qu.:1 1st Qu.: 94 1st Qu.: 138
Median : 89.00 Median :1 Median : 2524 Median : 4572
Mean : 89.81 Mean :1 Mean : 2825772 Mean : 2625047
3rd Qu.:135.00 3rd Qu.:1 3rd Qu.: 52463 3rd Qu.: 103077
Max. :181.00 Max. :1 Max. :363721233 Max. :292512406
glmtheta rlmtheta lqstheta
Min. : 1 Min. : 1 Min. : 0
1st Qu.: 80 1st Qu.: 84 1st Qu.: 118
Median : 2545 Median : 2545 Median : 1988
Mean : 2478384 Mean : 2449829 Mean : 2966028
3rd Qu.: 67371 3rd Qu.: 73562 3rd Qu.: 99765
Max. :272681766 Max. :266401330 Max. :250335398
gamtheta quantregtheta glmboosttheta
Min. : 1 Min. : 0 Min. : 1
1st Qu.: 80 1st Qu.: 98 1st Qu.: 80
Median : 2545 Median : 2052 Median : 2546
Mean : 2478384 Mean : 2501609 Mean : 2478381
3rd Qu.: 67371 3rd Qu.: 72881 3rd Qu.: 67371
Max. :272681766 Max. :256611668 Max. :272682043
WINKLER - QUARTERLY -----
series period theta glmnbtheta
Min. :182.0 Min. :4 Min. : 0.1 Min. : 0.2
1st Qu.:231.0 1st Qu.:4 1st Qu.: 29.9 1st Qu.: 44.1
Median :282.0 Median :4 Median : 161.0 Median : 168.8
Mean :281.8 Mean :4 Mean : 16183.1 Mean : 17696.5
3rd Qu.:331.0 3rd Qu.:4 3rd Qu.: 2614.2 3rd Qu.: 2741.3
Max. :384.0 Max. :4 Max. :558932.9 Max. :648026.8
glmtheta rlmtheta lqstheta gamtheta
Min. : 0.2 Min. : 0.2 Min. : 0.2 Min. : 0.2
1st Qu.: 71.6 1st Qu.: 75.2 1st Qu.: 82.3 1st Qu.: 71.6
Median : 244.4 Median : 254.6 Median : 252.7 Median : 244.4
Mean : 16607.8 Mean : 16945.3 Mean : 29875.9 Mean : 16607.8
3rd Qu.: 2168.3 3rd Qu.: 2686.1 3rd Qu.: 2491.8 3rd Qu.: 2168.3
Max. :619354.8 Max. :593478.7 Max. :1938535.2 Max. :619354.8
quantregtheta glmboosttheta
Min. : 0.2 Min. : 0.2
1st Qu.: 73.4 1st Qu.: 71.6
Median : 260.7 Median : 244.3
Mean : 18923.8 Mean : 16607.8
3rd Qu.: 3340.1 3rd Qu.: 2168.3
Max. :598457.6 Max. :619355.6
WINKLER - MONTHLY -----
series period theta glmnbtheta
Min. : 385 Min. :12 Min. : 0.1 Min. : 0.2
1st Qu.: 539 1st Qu.:12 1st Qu.: 39.7 1st Qu.: 47.8
Median : 693 Median :12 Median : 286.6 Median : 403.2
Mean : 693 Mean :12 Mean : 15275.0 Mean : 14985.3
3rd Qu.: 847 3rd Qu.:12 3rd Qu.: 2956.9 3rd Qu.: 3832.6
Max. :1001 Max. :12 Max. :3159077.6 Max. :2662241.0
glmtheta rlmtheta lqstheta gamtheta
Min. : 0 Min. : 0 Min. : 0 Min. : 0
1st Qu.: 57 1st Qu.: 58 1st Qu.: 60 1st Qu.: 57
Median : 474 Median : 473 Median : 546 Median : 474
Mean : 35530 Mean : 34776 Mean : 46968 Mean : 35530
3rd Qu.: 4202 3rd Qu.: 4181 3rd Qu.: 4098 3rd Qu.: 4202
Max. :13125821 Max. :12816589 Max. :19791829 Max. :13125821
quantregtheta glmboosttheta
Min. : 0 Min. : 0
1st Qu.: 61 1st Qu.: 57
Median : 450 Median : 474
Mean : 27957 Mean : 35529
3rd Qu.: 3920 3rd Qu.: 4202
Max. :8714877 Max. :13125496
1 - 4 M4 Yearly
%%R
library(M4comp2018)
M4Yearly <- Filter(function(l) l$period == "Yearly", M4)
# Load necessary libraries
library(doSNOW)
library(tcltk)
require(Mcomp)
nseries <- length(M4Yearly)
# Set up parallel backend
cl <- makeSOCKcluster(parallel::detectCores()) # Use 2 cores (adjust as needed)
registerDoSNOW(cl)
# Define progress bar
pb <- txtProgressBar(min = 0, max = nseries, style = 3)
# Progress function
progress <- function(n) setTxtProgressBar(pb, n)
# Options for progress tracking
opts <- list(progress = progress)
pb <- utils::txtProgressBar(min=0, max=nseries, style = 3)
(M4results <- foreach::foreach(i = 1:nseries, .combine = rbind,
.errorhandling = "remove",
.verbose=FALSE,
.options.snow = opts)%dopar%{
x <- M4Yearly[[i]]$x
xx <- M4Yearly[[i]]$xx
h <- length(xx)
obj <- suppressWarnings(thetaf(x, h=h, level=95))
res1 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=MASS::glm.nb,
attention = TRUE))
res2 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=stats::glm,
attention = TRUE))
res3 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=MASS::rlm,
attention = TRUE))
res4 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=MASS::lqs,
attention = TRUE))
res5 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=gam::gam,
attention = TRUE))
res6 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=quantreg::rq,
attention = TRUE))
res7 <- accuracy(obj, xx)
obj <- suppressWarnings(glmthetaf(x, h=h,
fit_func=mboost::glmboost,
attention = TRUE))
res8 <- accuracy(obj, xx)
utils::setTxtProgressBar(pb, i)
res <- cbind(i,
res1, res2,
res3, res4,
res5, res6,
res7, res8)
colnames(res) <- c("series", "theta", "glmnbtheta",
"glmtheta", "rlmtheta", "lqstheta",
"gamtheta", "quantregtheta", "glmboosttheta")
res
})
close(pb)
M4results <- data.frame(M4results)
print(head(M4results))
print(tail(M4results))
print(dim(M4results))
base::saveRDS(M4results, "results_M4.rds")
%%R
print(summary(subset(M4results[grep("mase", rownames(M4results)), ])))
from IPython.display import FileLink
# Create a download link for the file
FileLink('results_M4.rds')
%%R
results_M4Yearly <- readRDS("results_M4.rds")
cat("\n\n MASE - YEARLY ----- \n\n")
print(summary(results_M4Yearly[grep("mase", rownames(results_M4Yearly)), ]))
cat("\n\n RMSE - YEARLY ----- \n\n")
print(summary(results_M4Yearly[grep("rmse", rownames(results_M4Yearly)), ]))
cat("\n\n COVERAGE - YEARLY ----- \n\n")
print(summary(results_M4Yearly[grep("coverage", rownames(results_M4Yearly)), ]))
cat("\n\n WINKLER - YEARLY ----- \n\n")
print(summary(results_M4Yearly[grep("winkler", rownames(results_M4Yearly)), ]))
MASE - YEARLY -----
series theta glmnbtheta glmtheta
Min. : 1 Min. : 0.03825 Min. : 0.08616 Min. : 0.05602
1st Qu.: 5750 1st Qu.: 1.24816 1st Qu.: 1.57047 1st Qu.: 1.25346
Median :11498 Median : 2.31134 Median : 2.95540 Median : 2.20297
Mean :11499 Mean : 3.37253 Mean : 3.98933 Mean : 3.08111
3rd Qu.:17246 3rd Qu.: 4.20756 3rd Qu.: 5.11213 3rd Qu.: 3.83220
Max. :23000 Max. :52.23208 Max. :53.45190 Max. :52.33301
rlmtheta lqstheta gamtheta quantregtheta
Min. : 0.01779 Min. : 0.04004 Min. : 0.05602 Min. : 0.01118
1st Qu.: 1.24618 1st Qu.: 1.30599 1st Qu.: 1.25346 1st Qu.: 1.26680
Median : 2.20604 Median : 2.35514 Median : 2.20297 Median : 2.25031
Mean : 3.08741 Mean : 3.28814 Mean : 3.08111 Mean : 3.13130
3rd Qu.: 3.83867 3rd Qu.: 4.09708 3rd Qu.: 3.83220 3rd Qu.: 3.89659
Max. :52.68334 Max. :51.94242 Max. :52.33301 Max. :52.45575
glmboosttheta
Min. : 0.05602
1st Qu.: 1.25324
Median : 2.20283
Mean : 3.08085
3rd Qu.: 3.83188
Max. :52.33302
NA's :4
RMSE - YEARLY -----
series theta glmnbtheta glmtheta
Min. : 1 Min. : 1.72 Min. : 4.94 Min. : 2.12
1st Qu.: 5750 1st Qu.: 200.02 1st Qu.: 264.62 1st Qu.: 189.72
Median :11498 Median : 499.14 Median : 614.67 Median : 457.67
Mean :11499 Mean : 1021.30 Mean : 1159.17 Mean : 995.90
3rd Qu.:17246 3rd Qu.: 1211.77 3rd Qu.: 1412.04 3rd Qu.: 1121.98
Max. :23000 Max. :34316.38 Max. :34391.85 Max. :35284.94
rlmtheta lqstheta gamtheta quantregtheta
Min. : 0.69 Min. : 1.27 Min. : 2.12 Min. : 0.48
1st Qu.: 189.85 1st Qu.: 199.59 1st Qu.: 189.72 1st Qu.: 191.53
Median : 457.02 Median : 479.90 Median : 457.67 Median : 462.37
Mean : 994.38 Mean : 1056.00 Mean : 995.90 Mean : 1010.53
3rd Qu.: 1117.41 3rd Qu.: 1182.88 3rd Qu.: 1121.98 3rd Qu.: 1128.71
Max. :34141.46 Max. :41798.59 Max. :35284.94 Max. :32639.88
glmboosttheta
Min. : 2.12
1st Qu.: 189.73
Median : 457.76
Mean : 996.01
3rd Qu.: 1122.19
Max. :35284.45
NA's :4
COVERAGE - YEARLY -----
series theta glmnbtheta glmtheta
Min. : 1 Min. : 0.00 Min. : 0.00 Min. : 0.00
1st Qu.: 5750 1st Qu.: 66.67 1st Qu.: 50.00 1st Qu.: 50.00
Median :11498 Median :100.00 Median :100.00 Median :100.00
Mean :11499 Mean : 78.74 Mean : 76.19 Mean : 74.67
3rd Qu.:17246 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :23000 Max. :100.00 Max. :100.00 Max. :100.00
rlmtheta lqstheta gamtheta quantregtheta
Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.00
1st Qu.: 50.00 1st Qu.: 50.00 1st Qu.: 50.00 1st Qu.: 50.00
Median :100.00 Median :100.00 Median :100.00 Median :100.00
Mean : 74.66 Mean : 73.06 Mean : 74.67 Mean : 73.99
3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:100.00
Max. :100.00 Max. :100.00 Max. :100.00 Max. :100.00
glmboosttheta
Min. : 0.00
1st Qu.: 50.00
Median :100.00
Mean : 74.68
3rd Qu.:100.00
Max. :100.00
NA's :4
WINKLER - YEARLY -----
series theta glmnbtheta glmtheta
Min. : 1 Min. : 48.2 Min. : 36.4 Min. : 38.1
1st Qu.: 5750 1st Qu.: 1125.6 1st Qu.: 1689.0 1st Qu.: 1293.0
Median :11498 Median : 2823.9 Median : 4013.1 Median : 3349.8
Mean :11499 Mean : 11418.0 Mean : 12791.4 Mean : 12283.2
3rd Qu.:17246 3rd Qu.: 8017.8 3rd Qu.: 10444.7 3rd Qu.: 9313.3
Max. :23000 Max. :886227.6 Max. :938877.6 Max. :930890.3
rlmtheta lqstheta gamtheta quantregtheta
Min. : 37.7 Min. : 23.6 Min. : 38.1 Min. : 35.3
1st Qu.: 1300.0 1st Qu.: 1418.7 1st Qu.: 1293.0 1st Qu.: 1331.0
Median : 3370.7 Median : 3686.6 Median : 3349.8 Median : 3470.1
Mean : 12298.1 Mean : 13778.0 Mean : 12283.2 Mean : 12656.4
3rd Qu.: 9311.0 3rd Qu.: 10250.2 3rd Qu.: 9313.3 3rd Qu.: 9559.5
Max. :938995.6 Max. :1336459.5 Max. :930890.3 Max. :933935.2
glmboosttheta
Min. : 38.1
1st Qu.: 1292.6
Median : 3349.9
Mean : 12284.5
3rd Qu.: 9313.4
Max. :930890.5
NA's :4
Comments powered by Talkyard.