R/wrappers.R
svlm.Rdsvlm is a wrapper around svsample with a formula interface.
The name derives from SV and lm because a linear model with SV residuals is fitted.
The function simulates from the joint posterior distribution of the regression coefficients and the SV
parameters mu, phi, sigma (and potentially nu and rho),
along with the latent log-volatilities h_0,...,h_n and returns the
MCMC draws.
svlm(
formula,
data,
draws = 10000,
burnin = 1000,
heavytails = FALSE,
asymmetry = FALSE,
priorspec = NULL,
thin = 1,
keeptime = "all",
quiet = FALSE,
startpara = NULL,
startlatent = NULL,
parallel = c("no", "multicore", "snow"),
n_cpus = 1L,
cl = NULL,
n_chains = 1L,
print_progress = "automatic",
expert = NULL,
...
)an object of class "formula", as in lm.
an optional data frame, list or environment (or object
coercible by as.data.frame to a data frame) containing the
variables in the model. If not found in data, the
variables are taken from environment(formula), typically
the environment from which svlm is called.
single number greater or equal to 1, indicating the number of draws after burn-in (see below). Will be automatically coerced to integer. The default value is 10000.
single number greater or equal to 0, indicating the number of draws discarded as burn-in. Will be automatically coerced to integer. The default value is 1000.
if TRUE, then the residuals of the linear model
will follow a t-distribution conditional on the latent volatility process.
This model is usually called SV-t. If priorspec is given, then
heavytails is ignored.
if TRUE, then the residuals of the linear model
will follow an SV process with leverage. If priorspec is given, then
heavytails is ignored.
using the smart constructor specify_priors,
one can set the details of the prior distribution.
single number greater or equal to 1, coercible to integer.
Every thinparath parameter and latent draw is kept and returned. The default
value is 1, corresponding to no thinning of the parameter draws i.e. every
draw is stored.
Either 'all' (the default) or 'last'. Indicates which latent volatility draws should be stored.
logical value indicating whether the progress bar and other
informative output during sampling should be omitted. The default value is
FALSE, implying verbose output.
optional named list, containing the starting values
for the parameter draws. If supplied, startpara may contain
elements named mu, phi, sigma, nu, rho,
beta, and latent0.
The default value is equal to the prior mean.
In case of parallel execution with cl provided, startpara can be a list of
named lists that initialize the parallel chains.
optional vector of length length(y),
containing the starting values for the latent log-volatility draws. The
default value is rep(-10, length(y)).
In case of parallel execution with cl provided, startlatent can be a list of
named lists that initialize the parallel chains.
optional one of "no" (default), "multicore", or "snow",
indicating what type of parallellism is to be applied. Option
"multicore" is not available on Windows.
optional positive integer, the number of CPUs to be used in case of
parallel computations. Defaults to 1L. Ignored if parameter
cl is supplied and parallel != "snow".
optional so-called SNOW cluster object as implemented in package
parallel. Ignored unless parallel == "snow".
optional positive integer specifying the number of independent MCMC chains
optional one of "automatic", "progressbar",
or "iteration", controls the output. Ignored if quiet is TRUE.
optional named list of expert parameters. For most
applications, the default values probably work best. Interested users are
referred to the literature provided in the References section. If
expert is provided, it may contain the following named elements:
Logical value. If TRUE (the default),
then ancillarity-sufficiency interweaving strategy (ASIS) is applied
to improve on the sampling efficiency for the parameters.
Otherwise one parameterization is used.
Logical value. If FALSE
(the default), then auxiliary mixture sampling is used to sample the latent
states. If TRUE, extra computations are made to correct for model
misspecification either ex-post by reweighting or on-line using a
Metropolis-Hastings step.
Any extra arguments will be forwarded to
updatesummary, controlling the type of statistics calculated
for the posterior draws.
The value returned is a list object of class svdraws holding
mcmc.list object containing the parameter draws from
the posterior distribution.
mcmc.list object containing the
latent instantaneous log-volatility draws from the posterior
distribution.
mcmc.list object containing the latent
initial log-volatility draws from the posterior distribution.
mcmc.list object containing the latent variance inflation
factors for the sampler with conditional t-innovations (optional).
mcmc.list object containing the regression coefficient
draws from the posterior distribution (optional).
the left hand side of the observation equation, usually
the argument y. In case of an AR(k) specification, the
first k elements are removed.
proc_time object containing the
run time of the sampler.
a priorspec object containing the parameter
values of the prior distributions for mu,
phi, sigma, nu, rho, and
betas, and the variance of specification for latent0.
list containing the thinning
parameters, i.e. the arguments thinpara, thinlatent and
keeptime.
list containing a collection of
summary statistics of the posterior draws for para, latent,
and latent0.
character containing information about how designmatrix
was employed.
a flag for the use of svlm
helper object that represents the formula
argument formula
helper object that is needed to interpret the formula
To display the output, use print, summary and plot. The
print method simply prints the posterior draws (which is very likely
a lot of output); the summary method displays the summary statistics
currently stored in the object; the plot method
plot.svdraws gives a graphical overview of the posterior
distribution by calling volplot, traceplot and
densplot and displaying the results on a single page.
For details concerning the algorithm please see the paper by Kastner and Frühwirth-Schnatter (2014) and Hosszejni and Kastner (2019).
Kastner, G. and Frühwirth-Schnatter, S. (2014). Ancillarity-sufficiency interweaving strategy (ASIS) for boosting MCMC estimation of stochastic volatility models. Computational Statistics & Data Analysis, 76, 408–423, doi:10.1016/j.csda.2013.01.002 .
Hosszejni, D. and Kastner, G. (2019). Approaches Toward the Bayesian Estimation of the Stochastic Volatility Model with Leverage. Springer Proceedings in Mathematics & Statistics, 296, 75–83, doi:10.1007/978-3-030-30611-3_8 .
# Simulate data
n <- 50L
dat <- data.frame(x = runif(n, 3, 4),
z = runif(n, -1, -0.5))
designmatrix <- matrix(c(dat$x, dat$x^2, log10(dat$x),
dat$z), ncol = 4)
betas <- matrix(c(-1, 1, 2, 0), ncol = 1)
y <- designmatrix %*% betas + svsim(n)$y
dat$y <- y
# Formula interface
res <- svlm(y ~ 0 + x + I(x^2) + log10(x) + z, data = dat)
#> Done!
#> Summarizing posterior draws...
# Prediction
predn <- 10L
preddat <- data.frame(x = runif(predn, 3, 4),
z = runif(predn, -1, -0.5))
pred <- predict(res, newdata = preddat, steps = predn)