Uses Gibbs sampling to fit an AR model to time series data.
ar.mcmc(xdata, porder, n.iter = 1000, n.warmup = 100, plot = TRUE,
prior_var_phi = 50, prior_sig_a = 1, prior_sig_b = 2, ...)In addition to the graphics (if plot is TRUE),
the draws of each parameter (phi0, phi1, ..., sigma)
are returned invisibly and means, standard deviations, and
various quantiles are displayed.
time series data (univariate only)
autoregression order
number of iterations for the sampler
number of startup iterations for the sampler (these are removed)
if TRUE (default) returns the draws after warmup (diagonal) and a scatterplot matrix of the draws (off-diagonal)
prior variance of the vector of AR coefficients; see details
first prior for the variance component; see details
second prior for the variance component; see details
additional graphic parameters passed to tspairs
D.S. Stoffer
Assumes a normal-inverse gamma model,
$$x_t = \phi_0 + \phi_1 x_{t-1} + \dots + \phi_p x_{t-p} + \sigma z_t ,$$
where \(z_t\) is standard Gaussian noise.
With \(\Phi\) being the (p+1)-dimensional vector of the \(\phi\)s,
the priors are
\(\Phi \mid \sigma \sim N(0, \sigma^2 V_0)\) and
\(\sigma^2 \sim IG(a,b)\), where \(V_0 = \gamma^2 I\).
Defaults are given for the hyperparameters, but the user
may choose \((a,b)\) as (prior_sig_a, prior_sig_b)
and \(\gamma^2\) as prior_var_phi.
The algorithm is efficient and converges quickly. Further details can be found in Chapter 6 of the 5th edition of the Springer text.
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/.
if (FALSE) {
u = ar.mcmc(rec, 2)
tspairs(u, hist=FALSE, col.diag=6) # another view
tsplot(u, ncol=2, col=4, xlab='Index') # traces only
}
Run the code above in your browser using DataLab