/atsar

Applied time series analysis in R with Stan. Allows fast Bayesian fitting of multivariate time-series models.

Primary LanguageStanGNU General Public License v3.0GPL-3.0

<style> .nav{ border:1px solid #ccc; border-width:1px 0; list-style:none; margin:0; padding:0; text-align:center; } .nav li{ display:inline-block; } .nav a{ display:inline-block; padding:5px; } </style>

The atsar R package implements Bayesian time series models using Stan, primarily for illustrative purposes and teaching (University of Washington’s Fish 507, Winter quarters). The Stan webpage, and appropriate citation guidelines are here.

INSTALL

You can install the development version of the package with:

# install.packages("devtools")
devtools::install_github("nwfsc-timeseries/atsar")

EXAMPLE

Simulate data:

library(rstan)
#> Loading required package: StanHeaders
#> Loading required package: ggplot2
#> rstan (Version 2.19.2, GitRev: 2e1f913d3ca3)
#> For execution on a local, multicore CPU with excess RAM we recommend calling
#> options(mc.cores = parallel::detectCores()).
#> To avoid recompilation of unchanged Stan programs, we recommend calling
#> rstan_options(auto_write = TRUE)
#> For improved execution time, we recommend calling
#> Sys.setenv(LOCAL_CPPFLAGS = '-march=native')
#> although this causes Stan to throw an error on a few processors.
library(atsar)
#> Loading required package: Rcpp
set.seed(123)
s = cumsum(rnorm(50))
plot(s)

Fit several models to this data:

# Regression, no slope
regression_model = fit_stan(y = s, x = model.matrix(lm(s~1)), model_name="regression")

# Regression, with slope
regression_model = fit_stan(y = s, x = model.matrix(lm(s~seq(1,length(s)))), model_name="regression")

# AR(1) time series model
ar1_model = fit_stan(y = s, est_drift=FALSE, P = 1, model_name = "ar")

# ARMA(1,1) time series model
arma1_model = fit_stan(y = s, model_name = "arma11")

# univariate ss model -- without drift but mean reversion estimated
ss_model = fit_stan(y = s, model_name = "ss_ar", est_drift=FALSE)

DOCUMENTATION

  • ATSA lab book - Many applications are covered in our Applied Time Series Analysis book developed from the labs in our course.
  • ATSA course website - We have lectures and all material from our course on our course website.
  • Additional information can be found on the NWFSC time series page which includes several additional books and packages, NWFSC time series page

CITATION

Ward, E.J., M.D. Scheuerell, and E.E. Holmes. 2018. ‘atsar’: Applied Time Series Analysis in R: an introduction to time series analysis for ecological and fisheries data with Stan. DOI

LICENSE

MARSS was developed by US federal government employees as part of their official duties. As such, it is not subject to copyright protection and is considered “public domain” (see 17 USC § 105). Public domain software can be used by anyone for any purpose, and cannot be released under a copyright license.