ar.mcmc: Fit Bayesian AR Model

View source: R/ar.mcmc.r

ar.mcmcR Documentation

Fit Bayesian AR Model

Description

Uses Gibbs sampling to fit an AR model to time series data.

Usage

ar.mcmc(xdata, porder, n.iter = 1000, n.warmup = 100, plot = TRUE, col = 4, 
        prior_var_phi = 50, prior_sig_a = 1, prior_sig_b = 2)

Arguments

xdata

time series data (univariate only)

porder

autoregression order

n.iter

number of iterations for the sampler

n.warmup

number of startup iterations for the sampler (these are removed)

plot

if TRUE (default) returns two graphics, (1) the draws after warmup and (2) a scatterplot matrix of the draws with histograms on the diagonal

col

color of the plots

prior_var_phi

prior variance of the vector of AR coefficients; see details

prior_sig_a

first prior for the variance component; see details

prior_sig_b

second prior for the variance component; see details

Details

Assumes a normal-inverse gamma model,

x_t = φ_0 + φ_1 x_{t-1} + … + φ_p x_{t-p} + σ z_t ,

where z_t is standard Gaussian noise. With Φ being the (p+1)-dimensional vector of the φs, the priors are Φ \mid σ \sim N(0, σ^2 V_0) and σ^2 \sim IG(a,b), where V_0 = γ^2 I. Defaults are given for the hyperparameters, but the user may choose (a,b) as (prior_sig_a, prior_sig_b) and γ^2 as prior_var_phi.

The algorithm is efficient and converges quickly. Further details can be found in Example 8.36 of Douc, Moulines, & Stoffer, D. (2014). Nonlinear Time Series: Theory, Methods and Applications with R Examples. CRC press. ISBN 9781466502253.

Value

In addition to the graphics (if plot is TRUE), the draws of each parameter (phi0, phi1, ..., sigma) are returned invisibly and various quantiles are displayed.

Author(s)

D.S. Stoffer

Source

Based on the script arp.mcmc used in Douc, Moulines, & Stoffer, D. (2014). Nonlinear Time Series: Theory, Methods and Applications with R Examples. CRC press. ISBN 9781466502253.

References

You can find demonstrations of astsa capabilities at FUN WITH ASTSA.

The most recent version of the package can be found at https://github.com/nickpoison/astsa/.

In addition, the News and ChangeLog files are at https://github.com/nickpoison/astsa/blob/master/NEWS.md.

The webpages for the texts and some help on using R for time series analysis can be found at https://nickpoison.github.io/.

Examples

## Not run: 

u = ar.mcmc(rec, 2)

tsplot(u, ncolm=2, col=4)  # plot the traces

apply(u, 2, ESS)    # effective sample sizes

## End(Not run)

astsa documentation built on Jan. 10, 2023, 1:11 a.m.