1.2. Prior distributions and implementation

1.2.1. Bayesian priors

N.B: In the description below :

  • start denotes the initial value for estimation

  • mean denotes the mean of the prior distribution

  • sd denotes the standard deviation

  • hpp1 denotes the first hyperparameter

  • hpp2 denotes the second hyperparameter

  • hpp3 denotes the third hyperparameter

  • hpp4 denotes the fourth hyperparameter

  • lb denotes the lower bound

  • ub denotes the upper bound

  • lq denotes the lower quantile

  • uq denotes the upper quantile

  • p is the structure containing the parameters to estimate

  • alpha is the name of some parameter to be estimated

Setting Uniform Priors

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

N.B: This prior will be rewritten internally as
p.alpha = {start,lb,ub,'uniform(1)'};

If you set all your parameters to be estimated in this way, this is how you perform Maximum Likelihood (See e.g. [Ireland, 2004]) in RISE.

Setting priors using Means and Standard deviations

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

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

*more hyperparameters e.g. generalized beta, t-student or truncated normal*
p.alpha = {start,mean,sd,hpp3,hpp4,'distribution'};

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

Setting priors using quantiles

One cannot always characterize the distribution of parameters in terms of means and standard deviations :

  • Not all distributions have means and standard deviations

  • Some distributions are such that for some specific values of the hyperparameters, the first and second moments do not exist

  • Oftentimes when we take our priors from the literature, the number of studies we take inspiration from are too few to rely on for the calculation of means and standard deviations.

Under such circumstances, one can instead use quantiles.

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

*adding truncation*
p.alpha = {start,lq,uq,'distribution(probability)',lb,ub};

*more hyperparameters e.g. generalized beta, t-student or truncated normal*
p.alpha = {start,lq,uq,hpp3,hpp4,'distribution(probability)'};

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

Setting priors using hyperparameters

In some cases, people prefer to characterize their distributions directly in terms of hyperparameters.

In fact all the previous approaches to setting priors will first determine the hyperparameters of the distributions.

RISE also allows you to set your priors directly in terms of hyperparameters if you choose to do so. Should you rely on this strategy, the recommendation is to plot the distributions and inspect them carefully before starting any estimation.

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

*adding truncation*
p.alpha = {start,hpp1,hpp2,'distribution(hpp)',lb,ub};

*more hyperparameters e.g. generalized beta, t-student or truncated normal*
p.alpha = {start,hpp1,hpp2,hpp3,hpp4,'distribution(hpp)'};

*adding truncation*
p.alpha = {start,hpp1,hpp2,hpp3,hpp4,'distribution(hpp)',lb,ub};

About the t-student prior

The third hyperparameter of the t-student distribution is the DOF (degree of freedom). There is not 4th hyperparameter and so the field can be nan or empty e.g. p.alpha = {start,3,7,10,nan,’t(.9)’};

The dirichlet prior

consider a transition matrix of the form

\[\begin{split}M = \begin{bmatrix} pname(1,1) & pname(1,2) & ... & pname(1,n) \\ pname(2,1) & pname(2,2) & ... & pname(2,n) \\ ... & ... & ... & ... \\ pname(n,1) & pname(n,2) & ... & pname(n,n) \end{bmatrix}\end{split}\]

Dirichlet priors can bet set as follows

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,3)+...+mean(1,n)=1
and mean(1,1) the mean of the first diagonal element
and stdev(1,1) its standard deviation

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

with mean(n,1)+mean(n,2)+mean(n,3)+...+mean(n,n)=1
and mean(n,n) the mean of the n-th diagonal element
and stdev(n,n) its standard deviation

N.B: The order of the names dirichlet_1, dirichlet_2, …, dirichlet_n is irrelevant and there need not be n such names. The key here is the syntax dirichlet_number

1.2.2. Endogenous Priors

Rather than setting priors on parameters, one can also set priors on the behavior or properties of the model. This is known in the literature under various appellations:

Setting endogenous priors involves placing constraints on model-implied behaviors, such as impulse responses, variance decompositions, or probabilities of certain states or regimes. Below, we describe the syntax for setting these priors, organized by their types and possible variations.

General Syntax for Endogenous Priors

The basic syntax for an endogenous prior is:

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

where:

  • `expression`: Defines the model behavior or property being constrained. This could be a covariance, correlation, impulse response, variance decomposition, historical decomposition, probability of being in a particular state, or a custom-defined function.

  • `mean`, `std`, `distribution`, `lb`, `ub`, `hpp1`, `hpp2`: are the same as defined for priors on parameters above.

Types of Endogenous Priors

This section covers the various types of endogenous priors and their specific syntax.

1. Covariance and Correlation Priors

Covariance and correlation priors constrain the covariance or correlation between two variables in the model. Under regime switching, the default regime is 1. The syntax for each is as follows:

  • Covariance:

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

    Example: ‘cov{C, Y, 1, 2}’ sets a prior on the covariance between C and Y with a lag of 1 in regime 2.

  • Correlation:

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

    Example: ‘corr{C, Y, 1, 3}’ sets a prior on the correlation between C and Y with a lag of 1 in regime 3.

2. Impulse Response Function (IRF) Priors

Impulse response priors specify the expected behavior of a variable in response to a shock. The syntax is:

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

Example: ‘irf{C, EA, 3, 2}’ constrains the impulse response of C to shock EA at horizon 3 in regime 2.

3. Variance Decomposition (VD) Priors

Variance decomposition priors specify the contribution of a shock to the variance of a variable over a specified horizon. The syntax varies depending on whether it is a finite or infinite horizon.

  • Finite-Horizon Variance Decomposition:

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

    Example: ‘vd{C, EA, 30, 2}’ constrains the finite-horizon variance decomposition of C explained by shock EA at horizon 30 in regime 2.

  • Infinite-Horizon (Long-Run) Variance Decomposition:

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

    Example: ‘vd{C, EA, inf, 3}’ constrains the long-run variance decomposition of C by shock EA in regime 3.

4. Historical Decomposition (HD) Priors

Historical decomposition priors measure the contribution of a shock to a variable over time. The syntax is:

'hd{variable, shock, horizon}'

Example: ‘hd{C, EA, 30}’ constrains the historical decomposition of C from shock EA at horizon 30.

5. First-order solution Priors

What is the impact of a particular state variable on some endogenous variable? The syntax is:

'Tz{variable, stateVariable}'
'Tz{variable, stateVariable, regime}'
  • Endogenous state variables impacts:

    Example: ‘Tz{C, C{-1}}’ constrains the impact of state variable C{-1} on endogenous C in the (default) first regime.

    Example: ‘Tz{C, C{-1},2}’ same as above but in the second regime.

  • Perturbation parameter impacts:

    Example: ‘Tz{C, @sig}’ constrains the impact on C of perturbation parameter in the (default) first regime.

    Example: ‘Tz{C, @sig, k}’ same as above but in the k-th regime.

  • Shock impacts:

    Example: ‘Tz{C, EA}’ constrains the impact on C of shock EA in the (default) first regime.

    Example: ‘Tz{C, EA{+3}, 2}’ constrains the expected impact of shock EA 3 periods ahead on C in the second regime.

6. Probability Priors (Filtered, Updated, Smoothed)

Probability priors set expectations for the likelihood of being in a particular regime or state at a specific date or over a range of dates. These can be filtered (f), updated (u), or smoothed (s).

  • Regime Probabilities:

    'mvar{f, regime, date_range}'
    'mvar{u, regime, date_range}'
    'mvar{s, regime, date_range}'
    

    Example: ‘mvar{f, regime_2, rq(2020,3)}’ specifies a prior on the filtered probability of regime 2 in 2020 Q3.

  • State Combination Probabilities:

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

    Example: ‘mvar{f, vol_2&pol_1, rq(2020,3)}’ sets a prior on the filtered probability of being in vol_2 and pol_1 in 2020 Q3.

Advanced Variants and Complex Functions

The following advanced options allow the application of mathematical functions to base expressions or combinations of base expressions, as well as the use of discontinuous date ranges.

6. E.g.: Aggregated IRF or Probability Expressions

Aggregate impulse responses or probabilities over a specified period using functions like sum, max, and min.

  • Sum of IRFs:

    'sum(irf{variable, shock, start:end, regime})'
    

    Example: ‘sum(irf{C, EA, 1:40, 3})’ sums the IRFs of C to EA over the range from 1 to 40 in regime 3.

  • Max/Min of IRFs or Probabilities:

    'max(expression)' or 'min(expression)'
    

    Example: ‘max(mvar{f, regime_2, rq(1970,3):rq(2024,3)})’ finds the maximum filtered probability of regime 2 over the specified period.

7. E.g.: Multi-Period Expressions with Discontinuous Ranges

Specify non-continuous date ranges to analyze behavior over irregular intervals.

  • Discontinuous Date Ranges:

    '[start1:end1, single_date, start2:end2]'
    

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

8. User-Defined Functions

Custom functions allow flexibility to capture specific model behaviors based on parameters or combinations of variables.

  • Custom Function:

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

    Example: {@(model) custom_autocorrelation(model), 0.5, 0.1, ‘normal’} defines a user-defined function to impose a prior on custom behavior.

9. Advanced User-Defined Endogenous priors

If is also possible for the user to create a function handle to endogenous priors. When called with only one input (the model object), the function should return a structure with fields priors and kf_filtering_level.

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

The priors field is a n x 1 cell array in which each entry is a cell with information on a particular endogenous prior. For example

v = cell(n,1);

    for ii=1:n

        v{ii}={0.005,2*0.005,'gamma'};

    end

The kf_filtering_level will be:

  • 0 : no filtering information required

  • 1 : 1-step ahead (filtered series) requested

  • 2 : updated series requested

  • 3 : smoothed series requested

When the function is called with two inputs (the model object + filtering information), the function shall return a vector of numbers evaluating the n priors.

Summary of Endogenous Prior Cases

Here is a summary of the main types and formats for endogenous priors:

  1. Covariance: 'cov{var1, var2, lag, regime}'

  2. Correlation: 'corr{var1, var2, lag, regime}'

  3. Impulse Response (IRF): 'irf{variable, shock, horizon, regime}'

  4. Variance Decomposition (Finite): 'vd{variable, shock, horizon, regime}'

  5. Variance Decomposition (Infinite): 'vd{variable, shock, inf, regime}'

  6. Historical Decomposition: 'hd{variable, shock, horizon}'

  7. Regime Probability (Filtered/Updated/Smoothed): 'mvar{f|u|s, regime, date_range}'

  8. State Combination Probability: 'mvar{f|u|s, state_combination, date_range}'

  9. Sum of IRFs or Probabilities: 'sum(irf{variable, shock, start:end, regime})'

  10. Max/Min of IRFs or Probabilities: 'max(expression)' or 'min(expression)'

  11. Multi-Period Expressions with Discontinuous Ranges: '[start:end, single_date, ...]'

  12. User-Defined Function: {@(model) function_name(model), mean, std, 'distribution'}

This comprehensive list provides all available cases and variations for setting endogenous priors, ensuring flexible specification of model behaviors. Use these forms to capture and constrain the model properties essential to your analysis.

1.2.3. User-defined Priors

It could be the case that you want to implement a prior that is not supported by RISE. In that case you should provide the PDF (not the log PDF!) of the prior as a function handle, the lower and upper bounds of the distribution. Internally, RISE will (empirically) construct routines for the CDF, the inverse CDF and everything needed. The syntax is as follows:

p.alpha = {start,LB,UB,function_handle};

1.2.4. Visualizing priors and posteriors

With the structure of priors in place, one can use the function rdist.plot to visualize priors and/or potentially posteriors, provided the simulation of the posterior distribution has been conducted.

The syntax is

rdist.plot(priors)

rdist.plot(priors,plotOpts)

rdist.plot(priors,plotOpts,this)

rdist.plot(priors,[],[])

rdist.plot(priors,[],this)

rdist.plot(priors,plotOpts,this,'linewidth',2)

rdist.plot(priors,plotOpts,this,varargin)

Args:

  • priors (struct): prior information

  • plotOpts (empty|struct): options for the plots. The fields are

    • ‘r0c0’,[vector|{[3,3]}] number of rows (first element) and number of columns (second element) in a figure

    • ‘prior_trunc’,[scalar|{1e-3}] truncation for the plots of the priors

    • ‘scale_IG_trunc’,[scalar|{25}] correction of prior_trunc for inverse gamma family i.e. {‘igamma’,’igamma1’,’igamma2’,…}

    • ‘npoints’,[scalar|{1000}] number of points for the computation of the prior and the posterior densities

    • ‘do’,[struct] fields are “priors” and “posteriors” and their default values are true and true. This gives the flexibility to choose what one wants to plot : priors, posteriors or both

    • ‘par_list’,[empty|cell array] list of parameters to plot

  • this (empty|mcmc object): this is where the information for plotting the posterior is obtained from

  • varargin (empty|pairwise): pairwise additional arguments entering the plot function. e.g. linewidth

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;

rdist.plot(priors,plotOpts,[],struct('linewidth',2))

1.2.5. List of prior distributions

  1. arcsine: \(\theta\) in \([0,1]\)

  2. beta: \(\theta\) in \([0,1]\)

  3. dirichlet : \(\theta _{i}\) in \([0,1]\), with \(\sum_{i}\theta _{i}=1\)

  4. betaprime : \(\theta\) in \([0,\infty)\)

  5. cauchy : \(\theta\) in \((-\infty ,\infty )\)

  6. exponential: \(\theta\) in \([0,\infty )\)

  7. folded_normal : \(\theta\) in \([0,\infty )\)

  8. gamma : \(\theta\) in \([0,\infty )\)

  9. gammatau (generalized gamma-tau): \(\theta ` in :math:`[0,\infty )\)

  10. gumbel : \(\theta\) in \((-\infty ,\infty )\)

  11. half_normal : \(\theta\) in \([0,\infty )\)

  12. igamma (igamma2) : \(\theta\) in \([0,\infty )\)

  13. igamma1 : \(\theta\) in \([0,\infty )\) : Dynare’s inv_gamma

  14. igamma2 : \(\theta\) in \([0,\infty )\)

  15. inverse_gaussian : \(\theta\) in \((0,\infty )\)

  16. kumaraswamy : \(\theta\) in \((0,1)\)

  17. laplace : \(\theta\) in \((-\infty ,\infty )\)

  18. left_triang (skewed to the left) : \(\theta\) in \([a,b]\)

  19. levy : \(\theta\) in \([\mu ,\infty )\)

  20. logistic : \(\theta\) in \((-\infty ,\infty )\)

  21. lognormal : \(\theta\) in \((0,\infty )\)

  22. normal : \(\theta\) in \((-\infty ,\infty )\)

  23. pareto : \(\theta\) in \([x_{m},\infty )\), \(x_{m}>0\)

  24. raised_cosine : \(\theta\) in \([\mu -s,\mu +s]\), \(s>0\)

  25. sichisq (scaled inverse \(\chi^2\)) : \(\theta\) in \((0,\infty )\)

  26. t (t-student) : \(\theta\) in \((-\infty ,\infty )\)

  27. truncated_normal: \(\theta\) in \([\underline{\theta },\overline{\theta}]\)

  28. uniform : \(\theta\) in \([\underline{\theta },\overline{\theta }]\)

  29. weibull : \(\theta\) in \([0,\infty )\)

Note

The following distributions can be used for standard deviations: igamma, igamma1, inverse_gaussian sichisq

For parameters in the \([0,1]\) interval, one case use beta, kumaraswamy