diff --git a/R/M3_example.R b/R/M3_example.R new file mode 100644 index 0000000..1acd0d8 --- /dev/null +++ b/R/M3_example.R @@ -0,0 +1,10 @@ +#' Example of a time series from the M3 forecasting competition +#' +#' A monthly time series, from the M3 forecasting competition ("N1485"). +#' +#' @format +#' List of time series of class \link[stats]{ts}. +#' +#' +#' @source [https://forecasters.org/resources/time-series-data/m3-competition/](https://forecasters.org/resources/time-series-data/m3-competition/) +"M3_example" \ No newline at end of file diff --git a/R/carparts_example.R b/R/carparts_example.R new file mode 100644 index 0000000..6c70c59 --- /dev/null +++ b/R/carparts_example.R @@ -0,0 +1,16 @@ +#' Example of a time series from carparts +#' +#' A monthly time series from the `carparts` dataset, 51 observations, Jan 1998 - Mar 2002. +#' +#' @format +#' Univariate time series of class \link[stats]{ts}. +#' +#' @references +#' Hyndman, R.J., Koehler, A.B., Ord, J.K., and Snyder, R.D., (2008) Forecasting with exponential +#' smoothing: the state space approach, Springer +#' +#' Godahewa, Rakshitha, Bergmeir, Christoph, Webb, Geoff, Hyndman, Rob, & Montero-Manso, Pablo. (2020). Car Parts Dataset (without Missing Values) (Version 2) \doi{10.5281/zenodo.4656021} +#' +#' @source +#' Godahewa, Rakshitha, Bergmeir, Christoph, Webb, Geoff, Hyndman, Rob, & Montero-Manso, Pablo. (2020). Car Parts Dataset (without Missing Values) (Version 2) \doi{10.5281/zenodo.4656021} +"carparts_example" \ No newline at end of file diff --git a/data/M3_example.rda b/data/M3_example.rda new file mode 100644 index 0000000..1042b89 Binary files /dev/null and b/data/M3_example.rda differ diff --git a/data/carparts_example.rda b/data/carparts_example.rda new file mode 100644 index 0000000..f631dc9 Binary files /dev/null and b/data/carparts_example.rda differ diff --git a/man/M3_example.Rd b/man/M3_example.Rd new file mode 100644 index 0000000..b28d993 --- /dev/null +++ b/man/M3_example.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/M3_example.R +\docType{data} +\name{M3_example} +\alias{M3_example} +\title{Example of a time series from the M3 forecasting competition} +\format{ +List of time series of class \link[stats]{ts}. +} +\source{ +\url{https://forecasters.org/resources/time-series-data/m3-competition/} +} +\usage{ +M3_example +} +\description{ +A monthly time series, from the M3 forecasting competition ("N1485"). +} +\keyword{datasets} diff --git a/man/carpart.Rd b/man/carparts_example.Rd similarity index 82% rename from man/carpart.Rd rename to man/carparts_example.Rd index e7f1756..0b84b5c 100644 --- a/man/carpart.Rd +++ b/man/carparts_example.Rd @@ -1,9 +1,9 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/carpart.R +% Please edit documentation in R/carparts_example.R \docType{data} -\name{carpart} -\alias{carpart} -\title{Carpart time series} +\name{carparts_example} +\alias{carparts_example} +\title{Example of a time series from carparts} \format{ Univariate time series of class \link[stats]{ts}. } @@ -11,7 +11,7 @@ Univariate time series of class \link[stats]{ts}. Godahewa, Rakshitha, Bergmeir, Christoph, Webb, Geoff, Hyndman, Rob, & Montero-Manso, Pablo. (2020). Car Parts Dataset (without Missing Values) (Version 2) \doi{10.5281/zenodo.4656021} } \usage{ -carpart +carparts_example } \description{ A monthly time series from the \code{carparts} dataset, 51 observations, Jan 1998 - Mar 2002. diff --git a/vignettes/bayesRecon.Rmd b/vignettes/bayesRecon.Rmd index 044b207..06b0a58 100644 --- a/vignettes/bayesRecon.Rmd +++ b/vignettes/bayesRecon.Rmd @@ -20,7 +20,8 @@ vignette: > knitr::opts_chunk$set( collapse = TRUE, comment = "#>", - eval=TRUE ### !!!! set to FALSE here to render only the text !!!! + #eval=TRUE ### !!!! set to FALSE here to render only the text !!!! + eval=FALSE ### !!!! set to FALSE here to render only the text !!!! ) set.seed(42) ``` @@ -34,28 +35,17 @@ klippy::klippy(position = c('top', 'right'), tooltip_message = 'Copy', tooltip_s This vignette shows how to perform *probabilistic reconciliation* with the `bayesRecon` package. We provide three examples: -1. *Temporal hierarchy for a count time series*: we build a temporal hierarchy over a count time series, produce base forecasts using glarma and reconcile them via Bottom-Up Importance Sampling (BUIS). +1. *Temporal hierarchy for a count time series*: we build a temporal hierarchy over a count time series, produce the base forecasts using `glarma` and reconcile them via Bottom-Up Importance Sampling (BUIS). -2. *Temporal hierarchy for a smooth time series*: we build a temporal hierarchy over a smooth time series, compute the base forecasts using ets and we reconcile them in closed form using Gaussian reconciliation. +2. *Temporal hierarchy for a smooth time series*: we build a temporal hierarchy over a smooth time series, compute the base forecasts using `ets` and we reconcile them in closed form using Gaussian reconciliation. -3. *Cross-sectional hierarchy of smooth time series*: we reconcile forecasts for a cross-sectional hierarchy. Also in this case we use ets to generate the base forecasts and we apply Gaussian reconciliation. +3. *Hierarchical of smooth time series*: this is an example of a cross-sectional hierarchy. We generate the base forecasts using `ets` and we reconcile them via Gaussian reconciliation. 4. *Cross-sectional hierarchy of count time series* LZ toglierei le citazioni -The reconciliation algorithms are discussed in: - -* Zambon, L., Azzimonti, D., & Corani, G. (2022). Efficient probabilistic reconciliation of forecasts for real-valued and count time series, -Statistics and Computing 34.1 (2024): 21. - -* Zambon, L., Agosto, A., Giudici, P., & Corani, G. (2023). Properties of the reconciled distributions for Gaussian and count forecasts, arXiv preprint arXiv:2303.15135. - -* Corani, G., Azzimonti, D., & Rubattu, N. (2023). Probabilistic reconciliation of count time series, International Journal of Forecasting (2023). - -* Corani, G., Azzimonti, D., Augusto, J. P., & Zaffalon, M. (2021). Probabilistic reconciliation of hierarchical forecast via Bayes' rule. -Proc. ECML-PKDD 2020, pp. 211-226. # Installation @@ -75,7 +65,7 @@ library(bayesRecon) We select a monthly time series of counts from the *carparts* dataset citerei piuttosto il package expsmooth [@expsmooth_pkg] [@hyndman2008forecasting]. -The data set contains time series of sales of cars part from Jan. 1998 to Mar. 2002. We select in particular time series #2655, which we make it available as `bayesRecon::carpart`. +The data set contains time series of sales of cars part from Jan. 1998 to Mar. 2002. We select in particular time series #2655, which we make it available as `bayesRecon::carparts_example`. la chiamerei piuttosto carparts_example @@ -83,15 +73,15 @@ This time series has a skewed distribution of values. ```{r carpart-plot, dpi=300, out.width = "100%", fig.align='center', fig.cap="**Figure 1**: Carpart - monthly car part sales.", fig.dim = c(6, 3)} layout(mat = matrix(c(1, 2), nrow = 1, ncol = 2), widths = c(2, 1)) -plot(carpart, xlab = "Time", ylab = "Car part sales", main = NULL) -hist(carpart, xlab = "Car part sales", main = NULL) +plot(carparts_example, xlab = "Time", ylab = "Car part sales", main = NULL) +hist(carparts_example, xlab = "Car part sales", main = NULL) ```

We divide the time series into train and test, such that the test set contains the last 12 months. ```{r train-test} -train <- window(carpart, end = c(2001, 3)) -test <- window(carpart, start = c(2001, 4)) +train <- window(carparts_example, end = c(2001, 3)) +test <- window(carparts_example, start = c(2001, 4)) ``` @@ -254,11 +244,11 @@ Note the improvements of the reconciled forecasts compared to the base forecasts We now consider a *monthly* time series (N1485) from the M3 forecasting competition [@makridakis2000m3]. citerei il pacchetto mcomp da cui l'abbiamo presa -It is available from `bayesRecon::M3sample`. +It is available from `bayesRecon::M3_example`. lo chiamerei m3_example ```{r m3-plot, dpi=300, out.width = "100%", fig.align='center', fig.cap="**Figure 3**: M3 - N1485 time series.", fig.dim = c(6, 3)} -plot(M3example$train, xlab = "Time", ylab = "y", main = "N1485") +plot(M3_example$train, xlab = "Time", ylab = "y", main = "N1485") ```
We build the temporal hierarchy using the `temporal_aggregation` function. diff --git a/vignettes/references.bib b/vignettes/references.bib index 283efd2..2cf4061 100644 --- a/vignettes/references.bib +++ b/vignettes/references.bib @@ -122,20 +122,23 @@ @InProceedings{corani2021probabilistic booktitle="Machine Learning and Knowledge Discovery in Databases", year="2021", publisher="Springer International Publishing", - address="Cham", pages="211--226" } @article{zambon2022efficient, title={Efficient probabilistic reconciliation of forecasts for real-valued and count time series}, author={Zambon, Lorenzo and Azzimonti, Dario and Corani, Giorgio}, - journal={stat}, - volume={1050}, - pages={8}, - year={2022} + journal={Statistics and Computing}, + volume={34}, + number={1}, + pages={21}, + year={2024}, + publisher={Springer} } + + @article{zambon2023properties, title={Properties of the reconciled distributions for Gaussian and count forecasts}, author={Zambon, Lorenzo and Agosto, Arianna and Giudici, Paolo and Corani, Giorgio},