## BEAST: A Bayesian Ensemble Algorithm for Change-Point Detection and Time Series Decomposition
#### BEAST (Bayesian Estimator of Abrupt change, Seasonality, and Trend) is a fast, generic Bayesian model averaging algorithm to decompose time series or 1D sequential data into individual components, such as abrupt changes, trends, and periodic/seasonal variations, as described in <ins>[Zhao et al. (2019)](https://go.osu.edu/beast2019)</ins>. BEAST is useful for *changepoint detection (e.g., breakpoints, structural breaks, regime shifts, or anomalies), trend analysis, time series decomposition (e.g., trend vs seasonality), time series segmentation, and interrupted time series analysis*. See a list of <a href="#publicationid"> selected studies using BEAST </a>.
**Quick Installation**
> BEAST was impemented in C/C++ but accessible from R, Python, Matlab, and Octave. Run the following to install:
* [Python](#python): **`pip install Rbeast`**
* [Matlab](#matlab): **`eval(webread('http://b.link/rbeast',weboptions('cert','')))`**
* [Octave](#octave): **`eval(webread('http://b.link/rbeast'))`**
* [R lang](#r): **`install.packages("Rbeast")`**
**Quick Usage**
> One-liner code for Python, Matlab and R. Check below or [github.com/zhaokg/Rbeast](https://github.com/zhaokg/Rbeast) for more details.
```
# Python example
import Rbeast as rb; (Nile, Year)=rb.load_example('nile'); o=rb.beast(Nile,season='none'); rb.plot(o)
# Matlab/Octave example
load('Nile'); o = beast(Nile, 'season','none'); plotbeast(o)
# R example
library(Rbeast); data(Nile); o = beast(Nile); plot(o)
```
## Installation for R <a name=r> </a>
<!---
=====================================================================================
=====================================================================================
=====================================================================================
This is our comments:
<table border="0" style='border:none;' bordercolor="#ffffff" > <tr style='border:none;' >
<td valign="center" style='border:none;' >
<img src="https://www.r-pkg.org/badges/version/Rbeast?color=green">
<img src="http://cranlogs.r-pkg.org/badges/grand-total/Rbeast?color=green">
</td>
<td valign="center" style='border:none;' >
In CRAN-Task-View:
<a href="https://cran.r-project.org/web/views/TimeSeries.html#forecasting-and-univariate-modeling">[Time Series Analysis]</a>
<a href="https://cran.r-project.org/web/views/Bayesian.html#time-series-models">[Bayesian inference]</a>
<a href="https://cran.r-project.org/web/views/Environmetrics.html#environmental-time-series">[Environmetrics]</a>
</td>
</tr></table>
[![](https://www.r-pkg.org/badges/version/Rbeast?color=green)](https://cran.r-project.org/package=Rbeast) [![](http://cranlogs.r-pkg.org/badges/grand-total/Rbeast?color=green)](https://cran.r-project.org/package=Rbeast)
In CRAN-Task-View: [[**Time Series Analysis**]](https://cran.r-project.org/web/views/TimeSeries.html#forecasting-and-univariate-modeling), [[**Bayesian inference**]](https://cran.r-project.org/web/views/Bayesian.html#time-series-models), and [[**Environmetrics**]](https://cran.r-project.org/web/views/Environmetrics.html#environmental-time-series)
from **GitHub**: The latest R versions are also available here at [GitHub](https://github.com/zhaokg/Rbeast) and can be installed using
```R
# Windows x86 or x64 (install from binary)
install.packages("https://github.com/zhaokg/Rbeast/raw/master/R/Windows/Rbeast_0.9.5.zip" ,repos=NULL)
# Linux/Mac (install from source)
install.packages("https://github.com/zhaokg/Rbeast/raw/master/R/Rbeast_0.9.5.tar.gz", repos = NULL, type="source")
```
=====================================================================================
=====================================================================================
=====================================================================================
-->
<p align="left">
<a href= "https://cran.r-project.org/package=Rbeast">
<img src="https://www.r-pkg.org/badges/version/Rbeast?color=green" height="20">
<img src="http://cranlogs.r-pkg.org/badges/grand-total/Rbeast?color=green" height="20">
<img src="https://img.shields.io/static/v1?style=plastic&logo=r&label=Rbeast%20%20&message= In CRAN-Task-View&color=brightgreen" height="20">
</a>
</p>
> **Rbeast in CRAN-TASK-VIEW**: <a href="https://cran.r-project.org/web/views/TimeSeries.html#forecasting-and-univariate-modeling">[Time Series Analysis]</a> <a href="https://cran.r-project.org/web/views/Bayesian.html#time-series-models">[Bayesian inference]</a> <a href="https://cran.r-project.org/web/views/Environmetrics.html#environmental-time-series">[Environmetrics]</a>
An R package **`Rbeast`** has been deposited at [CRAN](https://CRAN.R-project.org/package=Rbeast). ( On CRAN, there is another Bayesian time-series package named "beast", which has nothing to do with the BEAST algorithim. Our package is `Rbeast`. Also, our package has nothing to do with the famous "Bayesian evolutionary analysis by sampling trees" aglorithm.) Install `Rbeast` in R using
```R
install.packages("Rbeast")
```
#### Run and test Rbeast in R
The main functions in Rbeast are `beast(Y, ...)`, `beast.irreg(Y, ...)`, and `beast123(Y, metadata, prior, mcmc, extra)`. The code snippet below provides a starting point for the basic usage.
```R
library(Rbeast)
data(Nile) # annual streamflow of the Nile River
out = beast(Nile, season='none') # 'none': trend-only data without seasonlaity
print(out)
plot(out)
?Rbeast # See more details about the usage of `beast`
tetris() # if you dare to waste a few moments of your life
minesweeper() # if you dare to waste a few more moments of your life
```
<table border="0" style='border:none;' bordercolor="#ffffff" width=100% >
<tr style='border:none;' >
<td valign="center" style='border:none;' >
<img height="300" align="left" src="https://github.com/zhaokg/Rbeast/raw/master/R/Images/beach.png">
</td>
<td valign="center" style='border:none;' >
<img height="300" align="center" src="https://github.com/zhaokg/Rbeast/raw/master/R/Images/Nile.png">
</td>
</tr>
</table>
<!---
[![](https://github.com/zhaokg/Rbeast/raw/master/R/Images/beach.png)](https://cran.r-project.org/package=Rbeast)
----
--->
<br/>
## Installation for Matlab <a name=matlab> </a>
[![View Rbeast on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/72515-rbeast)
Install the Matlab version of **BEAST** automatically to a local folder of your choice by running
```Matlab
beastPath = 'C:\beast\'
eval( webread('http://b.link/rbeast') )
%%%%%%%%%%%%%%%%%%%%%%%%%%% Note on Automatic Installtion %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1. Write permission needed for your chosen path; the variable name must be 'beastPath'. %
% 2. If webread has a certificate error, run the following line instead: %
eval( webread( 'http://b.link/rbeast', weboptions('cert','') ) ) %
% 3. If the automatic installation fails, please manually download all the files (see blow) %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
```
> The above will download all the files in the [Rbeast\Matlab folder at Github](https://github.com/zhaokg/Rbeast) to the chosen folder: if `beastPath` is missing, a default temporary folder (e.g., `C:\Users\$user_name$\AppData\Local\Temp\Rbeast for Windows 10`) will be used. If the automatic script fails, please download the Matlab files from