1. Estimation

RISE estimates models by three approaches through a single entry point:

Approach

When to use it

How to call

Bayesian

Informative priors, fragile identification, or model comparison via posterior model probabilities.

estimate(m, estim_priors = priors)

Maximum likelihood

Data-only inference, comparison with Bayesian, or classical inference on a non-DSGE shape.

estimate(m, estim_priors = boundsOnly) (uniform-bounds priors)

Indirect inference

Likelihood intractable; match specific moments, IRFs, or auxiliary statistics.

indirect_inference(m, myobjective, estim_priors = priors)

All three share the same mode-finding optimizers, the same restriction machinery, the same Hessian / standard-error pipeline, and the same visualization tooling. The differences are entirely in the objective and in which post-estimation outputs are meaningful.

This chapter is the modern overview of the estimation surface. The in-depth treatment is split into the sub-chapters below (restrictions, priors, posterior maximization, posterior simulation, marginal data density, processing posterior draws, indirect inference), mirroring the legacy structure.

1.17. The estimation pipeline at a glance

A complete estimation run is four steps:

% 1. Bind data and priors to a parsed model
m = set(m, data = mydata, estim_priors = priors);

% 2. Find the posterior mode
m_est = estimate(m);

% 3. (Optional) sample the posterior
[objective,lb,ub,x0,SIG]=pull_objective(m_est);

logpost=@(x)-objective(x);   % objective is minus the log posterior; the samplers maximize

obj=rise.engine.estimation.rsamplers.rwmh(logpost,x0,lb,ub,struct(N=2000,tunedCov=SIG));

results=sample(obj);

% 4. (Optional) diagnose the chain
mc=mcmc(results,fieldnames(m_est.estimation.priors));   % parameter names, in the order of the draws
mc.summary();
mc.traceplot('phi_pi');

1.18. Dispatch on properties, not class

A modern-toolbox distinctive worth flagging up front: the estimator chooses its likelihood path based on properties of the data and the model, never the model’s class. Concretely:

  • If the data has missing observations or unobserved states, the estimator runs a Kalman filter (or the regime-conditional Kalman filter, if h > 1); above the first order, a sigma-point filter.

  • If the data are complete and the model admits a closed-form posterior moment (notably BVAR with a conjugate prior), the estimator short-circuits to the closed form.

  • If every endogenous variable is observed and the data are complete, and the shock map is proved affine (every first-order model) or triangular and affine in each shock (class B, above the first order), the shocks follow from the data: the likelihood is their density times the Jacobian term, and only the regimes are filtered. Otherwise the filter runs and estimate prints why. See Direct likelihood of fully observed models. estim_force_filter = true runs the filter instead, to check the two routes against each other. They follow the same rule for the regime probabilities; see Where the regime probabilities start for when they give the same numbers.

User code that constructs a model from a new shape gets correct estimation behavior for free – there is no estimator branch keyed on class name. See Modern architecture for the broader pattern.

1.19. Priors

A prior is a struct whose fields are parameter names and whose values are cell arrays describing the prior. RISE accepts five parametrizations for a single-parameter prior, plus a Dirichlet form for transition probabilities and a rich endogenous priors facility for behavioral constraints.

Common abbreviations used below:

  • start – initial value for the optimizer.

  • mean – mean of the prior distribution.

  • sd – standard deviation.

  • lb, ub – absolute bounds (hard truncation).

  • lq, uq – lower and upper quantiles.

  • hpp1, hpp2, hpp3, hpp4 – raw hyperparameters.

  • p – the struct of priors; alpha – a parameter name.

1.19.1. Uniform priors

p.alpha = {start, lb, ub};

Internally rewritten to {start, lb, ub, 'uniform(1)'}. If you set every estimated parameter this way, you have done maximum likelihood (see Ireland, 2004) – the posterior reduces to the likelihood up to a constant.

1.19.2. Means and standard deviations

p.alpha = {start, mean, sd, 'distribution'};

With hard truncation:

p.alpha = {start, mean, sd, 'distribution', lb, ub};

With more hyperparameters (e.g. generalized beta, t-student, truncated normal):

p.alpha = {start, mean, sd, hpp3, hpp4, 'distribution'};
p.alpha = {start, mean, sd, hpp3, hpp4, 'distribution', lb, ub};

1.19.3. Quantiles

Means and standard deviations do not always exist (e.g. inverse gamma with certain hyperparameters; Cauchy). Quantile-based parametrization is the universal workaround:

p.alpha = {start, lq, uq, 'distribution(probability)'};

The (probability) suffix is the mass that should fall between lq and uq – typically 0.9.

With truncation and additional hyperparameters:

p.alpha = {start, lq, uq, 'distribution(probability)', lb, ub};
p.alpha = {start, lq, uq, hpp3, hpp4, 'distribution(probability)'};
p.alpha = {start, lq, uq, hpp3, hpp4, 'distribution(probability)', lb, ub};

1.19.4. Direct hyperparameters

The previous parametrizations are convenience wrappers around the distribution’s hyperparameters. You may set them directly:

p.alpha = {start, hpp1, hpp2, 'distribution(hpp)'};

with truncation and extra hyperparameters as for the other forms. When using this parametrization, plot the distribution and inspect it carefully before estimating; it is the most error-prone way.

1.19.5. User-defined priors via PDF

If you need a prior RISE does not support, supply the PDF (not the log-PDF) as a function handle plus hard bounds:

p.alpha = {start, lb, ub, function_handle};

RISE constructs the CDF, the inverse CDF, and everything else internally.

1.19.6. The t-student special case

The t-student’s third hyperparameter is the degrees of freedom; there is no fourth, so leave it as nan or empty:

p.alpha = {start, 3, 7, 10, nan, 't(.9)'};

1.19.7. The generalized gamma (gammatau)

The generalized gamma has a shape parameter \(\tau\) besides its two hyperparameters. It goes in the name of the distribution, after a colon; it is required there, and anything but 0. A negative \(\tau\) gives the inverse gamma cases, 'gammatau:-0.5' and 'gammatau:-1':

p.alpha = {start, mean, sd, 'gammatau:2'};
p.alpha = {start, lq, uq, 'gammatau:2(0.9)'};
p.alpha = {start, hpp1, hpp2, 'gammatau:2(hpp)'};
p.alpha = {start, mean, sd, 'gammatau:2', lb, ub};
p.alpha = {start, lq, uq, 'gammatau:2(0.9)', lb, ub};

The same in a model file’s parameterization block:

alpha, start, mean, sd, gammatau:2;
alpha, start, lq, uq, gammatau:2(0.9);

No other distribution takes a value after a colon.

1.19.8. Dirichlet priors for transition matrices

For a n x n transition matrix whose entries are named pname(i,j), declare one Dirichlet per row:

p.dirichlet_1 = {stdev(1,1), pname(1,2), mean(1,2), ...
                 pname(1,3), mean(1,3), ..., pname(1,n), mean(1,n)};

with mean(1,1) + mean(1,2) + ... + mean(1,n) = 1 (the diagonal mean is implied) and stdev(1,1) the standard deviation of the diagonal element. The _1, _2, …, _n suffix is just a label – the order is irrelevant and you only need one Dirichlet per row you actually want to put a prior on.

1.20. Endogenous (system / property / behavioral) priors

Rather than placing priors on parameters, you may place priors on model-implied behaviors: covariances, IRFs, variance and historical decompositions, first-order solution coefficients, regime probabilities at specific dates, aggregates of any of the above. The literature calls these endogenous priors (Del Negro & Schorfheide, 2008; Christiano et al., 2011), system priors (Andrle & Benes, 2013; Andrle & Plasil, 2017, 2018), property priors (Tetlow), or behavioral priors.

The general syntax mirrors the parameter-prior cell shapes, with the parameter name replaced by an expression string:

{'expression', mean, std, 'distribution'}
{'expression', lb, ub}
{'expression', lq, uq, 'distribution(probability)'}
{'expression', hpp1, hpp2, 'distribution(hpp)'}

The expression syntax covers seven classes; regime arguments default to 1 in switching models when omitted.

1.20.1. Covariance and correlation

'cov{var1, var2, lag}'
'cov{var1, var2, lag, regime}'
'corr{var1, var2, lag}'
'corr{var1, var2, lag, regime}'

'cov{C, Y, 1, 2}' is the covariance between C and Y at lag 1 in regime 2.

1.20.2. Impulse responses

'irf{variable, shock, horizon}'
'irf{variable, shock, horizon, regime}'

'irf{C, EA, 3, 2}' is the response of C to shock EA at horizon 3 in regime 2.

1.20.3. Variance decomposition

Finite horizon:

'vd{variable, shock, horizon}'
'vd{variable, shock, horizon, regime}'

Long run (set horizon = inf):

'vd{variable, shock, inf}'
'vd{variable, shock, inf, regime}'

1.20.4. Historical decomposition

'hd{variable, shock, horizon}'

1.20.5. First-order solution coefficients

Impact of a state variable on an endogenous variable:

'Tz{variable, stateVariable}'
'Tz{variable, stateVariable, regime}'

Examples:

  • 'Tz{C, C{-1}}' – impact of C{-1} on C in regime 1.

  • 'Tz{C, @sig}' – impact of the perturbation parameter.

  • 'Tz{C, EA}' – impact of shock EA.

  • 'Tz{C, EA{+3}, 2}' – expected impact of EA three periods ahead, in regime 2.

1.20.6. Filtered / updated / smoothed probabilities

Regime probabilities:

'mvar{f, regime, date_range}'        % filtered
'mvar{u, regime, date_range}'        % updated
'mvar{s, regime, date_range}'        % smoothed

State combinations across chains:

'mvar{f, state1 & state2 & ... & stateN, date_range}'

'mvar{f, vol_2 & pol_1, rq(2020,3)}' – filtered probability of being simultaneously in vol_2 and pol_1 in 2020Q3.

1.20.7. Aggregations and discontinuous ranges

sum, max, min over a date or horizon range:

'sum(irf{C, EA, 1:40, 3})'
'max(mvar{f, regime_2, rq(1970,3):rq(2024,3)})'

Discontinuous ranges:

'mvar{f, regime_2, [rq(1970,3):rq(1975,3), rq(1978,3), rq(1980,3):rq(1985,4)]}'

1.20.8. User-defined endogenous priors

A custom function on the model:

{@(model) my_function(model), mean, std, 'distribution'}
{@(model) my_function(model), lb, ub}

For advanced cases where the prior needs filtration information, the function handle, called with one input (the model object), returns a struct:

v = struct('priors',             prior_cell, ...
           'kf_filtering_level', 0);

with kf_filtering_level in:

  • 0 – no filtering information required;

  • 1 – one-step-ahead (filtered);

  • 2 – updated;

  • 3 – smoothed.

When called with two inputs (model + filtering struct), the function returns a vector of numbers evaluating the priors.

1.21. List of supported prior distributions

The complete catalog, with their supports. Names with _pdf suffix (e.g. beta_pdf) are accepted as synonyms.

Name

Support

Notes

arcsine

\([0, 1]\)

beta

\([0, 1]\)

Conjugate for Bernoulli/binomial.

dirichlet

simplex

For transition-matrix rows; see above.

betaprime

\([0, \infty)\)

cauchy

\((-\infty, \infty)\)

No mean; quantile parametrization only.

exponential

\([0, \infty)\)

folded_normal

\([0, \infty)\)

gamma

\([0, \infty)\)

With a shift \(c\) (third hyperparameter), \([c, \infty)\): \(\theta-c\) is gamma, and the mean and quantiles given are those of \(\theta\).

gammatau

\([0, \infty)\)

Generalized gamma-tau; \(\tau\) after a colon, e.g. 'gammatau:2' (see above).

gumbel

\((-\infty, \infty)\)

half_normal

\([a, \infty)\)

\(a+b|z|\), \(z\) standard normal: \(a=0\) is the standard half normal; a mean and a standard deviation set both.

igamma (= igamma2)

\([0, \infty)\)

Use for standard deviations.

igamma1

\([0, \infty)\)

Inverse-gamma, shape/scale parametrization. Use for standard deviations.

igamma2

\([0, \infty)\)

Use for standard deviations.

inverse_gaussian

\((0, \infty)\)

Use for standard deviations.

kumaraswamy

\((0, 1)\)

Alternative to beta on the unit interval.

laplace

\((-\infty, \infty)\)

left_triang

\([a, b]\)

Skewed to the left.

levy

\([\mu, \infty)\)

logistic

\((-\infty, \infty)\)

lognormal

\((0, \infty)\)

normal

\((-\infty, \infty)\)

pareto

\([x_m, \infty)\) with \(x_m > 0\)

raised_cosine

\([\mu - s, \mu + s]\) with \(s > 0\)

sichisq

\((0, \infty)\)

Scaled inverse \(\chi^2\). Use for standard deviations.

t

\((-\infty, \infty)\)

DOF is the third hyperparameter; no fourth (set nan). Given by a mean and a standard deviation, it has that standard deviation (DOF must exceed 2); t(hpp) takes the location and the scale.

truncated_normal

\([\underline{\theta}, \overline{\theta}]\)

uniform

\([\underline{\theta}, \overline{\theta}]\)

Implied when only the three-slot form is used.

weibull

\([0, \infty)\)

1.22. Visualizing priors (and posteriors)

rise.engine.estimation.rdist.plot plots the priors and, when given an @mcmc object, overlays the posterior densities:

rise.engine.estimation.rdist.plot(priors);
rise.engine.estimation.rdist.plot(priors, plotOpts);
rise.engine.estimation.rdist.plot(priors, plotOpts, mc);
rise.engine.estimation.rdist.plot(priors, plotOpts, mc, 'linewidth', 2);

plotOpts is a struct with the following fields:

Field

Effect

r0c0

Vector [nrows, ncols] of the figure grid. Default [3, 3].

prior_trunc

Density-tail truncation. Default 1e-3.

scale_IG_trunc

Correction of prior_trunc for inverse-gamma families. Default 25.

npoints

Number of points for the density evaluation. Default 1000.

do

Struct with logical fields priors, posteriors – whether to draw each.

par_list

Cell array of parameter names to restrict the plot to.

Example:

priors           = struct();
priors.beta      = {.5, 95, 5,       'beta(hpp)'};
priors.delta     = {.5, 40, 860,     'beta(hpp)'};
priors.alpha     = {.5, 360, 590,    'gamma(hpp)'};
priors.rhoz      = {.5, 80, 20,      'beta(hpp)'};
priors.sdez      = {0.1, 0.01, 0.01, 'igamma(hpp)'};

plotOpts             = struct();
plotOpts.prior_trunc = 2.6e-3;

rise.engine.estimation.rdist.plot(priors, plotOpts, [], struct('linewidth', 2));

1.23. Where priors live in the toolbox

Calibration and priors can be returned by any MATLAB function, with any name. For example, function [p, priors] = calibration_and_priors() returns two structs; pass them as parameters and estim_priors to set. RISE imposes no filename suffix. See Model file language for the complete example and the in-file @parameterization alternative.

Switching parameters use their flat names with chain and regime appended (phi_pi_mon_1, mon_tp_1_2, …). Transition probabilities under a Dirichlet prior use the dirichlet_* naming pattern shown above.

1.24. Maximum likelihood (no priors)

To estimate by maximum likelihood, supply only bounds for each parameter – no mean, no distribution:

priors.alpha   = {start, lb, ub};
priors.rho     = {start, lb, ub};
priors.sigma_a = {start, lb, ub};

m_est = estimate(m, data = mydata, estim_priors = priors);

Internally RISE rewrites each entry as {start, lb, ub, 'uniform(1)'}: a uniform prior on the box. Its density is constant on the box, so the posterior is the likelihood restricted to the box, up to that constant. [Ireland, 2004] is the canonical DSGE reference for this practice.

What bounds-only priors mean in practice:

  • The mode is the maximum-likelihood estimator on the box: the constant prior does not move it.

  • The Hessian at the mode is that of the log likelihood, \(H = -\partial^2 \log L / \partial \theta^2\), and the covariance derived from it is the standard ML covariance.

  • The uniform prior is a proper prior, normalized on the box, so the marginal data density is still the Bayesian evidence. With \(V\) the volume of the box, it is \(p(y) = V^{-1} \int_{\mathrm{box}} L(y \mid \theta)\, d\theta\), the likelihood averaged over the box. It depends on the bounds – widening the box lowers it – so it compares models only as far as the boxes are priors you stand by.

  • Posterior simulation explores the posterior under that uniform prior, the likelihood restricted to the box. It is not a profile likelihood.

To estimate by maximum likelihood while keeping informative priors in estim_priors, set estim_mle = true: the priors then contribute nothing to the objective and only supply the bounds.

Mixing approaches per parameter is allowed: some parameters can carry informative priors and others can be left with bounds-only (uniform). The dimension of the prior contribution adapts automatically.

When the likelihood is intractable – nonlinear filters that fail on your sample, or quantities of interest that depend on simulated paths – consider indirect inference instead. The optimizer suite and restriction machinery are the same.

1.25. Mode finding

With data and priors bound, estimate runs an optimizer on the log-posterior:

m_est = estimate(m);

The default optimizer is fmincon. Pick a different one with the estim_optimizer option:

m_est=estimate(m,estim_optimizer='wcsminwel');

To pass options to the optimizer, use a cell: the optimizer first, then either one options struct or name/value pairs:

opt=optimset('fmincon');

opt.MaxIter=2000;

opt.TolFun=1e-8;

opt.Display='iter';

m_est=estimate(m,estim_optimizer={'fmincon',opt});

m_est=estimate(m,estim_optimizer={'fmincon','MaxIter',2000,'TolFun',1e-8});

Each field given replaces the default of the same name (see the table below); the others keep their defaults.

1.25.1. Bundled optimizers

Optimizer

Family

Scope

Parallel

Typical use

fmincon

SQP / interior-point

local

via UseParallel

default; smooth likelihoods.

fminunc_bnd

quasi-Newton (BFGS)

local

no

smooth, only-bound constraints.

fminsearch_bnd

Nelder-Mead

local

no

very small problems; non-smooth.

patternsearch

direct search (GPS / MADS)

local

via Global Opt Toolbox

non-smooth / noisy objectives.

wcsminwel

Sims’s csminwel + restart

local

no

robust on awkward DSGE surfaces.

wnewrat

Newton with numerical Hessian

local

no

mode polishing after a global pass.

wgmhmaxlik

MH-driven climb

local + exploration

no

pre-conditioner for multi-modal surfaces.

bee_gate

artificial bee colony

global (population)

yes

older global default.

rise_lshade, rise_jso, rise_cma_es, rise_de, rise_abc, rise_aco, rise_bbo, rise_agsk, rise_mads

+globalopt family

global

yes (per algorithm)

the modern global search menu.

sa.gmhmaxlik

simulated annealing

global

no

robust, slow; legacy.

blockwise_optimization

dispatcher

same as inner

same as inner

wraps any optimizer to optimize block-by-block; triggered automatically when estim_blocks is non-empty.

1.25.2. Default optimizer options

Every optimizer receives one options struct: MATLAB’s defaults for the chosen optimizer (those of fmincon for an optimizer that is not MATLAB’s), with the following fields set by the estimation.

Field

Meaning

Default

MaxIter

iteration cap

1000

MaxFunEvals

total function-eval cap

Inf

MaxTime

wall-clock cap (seconds)

7200

TolFun

objective tolerance

sqrt(eps)

TolX

step tolerance

sqrt(eps)

Display

'iter' / 'on' / 'off'

'iter'

MaxNodes

population size (population methods)

20

ObjectiveLimit

early-stop floor

-1e12

fmincon also gets Algorithm = 'sqp'. Each optimizer reads the fields it knows and ignores the rest; no field is enforced for all of them. fmincon, fminunc and fminsearch read MATLAB’s fields and have no wall-clock cap (MaxTime and MaxNodes are ignored); wcsminwel and wnewrat read MaxIter only; bee_gate and the +globalopt family read MaxIter, MaxFunEvals and MaxTime.

The +globalopt family stops at the evaluation that would exceed MaxFunEvals or MaxTime, not at the end of a generation, and reports why in exitflag (1 its own goal, 0 a budget, -1 a manual abort). wcsminwel, wnewrat and wgmhmaxlik return exitflag = 1 when the optimizer’s own criterion is met, 0 at the iteration limit and -2 when the start or the end point has no usable objective (not finite, or outside the bounds). bee_gate needs MaxNodes of at least 3.

Algorithm-specific hyperparameters (F, CR for rise_de; sigma0 for rise_cma_es; limit for rise_abc; …) are documented in legacy Stochastic Global Optimization.

1.25.3. Running several optimizers in turn

A common strategy is global search to locate the basin, then a fast local method to polish. estim_optimizer holds one optimizer: in the cell form everything after the first entry is options, so {'rise_lshade','wcsminwel'} is the optimizer rise_lshade with one unpaired option, and estimate stops with “arguments should come in pairs”. Call estimate once per optimizer instead, each call starting from the mode of the previous one:

m_glob=estimate(m,estim_optimizer='rise_lshade');

m_est=estimate(m_glob,estim_optimizer='wcsminwel',estim_start_from_mode=true);

1.25.4. User-defined optimizers

estim_optimizer may also be a function name or a function handle implementing:

[xfinal,ffinal,exitflag,H]=myOptimizer(fh,x0,lb,ub,options)

fh is the negative log-posterior to minimize; RISE guarantees lb <= x0 <= ub, and options is the struct above, with the options given in the estim_optimizer cell merged in. Outputs: xfinal (column vector in bounds), ffinal (scalar value fh(xfinal)), exitflag (MATLAB convention: 1 = converged, 0 = budget exhausted, negative = failed) and H, the n x n Hessian of fh at xfinal, or [] if not available. An optimizer with three outputs is accepted too. H is used only under estim_hessian_type = 'optimizer'; by default ('fd') the estimation computes the Hessian at the mode by finite differences. Details in Posterior maximization.

Manual stopping is honored by every +globalopt optimizer: drop a file ManualStoppingFile.txt in the working directory and the next iteration boundary returns the current best.

1.25.5. What estimate puts on the model

After estimate returns:

m_est.estimation.posterior_maximization.mode
m_est.estimation.posterior_maximization.mode_stdev
m_est.estimation.posterior_maximization.hessian
m_est.estimation.posterior_maximization.vcov
m_est.estimation.posterior_maximization.log_post
m_est.estimation.posterior_maximization.log_lik
m_est.estimation.posterior_maximization.log_prior
m_est.estimation.posterior_maximization.log_marginal_data_density_laplace
m_est.estimation.posterior_maximization.estim_start_time
m_est.estimation.posterior_maximization.estim_end_time
m_est.estimation.posterior_maximization.estim_run_start_time
m_est.estimation.posterior_maximization.estim_run_seconds

Parameter names corresponding to the mode vector are fieldnames(m_est.estimation.priors) in declaration order.

The three timestamps are MATLAB datetime values. estim_start_time is the start of the first estimation on this object and is kept when the estimated object is passed to estimate again. estim_end_time is the end of the latest estimation, before final filtering and smoothing. Their difference is the cumulative wall-clock interval, including gaps between calls. The printout retains this interval as total time.

estim_run_start_time is reset for each call. estim_run_seconds is the numeric elapsed time in seconds from that start to estim_end_time. The printout shows it as current run time. On the first estimation, the current and cumulative intervals are equal. These fields also apply to closed-form estimation and least squares. Saved results without these fields retain their cumulative printout.

The Hessian, vcov, mode_stdev and the Laplace value come from the curvature at the mode: by finite differences under the default estim_hessian_type = 'fd'. With 'none', hessian(m_est) computes them after the estimation, and a calculation that outlasts the time limit of a job resumes from a file: see Resuming the finite-difference Hessian.

1.26. Posterior simulation

The mode is rarely the end. To explore the posterior, run an MCMC sampler. The modern API is class-based – each sampler is a class in the package rise.engine.estimation.rsamplers, constructed from a target function and bounds, then sampled with the sample method.

pull_objective lifts the objective of the estimation out of the estimated model, with the bounds, the mode and the covariance at the mode, in that order:

[objective,lb,ub,x0,SIG]=pull_objective(m_est);

logpost=@(x)-objective(x);
  • objective is minus the log posterior kernel at a parameter vector: the value the optimizers minimize. The samplers maximize their target, so they take logpost, its negative. Passing objective itself makes the chain favor the regions of low posterior density. (The legacy sampler_rwmh shortcut and its siblings take objective and negate it themselves.)

  • lb, ub are the bounds and x0 the posterior mode, the starting point of the chain.

  • SIG is the Hessian-derived covariance at the mode, a sensible proposal covariance.

1.26.1. Available samplers

The samplers are classes of the package rise.engine.estimation.rsamplers:

Class

Algorithm

rwmh

Random-walk Metropolis-Hastings. Defaults: c=1, proposal='normal', tunedCov=eye(d); pass SIG from pull_objective as tunedCov.

imh

Independent Metropolis-Hastings.

apt

Adaptive parallel tempering. Useful for multi-modal posteriors.

slice

Slice sampler. No proposal covariance to tune.

usrsmplr

User-defined sampler hook.

Options shared by every sampler (inherited from rise.engine.estimation.rsamplers.rsampler):

Field

Default

Role

N

5000

Draws per chain.

nchain

1

Number of chains.

burnin

100

Burn-in draws (discarded).

thinning

1

Keep every thinning-th draw.

MaxTime

inf

Wall-clock cap (seconds).

MaxFunEvals

inf

Total function-eval cap.

1.26.2. Constructing and running

opts = struct( ...
    N        = 2000, ...
    nchain   = 2, ...
    burnin   = 500, ...
    c        = 0.5, ...
    tunedCov = SIG);

obj=rise.engine.estimation.rsamplers.rwmh(logpost,x0,lb,ub,opts);

results=sample(obj);

results is a cell of length nchain. Each results{k} carries pop (struct array of draws with .x (parameter vector) and .f (the target, here the log posterior), stats, SIG, c, x0, best. Extract draws as a matrix:

draws = [results{1}.pop.x];   % nparams x N

Note

The legacy toolbox exposed convenience shortcuts sampler_rwmh, sampler_imh, sampler_apt, sampler_slice that expected a value to minimize and ran the sampler in one call. The modern path uses the class directly. The sampler_* shortcuts still work but should be migrated.

1.26.3. User-defined sampler via rise.engine.estimation.rsamplers.usrsmplr

For samplers not in the bundle (e.g. DRAM, DA-DRAM, NUTS), write the sampling function and let rise.engine.estimation.rsamplers.usrsmplr run it: RISE passes it the target, the starting point, the proposal covariance, the number of draws, the burn-in and a function that keeps points admissible, and stores the draws and their log-posterior values it returns as for the built-in samplers. The contract of the function and an example are in the reference of usrsmplr.

A sampler that runs on its own can instead be wrapped so that its output follows the RISE convention: a cell of nchain structs, each with the pop (x and f, the log posterior), best/stats/SIG/c fields. The Posterior simulation chapter contains a worked DRAM wrapper.

1.27. Marginal data density

For Bayesian model comparison, the mdd class wraps several estimators of \(\log p(y)\):

  • Laplace approximation – automatic; available without a posterior simulation.

  • Modified harmonic mean (Geweke).

  • Bridge sampling (Meng-Wong).

  • Mueller (importance / reciprocal-importance).

  • Chib-Jeliazkov (auxiliary Gibbs).

The Laplace approximation is cached on the estimated model:

log_mdd_laplace = ...
    m_est.estimation.posterior_maximization.log_marginal_data_density_laplace;

A reduced-form VAR under a natural-conjugate prior has the exact value too, in log_marginal_data_density_closed_form; see Closed-form marginal data density of VARs.

For the estimators that use the posterior draws, build an mdd object from the draws, the log posterior kernel and the bounds – the logpost, lb and ub given to the sampler above – and call its methods:

md=mdd(results,logpost,lb,ub,[],[],true);

log_mdd_mhm=mhm(md);

log_mdd_bs=bridge(md);

log_mdd_cj=cj(md);

The constructor is mdd(draws,log_post_kern,lb,ub,subset,H,maximization). Its last argument gives the sign convention of the draws: true when their f field holds the log posterior, as with the samplers above, false (the default) when it holds minus the log posterior. The optional Hessian H (laplace computes one by finite differences when it is empty) is that of log_post_kern at the mode: negative definite with true, positive definite with false; the constructor refuses the other sign. mhm(md,tau) takes the truncation probabilities tau, .1:.1:.9 by default. The other estimators are the methods laplace, laplace_mcmc, is, ris, mueller and swz. Their options are those of mdd.global_options; see The properties.

A RISE model can take the place of the kernel: mdd(draws,m) uses minus its log posterior (pull_objective, the space its samplers draw in, so the f of the draws must be minus the log posterior), its estimation bounds, and its improper_prior. Under an improper prior (a parameter without a proper prior, see posterior_maximization.improper_prior) the marginal data density is not defined: every estimator returns NaN and warns (rise:mdd:improperPrior) with the reason and the parameters, as estimate does for the Laplace approximation. For a kernel of your own, set the property improper_prior yourself.

1.28. Chain diagnostics: @mcmc

The @mcmc class processes the output of sample and provides the standard convergence and quality diagnostics. The class itself has not changed between legacy and modern.

Constructor:

mc=mcmc(results);

mc=mcmc(results,pnames);

The second argument, pnames, holds the names of the parameters, in the order of the parameter vector in the draws. When the estimation has neither linear restrictions nor dirichlet priors, that order is pnames=fieldnames(m_est.estimation.priors); otherwise the draws are in the transformed coordinates the estimation works in (see the ilinres argument in the constructor reference). Without pnames the parameters are named p_1, p_2, …, and the methods that take a parameter name expect those. The chains are named chain_1, chain_2, … (property chain_names) whatever the arguments.

Properties

Property

Content

pnames

Names of the estimated parameters.

nchains

Number of chains.

chain_names

Names assigned to the chains.

npop

Number of population (parameter) draws.

nparams

Number of parameters.

draws

MCMC parameter draws stored as a 3D array (nparams x npop x nchains).

psrf

Potential scale reduction factor (Gelman-Rubin).

best

Best parameter draw.

log_post

Log-posterior values for each draw.

Diagnostic methods

Method

Effect

traceplot(pname)

Per-chain trace plot of a parameter.

densplot(pname)

Posterior density of a parameter.

autocorrplot(pname)

Autocorrelation of a parameter’s chain.

meanplot(pname)

Running mean of a parameter’s chain.

scatterplot(pname1, pname2)

Joint scatter of two parameters.

brooks_gelman()

Brooks-Gelman convergence diagnostics (requires nchain > 1); brooks_gelman(true) also plots them.

plot_brooks_gelman(bg)

Plot bg, the output of brooks_gelman.

psrf_plot(pname)

Plot the Gelman-Rubin potential scale reduction factor of a parameter ('multivariate_' for all of them; requires nchain > 1). The constructor computes the factors and stores them in the property psrf; there is no gelman_rubin method.

geweke(), geweke(Opts, chain_id)

Geweke convergence diagnostic of every parameter, on one chain (default 1); the output has one field per parameter name. Opts is an optional struct (see the reference).

raftery_lewis(), raftery_lewis(Opts, chain_id)

Raftery-Lewis diagnostic of every parameter, on one chain (default 1). Opts is an optional struct.

inefficiency_factors(pname)

Inefficiency factors.

summary()

Compact tabular summary.

posterior_parameter_statistics()

Posterior moments + credible intervals.

Warning

mcmc is a diagnostics class constructed from existing draws. mcmc(m_est, ...) is not a sampler call and will error with “Brace indexing is not supported”. To sample, use a rise.engine.estimation.rsamplers.* class; to diagnose, pass the result to mcmc.

1.29. Estimation restrictions

Linear and nonlinear restrictions on the estimated parameters are declared at the model level via the estim_linear_restrictions and estim_nonlinear_restrictions options on set / estimate. The general form is a cellstr of restrictions, one per row:

m = set(m, ...
    estim_linear_restrictions = { ...
        'phi_pi - phi_y' ; ...
        'mon_tp_1_2 - mon_tp_2_1' });

Each restriction is an expression that should equal zero. For inequalities, write them as differences with the appropriate sign convention. See the legacy chapter Estimation restrictions for the nonlinear and block-restriction extensions.

A linear restriction is a sum of the estimated parameters times constants ('phi_pi - phi_y', 'a + 2*b = 3', a constant of any size). One that is not linear in them – a product of parameters, a power, a function of a parameter – is refused by name (parse_linear_restrictions:notLinear); declare it among the nonlinear restrictions (Restrictions on parameters during estimation).

For a panel VAR, estim_panel_estimator adds the linear restrictions of a panel estimator (‘pooled’, ‘fixed_effects’, …) to these: see Panel VAR Modeling.

For a structural VAR, estim_svar_start = 'concentrated' starts the mode search from a point that satisfies these restrictions on \(A_{0}\) and sits near the mode (the default, 'ols_identity', starts from \(A_{0} = I\)): see Structural VAR Modeling. With a structural lag prior, estim_svar_integrate_lags = true integrates the lags and shock variances out analytically and searches over \(A_{0}\) alone (under regime switching: over \(A_{0}\) and the transition probabilities, the lags and variances integrated out by EM; same page).

1.30. The pipeline, skeletally

% data, parameters, priors
m     = set(m, data = db, parameters = p, estim_priors = priors);

% mode
m_est = estimate(m);

% a posterior sample
[objective,lb,ub,x0,SIG]=pull_objective(m_est);

logpost=@(x)-objective(x);

obj=rise.engine.estimation.rsamplers.rwmh(logpost,x0,lb,ub,struct(N=2000,tunedCov=SIG));

results=sample(obj);

% diagnose, compute the MDD
mc=mcmc(results,fieldnames(m_est.estimation.priors));

log_mdd_mhm=mhm(mdd(results,logpost,lb,ub,[],[],true));