fsvsample
simulates from the joint posterior distribution and returns
the MCMC draws. It is the main workhorse to conduct inference for factor
stochastic volatility models in this package.
fsvsample(y, draws = 1000, burnin = 100, factors = 1, priormu = c(0, 10), priorphi = c(10, 3, 3, 3), priorsigma = 1, priorfacload = 1, priorng = c(1, 1), columnwise = FALSE, priorh0 = c("stationary", 1), thin = 1, keeptime = "last", runningstore = 1, runningstorethin = 1, runningstoremoments = 2, quiet = FALSE, restrict = "upper", interweaving = 4, signswitch = FALSE, heteroskedastic = TRUE, priorhomoskedastic = NA, expert, startpara, startlatent, startfacload, startfac)
m
rows is assumed to contain a single
(univariate) series of length n
.(phi+1)/2
, where
phi
denotes the persistence of the log-variances The first two
elements of priorphi
are interpreted to belong to the idiosyncratic
series, the third and fourth element of priorphi
are interpreted to
belong to the latent factors.m + factors
containing the
prior volatilities of log-variances Note: If priorsigma
has exactly
two elements, the first one will be recycled for all idiosyncratic series and
the second one will be recycled for all latent factors.m
times factors
with nonnegative elements or a single number. If a matrix is provided, its
elements are the standard deviations of the Gaussian prior distributions for
the factor loadings. If a single nonnegative number is provided, it will be
recycled accordingly. If a single negative number is provided, a Normal-Gamma
shrinkage prior for the factor loadings is assumed, where -priorfacload
is interpreted as the shrinkage parameter a
.c
and d
.TRUE
if you want to use column-wise shrinkage
and to FALSE
for row-wise shrinkage. For details please see the paper by
Kastner et al. (2016).m + factors
, containing
information about the Gaussian prior for the initial log-variances The
first m
elements are used for the idiosyncratic log-variances, the
last factors
elements are used for the factor log-variances
If an element of priorh0
is a nonnegative number, the conditional
prior of the corresponding initial log-volatility h0 is assumed to be Gaussian
with mean 0 and standard deviation priorh0 time sigma. If an element of
priorh0
is the string 'stationary', the prior of the corresponding
initial log volatility is taken to be from the stationary distribution, i.e.
h0 is assumed to be Gaussian with mean 0 and variance $sigma^2/(1-phi^2)$.
If priorh0
is of length 2 it will be recycled accordingly, whereby
the first element is used for all idiosyncratic log-variances and the
second element is used for all factor log-variances.thin
th MCMC draw is kept and returned. The default value
is 1, corresponding to no thinning of the draws, i.e. every draw is
stored.keeptime
th latent log-volatility is being monitored. If, e.g.,
keeptime = 3
, draws for the latent log-variances
h_1,h_4,h_7,...
will
be kept. If keeptime
is set to "all", this is equivalent to setting it
to 1. If
keeptime
is set to "last" (the default), only draws for the very last
latent log-variances h_n are kept.runningstore
to an
integer greater than 0 will cause fsvsample
to store the first
runningstoremoments
ergodic moments of certain variables of interest. More specifically, mean,
variance, skewness, etc. will be stored for certain variables
if runningstore
is set to a value...
>= 1
: Latent log-variances h_1,h_2,...,h_(n+r)
.
>= 2
: Latent factors f_1,...,f_r
.
>= 3
: Latent volatilities sqrt(exp(h_1,h_2,...,h_(n+r)))
.
>= 4
: Conditional covariance matrix and the square roots of its
diagonal elements.
>= 5
: Conditional correlation matrix.
>= 6
: Communalities, i.e. proportions of variances explained
through the common factors.
FALSE
, implying verbose output.restrict
to "upper" often stabilizes MCMC
estimation and can be important for identifying the factor loadings matrix,
however, it imposes a dependence on how the data are ordered. Setting
restrict
to "none" is usually the preferred option if identification
of the factor loadings matrix is of less concern but covariance estimation
or prediction is the goal. Alternatively, restrict
can be a
logical matrix
of dimension c(m, r)
indicating which elements should be unrestricted
(where restrict
is FALSE
) or zero (where restrict
is
TRUE
).For details please see Kastner et al. (2016). A value of 4 is the highly recommended default.
TRUE
to turn on a random sign switch of
factors and loadings. Note that the signs of each factor loadings matrix column
and the corresponding factor cannot be identified from the likelihood.m + factors
,
containing logical values indicating whether time-varying
(heteroskedastic = TRUE
) or constant (heteroskedastic = FALSE
)
variance should be estimated.
If heteroskedastic
is of length 2 it will be recycled accordingly,
whereby the first element is used for all idiosyncratic variances and
the second element is used for all factor variances.heteroskedastic
is set to FALSE
. In that case,
priorhomoskedastic
must be must be a matrix with positive entries
and dimension c(factors + m, 2). Values in column 1 will be interpreted as
shape and values in column 2 will be interpreted as the rate parameter
of the corresponding inverse gamma prior distribution.stochvol
package). For most
applications, the default values probably work best. Interested users are
referred to Kastner and Frühwirth-Schnatter (2014) and Kastner (2016). If
expert
is provided, it may contain the following named elements:
parameterization
: Character string equal to "centered"
,
"noncentered"
, "GIS_C"
, or "GIS_NC"
. Defaults to
"GIS_C"
.
mhcontrol
: Single numeric value controlling the proposal
density of a Metropolis-Hastings (MH) update step when sampling
sigma
. If mhcontrol
is smaller than 0, an independence
proposal will be used, while values greater than zero control the
stepsize of a log-random-walk proposal. Defaults to -1
.
gammaprior
: Single logical value indicating whether a Gamma
prior for sigma^2
should be used. If set to FALSE
,
an Inverse Gamma prior is employed. Defaults to TRUE
.
truncnormal
: Single logical value indicating whether a
truncated Gaussian distribution should be used as proposal for
draws of phi
. If set to FALSE
, a regular Gaussian
prior is employed and the draw is immediately discarded when values
outside the unit ball happen to be drawn. Defaults to FALSE
.
mhsteps
: Either 1
, 2
, or 3
. Indicates
the number of blocks used for drawing from the posterior of the
parameters. Defaults to 2
.
proposalvar4sigmaphi
: Single positive number indicating the
conditional prior variance of sigma*phi
in the ridge
proposal density for sampling (mu, phi)
.
Defaults to 10^8
.
proposalvar4sigmatheta
: Single positive number indicating
the conditional prior variance of sigma*theta
in the ridge
proposal density for sampling (mu, phi)
.
Defaults to 10^12
.
startpara
must contain three
elements named mu
(vector of length m
), phi
(vector
of length m+r
) and sigma
(vector of length m+r
).
The elements of mu
can be arbitrary numerical values, the
phi
s must be real numbers between -1
and 1
, and
the sigma
s must be positive real numbers.c(n, m + factors)
, containing the starting values of the
latent log-variances.c(m, factors)
, containing the starting values of the
factor loadings.c(factors, n)
, containing the starting values of the
latent factors.fsvdraws
holding
runningstore
for details about what
is being stored here.
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.fsvdraws
gives a graphical overview.
Kastner, G. (2016). Dealing with stochastic volatility in time series using the R package stochvol. Journal of Statistical Software, 69(5), 1--30, http://dx.doi.org/10.18637/jss.v069.i05.
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, http://dx.doi.org/10.1016/j.csda.2013.01.002.
## Not run:
# # Load exchange rate data (ships with stochvol):
# data(exrates, package = "stochvol")
# exrates$date <- NULL
#
# # Compute the de-meaned percentage log returns:
# dat <- 100 * logret(exrates, demean = TRUE)
#
# # We are going to fit a one-factor model so the ordering is irrelevant
# # NOTE that these are very few draws, you probably want more...
# res <- fsvsample(dat, factors = 1, draws = 2000, burnin = 1000, runningstore = 6)
#
# voltimeplot(res)
#
# corimageplot(res, nrow(dat), plotCI = 'circle')
#
# oldpar <- par(ask = TRUE)
# plot(res)
# par(oldpar)
# ## End(Not run)
Run the code above in your browser using DataLab