├── src ├── .gitignore ├── Makevars ├── Makevars.win ├── ExtractComponentC.cpp ├── SimulateC.cpp ├── LogLikC.cpp └── RcppExports.cpp ├── vignettes ├── .gitignore ├── intro.Rmd └── boxjenkins.Rmd ├── LICENSE ├── docs ├── logo.png ├── favicon.ico ├── dev │ ├── logo.png │ ├── favicon.ico │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── apple-touch-icon.png │ ├── reference │ │ ├── Rplot001.png │ │ ├── Rplot002.png │ │ ├── figures │ │ │ ├── logo.png │ │ │ └── README-unnamed-chunk-4-1.png │ │ ├── statespacer-1.png │ │ ├── statespacer-2.png │ │ ├── StateSpaceFit-1.png │ │ ├── StateSpaceFit-2.png │ │ ├── StateSpaceForecast-1.png │ │ └── predict.statespacer-1.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── articles │ │ ├── intro_files │ │ │ ├── figure-html │ │ │ │ ├── unnamed-chunk-4-1.png │ │ │ │ └── unnamed-chunk-5-1.png │ │ │ ├── header-attrs-2.1 │ │ │ │ └── header-attrs.js │ │ │ ├── header-attrs-2.3 │ │ │ │ └── header-attrs.js │ │ │ ├── header-attrs-2.4 │ │ │ │ └── header-attrs.js │ │ │ └── accessible-code-block-0.0.1 │ │ │ │ └── empty-anchor.js │ │ ├── seatbelt_files │ │ │ ├── figure-html │ │ │ │ ├── unnamed-chunk-3-1.png │ │ │ │ ├── unnamed-chunk-4-1.png │ │ │ │ ├── unnamed-chunk-5-1.png │ │ │ │ ├── unnamed-chunk-6-1.png │ │ │ │ ├── unnamed-chunk-8-1.png │ │ │ │ └── unnamed-chunk-8-2.png │ │ │ ├── header-attrs-2.1 │ │ │ │ └── header-attrs.js │ │ │ ├── header-attrs-2.3 │ │ │ │ └── header-attrs.js │ │ │ ├── header-attrs-2.4 │ │ │ │ └── header-attrs.js │ │ │ └── accessible-code-block-0.0.1 │ │ │ │ └── empty-anchor.js │ │ ├── selfspec_files │ │ │ ├── figure-html │ │ │ │ ├── unnamed-chunk-8-1.png │ │ │ │ ├── unnamed-chunk-8-2.png │ │ │ │ └── unnamed-chunk-8-3.png │ │ │ ├── header-attrs-2.1 │ │ │ │ └── header-attrs.js │ │ │ ├── header-attrs-2.3 │ │ │ │ └── header-attrs.js │ │ │ ├── header-attrs-2.4 │ │ │ │ └── header-attrs.js │ │ │ └── accessible-code-block-0.0.1 │ │ │ │ └── empty-anchor.js │ │ ├── boxjenkins_files │ │ │ ├── header-attrs-2.1 │ │ │ │ └── header-attrs.js │ │ │ ├── header-attrs-2.3 │ │ │ │ └── header-attrs.js │ │ │ ├── header-attrs-2.4 │ │ │ │ └── header-attrs.js │ │ │ └── accessible-code-block-0.0.1 │ │ │ │ └── empty-anchor.js │ │ └── dictionary_files │ │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ │ ├── header-attrs-2.3 │ │ │ └── header-attrs.js │ │ │ ├── header-attrs-2.4 │ │ │ └── header-attrs.js │ │ │ └── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ ├── pkgdown.yml │ ├── link.svg │ ├── sitemap.xml │ ├── bootstrap-toc.css │ ├── docsearch.js │ ├── extra.css │ ├── docsearch.json │ ├── pkgdown.js │ └── bootstrap-toc.js ├── favicon-16x16.png ├── favicon-32x32.png ├── apple-touch-icon.png ├── reference │ ├── Rplot001.png │ ├── Rplot002.png │ ├── figures │ │ ├── logo.png │ │ └── README-unnamed-chunk-4-1.png │ ├── SimSmoother-1.png │ ├── statespacer-1.png │ ├── statespacer-2.png │ ├── StateSpaceFit-1.png │ ├── StateSpaceFit-2.png │ ├── StateSpaceForecast-1.png │ └── predict.statespacer-1.png ├── apple-touch-icon-60x60.png ├── apple-touch-icon-76x76.png ├── apple-touch-icon-120x120.png ├── apple-touch-icon-152x152.png ├── apple-touch-icon-180x180.png ├── articles │ ├── intro_files │ │ ├── figure-html │ │ │ ├── unnamed-chunk-4-1.png │ │ │ └── unnamed-chunk-5-1.png │ │ ├── anchor-sections-1.0 │ │ │ ├── anchor-sections.css │ │ │ └── anchor-sections.js │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.3 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.4 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.5 │ │ │ └── header-attrs.js │ │ └── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ ├── seatbelt_files │ │ ├── figure-html │ │ │ ├── unnamed-chunk-3-1.png │ │ │ ├── unnamed-chunk-4-1.png │ │ │ ├── unnamed-chunk-5-1.png │ │ │ ├── unnamed-chunk-6-1.png │ │ │ ├── unnamed-chunk-8-1.png │ │ │ └── unnamed-chunk-8-2.png │ │ ├── anchor-sections-1.0 │ │ │ ├── anchor-sections.css │ │ │ └── anchor-sections.js │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.3 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.4 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.5 │ │ │ └── header-attrs.js │ │ └── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ ├── selfspec_files │ │ ├── figure-html │ │ │ ├── unnamed-chunk-8-1.png │ │ │ ├── unnamed-chunk-8-2.png │ │ │ └── unnamed-chunk-8-3.png │ │ ├── anchor-sections-1.0 │ │ │ ├── anchor-sections.css │ │ │ └── anchor-sections.js │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.3 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.4 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.5 │ │ │ └── header-attrs.js │ │ └── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ ├── boxjenkins_files │ │ ├── anchor-sections-1.0 │ │ │ ├── anchor-sections.css │ │ │ └── anchor-sections.js │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.3 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.4 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.5 │ │ │ └── header-attrs.js │ │ └── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ └── dictionary_files │ │ ├── anchor-sections-1.0 │ │ ├── anchor-sections.css │ │ └── anchor-sections.js │ │ ├── header-attrs-2.1 │ │ └── header-attrs.js │ │ ├── header-attrs-2.3 │ │ └── header-attrs.js │ │ ├── header-attrs-2.4 │ │ └── header-attrs.js │ │ ├── header-attrs-2.5 │ │ └── header-attrs.js │ │ └── accessible-code-block-0.0.1 │ │ └── empty-anchor.js ├── pkgdown.yml ├── link.svg ├── bootstrap-toc.css ├── docsearch.js ├── extra.css ├── docsearch.json ├── sitemap.xml ├── pkgdown.js ├── bootstrap-toc.js └── LICENSE-text.html ├── man ├── figures │ ├── logo.png │ └── README-unnamed-chunk-4-1.png ├── BlockMatrix.Rd ├── CoeffARMA.Rd ├── SimSmoother.Rd ├── Cholesky.Rd ├── FedYieldCurve.Rd ├── statespacer-package.Rd └── predict.statespacer.Rd ├── R ├── zzz.R ├── FedYieldCurve.R ├── BlockMatrix.R ├── statespacer-package.R ├── CombineSysMat.R ├── RcppExports.R ├── Cholesky.R └── AnsleyKohn.R ├── data └── FedYieldCurve.rda ├── pkgdown ├── favicon │ ├── favicon.ico │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── apple-touch-icon.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ └── apple-touch-icon-180x180.png └── extra.css ├── CRAN-SUBMISSION ├── NAMESPACE ├── data-raw └── FedYieldCurve.R ├── .gitignore ├── .Rbuildignore ├── cran-comments.md ├── .travis.yml ├── inst ├── CITATION └── REFERENCES.bib ├── DESCRIPTION ├── LICENSE.md ├── CODE_OF_CONDUCT.md ├── _pkgdown.yml ├── NEWS.md ├── README.Rmd └── README.md /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | *.dll 4 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2020 2 | COPYRIGHT HOLDER: Dylan Beijers 3 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/logo.png -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/favicon.ico -------------------------------------------------------------------------------- /docs/dev/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/logo.png -------------------------------------------------------------------------------- /docs/dev/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/favicon.ico -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/man/figures/logo.png -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | .onUnload <- function (libpath) { 2 | library.dynam.unload("statespacer", libpath) 3 | } 4 | -------------------------------------------------------------------------------- /data/FedYieldCurve.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/data/FedYieldCurve.rda -------------------------------------------------------------------------------- /docs/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/favicon-16x16.png -------------------------------------------------------------------------------- /docs/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/favicon-32x32.png -------------------------------------------------------------------------------- /docs/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/dev/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/favicon-16x16.png -------------------------------------------------------------------------------- /docs/dev/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/favicon-32x32.png -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/Rplot002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/reference/Rplot002.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 0.5.0 2 | Date: 2023-01-27 22:44:48 UTC 3 | SHA: 674c8a38760a514b9b5bba80083c4c47c4e30db0 4 | -------------------------------------------------------------------------------- /docs/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /docs/dev/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/dev/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/dev/reference/Rplot002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/reference/Rplot002.png -------------------------------------------------------------------------------- /docs/reference/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/reference/figures/logo.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /docs/reference/SimSmoother-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/reference/SimSmoother-1.png -------------------------------------------------------------------------------- /docs/reference/statespacer-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/reference/statespacer-1.png -------------------------------------------------------------------------------- /docs/reference/statespacer-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/reference/statespacer-2.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /docs/dev/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /docs/dev/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /docs/dev/reference/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/reference/figures/logo.png -------------------------------------------------------------------------------- /docs/dev/reference/statespacer-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/reference/statespacer-1.png -------------------------------------------------------------------------------- /docs/dev/reference/statespacer-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/reference/statespacer-2.png -------------------------------------------------------------------------------- /docs/reference/StateSpaceFit-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/reference/StateSpaceFit-1.png -------------------------------------------------------------------------------- /docs/reference/StateSpaceFit-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/reference/StateSpaceFit-2.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/dev/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /docs/dev/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /docs/dev/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /docs/dev/reference/StateSpaceFit-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/reference/StateSpaceFit-1.png -------------------------------------------------------------------------------- /docs/dev/reference/StateSpaceFit-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/reference/StateSpaceFit-2.png -------------------------------------------------------------------------------- /docs/reference/StateSpaceForecast-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/reference/StateSpaceForecast-1.png -------------------------------------------------------------------------------- /docs/reference/predict.statespacer-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/reference/predict.statespacer-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/man/figures/README-unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/dev/reference/StateSpaceForecast-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/reference/StateSpaceForecast-1.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /docs/dev/reference/predict.statespacer-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/reference/predict.statespacer-1.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | CXX_STD = CXX17 2 | PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) 3 | PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) 4 | -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/reference/figures/README-unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | CXX_STD = CXX17 2 | PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) 3 | PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) 4 | -------------------------------------------------------------------------------- /docs/dev/reference/figures/README-unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/reference/figures/README-unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/intro_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/articles/intro_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/intro_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/articles/intro_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/articles/seatbelt_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/articles/seatbelt_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/articles/seatbelt_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/articles/seatbelt_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/articles/seatbelt_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/figure-html/unnamed-chunk-8-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/articles/seatbelt_files/figure-html/unnamed-chunk-8-2.png -------------------------------------------------------------------------------- /docs/articles/selfspec_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/articles/selfspec_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/articles/selfspec_files/figure-html/unnamed-chunk-8-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/articles/selfspec_files/figure-html/unnamed-chunk-8-2.png -------------------------------------------------------------------------------- /docs/articles/selfspec_files/figure-html/unnamed-chunk-8-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/articles/selfspec_files/figure-html/unnamed-chunk-8-3.png -------------------------------------------------------------------------------- /docs/dev/articles/intro_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/articles/intro_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/dev/articles/intro_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/articles/intro_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-8-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/articles/seatbelt_files/figure-html/unnamed-chunk-8-2.png -------------------------------------------------------------------------------- /docs/dev/articles/selfspec_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/articles/selfspec_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/dev/articles/selfspec_files/figure-html/unnamed-chunk-8-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/articles/selfspec_files/figure-html/unnamed-chunk-8-2.png -------------------------------------------------------------------------------- /docs/dev/articles/selfspec_files/figure-html/unnamed-chunk-8-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DylanB95/statespacer/HEAD/docs/dev/articles/selfspec_files/figure-html/unnamed-chunk-8-3.png -------------------------------------------------------------------------------- /docs/articles/intro_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /docs/articles/boxjenkins_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /docs/articles/dictionary_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /docs/articles/selfspec_files/anchor-sections-1.0/anchor-sections.css: -------------------------------------------------------------------------------- 1 | /* Styles for section anchors */ 2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} 3 | a.anchor-section::before {content: '#';} 4 | .hasAnchor:hover a.anchor-section {visibility: visible;} 5 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(predict,statespacer) 4 | export(BlockMatrix) 5 | export(Cholesky) 6 | export(CoeffARMA) 7 | export(SimSmoother) 8 | export(statespacer) 9 | importFrom(Rcpp,sourceCpp) 10 | importFrom(Rdpack,reprompt) 11 | useDynLib(statespacer, .registration = TRUE) 12 | -------------------------------------------------------------------------------- /data-raw/FedYieldCurve.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `FedYieldCurve` dataset 2 | FedYieldCurve = read.csv(file.path(getwd(), "data-raw", "FedYieldCurve.csv"), sep=";") 3 | FedYieldCurve$Month = paste0(FedYieldCurve$Month, "-01") 4 | FedYieldCurve$Month = base::as.Date(FedYieldCurve$Month) 5 | usethis::use_data(FedYieldCurve, overwrite = TRUE) 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rhistory 2 | .Rapp.history 3 | .RData 4 | .Ruserdata 5 | *-Ex.R 6 | /*.tar.gz 7 | /*.Rcheck/ 8 | .Rproj.user/ 9 | vignettes/*.html 10 | vignettes/*.pdf 11 | .httr-oauth 12 | *_cache/ 13 | /cache/ 14 | *.utf8.md 15 | *.knit.md 16 | .Renviron 17 | .Rproj.user 18 | *.Rproj 19 | inst/doc 20 | doc 21 | Meta 22 | src-i386 23 | src-x64 24 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^statespacer\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.Rhistory$ 4 | ^README\.md$ 5 | ^_pkgdown\.yml$ 6 | ^docs$ 7 | ^pkgdown$ 8 | ^doc$ 9 | ^Meta$ 10 | ^LICENSE\.md$ 11 | ^CODE_OF_CONDUCT\.md$ 12 | ^README\.Rmd$ 13 | ^\.travis\.yml$ 14 | ^cran-comments\.md$ 15 | ^CRAN-RELEASE$ 16 | ^src-i386$ 17 | ^src-x64$ 18 | ^data-raw$ 19 | ^CRAN-SUBMISSION$ 20 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.19.2 2 | pkgdown: 2.0.7 3 | pkgdown_sha: ~ 4 | articles: 5 | boxjenkins: boxjenkins.html 6 | dictionary: dictionary.html 7 | intro: intro.html 8 | seatbelt: seatbelt.html 9 | selfspec: selfspec.html 10 | last_built: 2023-01-27T21:25Z 11 | urls: 12 | reference: https://dylanb95.github.io/statespacer/reference 13 | article: https://dylanb95.github.io/statespacer/articles 14 | 15 | -------------------------------------------------------------------------------- /docs/dev/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.9.2.1 2 | pkgdown: 1.6.1 3 | pkgdown_sha: ~ 4 | articles: 5 | boxjenkins: boxjenkins.html 6 | dictionary: dictionary.html 7 | intro: intro.html 8 | seatbelt: seatbelt.html 9 | selfspec: selfspec.html 10 | last_built: 2020-10-27T08:51Z 11 | urls: 12 | reference: https://dylanb95.github.io/statespacer/reference 13 | article: https://dylanb95.github.io/statespacer/articles 14 | 15 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Test environments 2 | * local R installation on Windows, R 4.2.2 3 | * ubuntu 16.04.7 (on travis-ci), R 4.0.2 4 | * Windows Server 2008 R2 SP1, R-devel, 32/64 bit (windows-x86_64-devel) 5 | * Windows Server 2008 R2 SP1, R-oldrel, 32/64 bit (windows-x86_64-oldrel) 6 | * Windows Server 2008 R2 SP1, R-release, 32/64 bit (windows-x86_64-release) 7 | 8 | ## R CMD check results 9 | 10 | 0 errors | 0 warnings | 0 notes -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | cache: packages 5 | 6 | before_install: 7 | - mkdir -p ~/.R 8 | - echo 'CXX17 = g++-7 -std=gnu++17 -fPIC' > ~/.R/Makevars 9 | - sudo apt-get install libgfortran-* 10 | 11 | addons: 12 | apt: 13 | sources: 14 | - sourceline: 'ppa:ubuntu-toolchain-r/test' 15 | packages: 16 | - g++-7 17 | 18 | brew_packages: 19 | - gcc 20 | -------------------------------------------------------------------------------- /docs/articles/intro_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/intro_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/intro_files/header-attrs-2.4/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/intro_files/header-attrs-2.5/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/boxjenkins_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/boxjenkins_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/boxjenkins_files/header-attrs-2.4/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/boxjenkins_files/header-attrs-2.5/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/dictionary_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/dictionary_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/dictionary_files/header-attrs-2.4/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/dictionary_files/header-attrs-2.5/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/header-attrs-2.4/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/header-attrs-2.5/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/selfspec_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/selfspec_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/selfspec_files/header-attrs-2.4/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/selfspec_files/header-attrs-2.5/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/intro_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/intro_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/intro_files/header-attrs-2.4/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/seatbelt_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/seatbelt_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/seatbelt_files/header-attrs-2.4/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/selfspec_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/selfspec_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/selfspec_files/header-attrs-2.4/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/boxjenkins_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/boxjenkins_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/boxjenkins_files/header-attrs-2.4/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/dictionary_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/dictionary_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/dev/articles/dictionary_files/header-attrs-2.4/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("To cite statespacer in publications, please use:") 2 | 3 | year <- sub("-.*", "", meta$Date) 4 | note <- sprintf("R package version %s", meta$Version) 5 | 6 | citEntry( 7 | entry = "Manual", 8 | title = "{statespacer}: State Space Modelling in R", 9 | author = "Dylan Beijers", 10 | year = year, 11 | url = "https://dylanb95.github.io/statespacer/", 12 | note = note, 13 | textVersion = 14 | paste0( 15 | "D. Beijers. (", 16 | year, 17 | "). statespacer: State Space Modelling in R. ", 18 | note, "." 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /docs/articles/intro_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/boxjenkins_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/dictionary_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/selfspec_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/dev/articles/intro_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/dev/articles/boxjenkins_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/dev/articles/dictionary_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/dev/articles/seatbelt_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/dev/articles/selfspec_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /man/BlockMatrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BlockMatrix.R 3 | \name{BlockMatrix} 4 | \alias{BlockMatrix} 5 | \title{Combine Matrices into a Block Diagonal Matrix} 6 | \usage{ 7 | BlockMatrix(...) 8 | } 9 | \arguments{ 10 | \item{...}{Matrices that should be put on the diagonal.} 11 | } 12 | \value{ 13 | Block diagonal matrix having the specified matrices on its diagonal. 14 | } 15 | \description{ 16 | Creates a block diagonal matrix with its arguments as the blocks. 17 | } 18 | \details{ 19 | \code{BlockMatrix()} tries to coerce its arguments to a matrix, 20 | using \code{\link[base:matrix]{as.matrix}}. 21 | } 22 | \examples{ 23 | BlockMatrix(diag(ceiling(9 * stats::runif(5))), matrix(1:8, 4, 2), c(14, 8)) 24 | } 25 | \author{ 26 | Dylan Beijers, \email{dylanbeijers@gmail.com} 27 | } 28 | -------------------------------------------------------------------------------- /docs/dev/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: statespacer 2 | Version: 0.5.0 3 | Date: 2023-01-27 4 | Title: State Space Modelling in 'R' 5 | Description: A tool that makes estimating models in state space form 6 | a breeze. See "Time Series Analysis by State Space Methods" by 7 | Durbin and Koopman (2012, ISBN: 978-0-19-964117-8) for details 8 | about the algorithms implemented. 9 | Authors@R: person("Dylan", "Beijers", email = "dylanbeijers@gmail.com", 10 | role = c("aut", "cre")) 11 | URL: https://DylanB95.github.io/statespacer/, 12 | https://github.com/DylanB95/statespacer/ 13 | BugReports: https://github.com/DylanB95/statespacer/issues/ 14 | License: MIT + file LICENSE 15 | RoxygenNote: 7.2.3 16 | Roxygen: list(markdown = TRUE) 17 | RdMacros: Rdpack 18 | Depends: R (>= 3.6) 19 | Imports: 20 | Rdpack, 21 | stats, 22 | Rcpp 23 | Suggests: 24 | datasets, 25 | graphics, 26 | knitr, 27 | numDeriv (>= 2016.8-1.1), 28 | optimx (>= 2020-4.2), 29 | rmarkdown 30 | VignetteBuilder: knitr 31 | Encoding: UTF-8 32 | LazyData: true 33 | LinkingTo: 34 | Rcpp, 35 | RcppArmadillo 36 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2020 Dylan Beijers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/ExtractComponentC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | // [[Rcpp::depends(RcppArmadillo)] 3 | 4 | //' Extract Component of Random Samples 5 | //' 6 | //' @param a Array containing the state vectors for each time point 7 | //' and random sample. 8 | //' @param Z Z system matrix of the State Space model component. 9 | //' 10 | //' @noRd 11 | // [[Rcpp::export]] 12 | arma::cube ExtractComponentC(const arma::cube& a, 13 | const arma::cube& Z) { 14 | 15 | // Number of time points, dependent variables, and random samples 16 | int N = a.n_slices, p = Z.n_rows, nsim = a.n_cols; 17 | 18 | // Check whether Z is time-varying 19 | bool Z_tv = Z.n_slices > 1; 20 | 21 | // Initial Z system matrix 22 | arma::mat Z_mat = Z.slice(0); 23 | 24 | // Initialise component 25 | arma::cube component(N, p, nsim); 26 | 27 | // Loop over time points 28 | for (int i = 0; i < N; i++) { 29 | 30 | // Get system matrices of current time point 31 | if (Z_tv && i > 0) { 32 | Z_mat = Z.slice(i); 33 | } 34 | 35 | // Simulated component 36 | component.row(i) = Z_mat * a.slice(i); 37 | } 38 | 39 | return component; 40 | } 41 | -------------------------------------------------------------------------------- /docs/articles/intro_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/articles/seatbelt_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/articles/selfspec_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/articles/boxjenkins_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /docs/articles/dictionary_files/anchor-sections-1.0/anchor-sections.js: -------------------------------------------------------------------------------- 1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2 | document.addEventListener('DOMContentLoaded', function() { 3 | // Do nothing if AnchorJS is used 4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 | return; 6 | } 7 | 8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 | 10 | // Do nothing if sections are already anchored 11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 | return null; 13 | } 14 | 15 | // Use section id when pandoc runs with --section-divs 16 | const section_id = function(x) { 17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 | ? x.id : ''); 19 | }; 20 | 21 | // Add anchors 22 | h.forEach(function(x) { 23 | const id = x.id || section_id(x.parentElement); 24 | if (id === '') { 25 | return null; 26 | } 27 | let anchor = document.createElement('a'); 28 | anchor.href = '#' + id; 29 | anchor.classList = ['anchor-section']; 30 | x.classList.add('hasAnchor'); 31 | x.appendChild(anchor); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /man/CoeffARMA.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AnsleyKohn.R 3 | \name{CoeffARMA} 4 | \alias{CoeffARMA} 5 | \title{Transform arbitrary matrices into ARMA coefficient matrices} 6 | \usage{ 7 | CoeffARMA(A, variance = NULL, ar = 1, ma = 0) 8 | } 9 | \arguments{ 10 | \item{A}{An array of arbitrary square matrices in the multivariate case, 11 | or a vector of arbitrary numbers in the univariate case.} 12 | 13 | \item{variance}{A variance - covariance matrix. 14 | Note: \code{variance} not needed for the univariate case!} 15 | 16 | \item{ar}{The order of the AR part.} 17 | 18 | \item{ma}{The order of the MA part.} 19 | } 20 | \value{ 21 | If multivariate, a list containing: 22 | \itemize{ 23 | \item An array of coefficient matrices for the AR part. 24 | \item An array of coefficient matrices for the MA part. 25 | } 26 | 27 | If univariate, a list containing: 28 | \itemize{ 29 | \item A vector of coefficients for the AR part. 30 | \item A vector of coefficients for the MA part. 31 | } 32 | } 33 | \description{ 34 | Creates coefficient matrices for which the characteristic polynomial 35 | corresponds to a stationary process. 36 | See \insertCite{ansley1986note;textual}{statespacer} for details about 37 | the transformation used. 38 | } 39 | \examples{ 40 | CoeffARMA(A = stats::rnorm(2), ar = 1, ma = 1) 41 | } 42 | \references{ 43 | \insertRef{ansley1986note}{statespacer} 44 | } 45 | \author{ 46 | Dylan Beijers, \email{dylanbeijers@gmail.com} 47 | } 48 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (https://www.contributor-covenant.org), version 1.0.0, available at 25 | https://contributor-covenant.org/version/1/0/0/. 26 | -------------------------------------------------------------------------------- /docs/dev/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | https://dylanb95.github.io/statespacer/index.html 5 | 6 | 7 | https://dylanb95.github.io/statespacer/reference/BlockMatrix.html 8 | 9 | 10 | https://dylanb95.github.io/statespacer/reference/Cholesky.html 11 | 12 | 13 | https://dylanb95.github.io/statespacer/reference/CoeffARMA.html 14 | 15 | 16 | https://dylanb95.github.io/statespacer/reference/predict.statespacer.html 17 | 18 | 19 | https://dylanb95.github.io/statespacer/reference/SimSmoother.html 20 | 21 | 22 | https://dylanb95.github.io/statespacer/reference/statespacer-package.html 23 | 24 | 25 | https://dylanb95.github.io/statespacer/reference/statespacer.html 26 | 27 | 28 | https://dylanb95.github.io/statespacer/articles/boxjenkins.html 29 | 30 | 31 | https://dylanb95.github.io/statespacer/articles/dictionary.html 32 | 33 | 34 | https://dylanb95.github.io/statespacer/articles/intro.html 35 | 36 | 37 | https://dylanb95.github.io/statespacer/articles/seatbelt.html 38 | 39 | 40 | https://dylanb95.github.io/statespacer/articles/selfspec.html 41 | 42 | 43 | -------------------------------------------------------------------------------- /man/SimSmoother.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SimSmoother.R 3 | \name{SimSmoother} 4 | \alias{SimSmoother} 5 | \title{Generating Random Samples using the Simulation Smoother} 6 | \usage{ 7 | SimSmoother(object, nsim = 1, components = TRUE) 8 | } 9 | \arguments{ 10 | \item{object}{A statespacer object as returned by \code{\link{statespacer}}.} 11 | 12 | \item{nsim}{Number of random samples to draw. Defaults to \code{1}.} 13 | 14 | \item{components}{Boolean indicating whether the components of 15 | the model should be extracted in each of the random samples.} 16 | } 17 | \value{ 18 | A list containing the simulated state parameters and disturbances. 19 | In addition, it returns the components as specified by the State Space model 20 | if \code{components = TRUE}. Each of the objects are arrays, where the first 21 | dimension equals the number of time points, the second dimension the number 22 | of state parameters, disturbances, or dependent variables, and the third 23 | dimension equals the number of random samples \code{nsim}. 24 | } 25 | \description{ 26 | Draws random samples of the specified model conditional 27 | on the observed data. 28 | } 29 | \examples{ 30 | # Fits a local level model for the Nile data 31 | library(datasets) 32 | y <- matrix(Nile) 33 | fit <- statespacer(initial = 10, y = y, local_level_ind = TRUE) 34 | 35 | # Obtain random sample using the fitted model 36 | sim <- SimSmoother(fit, nsim = 1, components = TRUE) 37 | 38 | # Plot the simulated level against the smoothed level of the original data 39 | plot(sim$level[, 1, 1], type = 'p') 40 | lines(fit$smoothed$level, type = 'l') 41 | } 42 | \author{ 43 | Dylan Beijers, \email{dylanbeijers@gmail.com} 44 | } 45 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://dylanb95.github.io/statespacer 2 | 3 | development: 4 | mode: auto 5 | 6 | template: 7 | params: 8 | bootswatch: cosmo 9 | docsearch: 10 | api_key: 7e05823736aed6581d25ab2a4c1524a0 11 | index_name: statespacer 12 | opengraph: 13 | twitter: 14 | creator: "@dylanbeijers" 15 | card: summary 16 | 17 | home: 18 | title: A package for state space modelling in R 19 | description: > 20 | Functions that make estimating models in State Space form a breeze. 21 | This package implements state-of-the-art algorithms for estimating 22 | State Space models, and using those models to produce forecasts. 23 | strip_header: false 24 | 25 | reference: 26 | - title: State Space Model 27 | contents: 28 | - statespacer 29 | - predict.statespacer 30 | - SimSmoother 31 | - title: Parameter Transformations 32 | contents: 33 | - Cholesky 34 | - CoeffARMA 35 | - title: Matrix Utilities 36 | contents: 37 | - BlockMatrix 38 | - title: Datasets 39 | contents: 40 | - FedYieldCurve 41 | 42 | navbar: 43 | type: inverse 44 | structure: 45 | left: [home] 46 | right: [intro, reference, dictionary, articles, news, github] 47 | components: 48 | home: ~ 49 | intro: 50 | text: Intro 51 | href: articles/intro.html 52 | dictionary: 53 | text: Dictionary 54 | href: articles/dictionary.html 55 | articles: 56 | text: Tutorials 57 | menu: 58 | - text: statespacer applied to UK Road Deaths 59 | href: articles/seatbelt.html 60 | - text: Fitting ARIMA models with statespacer 61 | href: articles/boxjenkins.html 62 | - text: Specify it yourself! 63 | href: articles/selfspec.html 64 | 65 | authors: 66 | Dylan Beijers: 67 | href: https://www.linkedin.com/in/dylanbeijers/ 68 | -------------------------------------------------------------------------------- /inst/REFERENCES.bib: -------------------------------------------------------------------------------- 1 | @book{durbin2012time, 2 | title={Time series analysis by state space methods}, 3 | author={Durbin, James and Koopman, Siem Jan}, 4 | year={2012}, 5 | publisher={Oxford university press} 6 | } 7 | 8 | @article{ansley1986note, 9 | title={A note on reparameterizing a vector autoregressive moving average model to enforce stationarity}, 10 | author={Ansley, Craig F and Kohn, Robert}, 11 | journal={Journal of Statistical Computation and Simulation}, 12 | volume={24}, 13 | number={2}, 14 | pages={99--106}, 15 | year={1986}, 16 | publisher={Taylor \& Francis} 17 | } 18 | 19 | @book{commandeur2007introduction, 20 | title={An introduction to state space time series analysis}, 21 | author={Commandeur, Jacques JF and Koopman, Siem Jan}, 22 | year={2007}, 23 | publisher={Oxford University Press} 24 | } 25 | 26 | @book{box2015time, 27 | title={Time series analysis: forecasting and control}, 28 | author={Box, George EP and Jenkins, Gwilym M and Reinsel, Gregory C and Ljung, Greta M}, 29 | year={2015}, 30 | publisher={John Wiley \& Sons} 31 | } 32 | 33 | @article{koopman2010analyzing, 34 | title={Analyzing the term structure of interest rates using the dynamic Nelson--Siegel model with time-varying parameters}, 35 | author={Koopman, Siem Jan and Mallee, Max IP and Van der Wel, Michel}, 36 | journal={Journal of Business \& Economic Statistics}, 37 | volume={28}, 38 | number={3}, 39 | pages={329--343}, 40 | year={2010}, 41 | publisher={Taylor \& Francis} 42 | } 43 | 44 | @article{diebold2006macroeconomy, 45 | title={The macroeconomy and the yield curve: a dynamic latent factor approach}, 46 | author={Diebold, Francis X and Rudebusch, Glenn D and Aruoba, S Boragan}, 47 | journal={Journal of econometrics}, 48 | volume={131}, 49 | number={1-2}, 50 | pages={309--338}, 51 | year={2006}, 52 | publisher={Elsevier} 53 | } -------------------------------------------------------------------------------- /R/FedYieldCurve.R: -------------------------------------------------------------------------------- 1 | #' Federal Reserve Interest Rates 2 | #' 3 | #' A dataset containing the interest rates of the Federal Reserve, from January 4 | #' 1982 up to April 2022. The interest rates are market yields on United States 5 | #' Treasury securities with constant maturity (CMT). The maturities contained 6 | #' in this dataset are the 3 months, 6 months, 1 year, 2 years, 3 years, 7 | #' 5 years, 7 years, and 10 years maturities. Each interest rate is quoted on 8 | #' investment basis, and are reported monthly. 9 | #' 10 | #' @format A data frame with 484 rows and 9 variables: 11 | #' \describe{ 12 | #' \item{Month}{The month of the quoted interest rates, format is yyyy-mm-dd} 13 | #' \item{M3}{Market yield on U.S. Treasury securities at 3-month constant 14 | #' maturity, quoted on investment basis, in percent per year.} 15 | #' \item{M6}{Market yield on U.S. Treasury securities at 6-month constant 16 | #' maturity, quoted on investment basis, in percent per year.} 17 | #' \item{Y1}{Market yield on U.S. Treasury securities at 1-year constant 18 | #' maturity, quoted on investment basis, in percent per year.} 19 | #' \item{Y2}{Market yield on U.S. Treasury securities at 2-year constant 20 | #' maturity, quoted on investment basis, in percent per year.} 21 | #' \item{Y3}{Market yield on U.S. Treasury securities at 3-year constant 22 | #' maturity, quoted on investment basis, in percent per year.} 23 | #' \item{Y5}{Market yield on U.S. Treasury securities at 5-year constant 24 | #' maturity, quoted on investment basis, in percent per year.} 25 | #' \item{Y7}{Market yield on U.S. Treasury securities at 7-year constant 26 | #' maturity, quoted on investment basis, in percent per year.} 27 | #' \item{Y10}{Market yield on U.S. Treasury securities at 10-year constant 28 | #' maturity, quoted on investment basis, in percent per year.} 29 | #' } 30 | #' @source \url{https://www.federalreserve.gov/datadownload/Build.aspx?rel=H15} 31 | #' @examples 32 | #' data(FedYieldCurve) 33 | "FedYieldCurve" 34 | -------------------------------------------------------------------------------- /R/BlockMatrix.R: -------------------------------------------------------------------------------- 1 | #' Combine Matrices into a Block Diagonal Matrix 2 | #' 3 | #' Creates a block diagonal matrix with its arguments as the blocks. 4 | #' 5 | #' @param ... Matrices that should be put on the diagonal. 6 | #' 7 | #' @details 8 | #' `BlockMatrix()` tries to coerce its arguments to a matrix, 9 | #' using \code{\link[base:matrix]{as.matrix}}. 10 | #' 11 | #' @return Block diagonal matrix having the specified matrices on its diagonal. 12 | #' 13 | #' @author Dylan Beijers, \email{dylanbeijers@@gmail.com} 14 | #' 15 | #' @examples 16 | #' BlockMatrix(diag(ceiling(9 * stats::runif(5))), matrix(1:8, 4, 2), c(14, 8)) 17 | #' @export 18 | BlockMatrix <- function(...) { 19 | 20 | # Retrieve the arguments and put them in a list 21 | dots <- list(...) 22 | 23 | # Eliminate NULLs 24 | dots[vapply(dots, is.null, logical(1))] <- NULL 25 | 26 | # If no block matrices are specified, return a 0 x 0 matrix 27 | if (length(dots) == 0) { 28 | return(matrix(nrow = 0, ncol = 0)) 29 | } 30 | 31 | # Coerce arguments to matrices 32 | dots <- lapply(dots, as.matrix) 33 | 34 | # Dimensions of blocks 35 | dim_blocks <- vapply(dots, dim, integer(2)) 36 | 37 | # Dimensions of result matrix 38 | dim_result <- rowSums(dim_blocks) 39 | 40 | # Initialise result matrix 41 | result <- matrix(0, nrow = dim_result[[1]], ncol = dim_result[[2]]) 42 | 43 | # Indices of blocks in result matrix 44 | row_2 <- cumsum(dim_blocks[1, ]) 45 | col_2 <- cumsum(dim_blocks[2, ]) 46 | row_1 <- c(1, 1 + row_2) 47 | col_1 <- c(1, 1 + col_2) 48 | 49 | # Add block matrices on the diagonal of the result matrix 50 | for (i in seq_along(dots)) { 51 | 52 | # If current block has a 0 dimension, go to the next block 53 | if (any(dim_blocks[, i] == 0)) { 54 | next 55 | } 56 | 57 | # Indices of the block in the result 58 | row_ind <- row_1[[i]]:row_2[[i]] 59 | col_ind <- col_1[[i]]:col_2[[i]] 60 | 61 | # Add the block into the result matrix 62 | result[row_ind, col_ind] <- dots[[i]] 63 | } 64 | 65 | # Return the final constructed matrix 66 | return(result) 67 | } 68 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/dev/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /man/Cholesky.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Cholesky.R 3 | \name{Cholesky} 4 | \alias{Cholesky} 5 | \title{Construct a Valid Variance - Covariance Matrix} 6 | \usage{ 7 | Cholesky(param = NULL, format = NULL, decompositions = TRUE) 8 | } 9 | \arguments{ 10 | \item{param}{Vector containing the parameters used to construct the 11 | variance - covariance matrix.} 12 | 13 | \item{format}{Matrix representing the format for the Loading matrix L 14 | and Diagonal matrix D. The lower triangular part of the format is used 15 | as the format for the Loading matrix L. The diagonal of the format is 16 | used as the format for the Diagonal matrix D. Must be a matrix.} 17 | 18 | \item{decompositions}{Boolean indicating whether the loading and diagonal 19 | matrix of the Cholesky decomposition, and the correlation matrix and 20 | standard deviations should be returned.} 21 | } 22 | \value{ 23 | A valid variance - covariance matrix. 24 | If \code{decompositions = TRUE} then it returns a list containing: 25 | \itemize{ 26 | \item \code{cov_mat}: The variance - covariance matrix. 27 | \item \code{loading_matrix}: The loading matrix of the Cholesky decomposition. 28 | \item \code{diagonal_matrix}: The diagonal matrix of the Cholesky decomposition. 29 | \item \code{correlation_matrix}: Matrix containing the correlations. 30 | \item \code{stdev_matrix}: Matrix containing the standard deviations on the diagonal. 31 | } 32 | } 33 | \description{ 34 | Constructs a valid variance - covariance matrix by using the Cholesky LDL 35 | decomposition. 36 | } 37 | \details{ 38 | \code{format} is used to specify which elements of the loading and diagonal 39 | matrix should be non-zero. The elements of \code{param} are then distributed 40 | along the non-zero elements of the loading and diagonal matrix. 41 | The parameters for the diagonal matrix are transformed using \code{exp(2 * x)}. 42 | } 43 | \examples{ 44 | format <- diag(1, 2, 2) 45 | format[2, 1] <- 1 46 | Cholesky(param = c(2, 4, 1), format = format, decompositions = TRUE) 47 | } 48 | \author{ 49 | Dylan Beijers, \email{dylanbeijers@gmail.com} 50 | } 51 | -------------------------------------------------------------------------------- /man/FedYieldCurve.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FedYieldCurve.R 3 | \docType{data} 4 | \name{FedYieldCurve} 5 | \alias{FedYieldCurve} 6 | \title{Federal Reserve Interest Rates} 7 | \format{ 8 | A data frame with 484 rows and 9 variables: 9 | \describe{ 10 | \item{Month}{The month of the quoted interest rates, format is yyyy-mm-dd} 11 | \item{M3}{Market yield on U.S. Treasury securities at 3-month constant 12 | maturity, quoted on investment basis, in percent per year.} 13 | \item{M6}{Market yield on U.S. Treasury securities at 6-month constant 14 | maturity, quoted on investment basis, in percent per year.} 15 | \item{Y1}{Market yield on U.S. Treasury securities at 1-year constant 16 | maturity, quoted on investment basis, in percent per year.} 17 | \item{Y2}{Market yield on U.S. Treasury securities at 2-year constant 18 | maturity, quoted on investment basis, in percent per year.} 19 | \item{Y3}{Market yield on U.S. Treasury securities at 3-year constant 20 | maturity, quoted on investment basis, in percent per year.} 21 | \item{Y5}{Market yield on U.S. Treasury securities at 5-year constant 22 | maturity, quoted on investment basis, in percent per year.} 23 | \item{Y7}{Market yield on U.S. Treasury securities at 7-year constant 24 | maturity, quoted on investment basis, in percent per year.} 25 | \item{Y10}{Market yield on U.S. Treasury securities at 10-year constant 26 | maturity, quoted on investment basis, in percent per year.} 27 | } 28 | } 29 | \source{ 30 | \url{https://www.federalreserve.gov/datadownload/Build.aspx?rel=H15} 31 | } 32 | \usage{ 33 | FedYieldCurve 34 | } 35 | \description{ 36 | A dataset containing the interest rates of the Federal Reserve, from January 37 | 1982 up to April 2022. The interest rates are market yields on United States 38 | Treasury securities with constant maturity (CMT). The maturities contained 39 | in this dataset are the 3 months, 6 months, 1 year, 2 years, 3 years, 40 | 5 years, 7 years, and 10 years maturities. Each interest rate is quoted on 41 | investment basis, and are reported monthly. 42 | } 43 | \examples{ 44 | data(FedYieldCurve) 45 | } 46 | \keyword{datasets} 47 | -------------------------------------------------------------------------------- /R/statespacer-package.R: -------------------------------------------------------------------------------- 1 | #' statespacer: A package for state space modelling in R. 2 | #' 3 | #' The statespacer package provides functions that make estimating models in 4 | #' State Space form a breeze. This package implements state-of-the-art 5 | #' algorithms developed by various time series practitioners such as J. Durbin 6 | #' and S.J. Koopman. Details about the algorithms can be found in their book, 7 | #' "Time Series Analysis by State Space Methods". 8 | #' 9 | #' @section State Space Components: 10 | #' This package supports numerous state space components: 11 | #' * The Local Level 12 | #' * The Local Level + Slope 13 | #' * Smoothing Splines 14 | #' * Trigonometric Seasonality, BSM 15 | #' * (Business) Cycles 16 | #' * Explanatory Variables 17 | #' * Explanatory Variables with time-varying coefficients 18 | #' * Explanatory Variables in the Local Level 19 | #' * Explanatory Variables in the Local Level + Slope 20 | #' * ARIMA 21 | #' * SARIMA 22 | #' * Moreover, you can specify a component yourself! 23 | #' 24 | #' These components can be used for both univariate, and multivariate models. 25 | #' The components can be combined in order to get more extensive models. 26 | #' Moreover, the user can control the format of the variance - covariance 27 | #' matrices of each of the components. This way, one could specify the 28 | #' components to be deterministic instead of stochastic. In the multivariate 29 | #' case, one could impose rank restrictions on the variance - covariance 30 | #' matrices such that commonalities in the components are estimated, like 31 | #' common levels, common slopes, etc. 32 | #' 33 | #' @section Fitting Procedure: 34 | #' The package employs a univariate treatment, and an exact initialisation for 35 | #' diffuse elements, to estimate the state parameters and compute the 36 | #' loglikelihood. Collapsing large observation vectors is supported as well. 37 | #' Moreover, missing observations are readily dealt with by putting the models 38 | #' in State Space form! 39 | #' 40 | #' @author Dylan Beijers, \email{dylanbeijers@@gmail.com} 41 | #' 42 | #' @references 43 | #' \insertRef{durbin2012time}{statespacer} 44 | #' 45 | #' @docType package 46 | #' @keywords internal 47 | #' @aliases statespacer-package 48 | #' @useDynLib statespacer, .registration = TRUE 49 | #' @importFrom Rcpp sourceCpp 50 | #' @importFrom Rdpack reprompt 51 | "_PACKAGE" 52 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/dev/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/dev/extra.css: -------------------------------------------------------------------------------- 1 | .navbar-inverse { 2 | background-color: #003f4f; 3 | border-color: #003f4f; 4 | } 5 | 6 | .navbar-inverse .navbar-nav>.active>a, .navbar-inverse .navbar-nav>.active>a:hover, .navbar-inverse .navbar-nav>.active>a:focus { 7 | color: #ffffff; 8 | background-color: #00718b; 9 | } 10 | 11 | .navbar-inverse .navbar-nav>li>a:hover, .navbar-inverse .navbar-nav>li>a:focus { 12 | color: #ffffff; 13 | background-color: #00718b; 14 | } 15 | 16 | .navbar-inverse .navbar-nav>.open>a, .navbar-inverse .navbar-nav>.open>a:hover, .navbar-inverse .navbar-nav>.open>a:focus { 17 | color: #ffffff; 18 | background-color: #00718b; 19 | } 20 | 21 | .dropdown-menu>.active>a, .dropdown-menu>.active>a:hover, .dropdown-menu>.active>a:focus { 22 | color: #ffffff; 23 | text-decoration: none; 24 | background-color: #00718b; 25 | outline: 0; 26 | } 27 | 28 | .dropdown-menu>li>a:hover, .dropdown-menu>li>a:focus { 29 | color: #ffffff; 30 | text-decoration: none; 31 | background-color: #00718b; 32 | } 33 | 34 | .navbar-inverse .navbar-collapse, .navbar-inverse .navbar-form { 35 | border-color: #003f4f; 36 | } 37 | 38 | .navbar-inverse .navbar-toggle:hover, .navbar-inverse .navbar-toggle:focus { 39 | background-color: #00718b; 40 | } 41 | 42 | .navbar-inverse .navbar-nav .open .dropdown-menu>.active>a, .navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:hover, .navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:focus { 43 | color: #ffffff; 44 | background-color: #00718b; 45 | } 46 | 47 | .navbar-inverse .navbar-nav .open .dropdown-menu>li>a:hover, .navbar-inverse .navbar-nav .open .dropdown-menu>li>a:focus { 48 | color: #ffffff; 49 | background-color: #00718b; 50 | } 51 | 52 | .navbar-brand { 53 | padding: 0 0 0 54px; 54 | height: 50px; 55 | line-height: 50px; 56 | background-image: url(logo.png); 57 | background-size: 32px auto; 58 | background-repeat: no-repeat; 59 | background-position: 15px center; 60 | } 61 | 62 | .label-default { 63 | background-color: #003f4f; 64 | } 65 | 66 | .label { 67 | padding: .0em .0em .0em; 68 | font-size: 65%; 69 | font-weight: 100; 70 | line-height: 1; 71 | text-align: left; 72 | white-space: nowrap; 73 | vertical-align: sub; 74 | } 75 | 76 | .algolia-autocomplete .algolia-docsearch-suggestion--category-header { 77 | color: #003f4f; 78 | } -------------------------------------------------------------------------------- /docs/extra.css: -------------------------------------------------------------------------------- 1 | .navbar-inverse { 2 | background-color: #003f4f; 3 | border-color: #003f4f; 4 | } 5 | 6 | .navbar-inverse .navbar-nav>.active>a, .navbar-inverse .navbar-nav>.active>a:hover, .navbar-inverse .navbar-nav>.active>a:focus { 7 | color: #ffffff; 8 | background-color: #00718b; 9 | } 10 | 11 | .navbar-inverse .navbar-nav>li>a:hover, .navbar-inverse .navbar-nav>li>a:focus { 12 | color: #ffffff; 13 | background-color: #00718b; 14 | } 15 | 16 | .navbar-inverse .navbar-nav>.open>a, .navbar-inverse .navbar-nav>.open>a:hover, .navbar-inverse .navbar-nav>.open>a:focus { 17 | color: #ffffff; 18 | background-color: #00718b; 19 | } 20 | 21 | .dropdown-menu>.active>a, .dropdown-menu>.active>a:hover, .dropdown-menu>.active>a:focus { 22 | color: #ffffff; 23 | text-decoration: none; 24 | background-color: #00718b; 25 | outline: 0; 26 | } 27 | 28 | .dropdown-menu>li>a:hover, .dropdown-menu>li>a:focus { 29 | color: #ffffff; 30 | text-decoration: none; 31 | background-color: #00718b; 32 | } 33 | 34 | .navbar-inverse .navbar-collapse, .navbar-inverse .navbar-form { 35 | border-color: #003f4f; 36 | } 37 | 38 | .navbar-inverse .navbar-toggle:hover, .navbar-inverse .navbar-toggle:focus { 39 | background-color: #00718b; 40 | } 41 | 42 | .navbar-inverse .navbar-nav .open .dropdown-menu>.active>a, .navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:hover, .navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:focus { 43 | color: #ffffff; 44 | background-color: #00718b; 45 | } 46 | 47 | .navbar-inverse .navbar-nav .open .dropdown-menu>li>a:hover, .navbar-inverse .navbar-nav .open .dropdown-menu>li>a:focus { 48 | color: #ffffff; 49 | background-color: #00718b; 50 | } 51 | 52 | .navbar-brand { 53 | padding: 0 0 0 54px; 54 | height: 50px; 55 | line-height: 50px; 56 | background-image: url(logo.png); 57 | background-size: 32px auto; 58 | background-repeat: no-repeat; 59 | background-position: 15px center; 60 | } 61 | 62 | .label-default { 63 | background-color: #003f4f; 64 | } 65 | 66 | .label { 67 | padding: .0em .0em .0em; 68 | font-size: 65%; 69 | font-weight: 100; 70 | line-height: 1; 71 | text-align: left; 72 | white-space: nowrap; 73 | vertical-align: sub; 74 | } 75 | 76 | .algolia-autocomplete .algolia-docsearch-suggestion--category-header { 77 | color: #003f4f; 78 | } -------------------------------------------------------------------------------- /pkgdown/extra.css: -------------------------------------------------------------------------------- 1 | .navbar-inverse { 2 | background-color: #003f4f; 3 | border-color: #003f4f; 4 | } 5 | 6 | .navbar-inverse .navbar-nav>.active>a, .navbar-inverse .navbar-nav>.active>a:hover, .navbar-inverse .navbar-nav>.active>a:focus { 7 | color: #ffffff; 8 | background-color: #00718b; 9 | } 10 | 11 | .navbar-inverse .navbar-nav>li>a:hover, .navbar-inverse .navbar-nav>li>a:focus { 12 | color: #ffffff; 13 | background-color: #00718b; 14 | } 15 | 16 | .navbar-inverse .navbar-nav>.open>a, .navbar-inverse .navbar-nav>.open>a:hover, .navbar-inverse .navbar-nav>.open>a:focus { 17 | color: #ffffff; 18 | background-color: #00718b; 19 | } 20 | 21 | .dropdown-menu>.active>a, .dropdown-menu>.active>a:hover, .dropdown-menu>.active>a:focus { 22 | color: #ffffff; 23 | text-decoration: none; 24 | background-color: #00718b; 25 | outline: 0; 26 | } 27 | 28 | .dropdown-menu>li>a:hover, .dropdown-menu>li>a:focus { 29 | color: #ffffff; 30 | text-decoration: none; 31 | background-color: #00718b; 32 | } 33 | 34 | .navbar-inverse .navbar-collapse, .navbar-inverse .navbar-form { 35 | border-color: #003f4f; 36 | } 37 | 38 | .navbar-inverse .navbar-toggle:hover, .navbar-inverse .navbar-toggle:focus { 39 | background-color: #00718b; 40 | } 41 | 42 | .navbar-inverse .navbar-nav .open .dropdown-menu>.active>a, .navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:hover, .navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:focus { 43 | color: #ffffff; 44 | background-color: #00718b; 45 | } 46 | 47 | .navbar-inverse .navbar-nav .open .dropdown-menu>li>a:hover, .navbar-inverse .navbar-nav .open .dropdown-menu>li>a:focus { 48 | color: #ffffff; 49 | background-color: #00718b; 50 | } 51 | 52 | .navbar-brand { 53 | padding: 0 0 0 54px; 54 | height: 50px; 55 | line-height: 50px; 56 | background-image: url(logo.png); 57 | background-size: 32px auto; 58 | background-repeat: no-repeat; 59 | background-position: 15px center; 60 | } 61 | 62 | .label-default { 63 | background-color: #003f4f; 64 | } 65 | 66 | .label { 67 | padding: .0em .0em .0em; 68 | font-size: 65%; 69 | font-weight: 100; 70 | line-height: 1; 71 | text-align: left; 72 | white-space: nowrap; 73 | vertical-align: sub; 74 | } 75 | 76 | .algolia-autocomplete .algolia-docsearch-suggestion--category-header { 77 | color: #003f4f; 78 | } -------------------------------------------------------------------------------- /docs/docsearch.json: -------------------------------------------------------------------------------- 1 | { 2 | "index_name": "statespacer", 3 | "start_urls": [ 4 | { 5 | "url": "https://dylanb95.github.io/statespacer/index.html", 6 | "selectors_key": "homepage", 7 | "tags": [ 8 | "homepage" 9 | ] 10 | }, 11 | { 12 | "url": "https://dylanb95.github.io/statespacer/reference", 13 | "selectors_key": "reference", 14 | "tags": [ 15 | "reference" 16 | ] 17 | }, 18 | { 19 | "url": "https://dylanb95.github.io/statespacer/articles", 20 | "selectors_key": "articles", 21 | "tags": [ 22 | "articles" 23 | ] 24 | } 25 | ], 26 | "stop_urls": [ 27 | "/reference/$", 28 | "/reference/index.html", 29 | "/articles/$", 30 | "/articles/index.html" 31 | ], 32 | "sitemap_urls": [ 33 | "https://dylanb95.github.io/statespacer/sitemap.xml" 34 | ], 35 | "selectors": { 36 | "homepage": { 37 | "lvl0": { 38 | "selector": ".contents h1", 39 | "default_value": "statespacer Home page" 40 | }, 41 | "lvl1": { 42 | "selector": ".contents h2" 43 | }, 44 | "lvl2": { 45 | "selector": ".contents h3", 46 | "default_value": "Context" 47 | }, 48 | "lvl3": ".ref-arguments td, .ref-description", 49 | "text": ".contents p, .contents li, .contents .pre" 50 | }, 51 | "reference": { 52 | "lvl0": { 53 | "selector": ".contents h1" 54 | }, 55 | "lvl1": { 56 | "selector": ".contents .name", 57 | "default_value": "Argument" 58 | }, 59 | "lvl2": { 60 | "selector": ".ref-arguments th", 61 | "default_value": "Description" 62 | }, 63 | "lvl3": ".ref-arguments td, .ref-description", 64 | "text": ".contents p, .contents li" 65 | }, 66 | "articles": { 67 | "lvl0": { 68 | "selector": ".contents h1" 69 | }, 70 | "lvl1": { 71 | "selector": ".contents .name" 72 | }, 73 | "lvl2": { 74 | "selector": ".contents h2, .contents h3", 75 | "default_value": "Context" 76 | }, 77 | "text": ".contents p, .contents li" 78 | } 79 | }, 80 | "selectors_exclude": [ 81 | ".dont-index" 82 | ], 83 | "min_indexed_level": 2, 84 | "custom_settings": { 85 | "separatorsToIndex": "_", 86 | "attributesToRetrieve": [ 87 | "hierarchy", 88 | "content", 89 | "anchor", 90 | "url", 91 | "url_without_anchor" 92 | ] 93 | } 94 | } 95 | 96 | -------------------------------------------------------------------------------- /docs/dev/docsearch.json: -------------------------------------------------------------------------------- 1 | { 2 | "index_name": "statespacer", 3 | "start_urls": [ 4 | { 5 | "url": "https://dylanb95.github.io/statespacer/index.html", 6 | "selectors_key": "homepage", 7 | "tags": [ 8 | "homepage" 9 | ] 10 | }, 11 | { 12 | "url": "https://dylanb95.github.io/statespacer/reference", 13 | "selectors_key": "reference", 14 | "tags": [ 15 | "reference" 16 | ] 17 | }, 18 | { 19 | "url": "https://dylanb95.github.io/statespacer/articles", 20 | "selectors_key": "articles", 21 | "tags": [ 22 | "articles" 23 | ] 24 | } 25 | ], 26 | "stop_urls": [ 27 | "/reference/$", 28 | "/reference/index.html", 29 | "/articles/$", 30 | "/articles/index.html" 31 | ], 32 | "sitemap_urls": [ 33 | "https://dylanb95.github.io/statespacer/sitemap.xml" 34 | ], 35 | "selectors": { 36 | "homepage": { 37 | "lvl0": { 38 | "selector": ".contents h1", 39 | "default_value": "statespacer Home page" 40 | }, 41 | "lvl1": { 42 | "selector": ".contents h2" 43 | }, 44 | "lvl2": { 45 | "selector": ".contents h3", 46 | "default_value": "Context" 47 | }, 48 | "lvl3": ".ref-arguments td, .ref-description", 49 | "text": ".contents p, .contents li, .contents .pre" 50 | }, 51 | "reference": { 52 | "lvl0": { 53 | "selector": ".contents h1" 54 | }, 55 | "lvl1": { 56 | "selector": ".contents .name", 57 | "default_value": "Argument" 58 | }, 59 | "lvl2": { 60 | "selector": ".ref-arguments th", 61 | "default_value": "Description" 62 | }, 63 | "lvl3": ".ref-arguments td, .ref-description", 64 | "text": ".contents p, .contents li" 65 | }, 66 | "articles": { 67 | "lvl0": { 68 | "selector": ".contents h1" 69 | }, 70 | "lvl1": { 71 | "selector": ".contents .name" 72 | }, 73 | "lvl2": { 74 | "selector": ".contents h2, .contents h3", 75 | "default_value": "Context" 76 | }, 77 | "text": ".contents p, .contents li" 78 | } 79 | }, 80 | "selectors_exclude": [ 81 | ".dont-index" 82 | ], 83 | "min_indexed_level": 2, 84 | "custom_settings": { 85 | "separatorsToIndex": "_", 86 | "attributesToRetrieve": [ 87 | "hierarchy", 88 | "content", 89 | "anchor", 90 | "url", 91 | "url_without_anchor" 92 | ] 93 | } 94 | } 95 | 96 | -------------------------------------------------------------------------------- /man/statespacer-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/statespacer-package.R 3 | \docType{package} 4 | \name{statespacer-package} 5 | \alias{statespacer-package} 6 | \alias{_PACKAGE} 7 | \title{statespacer: A package for state space modelling in R.} 8 | \description{ 9 | The statespacer package provides functions that make estimating models in 10 | State Space form a breeze. This package implements state-of-the-art 11 | algorithms developed by various time series practitioners such as J. Durbin 12 | and S.J. Koopman. Details about the algorithms can be found in their book, 13 | "Time Series Analysis by State Space Methods". 14 | } 15 | \section{State Space Components}{ 16 | 17 | This package supports numerous state space components: 18 | \itemize{ 19 | \item The Local Level 20 | \item The Local Level + Slope 21 | \item Smoothing Splines 22 | \item Trigonometric Seasonality, BSM 23 | \item (Business) Cycles 24 | \item Explanatory Variables 25 | \item Explanatory Variables with time-varying coefficients 26 | \item Explanatory Variables in the Local Level 27 | \item Explanatory Variables in the Local Level + Slope 28 | \item ARIMA 29 | \item SARIMA 30 | \item Moreover, you can specify a component yourself! 31 | } 32 | 33 | These components can be used for both univariate, and multivariate models. 34 | The components can be combined in order to get more extensive models. 35 | Moreover, the user can control the format of the variance - covariance 36 | matrices of each of the components. This way, one could specify the 37 | components to be deterministic instead of stochastic. In the multivariate 38 | case, one could impose rank restrictions on the variance - covariance 39 | matrices such that commonalities in the components are estimated, like 40 | common levels, common slopes, etc. 41 | } 42 | 43 | \section{Fitting Procedure}{ 44 | 45 | The package employs a univariate treatment, and an exact initialisation for 46 | diffuse elements, to estimate the state parameters and compute the 47 | loglikelihood. Collapsing large observation vectors is supported as well. 48 | Moreover, missing observations are readily dealt with by putting the models 49 | in State Space form! 50 | } 51 | 52 | \references{ 53 | \insertRef{durbin2012time}{statespacer} 54 | } 55 | \seealso{ 56 | Useful links: 57 | \itemize{ 58 | \item \url{https://DylanB95.github.io/statespacer/} 59 | \item \url{https://github.com/DylanB95/statespacer/} 60 | \item Report bugs at \url{https://github.com/DylanB95/statespacer/issues/} 61 | } 62 | 63 | } 64 | \author{ 65 | Dylan Beijers, \email{dylanbeijers@gmail.com} 66 | } 67 | \keyword{internal} 68 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | https://dylanb95.github.io/statespacer/404.html 5 | 6 | 7 | https://dylanb95.github.io/statespacer/articles/boxjenkins.html 8 | 9 | 10 | https://dylanb95.github.io/statespacer/articles/dictionary.html 11 | 12 | 13 | https://dylanb95.github.io/statespacer/articles/index.html 14 | 15 | 16 | https://dylanb95.github.io/statespacer/articles/intro.html 17 | 18 | 19 | https://dylanb95.github.io/statespacer/articles/seatbelt.html 20 | 21 | 22 | https://dylanb95.github.io/statespacer/articles/selfspec.html 23 | 24 | 25 | https://dylanb95.github.io/statespacer/authors.html 26 | 27 | 28 | https://dylanb95.github.io/statespacer/CODE_OF_CONDUCT.html 29 | 30 | 31 | https://dylanb95.github.io/statespacer/index.html 32 | 33 | 34 | https://dylanb95.github.io/statespacer/LICENSE-text.html 35 | 36 | 37 | https://dylanb95.github.io/statespacer/LICENSE.html 38 | 39 | 40 | https://dylanb95.github.io/statespacer/news/index.html 41 | 42 | 43 | https://dylanb95.github.io/statespacer/reference/BlockMatrix.html 44 | 45 | 46 | https://dylanb95.github.io/statespacer/reference/Cholesky.html 47 | 48 | 49 | https://dylanb95.github.io/statespacer/reference/CoeffARMA.html 50 | 51 | 52 | https://dylanb95.github.io/statespacer/reference/FedYieldCurve.html 53 | 54 | 55 | https://dylanb95.github.io/statespacer/reference/index.html 56 | 57 | 58 | https://dylanb95.github.io/statespacer/reference/predict.statespacer.html 59 | 60 | 61 | https://dylanb95.github.io/statespacer/reference/SimSmoother.html 62 | 63 | 64 | https://dylanb95.github.io/statespacer/reference/StateSpaceEval.html 65 | 66 | 67 | https://dylanb95.github.io/statespacer/reference/StateSpaceFit.html 68 | 69 | 70 | https://dylanb95.github.io/statespacer/reference/StateSpaceForecast.html 71 | 72 | 73 | https://dylanb95.github.io/statespacer/reference/statespacer-package.html 74 | 75 | 76 | https://dylanb95.github.io/statespacer/reference/statespacer.html 77 | 78 | 79 | -------------------------------------------------------------------------------- /man/predict.statespacer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/predict.R 3 | \name{predict.statespacer} 4 | \alias{predict.statespacer} 5 | \title{State Space Model Forecasting} 6 | \usage{ 7 | \method{predict}{statespacer}( 8 | object, 9 | addvar_list_fc = NULL, 10 | level_addvar_list_fc = NULL, 11 | self_spec_list_fc = NULL, 12 | forecast_period = 1, 13 | nsim = 0, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{object}{A statespacer object as returned by \code{\link{statespacer}}.} 19 | 20 | \item{addvar_list_fc}{A list containing the explanatory variables for each 21 | of the dependent variables. The list should contain p (number of dependent 22 | variables) elements. Each element of the list should be a 23 | \code{forecast_period} x k_p matrix, with k_p being the number of explanatory 24 | variables for the pth dependent variable. If no explanatory variables 25 | should be added for one of the dependent variables, then set the 26 | corresponding element to \code{NULL}.} 27 | 28 | \item{level_addvar_list_fc}{A list containing the explanatory variables 29 | for each of the dependent variables. The list should contain p 30 | (number of dependent variables) elements. Each element of the list should 31 | be a \code{forecast_period} x k_p matrix, with k_p being the number of 32 | explanatory variables for the pth dependent variable. If no explanatory 33 | variables should be added for one of the dependent variables, then set 34 | the corresponding element to \code{NULL}.} 35 | 36 | \item{self_spec_list_fc}{A list containing the specification of the self 37 | specified component. Does not have to be specified if it does not differ 38 | from \code{self_spec_list} as passed on to \code{\link{statespacer}}. If some 39 | system matrices are time-varying then you should specify this argument. 40 | See \code{\link{statespacer}} for details about the format that must be 41 | followed for this argument.} 42 | 43 | \item{forecast_period}{Number of time steps to forecast ahead.} 44 | 45 | \item{nsim}{Number of simulations to generate over the forecast period.} 46 | 47 | \item{...}{Arguments passed on to the \code{predict} generic. Should not be used!} 48 | } 49 | \value{ 50 | A list containing the forecasts and corresponding uncertainties. 51 | In addition, it returns the components of the forecasts, as specified 52 | by the State Space model. 53 | } 54 | \description{ 55 | Produces forecasts and out of sample simulations using a fitted State Space Model. 56 | } 57 | \examples{ 58 | # Fit a SARIMA model on the AirPassengers data 59 | library(datasets) 60 | Data <- matrix(log(AirPassengers)) 61 | sarima_list <- list(list(s = c(12, 1), ar = c(0, 0), i = c(1, 1), ma = c(1, 1))) 62 | fit <- statespacer(y = Data, 63 | H_format = matrix(0), 64 | sarima_list = sarima_list, 65 | initial = c(0.5*log(var(diff(Data))), 0, 0)) 66 | 67 | # Obtain forecasts for 100 steps ahead using the fitted model 68 | fc <- predict(fit, forecast_period = 100, nsim = 10) 69 | 70 | # Plot the forecasts and one of the simulation paths 71 | plot(fc$y_fc, type = 'l') 72 | lines(fc$sim$y[, 1, 1], type = 'p') 73 | } 74 | \references{ 75 | \insertRef{durbin2012time}{statespacer} 76 | } 77 | \author{ 78 | Dylan Beijers, \email{dylanbeijers@gmail.com} 79 | } 80 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # statespacer 0.5.0 2 | 3 | ## Extra functionality 4 | 5 | * Adds the option to generate forward simulations. See `?predict.statespacer` for details. 6 | 7 | ## Bug Fixes 8 | 9 | * Fixes the returning of NA when calling `Cholesky()` without a format. 10 | 11 | # statespacer 0.4.1 12 | 13 | ## Removed dependency 14 | 15 | * Removes the dependency on the YieldCurve package by including an updated FedYieldCurve dataset in the statespacer package. See `?FedYieldCurve` for details. 16 | 17 | # statespacer 0.4.0 18 | 19 | ## Extra functionality 20 | 21 | * Introduces the simulation smoother for drawing random samples conditional on the observed data. See `?SimSmoother` for details. 22 | 23 | ## Performance improvements 24 | 25 | * Extraction of components now done a bit more efficiently. 26 | 27 | ## Bug fixes 28 | 29 | * Fixed incrementation of initialisation_steps during initialisation when the dependent variable was missing. 30 | 31 | # statespacer 0.3.0 32 | 33 | ## Performance improvements 34 | 35 | * Kalman Filter and Smoother now fully written in c++. 36 | 37 | ## Extra functionality 38 | 39 | * Computation of diagnostics now optional using `diagnostics = TRUE`. 40 | * Added full system matrices to the statespacer object. 41 | * Added predicted, filtered, and forecasted `P_star` and `P_inf`. 42 | 43 | ## Bug fixes 44 | 45 | * Fixed bug in predicting using explanatory variables. 46 | * Fixed edge case in adding explanatory variables. The bug occurred when there was only 1 explanatory variable and 1 dependent variable supplied, causing the Z system matrix to be a vector instead of an array. 47 | 48 | # statespacer 0.2.1 49 | 50 | ## Bug fixes 51 | 52 | * Patch for macOS. On macOS, assignment of nested lists is handled a bit differently than on other platforms. For instance, if `first <- list()`, then assigning `first$second[[["third"]] <- 1` returns on Windows (and other platforms) a list named `first`, that contains another list named `second`, that contains a named element `third` equal to an unnamed length 1 numerical vector. On macOS though, it returns a list named `first`, that contains a named element `second` equal to a named (`third`) length 1 numerical vector. So `second` is a list on the other platforms, while being a named numerical vector on macOS. This caused a bug on macOS while computing standard errors. 53 | 54 | # statespacer 0.2.0 55 | 56 | ## Breaking changes 57 | 58 | * API change by making use of S3 classes and methods: 59 | 60 | * Replaced `StateSpaceFit()` for `statespacer()`. 61 | 62 | * Replaced `StateSpaceEval(...)` for `statespacer(..., fit = FALSE)`. 63 | 64 | * `statespacer()` returns a list object of class `statespacer`. 65 | 66 | * Replaced `StateSpaceForecast()` for the S3 method `predict.statespacer()`. 67 | 68 | ## Performance improvements 69 | 70 | * Major: 71 | 72 | * Calculation of loglikelihood now done using c++. Major performance improvement as the loglikelihood potentially gets calculated a lot of times by the optimisation procedure. 73 | 74 | * Minor: 75 | 76 | * Making use of crossprod and tcrossprod. 77 | 78 | * Improved efficiency of the computation of standard_errors. 79 | 80 | * y_temp outside of LogLikelihood function. 81 | 82 | * Easier to find proper initial values, reducing time spent on trial and error by the user. 83 | 84 | ## Extra functionality 85 | 86 | * Printing progress now optional using `verbose = TRUE`. 87 | 88 | * Computation of standard_errors now optional using `standard_errors = TRUE`. 89 | 90 | # statespacer 0.1.0 91 | 92 | * Initial release to CRAN! 93 | -------------------------------------------------------------------------------- /docs/dev/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $(".examples, div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent; 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /R/CombineSysMat.R: -------------------------------------------------------------------------------- 1 | #' Combine the Z System Matrices of two State Space Components 2 | #' 3 | #' Combines the Z system matrices of two State Space components. 4 | #' 5 | #' @param Z1 Z system matrix of the first component. 6 | #' @param Z2 Z system matrix of the second component. 7 | #' 8 | #' @return 9 | #' Returns a matrix if both `Z1` and `Z2` are matrices. 10 | #' Returns an array if at least one of them is an array. 11 | #' 12 | #' @noRd 13 | CombineZ <- function(Z1, Z2) { 14 | 15 | # Check if one of the arguments is NULL 16 | if (is.null(Z1)) { 17 | return(Z2) 18 | } 19 | if (is.null(Z2)) { 20 | return(Z1) 21 | } 22 | 23 | # Check if Z1 and Z2 are matrices 24 | is_mat_Z1 <- is.matrix(Z1) 25 | is_mat_Z2 <- is.matrix(Z2) 26 | 27 | # Dimensions of Z matrices 28 | dimZ1 <- dim(Z1) 29 | dimZ2 <- dim(Z2) 30 | 31 | # Check if rows match 32 | if (dimZ1[[1]] != dimZ2[[1]]) { 33 | stop("Number of rows of Z matrices must match!", call. = FALSE) 34 | } 35 | 36 | # Compute result 37 | if (is_mat_Z1 && is_mat_Z2) { 38 | result <- cbind(Z1, Z2) 39 | } else if (is_mat_Z1 && !is_mat_Z2) { 40 | result <- array(0, dim = c(dimZ1[[1]], dimZ1[[2]] + dimZ2[[2]], dimZ2[[3]])) 41 | result[, 1:dimZ1[[2]], ] <- Z1 42 | result[, (dimZ1[[2]] + 1):(dimZ1[[2]] + dimZ2[[2]]), ] <- Z2 43 | } else if (!is_mat_Z1 && is_mat_Z2) { 44 | result <- array(0, dim = c(dimZ1[[1]], dimZ1[[2]] + dimZ2[[2]], dimZ1[[3]])) 45 | result[, 1:dimZ1[[2]], ] <- Z1 46 | result[, (dimZ1[[2]] + 1):(dimZ1[[2]] + dimZ2[[2]]), ] <- Z2 47 | } else { 48 | # Check if 3rd dimensions match 49 | if (dimZ1[[3]] != dimZ2[[3]]) { 50 | stop("3rd dimensions of Z matrices must match!", call. = FALSE) 51 | } 52 | result <- array(0, dim = c(dimZ1[[1]], dimZ1[[2]] + dimZ2[[2]], dimZ1[[3]])) 53 | result[, 1:dimZ1[[2]], ] <- Z1 54 | result[, (dimZ1[[2]] + 1):(dimZ1[[2]] + dimZ2[[2]]), ] <- Z2 55 | } 56 | 57 | return(result) 58 | } 59 | 60 | #' Combine T, R, Q System Matrices of two State Space Components 61 | #' 62 | #' Combines the T, R, or Q system matrices of two State Space components. 63 | #' 64 | #' @param S1 system matrix of the first component. 65 | #' @param S2 system matrix of the second component. 66 | #' 67 | #' @return 68 | #' Returns a matrix if both `S1` and `S2` are matrices. 69 | #' Returns an array if at least one of them is an array. 70 | #' 71 | #' @noRd 72 | CombineTRQ <- function(S1, S2) { 73 | 74 | # Check if one of the arguments is NULL 75 | if (is.null(S1)) { 76 | return(S2) 77 | } 78 | if (is.null(S2)) { 79 | return(S1) 80 | } 81 | 82 | # Check if S1 and S2 are matrices 83 | is_mat_S1 <- is.matrix(S1) 84 | is_mat_S2 <- is.matrix(S2) 85 | 86 | # Dimensions of S matrices 87 | dimS1 <- dim(S1) 88 | dimS2 <- dim(S2) 89 | 90 | # Compute result 91 | if (is_mat_S1 && is_mat_S2) { 92 | result <- BlockMatrix(S1, S2) 93 | } else if (is_mat_S1 && !is_mat_S2) { 94 | result <- array( 95 | 0, 96 | dim = c(dimS1[[1]] + dimS2[[1]], dimS1[[2]] + dimS2[[2]], dimS2[[3]]) 97 | ) 98 | result[1:dimS1[[1]], 1:dimS1[[2]], ] <- S1 99 | result[ 100 | (dimS1[[1]] + 1):(dimS1[[1]] + dimS2[[1]]), 101 | (dimS1[[2]] + 1):(dimS1[[2]] + dimS2[[2]]), 102 | ] <- S2 103 | } else if (!is_mat_S1 && is_mat_S2) { 104 | result <- array( 105 | 0, 106 | dim = c(dimS1[[1]] + dimS2[[1]], dimS1[[2]] + dimS2[[2]], dimS1[[3]]) 107 | ) 108 | result[1:dimS1[[1]], 1:dimS1[[2]], ] <- S1 109 | result[ 110 | (dimS1[[1]] + 1):(dimS1[[1]] + dimS2[[1]]), 111 | (dimS1[[2]] + 1):(dimS1[[2]] + dimS2[[2]]), 112 | ] <- S2 113 | } else { 114 | # Check if 3rd dimensions match 115 | if (dimS1[[3]] != dimS2[[3]]) { 116 | stop("3rd dimensions of S matrices must match!", call. = FALSE) 117 | } 118 | result <- array( 119 | 0, 120 | dim = c(dimS1[[1]] + dimS2[[1]], dimS1[[2]] + dimS2[[2]], dimS1[[3]]) 121 | ) 122 | result[1:dimS1[[1]], 1:dimS1[[2]], ] <- S1 123 | result[ 124 | (dimS1[[1]] + 1):(dimS1[[1]] + dimS2[[1]]), 125 | (dimS1[[2]] + 1):(dimS1[[2]] + dimS2[[2]]), 126 | ] <- S2 127 | } 128 | 129 | return(result) 130 | } 131 | -------------------------------------------------------------------------------- /R/RcppExports.R: -------------------------------------------------------------------------------- 1 | # Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | #' Extract Component of Random Samples 5 | #' 6 | #' @param a Array containing the state vectors for each time point 7 | #' and random sample. 8 | #' @param Z Z system matrix of the State Space model component. 9 | #' 10 | #' @noRd 11 | ExtractComponentC <- function(a, Z) { 12 | .Call(`_statespacer_ExtractComponentC`, a, Z) 13 | } 14 | 15 | #' Employ the Fast Kalman Smoother on multiple samples 16 | #' 17 | #' @param y Array of samples. 18 | #' @param a Initial values of the state vector. 19 | #' @param P_inf Diffuse part of the variance - covariance matrix of the 20 | #' state vector. 21 | #' @param P_star Stationary part of the variance - covariance matrix of the 22 | #' state vector. 23 | #' @param Z Z system matrix of the State Space model. 24 | #' @param T T system matrix of the State Space model. 25 | #' @param R R system matrix of the State Space model. 26 | #' @param Q Q system matrix of the State Space model. 27 | #' @param initialisation_steps Number of steps that were 28 | #' needed during initialisation. 29 | #' @param transposed_state Boolean indicating whether a 30 | #' transposed variant of the state should be returned. 31 | #' 32 | #' @noRd 33 | FastSmootherC <- function(y, a, P_inf, P_star, Z, T, R, Q, initialisation_steps, transposed_state) { 34 | .Call(`_statespacer_FastSmootherC`, y, a, P_inf, P_star, Z, T, R, Q, initialisation_steps, transposed_state) 35 | } 36 | 37 | #' Employ the Kalman Filter and Smoother 38 | #' 39 | #' @param y Matrix of observations. 40 | #' @param y_isna Matrix indicating which observations are missing. 41 | #' @param a Initial values of the state vector. 42 | #' @param P_inf Diffuse part of the variance - covariance matrix of the 43 | #' state vector. 44 | #' @param P_star Stationary part of the variance - covariance matrix of the 45 | #' state vector. 46 | #' @param Z Z system matrix of the State Space model. 47 | #' @param T T system matrix of the State Space model. 48 | #' @param R R system matrix of the State Space model. 49 | #' @param Q Q system matrix of the State Space model. 50 | #' @param diagnostics Boolean indicating whether diagnostics should be computed. 51 | #' 52 | #' @noRd 53 | KalmanC <- function(y, y_isna, a, P_inf, P_star, Z, T, R, Q, diagnostics) { 54 | .Call(`_statespacer_KalmanC`, y, y_isna, a, P_inf, P_star, Z, T, R, Q, diagnostics) 55 | } 56 | 57 | #' Employ the Kalman Filter to calculate the loglikelihood 58 | #' 59 | #' @param y Matrix of observations. 60 | #' @param y_isna Matrix indicating which observations are missing. 61 | #' @param a Initial values of the state vector. 62 | #' @param P_inf Diffuse part of the variance - covariance matrix of the 63 | #' state vector. 64 | #' @param P_star Stationary part of the variance - covariance matrix of the 65 | #' state vector. 66 | #' @param Z Z system matrix of the State Space model. 67 | #' @param T T system matrix of the State Space model. 68 | #' @param R R system matrix of the State Space model. 69 | #' @param Q Q system matrix of the State Space model. 70 | #' 71 | #' @noRd 72 | LogLikC <- function(y, y_isna, a, P_inf, P_star, Z, T, R, Q) { 73 | .Call(`_statespacer_LogLikC`, y, y_isna, a, P_inf, P_star, Z, T, R, Q) 74 | } 75 | 76 | #' Draw Random Samples of a State Space Component 77 | #' 78 | #' @param nsim Number of random samples to draw. 79 | #' @param repeat_Q Number of times the drawing of random samples 80 | #' using Q should be repeated. 81 | #' @param N Number of time points. 82 | #' @param a Initial values of the state vector of the component. 83 | #' @param Z Z system matrix of the State Space model component. 84 | #' @param T T system matrix of the State Space model component. 85 | #' @param R R system matrix of the State Space model component. 86 | #' @param Q Q system matrix of the State Space model component. 87 | #' @param P_star P_star system matrix of the State Space model component. 88 | #' Only used when draw_initial = true. 89 | #' @param draw_initial Boolean indicating whether the initial state 90 | #' should be simulated. 91 | #' @param eta_only Boolean indicating whether only the 92 | #' disturbances should be simulated. 93 | #' @param transposed_state Boolean indicating whether a 94 | #' transposed variant of the state should be returned. 95 | #' 96 | #' @noRd 97 | SimulateC <- function(nsim, repeat_Q, N, a, Z, T, R, Q, P_star, draw_initial, eta_only, transposed_state) { 98 | .Call(`_statespacer_SimulateC`, nsim, repeat_Q, N, a, Z, T, R, Q, P_star, draw_initial, eta_only, transposed_state) 99 | } 100 | 101 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%" 13 | ) 14 | ``` 15 | 16 | # State Space Modelling in R 17 | 18 | 19 | [![Travis build status](https://travis-ci.com/DylanB95/statespacer.svg?branch=master)](https://travis-ci.com/DylanB95/statespacer) 20 | [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) 21 | [![CRAN status](https://www.r-pkg.org/badges/version/statespacer)](https://CRAN.R-project.org/package=statespacer) 22 | 23 | 24 | ## Overview 25 | statespacer is a package for state space modelling and forecasting in R. It provides functions that make estimating models in State Space form a breeze. This package implements state-of-the-art algorithms developed by various time series practitioners such as J. Durbin and S.J. Koopman. Details about the algorithms can be found in their book, "Time Series Analysis by State Space Methods". 26 | 27 | If you are new to statespacer, check out `vignette("intro", "statespacer")` for a quick start to the statespacer package! Also check out the references for the following functions: 28 | 29 | * `statespacer()` for fitting State Space models. 30 | * `predict.statespacer()` for producing forecasts and out-of-sample simulations using fitted State Space models. 31 | * `SimSmoother()` for drawing random samples of the hidden state of a State Space model conditional on the data. 32 | 33 | ## State Space Components 34 | This package supports numerous state space components: 35 | 36 | * The Local Level 37 | * The Local Level + Slope 38 | * Smoothing Splines 39 | * Trigonometric Seasonality, BSM 40 | * (Business) Cycles 41 | * Explanatory Variables 42 | * Explanatory Variables with time-varying coefficients 43 | * Explanatory Variables in the Local Level 44 | * Explanatory Variables in the Local Level + Slope 45 | * ARIMA 46 | * SARIMA 47 | * Moreover, you can specify a component yourself! 48 | 49 | These components can be used for both univariate, and multivariate models. The components can be combined in order to get more extensive models. Moreover, the user can control the format of the variance - covariance matrices of each of the components. This way, one could specify the components to be deterministic instead of stochastic. In the multivariate case, one could impose rank restrictions on the variance - covariance matrices such that commonalities in the components are estimated, like common levels, common slopes, etc. 50 | 51 | ## Fitting Procedure 52 | The package employs a univariate treatment, and an exact initialisation for diffuse elements, to estimate the state parameters and compute the loglikelihood. Collapsing large observation vectors is supported as well. Moreover, missing observations are readily dealt with by putting the models in State Space form! 53 | 54 | ## Installation 55 | 56 | You can install statespacer from CRAN with: 57 | 58 | ```{r, eval = FALSE} 59 | install.packages("statespacer") 60 | ``` 61 | 62 | ### Development version 63 | 64 | To get a bug fix or to use a feature from the development version, you can install the development version of statespacer from GitHub. 65 | 66 | ```{r, eval = FALSE} 67 | # install.packages("devtools") 68 | devtools::install_github("DylanB95/statespacer") 69 | ``` 70 | 71 | ## Usage 72 | ```{r, message = FALSE, warning = FALSE} 73 | library(statespacer) 74 | 75 | library(datasets) 76 | y <- matrix(Nile) 77 | 78 | fit <- statespacer(y = y, 79 | local_level_ind = TRUE, 80 | initial = 0.5*log(var(y))) 81 | 82 | plot(1871:1970, fit$function_call$y, type = 'p', ylim = c(500, 1400), 83 | xlab = NA, ylab = NA, 84 | sub = "The smoothed level with 90% confidence intervals, 85 | and the observed data points") 86 | lines(1871:1970, fit$smoothed$level, type = 'l') 87 | lines(1871:1970, fit$smoothed$level + qnorm(0.95) * sqrt(fit$smoothed$V[1,1,]), 88 | type = 'l', col = 'gray' 89 | ) 90 | lines(1871:1970, fit$smoothed$level - qnorm(0.95) * sqrt(fit$smoothed$V[1,1,]), 91 | type = 'l', col = 'gray' 92 | ) 93 | ``` 94 | 95 | ## Getting help 96 | 97 | If you encounter a clear bug, please file an issue with a minimal reproducible example on [GitHub](https://github.com/DylanB95/statespacer/issues). 98 | 99 | --- 100 | Please note that the 'statespacer' project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms. 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # State Space Modelling in R 5 | 6 | 7 | 8 | [![Travis build 9 | status](https://travis-ci.com/DylanB95/statespacer.svg?branch=master)](https://travis-ci.com/DylanB95/statespacer) 10 | [![Lifecycle: 11 | stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) 12 | [![CRAN 13 | status](https://www.r-pkg.org/badges/version/statespacer)](https://CRAN.R-project.org/package=statespacer) 14 | 15 | 16 | ## Overview 17 | 18 | statespacer is a package for state space modelling and forecasting in R. 19 | It provides functions that make estimating models in State Space form a 20 | breeze. This package implements state-of-the-art algorithms developed by 21 | various time series practitioners such as J. Durbin and S.J. Koopman. 22 | Details about the algorithms can be found in their book, “Time Series 23 | Analysis by State Space Methods”. 24 | 25 | If you are new to statespacer, check out 26 | `vignette("intro", "statespacer")` for a quick start to the statespacer 27 | package! Also check out the references for the following functions: 28 | 29 | - `statespacer()` for fitting State Space models. 30 | - `predict.statespacer()` for producing forecasts and out-of-sample 31 | simulations using fitted State Space models. 32 | - `SimSmoother()` for drawing random samples of the hidden state of a 33 | State Space model conditional on the data. 34 | 35 | ## State Space Components 36 | 37 | This package supports numerous state space components: 38 | 39 | - The Local Level 40 | - The Local Level + Slope 41 | - Smoothing Splines 42 | - Trigonometric Seasonality, BSM 43 | - (Business) Cycles 44 | - Explanatory Variables 45 | - Explanatory Variables with time-varying coefficients 46 | - Explanatory Variables in the Local Level 47 | - Explanatory Variables in the Local Level + Slope 48 | - ARIMA 49 | - SARIMA 50 | - Moreover, you can specify a component yourself! 51 | 52 | These components can be used for both univariate, and multivariate 53 | models. The components can be combined in order to get more extensive 54 | models. Moreover, the user can control the format of the variance - 55 | covariance matrices of each of the components. This way, one could 56 | specify the components to be deterministic instead of stochastic. In the 57 | multivariate case, one could impose rank restrictions on the variance - 58 | covariance matrices such that commonalities in the components are 59 | estimated, like common levels, common slopes, etc. 60 | 61 | ## Fitting Procedure 62 | 63 | The package employs a univariate treatment, and an exact initialisation 64 | for diffuse elements, to estimate the state parameters and compute the 65 | loglikelihood. Collapsing large observation vectors is supported as 66 | well. Moreover, missing observations are readily dealt with by putting 67 | the models in State Space form! 68 | 69 | ## Installation 70 | 71 | You can install statespacer from CRAN with: 72 | 73 | ``` r 74 | install.packages("statespacer") 75 | ``` 76 | 77 | ### Development version 78 | 79 | To get a bug fix or to use a feature from the development version, you 80 | can install the development version of statespacer from GitHub. 81 | 82 | ``` r 83 | # install.packages("devtools") 84 | devtools::install_github("DylanB95/statespacer") 85 | ``` 86 | 87 | ## Usage 88 | 89 | ``` r 90 | library(statespacer) 91 | 92 | library(datasets) 93 | y <- matrix(Nile) 94 | 95 | fit <- statespacer(y = y, 96 | local_level_ind = TRUE, 97 | initial = 0.5*log(var(y))) 98 | 99 | plot(1871:1970, fit$function_call$y, type = 'p', ylim = c(500, 1400), 100 | xlab = NA, ylab = NA, 101 | sub = "The smoothed level with 90% confidence intervals, 102 | and the observed data points") 103 | lines(1871:1970, fit$smoothed$level, type = 'l') 104 | lines(1871:1970, fit$smoothed$level + qnorm(0.95) * sqrt(fit$smoothed$V[1,1,]), 105 | type = 'l', col = 'gray' 106 | ) 107 | lines(1871:1970, fit$smoothed$level - qnorm(0.95) * sqrt(fit$smoothed$V[1,1,]), 108 | type = 'l', col = 'gray' 109 | ) 110 | ``` 111 | 112 | 113 | 114 | ## Getting help 115 | 116 | If you encounter a clear bug, please file an issue with a minimal 117 | reproducible example on 118 | [GitHub](https://github.com/DylanB95/statespacer/issues). 119 | 120 | ------------------------------------------------------------------------ 121 | 122 | Please note that the ‘statespacer’ project is released with a 123 | [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By contributing to 124 | this project, you agree to abide by its terms. 125 | -------------------------------------------------------------------------------- /vignettes/intro.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introduction to statespacer" 3 | description: > 4 | Start here if this is your first time using statespacer. You'll learn how to 5 | use `statespacer()` to fit a simple State Space model, called the Local 6 | Level model, to the Nile dataset. 7 | output: rmarkdown::html_vignette 8 | bibliography: ../inst/REFERENCES.bib 9 | vignette: > 10 | %\VignetteIndexEntry{Introduction to statespacer} 11 | %\VignetteEngine{knitr::rmarkdown} 12 | %\VignetteEncoding{UTF-8} 13 | --- 14 | 15 | ```{r, include = FALSE} 16 | knitr::opts_chunk$set( 17 | collapse = TRUE, 18 | comment = "#>" 19 | ) 20 | ``` 21 | 22 | This document provides a brief introduction to using the statespacer package. It does so by showcasing the estimation of a Local Level model on the well known Nile data. See `?Nile` for more information about this dataset. 23 | 24 | To start, let's first introduce the Local Level model. Mathematically, this model can be represented as follows: 25 | 26 | $$ 27 | \begin{aligned} 28 | y_t ~ &= ~ \mu_t ~ + ~ \varepsilon_t, ~~~~~~ \varepsilon_t ~ \sim ~ N(0, ~ \sigma_\varepsilon^2), \\ 29 | \mu_{t+1} ~ &= ~ \mu_t ~ + ~ \eta_t, ~~~~~~ \eta_t ~ \sim ~ N(0, ~ \sigma_\eta^2), 30 | \end{aligned} 31 | $$ 32 | 33 | where $y_t$ is the dependent variable at time $t$, $\mu_t$ is the unobserved level at time $t$, and $\varepsilon_t$ and $\eta_t$ are disturbances. This model has two parameters, $\sigma_\varepsilon^2$ and $\sigma_\eta^2$ that will be estimated by maximising the loglikelihood. In addition, the level $\mu_t$ is a state parameter that will be estimated by employing the Kalman Filter. For extensive details about the algorithms employed, see @durbin2012time. 34 | 35 | Estimating this model using the statespacer package is simple. First, we load the data and extract the dependent variable. The dependent variable needs to be specified as a matrix, with each column being one of the dependents. In this case, we just have one column, as the Nile data comprises a univariate series. 36 | 37 | ```{r, setup} 38 | # Load statespacer 39 | library(statespacer) 40 | 41 | # Load the dataset 42 | library(datasets) 43 | y <- matrix(Nile) 44 | ``` 45 | 46 | To fit a local level model, we simply call the `statespacer()` function. See `?statespacer` for further details. 47 | 48 | ```{r} 49 | fit <- statespacer(y = y, 50 | local_level_ind = TRUE, 51 | initial = 0.5*log(var(y)), 52 | verbose = TRUE) 53 | ``` 54 | 55 | We get a warning message about the number of initial parameters, as we didn't specify enough of them. We needed 2 initial parameters, but specified only 1. This is okay, as the function just replicates the specified parameters the required amount of times. This way, we don't need to worry about how many parameters are needed. We could also specify too many initial parameters, in which case only the first few are used. This is particularly useful when we want random initial parameters. One could just simply specify `initial = rnorm(1000)`, and not have to worry about if enough parameters were supplied. 56 | 57 | Now, let's check the estimated values of $\sigma_\varepsilon^2$ and $\sigma_\eta^2$. 58 | 59 | ```{r} 60 | c(fit$system_matrices$H$H, fit$system_matrices$Q$level) 61 | ``` 62 | 63 | Note that we use the notation used in @durbin2012time for the system matrices. $H$ being the system matrix for the variance - covariance matrix of the observation equation, and $Q$ being the system matrix for the variance - covariance matrix of the state equation. 64 | 65 | Checking out the estimated level is easy as well. The filtered level: 66 | 67 | ```{r, fig.height = 4.5, fig.width = 7} 68 | plot(1871:1970, fit$function_call$y, type = 'p', ylim = c(500, 1400), 69 | xlab = NA, ylab = NA, 70 | sub = "The filtered level with 90% confidence intervals, 71 | and the observed data points" 72 | ) 73 | lines(1871:1970, fit$filtered$level, type = 'l') 74 | lines(1871:1970, fit$filtered$level + qnorm(0.95) * sqrt(fit$filtered$P[1,1,]), 75 | type = 'l', col = 'gray' 76 | ) 77 | lines(1871:1970, fit$filtered$level - qnorm(0.95) * sqrt(fit$filtered$P[1,1,]), 78 | type = 'l', col = 'gray' 79 | ) 80 | ``` 81 | 82 | And the smoothed level: 83 | 84 | ```{r, fig.height = 4.5, fig.width = 7} 85 | plot(1871:1970, fit$function_call$y, type = 'p', ylim = c(500, 1400), 86 | xlab = NA, ylab = NA, 87 | sub = "The smoothed level with 90% confidence intervals, 88 | and the observed data points") 89 | lines(1871:1970, fit$smoothed$level, type = 'l') 90 | lines(1871:1970, fit$smoothed$level + qnorm(0.95) * sqrt(fit$smoothed$V[1,1,]), 91 | type = 'l', col = 'gray' 92 | ) 93 | lines(1871:1970, fit$smoothed$level - qnorm(0.95) * sqrt(fit$smoothed$V[1,1,]), 94 | type = 'l', col = 'gray' 95 | ) 96 | ``` 97 | 98 | The object returned by `statespacer()` exhibits many other useful items. For more information about these items, please see `vignette("dictionary", "statespacer")`. For more exhibitions of the statespacer package, please see the other tutorials on or `browseVignettes("statespacer")`. 99 | 100 | ## References 101 | -------------------------------------------------------------------------------- /src/SimulateC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | // [[Rcpp::depends(RcppArmadillo)] 3 | 4 | //' Draw Random Samples of a State Space Component 5 | //' 6 | //' @param nsim Number of random samples to draw. 7 | //' @param repeat_Q Number of times the drawing of random samples 8 | //' using Q should be repeated. 9 | //' @param N Number of time points. 10 | //' @param a Initial values of the state vector of the component. 11 | //' @param Z Z system matrix of the State Space model component. 12 | //' @param T T system matrix of the State Space model component. 13 | //' @param R R system matrix of the State Space model component. 14 | //' @param Q Q system matrix of the State Space model component. 15 | //' @param P_star P_star system matrix of the State Space model component. 16 | //' Only used when draw_initial = true. 17 | //' @param draw_initial Boolean indicating whether the initial state 18 | //' should be simulated. 19 | //' @param eta_only Boolean indicating whether only the 20 | //' disturbances should be simulated. 21 | //' @param transposed_state Boolean indicating whether a 22 | //' transposed variant of the state should be returned. 23 | //' 24 | //' @noRd 25 | // [[Rcpp::export]] 26 | Rcpp::List SimulateC(const int& nsim, 27 | const int& repeat_Q, 28 | const int& N, 29 | const arma::colvec& a, 30 | const arma::cube& Z, 31 | const arma::cube& T, 32 | const arma::cube& R, 33 | const arma::cube& Q, 34 | const arma::mat& P_star, 35 | const bool& draw_initial, 36 | const bool& eta_only, 37 | const bool& transposed_state) { 38 | 39 | // Number of dependent variables, state parameters and state disturbances 40 | int p = Z.n_rows, m = a.n_rows, r = Q.n_rows, r_tot = r * repeat_Q, 41 | nsim_rep = nsim * repeat_Q, total = r_tot * nsim, m_nsim = m * nsim; 42 | 43 | // The last time point 44 | int N_min1 = N - 1; 45 | 46 | // Check which system matrices are time-varying 47 | bool Z_tv = Z.n_slices > 1, T_tv = T.n_slices > 1, 48 | R_tv = R.n_slices > 1, Q_tv = Q.n_slices > 1; 49 | 50 | // Check if repeat_Q is greater than 1 51 | bool rep_g1 = repeat_Q > 1; 52 | 53 | // Initial system matrices 54 | arma::mat Z_mat = Z.slice(0), T_mat = T.slice(0), 55 | R_mat = R.slice(0), Q_mat = Q.slice(0); 56 | 57 | // Initialise simulated disturbances, (transposed) state, and dependent 58 | arma::cube eta(N, r_tot, nsim), 59 | a_cube(N, m, nsim), a_t(m, nsim, N), y(N, p, nsim); 60 | arma::mat eta_sim(r, nsim_rep), eta_temp(r_tot, nsim); 61 | 62 | // Initialise vector of random draws 63 | Rcpp::NumericVector draw(total), a_draw(m_nsim); 64 | 65 | // Helpers for calculating root of Q and P_star 66 | arma::mat Q_root(r, r), U_Q(r, r), V_Q(r, r), 67 | P_root(m, m), U_P(m, m), V_P(m, m); 68 | arma::colvec s_Q(r), s_P(m); 69 | 70 | // Initial state 71 | arma::mat a_temp = arma::repmat(a, 1, nsim); 72 | if (draw_initial) { 73 | arma::svd(U_P, s_P, V_P, P_star); 74 | P_root = U_P * arma::diagmat(arma::sqrt(s_P)) * U_P.t(); 75 | a_draw = Rcpp::rnorm(m_nsim); 76 | a_temp = a_temp + P_root * arma::mat(a_draw.begin(), m, nsim); 77 | } 78 | a_cube.row(0) = a_temp; 79 | if (transposed_state) { 80 | a_t.slice(0) = a_temp; 81 | } 82 | 83 | // Initial root of Q 84 | arma::svd(U_Q, s_Q, V_Q, Q_mat); 85 | Q_root = U_Q * arma::diagmat(arma::sqrt(s_Q)) * U_Q.t(); 86 | 87 | // Loop over time points 88 | for (int i = 0; i < N; i++) { 89 | 90 | // Get system matrices of current time point 91 | if (Z_tv && !eta_only && i > 0) { 92 | Z_mat = Z.slice(i); 93 | } 94 | if (T_tv && !eta_only && i > 0) { 95 | T_mat = T.slice(i); 96 | } 97 | if (R_tv && !eta_only && i > 0) { 98 | R_mat = R.slice(i); 99 | } 100 | if (Q_tv && i > 0) { 101 | Q_mat = Q.slice(i); 102 | arma::svd(U_Q, s_Q, V_Q, Q_mat); 103 | Q_root = U_Q * arma::diagmat(arma::sqrt(s_Q)) * U_Q.t(); 104 | } 105 | 106 | // Simulated y component 107 | if (!eta_only) { 108 | y.row(i) = Z_mat * a_temp; 109 | } 110 | 111 | // Draw random numbers following the standard normal distribution 112 | draw = Rcpp::rnorm(total); 113 | 114 | // Transform such that the random numbers have variance Q 115 | if (rep_g1) { 116 | eta_sim = Q_root * arma::mat(draw.begin(), r, nsim_rep); 117 | eta_temp = arma::mat(eta_sim.begin(), r_tot, nsim); 118 | } else { 119 | eta_temp = Q_root * arma::mat(draw.begin(), r_tot, nsim); 120 | } 121 | eta.row(i) = eta_temp; 122 | 123 | // Simulated state 124 | if (!eta_only && i < N_min1) { 125 | a_temp = T_mat * a_temp + R_mat * eta_temp; 126 | a_cube.row(i + 1) = a_temp; 127 | if (transposed_state) { 128 | a_t.slice(i + 1) = a_temp; 129 | } 130 | } 131 | } 132 | 133 | return Rcpp::List::create( 134 | Rcpp::Named("y") = y, 135 | Rcpp::Named("a") = a_cube, 136 | Rcpp::Named("a_t") = a_t, 137 | Rcpp::Named("eta") = eta 138 | ); 139 | } 140 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/dev/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /vignettes/boxjenkins.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Fitting ARIMA models with statespacer" 3 | description: > 4 | A lot of time series practitiones resort to the well-known Box-Jenkins 5 | methods, such as ARIMA and SARIMA, when modelling time series. Those methods 6 | are easily incorporated into the State Space framework. This provides to be 7 | beneficial, as missing observations are easily dealt with in the State Space 8 | framework. Moreover, no observations need to be discarded due to the 9 | differencing and introduced lagged variables. The loglikelihood is calculated in an 10 | exact manner! In this document, we'll show you how to estimate ARIMA and 11 | SARIMA models using statespacer. 12 | output: rmarkdown::html_vignette 13 | bibliography: ../inst/REFERENCES.bib 14 | vignette: > 15 | %\VignetteIndexEntry{Fitting ARIMA models with statespacer} 16 | %\VignetteEngine{knitr::rmarkdown} 17 | %\VignetteEncoding{UTF-8} 18 | --- 19 | 20 | ```{r, include = FALSE} 21 | knitr::opts_chunk$set( 22 | collapse = TRUE, 23 | comment = "#>" 24 | ) 25 | ``` 26 | 27 | A lot of time series practitioners resort to the well-known Box-Jenkins methods, such as ARIMA and SARIMA, when modelling time series. Those methods are easily incorporated into the State Space framework. This provides to be beneficial, as missing observations are easily dealt with in the State Space framework. Moreover, no observations need to be discarded due to the differencing and introduced lagged variables. The loglikelihood is calculated in an exact manner! In this document, we show you how to estimate ARIMA and SARIMA models using statespacer. We reproduce some estimation results as in @box2015time. 28 | 29 | ## ARIMA modelling of the yearly sunspot data 30 | To showcase the estimation of ARIMA models, we make use of the `sunspot.year` data, which contains yearly numbers of sunspots from 1700 to 1988. See `?sunspot.year` for details. We only use the data from 1770 to 1869, to stay in line with @box2015time. We estimate an $\text{ARIMA}(3, ~ 0, ~ 0)$ with deterministic level (or constant if you prefer) as follows: 31 | 32 | ```{r, setup} 33 | # Load statespacer 34 | library(statespacer) 35 | 36 | # Load the dataset 37 | library(datasets) 38 | Data <- matrix(window(sunspot.year, start = 1770, end = 1869)) 39 | 40 | # Estimate the ARIMA model 41 | fit <- statespacer(y = Data, 42 | H_format = matrix(0), 43 | local_level_ind = TRUE, 44 | arima_list = list(c(3, 0, 0)), 45 | format_level = matrix(0), 46 | initial = c(0.5*log(var(Data)), 0, 0, 0), 47 | verbose = TRUE, 48 | standard_errors = TRUE) 49 | ``` 50 | 51 | Note that we eliminate the observation error by setting its variance to 0, although it's perfectly fine to include observation errors along with ARIMA models, as long as you watch out for identification issues of course. For details about specifying proper initial values, please see `vignette("dictionary", "statespacer")`. 52 | 53 | We obtain the following estimates: 54 | 55 | ```{r} 56 | # Coefficients of the ARMA component 57 | arma_coeff <- rbind( 58 | fit$system_matrices$AR$ARIMA1, 59 | fit$standard_errors$AR$ARIMA1 60 | ) 61 | arma_coeff <- cbind( 62 | arma_coeff, 63 | c(fit$smoothed$level[1], 64 | sqrt(fit$system_matrices$Z_padded$level %*% 65 | fit$smoothed$V[,,1] %*% 66 | t(fit$system_matrices$Z_padded$level)) 67 | ) 68 | ) 69 | rownames(arma_coeff) <- c("coefficient", "std_error") 70 | colnames(arma_coeff) <- c("ar1", "ar2", "ar3", "intercept") 71 | arma_coeff 72 | 73 | goodness_fit <- rbind( 74 | fit$system_matrices$Q$ARIMA1, 75 | fit$diagnostics$loglik, 76 | fit$diagnostics$AIC 77 | ) 78 | rownames(goodness_fit) <- c("Variance", "Loglikelihood", "AIC") 79 | goodness_fit 80 | ``` 81 | 82 | We see that the results are fairly similar to the results as obtained by @box2015time. Differences may occur due to the different estimation procedures. We don't have to eliminate observations, so we use the full information available at hand, in contrast to traditional estimation procedures. Note that not much has to be done to estimate VARIMA models. In fact, you only need to specify a dependent variable `y` that has more than one column! It's also straightforward to add explanatory variables, by making use of the `addvar_list` option, see `vignette("seatbelt", "statespacer")` for an example of adding explanatory variables. 83 | 84 | ## SARIMA modelling of the airline data 85 | To showcase the estimation of SARIMA models, we make use of the classic `AirPassengers` data, which contains monthly totals of international airline passengers from 1949 to 1960. See `?AirPassengers` for details. We estimate a $\text{SARIMA}(0, ~ 1, ~ 1)_{1} ~ \times ~ (0, ~ 1, ~ 1)_{12}$. Note that in the multivariate case, there is a subtle difference between $\text{SARIMA}(0, ~ 1, ~ 1)_{1} ~ \times ~ (0, ~ 1, ~ 1)_{12}$ and $\text{SARIMA}(0, ~ 1, ~ 1)_{12} ~ \times ~ (0, ~ 1, ~ 1)_{1}$ as matrix multiplication is not commutative. 86 | 87 | We proceed as follows: 88 | ```{r, warning = FALSE} 89 | # Load the dataset 90 | Data <- matrix(log(AirPassengers)) 91 | 92 | # The SARIMA specification, must be a list containing lists! 93 | sarima_list <- list(list(s = c(12, 1), ar = c(0, 0), i = c(1, 1), ma = c(1, 1))) 94 | 95 | # Fit the SARIMA model 96 | fit <- statespacer(y = Data, 97 | H_format = matrix(0), 98 | sarima_list = sarima_list, 99 | initial = c(0.5*log(var(diff(Data))), 0, 0), 100 | verbose = TRUE) 101 | ``` 102 | 103 | We obtain the following estimates: 104 | 105 | ```{r} 106 | # Coefficients of the ARMA component 107 | arma_coeff <- rbind( 108 | c(fit$system_matrices$SMA$SARIMA1$S1, fit$system_matrices$SMA$SARIMA1$S12), 109 | c(fit$standard_errors$SMA$SARIMA1$S1, fit$standard_errors$SMA$SARIMA1$S12) 110 | ) 111 | 112 | rownames(arma_coeff) <- c("coefficient", "std_error") 113 | colnames(arma_coeff) <- c("ma1 s = 1", "ma1 s = 12") 114 | arma_coeff 115 | 116 | goodness_fit <- rbind( 117 | fit$system_matrices$Q$SARIMA1, 118 | fit$diagnostics$loglik, 119 | fit$diagnostics$AIC 120 | ) 121 | rownames(goodness_fit) <- c("Variance", "Loglikelihood", "AIC") 122 | goodness_fit 123 | ``` 124 | 125 | As you can see, fitting the Box-Jenkins models with statespacer is quite easy! 126 | 127 | ## References 128 | -------------------------------------------------------------------------------- /src/LogLikC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | // [[Rcpp::depends(RcppArmadillo)] 3 | 4 | //' Employ the Kalman Filter to calculate the loglikelihood 5 | //' 6 | //' @param y Matrix of observations. 7 | //' @param y_isna Matrix indicating which observations are missing. 8 | //' @param a Initial values of the state vector. 9 | //' @param P_inf Diffuse part of the variance - covariance matrix of the 10 | //' state vector. 11 | //' @param P_star Stationary part of the variance - covariance matrix of the 12 | //' state vector. 13 | //' @param Z Z system matrix of the State Space model. 14 | //' @param T T system matrix of the State Space model. 15 | //' @param R R system matrix of the State Space model. 16 | //' @param Q Q system matrix of the State Space model. 17 | //' 18 | //' @noRd 19 | // [[Rcpp::export]] 20 | double LogLikC(const Rcpp::NumericMatrix& y, 21 | const Rcpp::LogicalMatrix& y_isna, 22 | arma::colvec a, 23 | arma::mat P_inf, 24 | arma::mat P_star, 25 | const arma::cube& Z, 26 | const arma::cube& T, 27 | const arma::cube& R, 28 | const arma::cube& Q) { 29 | 30 | // Number of observations, dependent variables, and state parameters 31 | int N = y.nrow(), p = y.ncol(), m = a.n_rows; 32 | 33 | // Keep track of the limits of the indices 34 | int N_min1 = N - 1, p_min1 = p - 1; 35 | 36 | // Check which system matrices are time-varying 37 | bool Z_tv = Z.n_slices > 1, T_tv = T.n_slices > 1, 38 | R_tv = R.n_slices > 1, Q_tv = Q.n_slices > 1; 39 | 40 | // Initial system matrices 41 | arma::mat Z_mat = Z.slice(0), T_mat = T.slice(0), 42 | R_mat = R.slice(0), Q_mat = Q.slice(0); 43 | arma::rowvec Z_row = Z_mat.row(0); 44 | 45 | // Indicator for whether the first row should be assigned 46 | bool row_assign = Z_tv || p > 1; 47 | 48 | // Check if P_inf is already 0 49 | bool initialisation = !arma::all(arma::vectorise(arma::abs(P_inf)) < 1e-7); 50 | 51 | // Initialise number of non-initialisation steps 52 | // and number of occurrences that F = 0 53 | int non_init = 0, F_eq0 = 0; 54 | 55 | // Initialise loglikelihood 56 | double loglik = 0; 57 | 58 | // Initialise objects used in computations 59 | arma::colvec M_inf(m), M_star(m), K_0(m), K_1(m); 60 | arma::mat L_0(m, m), L_1(m, m); 61 | double F_inf, F_star, F_1, F_2, v; 62 | double constant = -log(2 * M_PI) / 2; 63 | 64 | // Iterators 65 | int i, j; 66 | 67 | // Loop over time points 68 | for (i = 0; i < N; i++) { 69 | 70 | // Get system matrices of current time point 71 | if (Z_tv && i > 0) { 72 | Z_mat = Z.slice(i); 73 | } 74 | if (T_tv && i > 0) { 75 | T_mat = T.slice(i); 76 | } 77 | if (R_tv && i > 0) { 78 | R_mat = R.slice(i); 79 | } 80 | if (Q_tv && i > 0) { 81 | Q_mat = Q.slice(i); 82 | } 83 | 84 | // Loop over dependent variables 85 | for (j = 0; j < p; j++) { 86 | 87 | // Check for missing value 88 | if (y_isna(i, j)) { 89 | continue; 90 | } 91 | 92 | // Retrieve row of Z 93 | if (j > 0 || (i > 0 && row_assign)) { 94 | Z_row = Z_mat.row(j); 95 | } 96 | 97 | // Exact Kalman filter in initialisation steps 98 | if (initialisation) { 99 | 100 | // PZ' as in Kalman formulae 101 | M_inf = P_inf * Z_row.t(); 102 | M_star = P_star * Z_row.t(); 103 | 104 | // Variance matrix of the current residual/fitted value 105 | F_inf = arma::as_scalar(Z_row * M_inf); 106 | F_star = arma::as_scalar(Z_row * M_star); 107 | 108 | // Check if F_inf is nearly 0 109 | if (F_inf < 1e-7) { 110 | 111 | // Check if F_star is nearly 0 112 | if (F_star < 1e-7) { 113 | continue; 114 | } else { 115 | 116 | // Inverse of Fmat 117 | F_1 = 1 / F_star; 118 | 119 | // Current residual 120 | v = y(i, j) - arma::as_scalar(Z_row * a); 121 | 122 | // Auxiliary matrices 123 | K_0 = M_star * F_1; 124 | L_0 = arma::mat(m, m, arma::fill::eye) - K_0 * Z_row; 125 | 126 | // Estimated state vector and corresponding variance - covariance 127 | // matrix for the next step 128 | a = a + K_0 * v; 129 | P_star = P_star * L_0.t(); 130 | loglik += constant - (log(F_star) + pow(v, 2.0) * F_1) / 2; 131 | continue; 132 | } 133 | } else { 134 | 135 | // Inverse of Fmat 136 | F_1 = 1 / F_inf; 137 | F_2 = -pow(F_1, 2.0) * F_star; 138 | 139 | // Current residual 140 | v = y(i, j) - arma::as_scalar(Z_row * a); 141 | 142 | // Auxiliary matrices 143 | K_0 = M_inf * F_1; 144 | L_0 = arma::mat(m, m, arma::fill::eye) - K_0 * Z_row; 145 | K_1 = M_star * F_1 + M_inf * F_2; 146 | L_1 = -K_1 * Z_row; 147 | 148 | // Estimated state vector and corresponding variance - covariance 149 | // matrix for the next step 150 | a = a + K_0 * v; 151 | P_star = P_inf * L_1.t() + P_star * L_0.t(); 152 | P_inf = P_inf * L_0.t(); 153 | loglik += constant - log(F_inf) / 2; 154 | } 155 | 156 | // Check if P_inf converged to 0 157 | if (j < p_min1) { 158 | initialisation = !arma::all(arma::vectorise(arma::abs(P_inf)) < 1e-7); 159 | } 160 | 161 | } else { 162 | 163 | // Increment non_init 164 | non_init++; 165 | 166 | // PZ' as in Kalman formulae 167 | M_star = P_star * Z_row.t(); 168 | 169 | // Variance matrix of the current residual/fitted value 170 | F_star = arma::as_scalar(Z_row * M_star); 171 | 172 | // Check if F_star is nearly 0 173 | if (F_star < 1e-7) { 174 | 175 | // Increment number of times F = 0 176 | F_eq0++; 177 | 178 | } else { 179 | 180 | // Inverse of Fmat 181 | F_1 = 1 / F_star; 182 | 183 | // Current residual 184 | v = y(i, j) - arma::as_scalar(Z_row * a); 185 | 186 | // Auxiliary matrices 187 | K_0 = M_star * F_1; 188 | L_0 = arma::mat(m, m, arma::fill::eye) - K_0 * Z_row; 189 | 190 | // Estimated state vector and corresponding variance - covariance 191 | // matrix for the next step 192 | a = a + K_0 * v; 193 | P_star = P_star * L_0.t(); 194 | loglik += constant - (log(F_star) + pow(v, 2.0) * F_1) / 2; 195 | } 196 | } 197 | } 198 | 199 | // Perform computations for the next time point 200 | if (i < N_min1) { 201 | a = T_mat * a; 202 | P_star = T_mat * P_star * T_mat.t() + R_mat * Q_mat * R_mat.t(); 203 | if (initialisation) { 204 | P_inf = T_mat * P_inf * T_mat.t(); 205 | initialisation = !arma::all(arma::vectorise(arma::abs(P_inf)) < 1e-7); 206 | } 207 | } 208 | } 209 | 210 | // Return NA if F equals 0 during all of the non-initialisation steps 211 | if (non_init == F_eq0) { 212 | return NA_REAL; 213 | } 214 | return loglik / N; 215 | } 216 | -------------------------------------------------------------------------------- /R/Cholesky.R: -------------------------------------------------------------------------------- 1 | #' Construct a Valid Variance - Covariance Matrix 2 | #' 3 | #' Constructs a valid variance - covariance matrix by using the Cholesky LDL 4 | #' decomposition. 5 | #' 6 | #' @param param Vector containing the parameters used to construct the 7 | #' variance - covariance matrix. 8 | #' @param format Matrix representing the format for the Loading matrix L 9 | #' and Diagonal matrix D. The lower triangular part of the format is used 10 | #' as the format for the Loading matrix L. The diagonal of the format is 11 | #' used as the format for the Diagonal matrix D. Must be a matrix. 12 | #' @param decompositions Boolean indicating whether the loading and diagonal 13 | #' matrix of the Cholesky decomposition, and the correlation matrix and 14 | #' standard deviations should be returned. 15 | #' 16 | #' @details 17 | #' `format` is used to specify which elements of the loading and diagonal 18 | #' matrix should be non-zero. The elements of `param` are then distributed 19 | #' along the non-zero elements of the loading and diagonal matrix. 20 | #' The parameters for the diagonal matrix are transformed using `exp(2 * x)`. 21 | #' 22 | #' @return 23 | #' A valid variance - covariance matrix. 24 | #' If `decompositions = TRUE` then it returns a list containing: 25 | #' * `cov_mat`: The variance - covariance matrix. 26 | #' * `loading_matrix`: The loading matrix of the Cholesky decomposition. 27 | #' * `diagonal_matrix`: The diagonal matrix of the Cholesky decomposition. 28 | #' * `correlation_matrix`: Matrix containing the correlations. 29 | #' * `stdev_matrix`: Matrix containing the standard deviations on the diagonal. 30 | #' 31 | #' @author Dylan Beijers, \email{dylanbeijers@@gmail.com} 32 | #' 33 | #' @examples 34 | #' format <- diag(1, 2, 2) 35 | #' format[2, 1] <- 1 36 | #' Cholesky(param = c(2, 4, 1), format = format, decompositions = TRUE) 37 | #' @export 38 | Cholesky <- function(param = NULL, format = NULL, decompositions = TRUE) { 39 | 40 | # Check if at least one of param and format is specified 41 | if (is.null(param) && is.null(format)) { 42 | stop( 43 | paste( 44 | "Both `param` and `format` were not specified.", 45 | "Must specify at least one of them." 46 | ), 47 | call. = FALSE 48 | ) 49 | } 50 | 51 | # Number of parameters that are specified 52 | param <- param[!is.na(param)] 53 | n_par <- length(param) 54 | 55 | # If no format is specified 56 | if (is.null(format)) { 57 | 58 | # Calculate the dimension using the number of parameters that are specified 59 | dimension <- (-1 + sqrt(1 + 8 * n_par)) / 2 60 | 61 | # if calculated dimension is not an integer, return an error message 62 | if ((dimension %% 1) != 0) { 63 | stop( 64 | paste( 65 | "Number of parameters supplied result in non-integer dimensions", 66 | "of the variance - covariance matrix,", 67 | "specify a correct number of parameters.", 68 | "Hint: The dimension is calculated as (-1 + sqrt(1 + 8 * n_par))/2." 69 | ), 70 | call. = FALSE 71 | ) 72 | } 73 | 74 | # LDL Cholesky algorithm for covariance matrix 75 | # L matrix: Putting ones on the diagonal 76 | # and the parameters on the lower triangle of the matrix 77 | # D matrix: Diagonal matrix containing the magnitudes 78 | chol_L <- diag(1, dimension, dimension) 79 | chol_L[lower.tri(chol_L)] <- param[(dimension + 1):n_par] 80 | chol_D <- exp(2 * param[1:dimension]) 81 | if (any(chol_D <= 1e-7)) { 82 | return(NA) 83 | } 84 | chol_D <- diag(chol_D, dimension, dimension) 85 | 86 | # If format is specified 87 | } else { 88 | 89 | # Dimension of format 90 | format_dim <- dim(format) 91 | 92 | # Number of columns must not exceed the number of rows 93 | if (format_dim[[1]] < format_dim[[2]]) { 94 | stop( 95 | paste( 96 | "Number of columns of `format` must be less than", 97 | "or equal to the number of rows." 98 | ), 99 | call. = FALSE 100 | ) 101 | } 102 | 103 | # Only the lower triangle (including diagonal) of the format is needed, 104 | # because the LDL decomposition uses a lower triangular Loading matrix 105 | format[upper.tri(format)] <- 0 106 | 107 | # Non zero elements of the format 108 | format_n0 <- format != 0 109 | 110 | # Non zero elements of the lower triangular part of the format 111 | format_n0_lt <- format_n0 & lower.tri(format) 112 | 113 | # Non zero elements of the diagonal of the format 114 | format_n0_diag <- diag(format_n0) 115 | 116 | # Number of parameters required for the matrix (lower + diagonal) 117 | lower <- sum(format_n0_lt) 118 | diagonal <- sum(format_n0_diag) 119 | 120 | # Check if magnitudes that are set to 0, have non-zero coefficients 121 | # specified in the loading matrix L 122 | if (diagonal < sum(colSums(format_n0) != 0)) { 123 | stop( 124 | paste( 125 | "The specified format is not valid.", 126 | "Columns of which the diagonal element is zero,", 127 | "should be set to zero." 128 | ), 129 | call. = FALSE 130 | ) 131 | } 132 | 133 | # If format is a matrix of zeroes, return the format itself 134 | if (diagonal == 0) { 135 | return(format) 136 | } 137 | 138 | # Check if more parameters are specified than needed 139 | if ((lower + diagonal) < n_par) { 140 | stop("Too many parameters supplied.", call. = FALSE) 141 | } 142 | 143 | # Check if not enough parameters are specified 144 | if ((lower + diagonal) > n_par) { 145 | stop("Not enough parameters supplied.", call. = FALSE) 146 | } 147 | 148 | # Initialising L matrix with specified dimensions 149 | chol_L <- diag(1, format_dim[[1]], format_dim[[2]]) 150 | 151 | # Putting the parameters into the right places according to format 152 | if (lower > 0) { 153 | chol_L[format_n0_lt] <- param[(diagonal + 1):(diagonal + lower)] 154 | } 155 | 156 | # Constructing D matrix 157 | param_diag <- rep(0, format_dim[[2]]) 158 | param_diag_non0 <- exp(2 * param[1:diagonal]) 159 | if (any(param_diag_non0 <= 1e-7)) { 160 | return(NA) 161 | } 162 | param_diag[format_n0_diag] <- param_diag_non0 163 | chol_D <- diag(param_diag, format_dim[[2]], format_dim[[2]]) 164 | } 165 | 166 | # LDL Cholesky algorithm, resulting in a valid Variance - Covariance matrix 167 | cov_mat <- tcrossprod(chol_L %*% chol_D, chol_L) 168 | 169 | # Returning the result 170 | if (decompositions) { 171 | 172 | # Diagonal matrix containing the standard deviations 173 | stdev_matrix <- diag(sqrt(diag(cov_mat)), dim(cov_mat)[[1]], dim(cov_mat)[[2]]) 174 | 175 | # Inverse of stdev_matrix 176 | stdev_inv <- stdev_matrix 177 | diag(stdev_inv)[diag(stdev_inv) > 0] <- 178 | 1 / diag(stdev_inv)[diag(stdev_inv) > 0] 179 | 180 | # Correlation matrix 181 | correlation_matrix <- stdev_inv %*% cov_mat %*% stdev_inv 182 | 183 | result <- list( 184 | cov_mat = cov_mat, 185 | loading_matrix = chol_L, 186 | diagonal_matrix = chol_D, 187 | correlation_matrix = correlation_matrix, 188 | stdev_matrix = stdev_matrix 189 | ) 190 | return(result) 191 | } else { 192 | return(cov_mat) 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /R/AnsleyKohn.R: -------------------------------------------------------------------------------- 1 | #' Transform arbitrary matrices into partial autocorrelation matrices 2 | #' 3 | #' Creates valid partial autocorrelation matrices. 4 | #' 5 | #' @param A An array of arbitrary square matrices in the multivariate case, 6 | #' or a vector of arbitrary numbers in the univariate case. 7 | #' 8 | #' @return An array of partial autocorrelation matrices in the multivariate 9 | #' case, or a vector of partial autocorrelations in the univariate case. 10 | #' 11 | #' @noRd 12 | PACMat <- function(A) { 13 | 14 | # If univariate, computations are less expensive 15 | if (is.vector(A)) { 16 | return(A / sqrt(1 + A^2)) 17 | } 18 | 19 | # Multivariate, for a single partial autocorrelation matrix 20 | if (is.matrix(A)) { 21 | return(crossprod(solve(chol(diag(dim(A)[[1]]) + tcrossprod(A))), A)) 22 | } 23 | 24 | # Multivariate, for multiple partial autocorrelation matrices 25 | return(array(apply(A, 3, PACMat), dim = dim(A))) 26 | } 27 | 28 | #' Transform partial autocorrelation matrices into coefficient matrices 29 | #' 30 | #' Creates coefficient matrices for which the characteristic polynomial 31 | #' corresponds to a stationary process. Note, this function covers a 32 | #' subset of the space of coefficient matrices that correspond to a 33 | #' stationary process. 34 | #' 35 | #' @param P An array of partial autocorrelation matrices in the multivariate 36 | #' case, or a vector of partial autocorrelations in the univariate case. 37 | #' 38 | #' @return 39 | #' Multivariate case: 40 | #' A list containing: 41 | #' An array of coefficient matrices. 42 | #' Variance - covariance matrix of the noise, in order to transform 43 | #' coefficients further. 44 | #' Univariate case: 45 | #' A vector of coefficients. 46 | #' 47 | #' @noRd 48 | TransformPAC <- function(P) { 49 | 50 | # Initialise 51 | coeff_new <- P 52 | 53 | # If univariate, computations are less expensive 54 | if (is.vector(P)) { 55 | if (length(P) > 1) { 56 | for (i in 1:(length(P) - 1)) { 57 | coeff_old <- coeff_new 58 | for (j in 1:i) { 59 | coeff_new[[j]] <- coeff_old[[j]] - 60 | coeff_new[[i + 1]] * coeff_old[[i - j + 1]] 61 | } 62 | } 63 | } 64 | return(coeff_new) 65 | } 66 | 67 | # Multivariate 68 | # Initialise with i = 0 69 | sigma_new <- diag(dim(P)[[1]]) - tcrossprod(coeff_new[, , 1]) 70 | 71 | if (dim(P)[[3]] > 1) { 72 | 73 | # i = 0 74 | coeff_star_new <- P 75 | coeff_star_new[, , 1] <- t(P[, , 1]) 76 | sigma_star_new <- diag(dim(P)[[1]]) - tcrossprod(coeff_star_new[, , 1]) 77 | L <- t(chol(sigma_new)) 78 | L_star <- t(chol(sigma_star_new)) 79 | 80 | for (i in 1:(dim(P)[[3]] - 1)) { 81 | 82 | # Storing former values 83 | coeff_old <- coeff_new 84 | coeff_star_old <- coeff_star_new 85 | sigma_old <- sigma_new 86 | sigma_star_old <- sigma_star_new 87 | 88 | # Calculating new values 89 | coeff_new[, , i + 1] <- L %*% P[, , i + 1] %*% solve(L_star) 90 | sigma_new <- sigma_old - tcrossprod( 91 | coeff_new[, , i + 1] %*% sigma_star_old, 92 | coeff_new[, , i + 1] 93 | ) 94 | if (i < (dim(P)[[3]] - 1)) { 95 | coeff_star_new[, , i + 1] <- tcrossprod(L_star, P[, , i + 1]) %*% 96 | solve(L) 97 | sigma_star_new <- sigma_star_old - tcrossprod( 98 | coeff_star_new[, , i + 1] %*% sigma_old, 99 | coeff_star_new[, , i + 1] 100 | ) 101 | L_star <- t(chol(sigma_star_new)) 102 | L <- t(chol(sigma_new)) 103 | } 104 | for (j in 1:i) { 105 | coeff_new[, , j] <- coeff_old[, , j] - 106 | coeff_new[, , i + 1] %*% coeff_star_old[, , i - j + 1] 107 | if (i < (dim(P)[[3]] - 1)) { 108 | coeff_star_new[, , j] <- coeff_star_old[, , j] - 109 | coeff_star_new[, , i + 1] %*% coeff_old[, , i - j + 1] 110 | } 111 | } 112 | } 113 | } 114 | return(list(coeff = coeff_new, variance = sigma_new)) 115 | } 116 | 117 | #' Transform arbitrary matrices into ARMA coefficient matrices 118 | #' 119 | #' Creates coefficient matrices for which the characteristic polynomial 120 | #' corresponds to a stationary process. 121 | #' See \insertCite{ansley1986note;textual}{statespacer} for details about 122 | #' the transformation used. 123 | #' 124 | #' @param A An array of arbitrary square matrices in the multivariate case, 125 | #' or a vector of arbitrary numbers in the univariate case. 126 | #' @param variance A variance - covariance matrix. 127 | #' Note: `variance` not needed for the univariate case! 128 | #' @param ar The order of the AR part. 129 | #' @param ma The order of the MA part. 130 | #' 131 | #' @return 132 | #' If multivariate, a list containing: 133 | #' * An array of coefficient matrices for the AR part. 134 | #' * An array of coefficient matrices for the MA part. 135 | #' 136 | #' If univariate, a list containing: 137 | #' * A vector of coefficients for the AR part. 138 | #' * A vector of coefficients for the MA part. 139 | #' 140 | #' @author Dylan Beijers, \email{dylanbeijers@@gmail.com} 141 | #' 142 | #' @references 143 | #' \insertRef{ansley1986note}{statespacer} 144 | #' 145 | #' @examples 146 | #' CoeffARMA(A = stats::rnorm(2), ar = 1, ma = 1) 147 | #' @export 148 | CoeffARMA <- function(A, variance = NULL, ar = 1, ma = 0) { 149 | 150 | # Check for erroneous input 151 | if (ar < 0) { 152 | stop("The order of the autoregressive part must be >= 0.", call. = FALSE) 153 | } 154 | if (ma < 0) { 155 | stop("The order of the moving average part must be >= 0.", call. = FALSE) 156 | } 157 | if (ar + ma == 0) { 158 | stop( 159 | "At least one of the orders of the AR and MA parts must be positive.", 160 | call. = FALSE 161 | ) 162 | } 163 | 164 | # Initialise list to return 165 | result <- list() 166 | 167 | # Check if array contains square matrices 168 | if (is.array(A)) { 169 | if (dim(A)[1] != dim(A)[[2]]) { 170 | stop("Matrices in `A` must be square matrices.", call. = FALSE) 171 | } 172 | } 173 | 174 | # Obtain partial autocorrelation matrices 175 | P <- PACMat(A) 176 | 177 | # If univariate, coefficients are readily returned by TransformPAC 178 | if (is.vector(P)) { 179 | if (ar > 0) { 180 | P_ar <- P[1:ar] 181 | result$ar <- TransformPAC(P_ar) 182 | } 183 | if (ma > 0) { 184 | P_ma <- P[(ar + 1):(ar + ma)] 185 | result$ma <- -TransformPAC(P_ma) # Note the minus sign 186 | } 187 | return(result) 188 | } 189 | 190 | # Cholesky decomposition of variance - covariance matrix 191 | L <- t(chol(variance)) 192 | L_inv <- solve(L) 193 | 194 | # Obtain coefficient matrices for AR part 195 | if (ar > 0) { 196 | P_ar <- P[, , 1:ar, drop = FALSE] 197 | ar_part <- TransformPAC(P_ar) 198 | L_ar <- t(chol(ar_part$variance)) 199 | L_ar_inv <- solve(L_ar) 200 | result$ar <- array( 201 | apply( 202 | ar_part$coeff, 3, 203 | function(x) L %*% L_ar_inv %*% x %*% L_ar %*% L_inv 204 | ), 205 | dim = dim(ar_part$coeff) 206 | ) 207 | } 208 | 209 | # Obtain coefficient matrices for MA part 210 | if (ma > 0) { 211 | P_ma <- P[, , (ar + 1):(ar + ma), drop = FALSE] 212 | ma_part <- TransformPAC(P_ma) 213 | L_ma <- t(chol(ma_part$variance)) 214 | L_ma_inv <- solve(L_ma) 215 | result$ma <- -array( # Note the minus sign 216 | apply( 217 | ma_part$coeff, 3, 218 | function(x) L %*% L_ma_inv %*% x %*% L_ma %*% L_inv 219 | ), 220 | dim = dim(ma_part$coeff) 221 | ) 222 | } 223 | return(result) 224 | } 225 | -------------------------------------------------------------------------------- /src/RcppExports.cpp: -------------------------------------------------------------------------------- 1 | // Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | #include 5 | #include 6 | 7 | using namespace Rcpp; 8 | 9 | #ifdef RCPP_USE_GLOBAL_ROSTREAM 10 | Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); 11 | Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); 12 | #endif 13 | 14 | // ExtractComponentC 15 | arma::cube ExtractComponentC(const arma::cube& a, const arma::cube& Z); 16 | RcppExport SEXP _statespacer_ExtractComponentC(SEXP aSEXP, SEXP ZSEXP) { 17 | BEGIN_RCPP 18 | Rcpp::RObject rcpp_result_gen; 19 | Rcpp::RNGScope rcpp_rngScope_gen; 20 | Rcpp::traits::input_parameter< const arma::cube& >::type a(aSEXP); 21 | Rcpp::traits::input_parameter< const arma::cube& >::type Z(ZSEXP); 22 | rcpp_result_gen = Rcpp::wrap(ExtractComponentC(a, Z)); 23 | return rcpp_result_gen; 24 | END_RCPP 25 | } 26 | // FastSmootherC 27 | Rcpp::List FastSmootherC(const arma::cube& y, const arma::colvec& a, const arma::mat& P_inf, const arma::mat& P_star, const arma::cube& Z, const arma::cube& T, const arma::cube& R, const arma::cube& Q, const int& initialisation_steps, const bool& transposed_state); 28 | RcppExport SEXP _statespacer_FastSmootherC(SEXP ySEXP, SEXP aSEXP, SEXP P_infSEXP, SEXP P_starSEXP, SEXP ZSEXP, SEXP TSEXP, SEXP RSEXP, SEXP QSEXP, SEXP initialisation_stepsSEXP, SEXP transposed_stateSEXP) { 29 | BEGIN_RCPP 30 | Rcpp::RObject rcpp_result_gen; 31 | Rcpp::RNGScope rcpp_rngScope_gen; 32 | Rcpp::traits::input_parameter< const arma::cube& >::type y(ySEXP); 33 | Rcpp::traits::input_parameter< const arma::colvec& >::type a(aSEXP); 34 | Rcpp::traits::input_parameter< const arma::mat& >::type P_inf(P_infSEXP); 35 | Rcpp::traits::input_parameter< const arma::mat& >::type P_star(P_starSEXP); 36 | Rcpp::traits::input_parameter< const arma::cube& >::type Z(ZSEXP); 37 | Rcpp::traits::input_parameter< const arma::cube& >::type T(TSEXP); 38 | Rcpp::traits::input_parameter< const arma::cube& >::type R(RSEXP); 39 | Rcpp::traits::input_parameter< const arma::cube& >::type Q(QSEXP); 40 | Rcpp::traits::input_parameter< const int& >::type initialisation_steps(initialisation_stepsSEXP); 41 | Rcpp::traits::input_parameter< const bool& >::type transposed_state(transposed_stateSEXP); 42 | rcpp_result_gen = Rcpp::wrap(FastSmootherC(y, a, P_inf, P_star, Z, T, R, Q, initialisation_steps, transposed_state)); 43 | return rcpp_result_gen; 44 | END_RCPP 45 | } 46 | // KalmanC 47 | Rcpp::List KalmanC(const arma::mat& y, const Rcpp::LogicalMatrix& y_isna, const arma::colvec& a, const arma::mat& P_inf, const arma::mat& P_star, const arma::cube& Z, const arma::cube& T, const arma::cube& R, const arma::cube& Q, const bool& diagnostics); 48 | RcppExport SEXP _statespacer_KalmanC(SEXP ySEXP, SEXP y_isnaSEXP, SEXP aSEXP, SEXP P_infSEXP, SEXP P_starSEXP, SEXP ZSEXP, SEXP TSEXP, SEXP RSEXP, SEXP QSEXP, SEXP diagnosticsSEXP) { 49 | BEGIN_RCPP 50 | Rcpp::RObject rcpp_result_gen; 51 | Rcpp::RNGScope rcpp_rngScope_gen; 52 | Rcpp::traits::input_parameter< const arma::mat& >::type y(ySEXP); 53 | Rcpp::traits::input_parameter< const Rcpp::LogicalMatrix& >::type y_isna(y_isnaSEXP); 54 | Rcpp::traits::input_parameter< const arma::colvec& >::type a(aSEXP); 55 | Rcpp::traits::input_parameter< const arma::mat& >::type P_inf(P_infSEXP); 56 | Rcpp::traits::input_parameter< const arma::mat& >::type P_star(P_starSEXP); 57 | Rcpp::traits::input_parameter< const arma::cube& >::type Z(ZSEXP); 58 | Rcpp::traits::input_parameter< const arma::cube& >::type T(TSEXP); 59 | Rcpp::traits::input_parameter< const arma::cube& >::type R(RSEXP); 60 | Rcpp::traits::input_parameter< const arma::cube& >::type Q(QSEXP); 61 | Rcpp::traits::input_parameter< const bool& >::type diagnostics(diagnosticsSEXP); 62 | rcpp_result_gen = Rcpp::wrap(KalmanC(y, y_isna, a, P_inf, P_star, Z, T, R, Q, diagnostics)); 63 | return rcpp_result_gen; 64 | END_RCPP 65 | } 66 | // LogLikC 67 | double LogLikC(const Rcpp::NumericMatrix& y, const Rcpp::LogicalMatrix& y_isna, arma::colvec a, arma::mat P_inf, arma::mat P_star, const arma::cube& Z, const arma::cube& T, const arma::cube& R, const arma::cube& Q); 68 | RcppExport SEXP _statespacer_LogLikC(SEXP ySEXP, SEXP y_isnaSEXP, SEXP aSEXP, SEXP P_infSEXP, SEXP P_starSEXP, SEXP ZSEXP, SEXP TSEXP, SEXP RSEXP, SEXP QSEXP) { 69 | BEGIN_RCPP 70 | Rcpp::RObject rcpp_result_gen; 71 | Rcpp::RNGScope rcpp_rngScope_gen; 72 | Rcpp::traits::input_parameter< const Rcpp::NumericMatrix& >::type y(ySEXP); 73 | Rcpp::traits::input_parameter< const Rcpp::LogicalMatrix& >::type y_isna(y_isnaSEXP); 74 | Rcpp::traits::input_parameter< arma::colvec >::type a(aSEXP); 75 | Rcpp::traits::input_parameter< arma::mat >::type P_inf(P_infSEXP); 76 | Rcpp::traits::input_parameter< arma::mat >::type P_star(P_starSEXP); 77 | Rcpp::traits::input_parameter< const arma::cube& >::type Z(ZSEXP); 78 | Rcpp::traits::input_parameter< const arma::cube& >::type T(TSEXP); 79 | Rcpp::traits::input_parameter< const arma::cube& >::type R(RSEXP); 80 | Rcpp::traits::input_parameter< const arma::cube& >::type Q(QSEXP); 81 | rcpp_result_gen = Rcpp::wrap(LogLikC(y, y_isna, a, P_inf, P_star, Z, T, R, Q)); 82 | return rcpp_result_gen; 83 | END_RCPP 84 | } 85 | // SimulateC 86 | Rcpp::List SimulateC(const int& nsim, const int& repeat_Q, const int& N, const arma::colvec& a, const arma::cube& Z, const arma::cube& T, const arma::cube& R, const arma::cube& Q, const arma::mat& P_star, const bool& draw_initial, const bool& eta_only, const bool& transposed_state); 87 | RcppExport SEXP _statespacer_SimulateC(SEXP nsimSEXP, SEXP repeat_QSEXP, SEXP NSEXP, SEXP aSEXP, SEXP ZSEXP, SEXP TSEXP, SEXP RSEXP, SEXP QSEXP, SEXP P_starSEXP, SEXP draw_initialSEXP, SEXP eta_onlySEXP, SEXP transposed_stateSEXP) { 88 | BEGIN_RCPP 89 | Rcpp::RObject rcpp_result_gen; 90 | Rcpp::RNGScope rcpp_rngScope_gen; 91 | Rcpp::traits::input_parameter< const int& >::type nsim(nsimSEXP); 92 | Rcpp::traits::input_parameter< const int& >::type repeat_Q(repeat_QSEXP); 93 | Rcpp::traits::input_parameter< const int& >::type N(NSEXP); 94 | Rcpp::traits::input_parameter< const arma::colvec& >::type a(aSEXP); 95 | Rcpp::traits::input_parameter< const arma::cube& >::type Z(ZSEXP); 96 | Rcpp::traits::input_parameter< const arma::cube& >::type T(TSEXP); 97 | Rcpp::traits::input_parameter< const arma::cube& >::type R(RSEXP); 98 | Rcpp::traits::input_parameter< const arma::cube& >::type Q(QSEXP); 99 | Rcpp::traits::input_parameter< const arma::mat& >::type P_star(P_starSEXP); 100 | Rcpp::traits::input_parameter< const bool& >::type draw_initial(draw_initialSEXP); 101 | Rcpp::traits::input_parameter< const bool& >::type eta_only(eta_onlySEXP); 102 | Rcpp::traits::input_parameter< const bool& >::type transposed_state(transposed_stateSEXP); 103 | rcpp_result_gen = Rcpp::wrap(SimulateC(nsim, repeat_Q, N, a, Z, T, R, Q, P_star, draw_initial, eta_only, transposed_state)); 104 | return rcpp_result_gen; 105 | END_RCPP 106 | } 107 | 108 | static const R_CallMethodDef CallEntries[] = { 109 | {"_statespacer_ExtractComponentC", (DL_FUNC) &_statespacer_ExtractComponentC, 2}, 110 | {"_statespacer_FastSmootherC", (DL_FUNC) &_statespacer_FastSmootherC, 10}, 111 | {"_statespacer_KalmanC", (DL_FUNC) &_statespacer_KalmanC, 10}, 112 | {"_statespacer_LogLikC", (DL_FUNC) &_statespacer_LogLikC, 9}, 113 | {"_statespacer_SimulateC", (DL_FUNC) &_statespacer_SimulateC, 12}, 114 | {NULL, NULL, 0} 115 | }; 116 | 117 | RcppExport void R_init_statespacer(DllInfo *dll) { 118 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 119 | R_useDynamicSymbols(dll, FALSE); 120 | } 121 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | License • statespacer 6 | 7 | 8 |
    9 |
    67 | 68 | 69 | 70 |
    71 |
    72 | 75 | 76 |
    YEAR: 2020
     77 | COPYRIGHT HOLDER: Dylan Beijers
     78 | 
    79 | 80 |
    81 | 82 | 85 | 86 |
    87 | 88 | 89 | 90 |
    93 | 94 |
    95 |

    Site built with pkgdown 2.0.7.

    96 |
    97 | 98 |
    99 | 100 | 101 | 116 | 117 | --------------------------------------------------------------------------------