| FitMCMC | R Documentation |
Method that performs MCMC/Bayesian estimation of
a MSGARCH_SPEC object on a set of observations.
FitMCMC(spec, data, ctr = list())
spec |
Model specification of class |
data |
Vector (of size T) of observations. |
ctr |
A list of control parameters:
|
The total number of draws is equal to nmcmc / nthin.
The MCMC/Bayesian estimation relies on an Rcpp implementation of the adaptive sampler of Vihola (2012).
The implementation is based on the R package adaptMCMC (Andreas, 2012).
Starting values when par0 is not provided are chosen automatically
before sampling (see Ardia et al. (2019) for more details).
SamplerFUN allows for a custom sampler to be used. The function
must take the form:
function(f_posterior, data, spec, par0, ctr),
where f_posterior is the function to optimize, data is
the data, spec is the specification,
par0 are the starting parameters, and ctr are the control
parameters. The inputs spec and data,
must be passed as inputs in the sampler (see *Examples*).
The custom sampler must output a matrix containing the MCMC chain.
When do.sort = TRUE, sorting of each MCMC draw conditional on the unconditional variance is done across homogeneous regime specification.
A list of class MSGARCH_MCMC_FIT with the following elements:
par: The MCMC chain (matrix from the R package
coda (Plummer et al., 2006) of size nmcmc / nthin x d).
accept: Acceptance rate of the sampler.
spec: Model specification of class MSGARCH_SPEC
created with CreateSpec.
data: Vector (of size T) of observations.
ctr: list of the control used for the fit.
The MSGARCH_MCMC_FIT with the following methods:
DIC: Deviance Information Criterion (DIC).
simulate: Simulation.
Volatility: In-sample conditional volatility.
predict: Forecast of the conditional volatility (and predictive distribution).
UncVol: Unconditional volatility.
PredPdf: Predictive density (pdf).
PIT: Probability Integral Transform.
Risk: Value-at-Risk and Expected-Shortfall.
State: State probabilities (smoothed, filtered, predictive, Viterbi).
ExtractStateFit: Single-regime model extractor.
summary: Summary of the fit.
Andreas, S. (2012).
adaptMCMC: Implementation of a generic adaptive Monte Carlo Markov chain sampler.
https://cran.r-project.org/package=adaptMCMC
Ardia, D. Bluteau, K. Boudt, K. Catania, L. Trottier, D.-A. (2019). Markov-switching GARCH models in R: The MSGARCH package. Journal of Statistical Software, 91(4), 1-38. doi: 10.18637/jss.v091.i04
Geweke J (2007). Interpretation and Inference in Mixture Models: Simple MCMC Works. Computational Statistics & Data Analysis, 51(7), 3529-3550. doi: 10.1016/j.csda.2006.11.026
MacDonald, I.L., Zucchini, W. (1997). Hidden Markov and other models for discrete-valued time series. CRC press.
Plummer, M. Best, N. Cowles, K. & Vines, K. (2006).
coda: Convergence diagnosis and output analysis for MCMC.
R News, 6, 7-11.
https://cran.r-project.org/package=coda
Vihola, M. (2012). Robust adaptive Metropolis algorithm with coerced acceptance rate. Statistics and Computing, 22, 997-1008. doi: 10.1007/s11222-011-9269-5
# create model specification
spec <- CreateSpec()
# load data
data("SMI", package = "MSGARCH")
# fit the model on the data by MCMC
set.seed(123)
fit <- FitMCMC(spec = spec, data = SMI, ctr = list(nburn = 500L, nmcmc = 500L, nthin = 1L))
summary(fit)
# custom sampler example
## Not run:
library("mcmc")
f_MCMC <- function(f_posterior, data, spec, par0, ctr){
par <- mcmc::metrop(f_posterior, initial = par0, nbatch = ctr$nmcmc + ctr$nburn,
data = data, spec = spec)$batch
colnames(par) = names(par0)
return(par)
}
set.seed(123)
fit <- FitMCMC(spec, data = SMI, ctr = list(SamplerFUN = f_MCMC,
nburn = 500L, nmcmc = 500L, nthin = 1L))
summary(fit)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.