Learn R Programming

bcpmeta (version 1.0)

bcpmeta.parameters: Estimate Model Parameters under a Given Configuration

Description

Given a changepoint configuration, use Gibbs sampler (or Metropolis-Hastings algorithm within Gibbs) to find posterior mean estimates of model parameters.

Usage

bcpmeta.parameters(X, meta, eta, iter = 10000, thin = 10, trend = TRUE, EB = TRUE, mu0 = NULL, nu0 = 5, phi.lower = -0.99, phi.upper = 0.99, sd.xi = 0.1, start.phi = NULL, burnin = 0.2, track.time = TRUE, show.summary = TRUE, start.year = 1, meta.year = FALSE, eta.year = FALSE)

Arguments

X
a numerical vector. Observed time series.
meta
metadata. Either a vector of 0-1 indicators of the same length as X, or a numerical vector of the time indice of the metadata times.
eta
the changepoint configuration. Either a vector of 0-1 indicators of the same length as X, or a numerical vector of the time indice of the changepoint times.
iter
total number of iterations of MCMC.
thin
thinning; save one iteration in every thin number of iterations.
trend
logical indicating whether to allow the linear trend component.
EB
logical indicating whether to use the empirical Bayes method for sigma^2 and phi.
mu0
prior mean of regime-wise means mu_j. If NULL, set to the default value mean(X).
nu0
constant factor in prior variance of regim-wise means mu_j.
phi.lower
lower bound of the range of phi
phi.upper
upper bound of the range of phi
sd.xi
standard deviation of the jump proposal of log(phi) in Metropolis-Hastings updating when the fully Bayes method is used.
start.phi
initial value phi for the MCMC when the fully Bayes method is used. If NULL, generated randomly.
burnin
the ratio of burnin length compared with the total length of MCMC. All posterior mean estimates are calculated without burnin periods.
track.time
logical indicating whether to show process time.
show.summary
logical indicating whether to show the estimates of parameters.
start.year
year index of the first time point in the series.
meta.year
logical indicating whether meta is indexed in year, if it consists of the locations of the metadata times (instead of 0-1 indicators).
eta.year
logical indicating whether eta is indexed in year, if it consists of the locations of the metadata times (instead of 0-1 indicators).

Value

Phi
the empirical Bayes estimate of phi if EB == TRUE; or a vector of length (iter/thin), the MCMC samples of phi if EB == FALSE.
Sigmasq
the empirical Bayes estimate of sigma2 if EB == TRUE; or a vector of length (iter/thin), the MCMC samples of sigma2 if EB == FALSE.
Alpha
a vector of length (iter/thin), the MCMC samples of alpha if trend == TRUE; or 0 if trend == FALSE.
Mu
a (iter/thin) * (sum(eta)+1) matrix. Each row is a MCMC sample of mu.
phi.est
the empirical Bayes estimate of phi if EB == TRUE; or the posterior mean if EB == FALSE.
sigmasq.est
the empirical Bayes estimate of sigma2 if EB == TRUE; or the posterior mean if EB == FALSE.
alpha.est
posterior mean estimate of alpha
mu.est
a vector of length sum(eta)+1, posterior mean estimate of mu
X
observed time series, same as the input value.
meta
metadata, same as the input value.
input.parameters
input parameters. Use command names to check its components.
change.phi
ratio of accepting a new phi in the MCMC chain, if EB == FALSE.

Details

Conditional on the given changepoint configuration eta, the posterior mean estimates of regime-wise mean mu and trend alphla (if trend == TRUE) is obtained via Gibbs sampler. If EB == TRUE, empirical Bayes estimates of sigma2 and phi are given; otherwise, fully Bayes estimates of them are obtained via Gibbs sampler and Metropolis-Hastings algorithm, under Jeffreys prior and uniform prior respectively.

References

Li, Y. and Lund, R. (2014) Bayesian Mulitple Changepoint Detection Using Metadata. (submitted)

See Also

Function cp.plot uses the output of this function as input.

Examples

Run this code
## Create a time series of length 200 with three mean shifts at 50, 100, 150.
data = simgen(2, 1);
X = data$X[1, ];  ## time series
meta = data$meta;  ## locations of metadata times

## Parameter estimation in the configuration where changepoints are time 50 and 99.
results = bcpmeta.parameters(X, meta = meta, eta = c(50, 99), trend = FALSE);  

Run the code above in your browser using DataLab