├── .github
├── .gitignore
├── ISSUE_TEMPLATE.md
├── CODE_OF_CONDUCT.md
├── workflows
│ ├── test-coverage.yaml
│ ├── pkgdown.yaml
│ ├── pr-commands.yaml
│ └── R-CMD-check.yaml
├── SUPPORT.md
└── CONTRIBUTING.md
├── revdep
├── failures.md
├── problems.md
├── checks.rds
├── cran.md
├── timing.md
└── README.md
├── data
├── htseg1.rda
├── htseg2.rda
└── infantgts.rda
├── inst
└── docs
│ └── hts.pdf
├── man
├── figures
│ ├── logo.png
│ ├── gts-eg-1.png
│ ├── gts-eg-2.png
│ ├── gts-eg-3.png
│ ├── hts-eg1-1.png
│ ├── hts-eg1-2.png
│ ├── hts-eg1-3.png
│ ├── hts-eg2-1.png
│ └── hts-eg2-2.png
├── helper-functions.Rd
├── window.gts.Rd
├── infantgts.Rd
├── allts.Rd
├── htseg1.Rd
├── aggts.Rd
├── smatrix.Rd
├── plot.gts.Rd
├── hts-package.Rd
├── accuracy.gts.Rd
├── hts-class.Rd
├── combinef.Rd
├── gts-class.Rd
├── MinT.Rd
└── forecast.gts.Rd
├── tests
├── testthat.R
└── testthat
│ ├── test-forecast.R
│ ├── test-aggts.R
│ ├── test-smatrix.R
│ ├── test-combinef.R
│ ├── test-gts.R
│ └── test-hts.R
├── CRAN-SUBMISSION
├── src
├── Makevars
├── Makevars.win
├── cgm_RcppEigen.cpp
└── RcppExports.cpp
├── CRAN-RELEASE
├── R
├── RcppExports.R
├── imports.R
├── combineg.R
├── window-gts.R
├── combinefm.R
├── middleout.R
├── smatrix.R
├── topdown.R
├── aggts.R
├── hts-package.R
├── accuracy-gts.R
├── plot-gts.R
├── tracemin.R
├── MinTbpv.R
├── recursive.R
├── bpv.R
├── hts.R
├── combinef.R
├── MinT.R
├── gts.R
└── forecast-gts.R
├── .Rbuildignore
├── .gitignore
├── codecov.yml
├── cran-comments.md
├── _pkgdown.yml
├── Makefile
├── NAMESPACE
├── DESCRIPTION
├── README.Rmd
├── NEWS.md
└── README.md
/.github/.gitignore:
--------------------------------------------------------------------------------
1 | *.html
2 |
--------------------------------------------------------------------------------
/revdep/failures.md:
--------------------------------------------------------------------------------
1 | *Wow, no problems at all. :)*
--------------------------------------------------------------------------------
/revdep/problems.md:
--------------------------------------------------------------------------------
1 | *Wow, no problems at all. :)*
--------------------------------------------------------------------------------
/data/htseg1.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/data/htseg1.rda
--------------------------------------------------------------------------------
/data/htseg2.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/data/htseg2.rda
--------------------------------------------------------------------------------
/inst/docs/hts.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/inst/docs/hts.pdf
--------------------------------------------------------------------------------
/revdep/checks.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/revdep/checks.rds
--------------------------------------------------------------------------------
/data/infantgts.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/data/infantgts.rda
--------------------------------------------------------------------------------
/man/figures/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/man/figures/logo.png
--------------------------------------------------------------------------------
/man/figures/gts-eg-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/man/figures/gts-eg-1.png
--------------------------------------------------------------------------------
/man/figures/gts-eg-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/man/figures/gts-eg-2.png
--------------------------------------------------------------------------------
/man/figures/gts-eg-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/man/figures/gts-eg-3.png
--------------------------------------------------------------------------------
/man/figures/hts-eg1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/man/figures/hts-eg1-1.png
--------------------------------------------------------------------------------
/man/figures/hts-eg1-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/man/figures/hts-eg1-2.png
--------------------------------------------------------------------------------
/man/figures/hts-eg1-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/man/figures/hts-eg1-3.png
--------------------------------------------------------------------------------
/man/figures/hts-eg2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/man/figures/hts-eg2-1.png
--------------------------------------------------------------------------------
/man/figures/hts-eg2-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/earowang/hts/HEAD/man/figures/hts-eg2-2.png
--------------------------------------------------------------------------------
/tests/testthat.R:
--------------------------------------------------------------------------------
1 | Sys.setenv("R_TESTS" = "")
2 | if(require(testthat) & require(hts))
3 | test_check("hts")
4 |
--------------------------------------------------------------------------------
/CRAN-SUBMISSION:
--------------------------------------------------------------------------------
1 | Version: 6.0.3
2 | Date: 2024-07-30 12:58:12 UTC
3 | SHA: 51b9dbf2f6e28f2b9830bb35bff65e1f8383b18e
4 |
--------------------------------------------------------------------------------
/src/Makevars:
--------------------------------------------------------------------------------
1 | ## Use the R_HOME indirection to support installations of multiple R version
2 | PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
3 |
--------------------------------------------------------------------------------
/CRAN-RELEASE:
--------------------------------------------------------------------------------
1 | This package was submitted to CRAN on 2021-05-30.
2 | Once it is accepted, delete this file and tag the release (commit 0108924).
3 |
--------------------------------------------------------------------------------
/src/Makevars.win:
--------------------------------------------------------------------------------
1 |
2 | ## This assume that we can call Rscript to ask Rcpp about its locations
3 | ## Use the R_HOME indirection to support installations of multiple R version
4 | PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
5 |
--------------------------------------------------------------------------------
/revdep/cran.md:
--------------------------------------------------------------------------------
1 | ## revdepcheck results
2 |
3 | We checked 3 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package.
4 |
5 | * We saw 0 new problems
6 | * We failed to check 0 packages
7 |
8 |
--------------------------------------------------------------------------------
/R/RcppExports.R:
--------------------------------------------------------------------------------
1 | # Generated by using Rcpp::compileAttributes() -> do not edit by hand
2 | # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3 |
4 | cgm_c <- function(As, bs) {
5 | .Call('_hts_cgm_c', PACKAGE = 'hts', As, bs)
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^.*\.Rproj$
2 | ^\.Rproj\.user$
3 | ^\.travis\.yml$
4 | ^docs$
5 | ^_pkgdown\.yml$
6 | ^README\.Rmd$
7 | ^Makefile$
8 | ^cran-comments\.md$
9 | ^revdep$
10 | ^.github$
11 | ^pkgdown$
12 | ^CRAN-RELEASE$
13 | ^codecov\.yml$
14 | ^\.github$
15 | ^CRAN-SUBMISSION$
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.so
3 | symbols.rds
4 | .Rhistory
5 | .Rproj.user
6 | hts.Rproj
7 | *.bbl
8 | *.blg
9 | *.dvi
10 | *.out
11 | *.aux
12 | *.log
13 | *.fdb_latexmk
14 | hts.tex
15 | inst/doc
16 | docs
17 | pkgdown/
18 | revdep/library
19 | revdep/checks
20 | revdep/data.sqlite
21 |
--------------------------------------------------------------------------------
/tests/testthat/test-forecast.R:
--------------------------------------------------------------------------------
1 | # A unit test for forecast.gts() function
2 | test_that("tests for 3 dots", {
3 | f1 <- forecast(htseg2, h = 4, algorithms = "lu")
4 | f2 <- forecast(htseg2, h = 4, ic = "aic", algorithms = "lu")
5 |
6 | expect_false(all(f1$bts == f2$bts))
7 | })
8 |
--------------------------------------------------------------------------------
/revdep/timing.md:
--------------------------------------------------------------------------------
1 | # Check times
2 |
3 | | |package |version | check_time|
4 | |:--|:-------|:-------|----------:|
5 | |4 |tsibble |0.1.3 | 65.9|
6 | |2 |gtop |0.2.0 | 45.3|
7 | |3 |thief |0.3 | 36.4|
8 | |1 |corset |0.1-4 | 15.4|
9 |
10 |
11 |
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | comment: false
2 |
3 | coverage:
4 | status:
5 | project:
6 | default:
7 | target: auto
8 | threshold: 1%
9 | informational: true
10 | patch:
11 | default:
12 | target: auto
13 | threshold: 1%
14 | informational: true
15 |
--------------------------------------------------------------------------------
/R/imports.R:
--------------------------------------------------------------------------------
1 | #' @importFrom graphics lines par plot strwidth text
2 | #' @import grDevices
3 | #' @importFrom utils combn
4 | #' @import methods
5 | #' @importFrom stats window as.ts fitted frequency is.ts na.omit residuals time ts tsp tsp<-
6 | #' @import Matrix
7 | #' @importFrom SparseM as.matrix.csr
8 | #' @import forecast
9 | #' @import parallel
10 | #' @useDynLib hts
11 | NULL
12 |
--------------------------------------------------------------------------------
/cran-comments.md:
--------------------------------------------------------------------------------
1 | ## Comments
2 |
3 | This is a resubmission to fix CRAN errors.
4 |
5 | ## R CMD check results
6 |
7 | 0 errors | 0 warnings | 0 notes
8 |
9 | ## Reverse dependencies
10 |
11 | We checked 3 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package.
12 |
13 | * We saw 0 new problems
14 | * We failed to check 0 packages
15 |
16 |
--------------------------------------------------------------------------------
/R/combineg.R:
--------------------------------------------------------------------------------
1 | SLM <- function(fcasts, S, weights = NULL) {
2 | class(fcasts) <- stats::tsp(fcasts) <- NULL
3 | fcasts <- t(stats::na.omit(t(fcasts))) # In case of "NA"
4 | if (is.null(weights)) {
5 | coef <- SparseM::slm.fit(S, fcasts)$coefficients
6 | } else {
7 | coef <- SparseM::slm.wfit(S, fcasts, weights = weights)$coefficients
8 | }
9 | fitted.v <- as.matrix(S %*% coef)
10 | return(fitted.v)
11 | }
12 |
--------------------------------------------------------------------------------
/man/helper-functions.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/gts.R, R/hts.R
3 | \name{get_groups}
4 | \alias{get_groups}
5 | \alias{get_nodes}
6 | \title{Get nodes/groups from an hts/gts object}
7 | \usage{
8 | get_groups(y)
9 |
10 | get_nodes(y)
11 | }
12 | \arguments{
13 | \item{y}{An hts or gts object
14 | series.}
15 | }
16 | \description{
17 | Get nodes/groups from an hts/gts object
18 | }
19 |
--------------------------------------------------------------------------------
/_pkgdown.yml:
--------------------------------------------------------------------------------
1 | template:
2 | params:
3 | bootswatch: united
4 |
5 | development:
6 | mode: auto
7 |
8 | authors:
9 | Rob Hyndman:
10 | href: http://robjhyndman.com
11 | Earo Wang:
12 | href: http://earo.me
13 |
14 | navbar:
15 | type: default
16 | left:
17 | - text: "Reference"
18 | href: reference/index.html
19 | - text: "Vignettes"
20 | href: https://CRAN.R-project.org/package=hts/vignettes/hts.pdf
21 | - text: "News"
22 | href: news/index.html
23 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Please briefly describe your problem and what output you expect. If you have a question, please don't use this form. Instead, ask on or .
2 |
3 | Please include a minimal reproducible example (AKA a reprex). If you've never heard of a [reprex](http://reprex.tidyverse.org/) before, start by reading .
4 |
5 | ---
6 |
7 | Brief description of the problem
8 |
9 | ```r
10 | # insert reprex here
11 | ```
12 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | document:
2 | Rscript -e "devtools::document()"
3 |
4 | readme:
5 | Rscript -e "rmarkdown::render('README.Rmd')"
6 |
7 | build:
8 | Rscript -e "devtools::build()"
9 |
10 | check:
11 | Rscript -e "devtools::check()"
12 |
13 | install:
14 | Rscript -e "devtools::install(build_vignettes = TRUE)"
15 |
16 | revdep-check:
17 | Rscript -e "devtools::revdep_check(); devtools::revdep_check_save_summary(); devtools::revdep_check_print_problems()"
18 |
19 | winbuild:
20 | Rscript -e "devtools::build_win(version = 'R-devel', quiet = TRUE)"
21 |
22 | pkgdown:
23 | Rscript -e "pkgdown::build_site(run_dont_run = TRUE)"
24 |
--------------------------------------------------------------------------------
/R/window-gts.R:
--------------------------------------------------------------------------------
1 | #' Time window of a gts object
2 | #'
3 | #' Extracts a subset of the time series from a grouped time series object.
4 | #'
5 | #'
6 | #' @param x An object of class \code{\link[hts]{gts}}.
7 | #' @param ... All other arguments are passed to \code{\link[stats]{window.ts}}.
8 | #' @author Rob J Hyndman
9 | #' @keywords ts
10 | #' @method window gts
11 | #' @examples
12 | #'
13 | #' window(htseg2, start = 2000, end = 2001)
14 | #'
15 | #' @export
16 | window.gts <- function(x, ...) {
17 | # Select a snapshot of hts or gts
18 | x$bts <- stats::window(x$bts, ...)
19 | tsp(x) <- stats::tsp(x)
20 | return(x)
21 | }
22 |
--------------------------------------------------------------------------------
/tests/testthat/test-aggts.R:
--------------------------------------------------------------------------------
1 | # A unit test for aggts() function
2 | context("Tests on input")
3 | test_that("tests for a non-gts object", {
4 | set.seed(1234)
5 | mts <- ts(matrix(5 + sort(rnorm(500)), nrow = 50, ncol = 10))
6 |
7 | expect_that(aggts(mts), throws_error())
8 | })
9 |
10 | context("Tests on output")
11 | test_that("tests for a non-gts object", {
12 | set.seed(1234)
13 | mts <- ts(matrix(5 + sort(rnorm(500)), nrow = 50, ncol = 10))
14 | node.list <- list(3, c(2, 3, 1), c(2, 2, 1, 1, 1, 3))
15 | hts <- hts(mts, nodes = node.list)
16 | out <- dim(aggts(hts))
17 |
18 | expect_that(out, equals(c(50, 20)))
19 | })
20 |
--------------------------------------------------------------------------------
/man/window.gts.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/window-gts.R
3 | \name{window.gts}
4 | \alias{window.gts}
5 | \title{Time window of a gts object}
6 | \usage{
7 | \method{window}{gts}(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object of class \code{\link[hts]{gts}}.}
11 |
12 | \item{...}{All other arguments are passed to \code{\link[stats]{window.ts}}.}
13 | }
14 | \description{
15 | Extracts a subset of the time series from a grouped time series object.
16 | }
17 | \examples{
18 |
19 | window(htseg2, start = 2000, end = 2001)
20 |
21 | }
22 | \author{
23 | Rob J Hyndman
24 | }
25 | \keyword{ts}
26 |
--------------------------------------------------------------------------------
/revdep/README.md:
--------------------------------------------------------------------------------
1 | # Platform
2 |
3 | |field |value |
4 | |:--------|:----------------------------|
5 | |version |R version 3.6.1 (2019-07-05) |
6 | |os |macOS Catalina 10.15.3 |
7 | |system |x86_64, darwin15.6.0 |
8 | |ui |RStudio |
9 | |language |(EN) |
10 | |collate |en_AU.UTF-8 |
11 | |ctype |en_AU.UTF-8 |
12 | |tz |Pacific/Auckland |
13 | |date |2020-03-29 |
14 |
15 | # Dependencies
16 |
17 | |package |old |new |Δ |
18 | |:-------|:-----|:----------|:--|
19 | |hts |5.1.5 |5.1.5.9000 |* |
20 |
21 | # Revdeps
22 |
23 |
--------------------------------------------------------------------------------
/man/infantgts.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/hts-package.R
3 | \docType{data}
4 | \name{infantgts}
5 | \alias{infantgts}
6 | \title{Regional infant mortality counts across Australia from 1933 to 2003.}
7 | \format{
8 | Objects of class \code{\link[hts]{gts}}.
9 | }
10 | \description{
11 | These are infant mortality counts. This data set is an example of
12 | \code{gts}, where the total infant mortality count in Australia can be first
13 | disaggregated by sex then by state, or vice versa.
14 | }
15 | \examples{
16 |
17 | plot(infantgts)
18 |
19 | }
20 | \references{
21 | R. J. Hyndman, R. A. Ahmed, G. Athanasopoulos and H.L. Shang
22 | (2011) Optimal combination forecasts for hierarchical time series.
23 | \emph{Computational Statistics and Data Analysis}, \bold{55}(9), 2579--2589.
24 | }
25 | \keyword{datasets}
26 |
--------------------------------------------------------------------------------
/man/allts.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/aggts.R
3 | \name{allts}
4 | \alias{allts}
5 | \title{Extract all time series from a gts object}
6 | \usage{
7 | allts(y, forecasts = TRUE)
8 | }
9 | \arguments{
10 | \item{y}{An object of class \code{\link[hts]{gts}}.}
11 |
12 | \item{forecasts}{If \code{y} contains forecasts and historical data, then
13 | \code{forecasts} indicates whether to return the forecasts or the historical
14 | data. Otherwise it is ignored.}
15 | }
16 | \description{
17 | The time series from all levels of a hierarchical/grouped time series or a
18 | forecasted hierarchical/grouped time series are returned as a multivariate
19 | time series.
20 | }
21 | \examples{
22 |
23 | allts(htseg1)
24 |
25 | }
26 | \seealso{
27 | \code{\link[hts]{aggts}}
28 | }
29 | \author{
30 | Rob J Hyndman
31 | }
32 | \keyword{ts}
33 |
--------------------------------------------------------------------------------
/man/htseg1.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/hts-package.R
3 | \docType{data}
4 | \name{htseg1}
5 | \alias{htseg1}
6 | \alias{htseg2}
7 | \title{Simple examples of hierarchical time series.}
8 | \format{
9 | Objects of class \code{\link[hts]{hts}}.
10 | }
11 | \description{
12 | These are simulated data. \code{htseg1} has three levels with a total of 8
13 | series each of length 10. \code{htseg2} has four levels with a total of 17
14 | series each of length 16.
15 | }
16 | \examples{
17 |
18 | plot(htseg1)
19 |
20 | }
21 | \references{
22 | R. J. Hyndman, R. A. Ahmed, G. Athanasopoulos and H.L. Shang
23 | (2011) Optimal combination forecasts for hierarchical time series.
24 | \emph{Computational Statistics and Data Analysis}, \bold{55}(9), 2579--2589.
25 | \url{https://robjhyndman.com/publications/hierarchical/}
26 | }
27 | \keyword{datasets}
28 |
--------------------------------------------------------------------------------
/tests/testthat/test-smatrix.R:
--------------------------------------------------------------------------------
1 | # A unit test for the inverse of row sums of smatrix
2 | test_that("tests for hts", {
3 | set.seed(1234)
4 | mts <- ts(matrix(5 + sort(rnorm(500)), nrow = 50, ncol = 10))
5 | node.list <- list(3, c(2, 3, 1), c(2, 2, 1, 1, 1, 3))
6 | hts <- hts(mts, nodes = node.list)
7 | s <- 1/rowSums(smatrix(hts))
8 |
9 | expect_that(InvS4h(node.list), equals(s))
10 | })
11 |
12 | test_that("tests for gts", {
13 | set.seed(1234)
14 | mts <- ts(5 + matrix(sort(rnorm(2700)), nrow = 100, ncol = 27),
15 | start = c(2001, 1), frequency = 12)
16 | g <- matrix(c(rep(1:3, each = 9), rep(c(rep(1, 3), rep(2, 3), rep(3, 3)), 3),
17 | rep(1:3, 9)), nrow = 3, byrow = TRUE)
18 | gts <- gts(mts, groups = g)
19 | s <- 1/rowSums(smatrix(gts))
20 | out <- InvS4g(gts$groups)
21 | names(out) <- NULL
22 |
23 | expect_that(out, equals(s))
24 | })
25 |
--------------------------------------------------------------------------------
/src/cgm_RcppEigen.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | //#include
5 | //#include
6 | using namespace Eigen;
7 | using namespace Rcpp;
8 |
9 | using Eigen::SparseMatrix;
10 | using Eigen::MappedSparseMatrix;
11 | using Eigen::Map;
12 | using Eigen::MatrixXd;
13 | using Eigen::VectorXd;
14 | using Rcpp::as;
15 | using Eigen::ConjugateGradient;
16 | typedef Eigen::MappedSparseMatrix MSpMat;
17 |
18 | // [[Rcpp::depends(RcppEigen)]]
19 | // [[Rcpp::export]]
20 | Eigen::MatrixXd cgm_c(SEXP As, SEXP bs) {
21 | const MSpMat A = as(As);
22 | //const Map A(as