Differences between revisions 6 and 7
Revision 6 as of 2010-04-28 14:22:45
Size: 8357
Comment:
Revision 7 as of 2010-05-05 15:28:47
Size: 8863
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
= Proposed specification for estimation functions = This page documents some parts of the design for the new estimation DLL.
Line 5: Line 5:
This includes factorization of common code and extensions for (unexpected) structural change Improvements over existing MATLAB code includes factorization of common code and extensions for (unexpected) structural change
Line 7: Line 7:
== Estimated parameters description == Since the code allows for unexpected structural changes, parameters will be allowed to change over time. More precisely,
the user will be allowed to associated a time range to each entry in the {{{estimated_params}}} block. For example, if a given
parameter can have a break between dates {{{t}}} and {{{t+1}}}, then the user will declare this parameter two times in the {{{estimated_params}}} block:
one time for the period {{{[1:t]}}}, another time for {{{[t+1:T]}}} (where {{{T}}} is the total length of the data sample).
Line 9: Line 12:
{{{xparam1}}} is a column n by 1 vector holding the current values of the estimated parameters (n is the number of parameters). = Terminology =
Line 11: Line 14:
{{{parameters_description}}} is a (global?) strucure of arrays describing the estimated parameters with the following fields:  * ''Deep parameters'' are the parameters declared by the user with the {{{parameters}}} keyword; their number is {{{M_.param_nbr}}}, and their values are in {{{M_.params}}}
 * ''Model parameters'' are deep parameters, plus the parameters which together form the variance matrix of shocks ({{{M_.Sigma_e}}}) and the measurement error matrix ({{{M_.H}}})
 * ''Estimated parameters'' are the model parameters which are estimated; they are declared by the user in {{{estimated_params}}} block. Technically, an estimated parameter is the tuple formed by a model parameter, a list of subsamples (see below), and prior information
Line 13: Line 18:
 * {{{type}}} is a n by one vector of integers (1,2,3,4,5) where: = List of sub-samples =
Line 15: Line 20:
   1 -> standard deviation of a structural shock. As they are declared by the user, time ranges for different estimated parameters can overlap.
Line 17: Line 22:
   2 -> standard deviation of a measurement error. For example, suppose there are 10 estimation periods, that parameter {{{alpha}}} has a break between date 3 and 4, while parameter {{{beta}}} has a break between date 5 and 6. There are therefore 4 estimated parameters: {{{alpha}}} over {{{[1:3]}}}, {{{alpha}}} over {{{[4:10]}}}, {{{beta}}} over {{{[1:5]}}}, {{{beta}}} over {{{[6:10]}}}.
Line 19: Line 24:
   3 -> correlation betwwen two structural shocks. The problem is that here, {{{alpha}}} is not constant inside the two subsamples for {{{beta}}}, and vice-versa. This creates implementation problems.
Line 21: Line 26:
   4 -> correlation between two measurement errors. The solution is to compute a partition of {{{[1:10]}}} such that every estimated parameter is constant inside every subsample. In our case, we have 3 subsamples in this partition: {{{[1:3], [4:5], [6:10]}}}. The estimated parameters become: {{{alpha}}} over {{{[1:3]}}}, {{{alpha}}} over {{{[4:5]+[6:10]}}}, {{{beta}}} over {{{[1:3]+[4:5]}}}, {{{beta}}} over {{{[6:10]}}}.
Line 23: Line 28:
   5 -> "deep" parameter. We will assume that the computing of this partition is done outside the Estimation DLL (in the preprocessor or in the M-files).
Line 25: Line 30:
 * {{{ID1}}} is a n by 1 vector of indices targeting to the (parameter, exogenous variable or endogenous variable) names (in M_.param_names, M_.exo_names and M_.endo_names). The estimation DLL will be passed a structure containing all the information for the subsamples. Each subsample will be assigned an ID, in chronological order. The estimation DLL will be passed a {{{vector<pair<int, int> >}}} which will associate a subsample ID to its start and end period.
Line 27: Line 32:
 * {{{ID2}}} is a n by 1 vector of NaNs or indices (second exogenous or endogenous variable index for the estimated correlations). = Estimated parameters description =
Line 29: Line 34:
 * {{{StartPeriod}}} n by 1 (beginning of sub-period) Suppose there are {{{n}}} estimated parameters. Then the estimation DLL will be passed a structure containing the following information for each estimated parameter:
Line 31: Line 36:
 * {{{EndPeriod}}} n by 1 (end of sub-period)  * {{{type}}}: an integer in {{{[1:5]}}}
  * 1 -> standard deviation of a structural shock
  * 2 -> standard deviation of a measurement error
  * 3 -> correlation betwwen two structural shocks
  * 4 -> correlation between two measurement errors
  * 5 -> deep parameter
Line 33: Line 43:
 * {{{Prior}}} is a sub-structure describing the prior belief on a parameter. The fiels are:  * {{{ID1, ID2}}}: two integers
  * For type 1, ID1 is the index in {{{M_.exo_names}}}, which is equal to the line/column index in {{{M_.Sigma_e}}}. ID2 is not used
  * For type 2, ID1 is the index in {{{options_.varobs}}}, which is equal to the line/column index in {{{M_.H}}}. ID2 is not used
  * For type 3, ID1 and ID2 are the line and column indices of the element in {{{M_.Sigma_e}}}
  * For type 4, ID1 and ID2 are the line and column indices of the element in {{{M_.H}}}
  * For type 5, ID1 is the index in {{{M_.params}}}, ID2 is not used
Line 35: Line 50:
  * {{{shape}}} is an n by 1 vector of integers (1,2,3,4,5,6) where:
   1 -> Beta density.
 * {{{Subsamples}}}: the list of the subsamples associated to this estimated parameter; the list needs not be contiguous
Line 38: Line 52:
   2 -> Gamma density.  * {{{Prior}}} is a sub-structure describing the prior belief on a parameter. The fields are:
Line 40: Line 54:
   3 -> Gaussian density.   * {{{shape}}}: an integer in {{{[1:6]}}}, where:
   * 1 -> Beta density
   * 2 -> Gamma density
   * 3 -> Gaussian density
   * 4 -> Inverse gamma (type 1) density
   * 5 -> Uniform density
   * 6 -> Inverse gamma (type 2) density
Line 42: Line 62:
   4 -> Inverse gamma (type 1) density.   * {{{mean}}}: mean of the prior density
  * {{{mode}}}: mode of the prior density
  * {{{standard}}}: standard deviation of the prior density
  * {{{lower_bound}}}: prior density domain (possibly {{{-Inf}}})
  * {{{upper_bound}}}: prior density domain (possibly {{{Inf}}})
  * {{{fhp}}}: first hypermarameter <<latex($\alpha$)>> for the beta and gamma priors, <<latex($s$)>> for the inverse gamma prior, lower bound for the uniform prior
  * {{{shp}}}: second hypermarameter <<latex($\beta$)>> for the beta and gamma priors, <<latex($\nu$)>> for the inverse gamma prior, upper bound for the uniform prior
 * {{{lower_bound}}}: effective lower bound for the estimated parameter
 * {{{upper_bound}}}: effective upper bound for the estimated parameter
Line 44: Line 72:
   5 -> Uniform density. '''Remark.''' The field {{{Prior}}} is empty if the model is estimated by maximum lilkelihood, simulated moments or indirect inference.
Line 46: Line 74:
   6 -> Inverse gamma (type 2) density. '''Remark 2.''' This list of estimated parameters description will be arranged in such a way that elements of type 1 and 2 all appear before elements of type 3 and 4. This greatly facilitates the work of computing the covariance elements (using the correlations and the diagonal variance elements).
Line 48: Line 76:
  * {{{mean}}} is an n by 1 vector of doubles (mean of the prior density).

  * {{{mode}}} is an n by 1 vector of doubles (mode of the prior density).

  * {{{standard}}} is an n by 1 vector of doubles (standard deviation of the prior density).

  * {{{lower_bound}}} is an n by 1 vector of doubles (and Inf/-Inf) (prior density domain).

  * {{{upper_bound}}} is an n by 1 vector of doubles (and Inf/-Inf) (prior density domain).

  * {{{fhp}}} is an n by 1 vector of doubles (first hypermarameter <<latex($\alpha$)>> for the beta and gamma priors, <<latex($s$)>> for the inverse gamma prior, lower bound for the uniform prior).

  * {{{shp}}} is an n by 1 vector of doubles (second hypermarameter <<latex($\beta$)>> for the beta and gamma priors, <<latex($\nu$)>> for the inverse gamma prior, upper bound for the uniform prior).
 
 * {{{lower_bound}}} n ny 1 vector of doubles (effective lower bound for the estimated parameter).

 * {{{upper_bound}}} n by 1 vector of doubles (effective upper bound for the estimated parameter).

 * {{{nvx}}} integer scalar (number of estimated structural shock standard deviations).

 * {{{nvx_id}}} nvx by 1 vector of integers.

 * {{{nvn}}} integer scalar (number of estimated measurement error standard deviations).

 * {{{nvn_id}}} nvn by 1 vector of integers.

 * {{{ncx}}} integer scalar (number of estimated structural shock correlations).

 * {{{ncx_id1_id2}}} ncx by 2 matrix of integers.

 * {{{ncn}}} integer scalar (number of estimated measurement error correlations).

 * {{{ncn_id1_id2}}} ncn by 2 matrix of integers.

 * {{{np}}} integer scalar (number of estimated "deep" parameters).

 * {{{np_id}}} np by 1 vector of integers.

'''Remark 1.''' The considered subsamples for different parameters may be different.

'''Remark 2.''' {{{StartPeriod}}} and {{{EndPeriod}}} specify the closed sub sample used to estimate the parameter. If these two fields are empty the parameter is estimated using the whole sample.

'''Remark 3.''' The field {{{Prior}}} is empty if the model is estimated by maximum lilkelihood, simulated moments or indirect inference.

'''Remark 4.''' {{{np_id}}} vectors select subset of {{{xparam1}}} (for instance, {{{xparam_1(np_id)}}} selects all the lines of {{{xparam1}}} corresponding to the estimated "deep" parameters).

'''Remark 5.''' {{{nvx_id}}} and {{{nvn_id}}} vectors select subset of the diagonal elements of {{{Q}}} and, respectively, {{{H}}}. (for instance {{{Q(ncx_id,ncx_id)}}} selects the diagonal elements of {{{Q}}} corresponding to the estimated variance of shocks).

'''Remark 6.''' {{{ncx_id1_id2}}} and {{{ncn_id1_id2}}} matrices select subset of the elements of {{{Q}}} and, respectively, {{{H}}}. (for instance {{{Q(ncx_id1_id2(1,1),ncx_id1_id2(1,2))}}} selects one element of {{{Q}}} corresponding to the first estimated covariance between two shocks).

== Functions ==
= Functions =
Line 158: Line 136:
== Additional Description Notes == = Additional Description Notes =
Line 160: Line 138:
=== Parameters and Sub-Samples ===

The initialization of estimation must detect the set of sub-samples where all parameters remain constant
(such that max(Start``Period)< t < min(End``Period) for the sub-sample)
and make a table of which parameter is active in which subsample. For this, we need an additional component to the structure describing the parameters.

There is a prior for each sub-sample where the parameter remains constant. These sub-samples can be the union of several elementary sub-sampels defined as above.


=== Kalman ===
== Kalman ==
Line 177: Line 146:
=== Likelihood Calculation === == Likelihood Calculation ==
Line 195: Line 164:
=== See also: === == See also ==

This page documents some parts of the design for the new estimation DLL.

Improvements over existing MATLAB code includes factorization of common code and extensions for (unexpected) structural change

Since the code allows for unexpected structural changes, parameters will be allowed to change over time. More precisely, the user will be allowed to associated a time range to each entry in the estimated_params block. For example, if a given parameter can have a break between dates t and t+1, then the user will declare this parameter two times in the estimated_params block: one time for the period [1:t], another time for [t+1:T] (where T is the total length of the data sample).

Terminology

  • Deep parameters are the parameters declared by the user with the parameters keyword; their number is M_.param_nbr, and their values are in M_.params

  • Model parameters are deep parameters, plus the parameters which together form the variance matrix of shocks (M_.Sigma_e) and the measurement error matrix (M_.H)

  • Estimated parameters are the model parameters which are estimated; they are declared by the user in estimated_params block. Technically, an estimated parameter is the tuple formed by a model parameter, a list of subsamples (see below), and prior information

List of sub-samples

As they are declared by the user, time ranges for different estimated parameters can overlap.

For example, suppose there are 10 estimation periods, that parameter alpha has a break between date 3 and 4, while parameter beta has a break between date 5 and 6. There are therefore 4 estimated parameters: alpha over [1:3], alpha over [4:10], beta over [1:5], beta over [6:10].

The problem is that here, alpha is not constant inside the two subsamples for beta, and vice-versa. This creates implementation problems.

The solution is to compute a partition of [1:10] such that every estimated parameter is constant inside every subsample. In our case, we have 3 subsamples in this partition: [1:3], [4:5], [6:10]. The estimated parameters become: alpha over [1:3], alpha over [4:5]+[6:10], beta over [1:3]+[4:5], beta over [6:10].

We will assume that the computing of this partition is done outside the Estimation DLL (in the preprocessor or in the M-files).

The estimation DLL will be passed a structure containing all the information for the subsamples. Each subsample will be assigned an ID, in chronological order. The estimation DLL will be passed a vector<pair<int, int> > which will associate a subsample ID to its start and end period.

Estimated parameters description

Suppose there are n estimated parameters. Then the estimation DLL will be passed a structure containing the following information for each estimated parameter:

  • type: an integer in [1:5]

    • 1 -> standard deviation of a structural shock

    • 2 -> standard deviation of a measurement error

    • 3 -> correlation betwwen two structural shocks

    • 4 -> correlation between two measurement errors

    • 5 -> deep parameter

  • ID1, ID2: two integers

    • For type 1, ID1 is the index in M_.exo_names, which is equal to the line/column index in M_.Sigma_e. ID2 is not used

    • For type 2, ID1 is the index in options_.varobs, which is equal to the line/column index in M_.H. ID2 is not used

    • For type 3, ID1 and ID2 are the line and column indices of the element in M_.Sigma_e

    • For type 4, ID1 and ID2 are the line and column indices of the element in M_.H

    • For type 5, ID1 is the index in M_.params, ID2 is not used

  • Subsamples: the list of the subsamples associated to this estimated parameter; the list needs not be contiguous

  • Prior is a sub-structure describing the prior belief on a parameter. The fields are:

    • shape: an integer in [1:6], where:

      • 1 -> Beta density

      • 2 -> Gamma density

      • 3 -> Gaussian density

      • 4 -> Inverse gamma (type 1) density

      • 5 -> Uniform density

      • 6 -> Inverse gamma (type 2) density

    • mean: mean of the prior density

    • mode: mode of the prior density

    • standard: standard deviation of the prior density

    • lower_bound: prior density domain (possibly -Inf)

    • upper_bound: prior density domain (possibly Inf)

    • fhp: first hypermarameter $\alpha$ for the beta and gamma priors, $s$ for the inverse gamma prior, lower bound for the uniform prior

    • shp: second hypermarameter $\beta$ for the beta and gamma priors, $\nu$ for the inverse gamma prior, upper bound for the uniform prior

  • lower_bound: effective lower bound for the estimated parameter

  • upper_bound: effective upper bound for the estimated parameter

Remark. The field Prior is empty if the model is estimated by maximum lilkelihood, simulated moments or indirect inference.

Remark 2. This list of estimated parameters description will be arranged in such a way that elements of type 1 and 2 all appear before elements of type 3 and 4. This greatly facilitates the work of computing the covariance elements (using the correlations and the diagonal variance elements).

Functions

  • Likelihood/posterior evaluation (separate two functions ?)
    • - INPUTS: xparam1, data, parameters_specification, ys, coeff_trends, M_.params, M_.Sigma_e, M_.H, list_of_observed_variables

      - OUTPUTS: likelihood/posterior value, info

    • Parameter updates (for period 1):
      • - INPUTS: xparam1, ys, coeff_trends,M_.params, M_.Sigma_e, M_.H

        - OUTUTS: coeff_trends, params, Sigma_e, H

    • reduced form (for period 1):
      • - INPUTS: params

        - OUTPUTS: T R ys

        • Computes steady state
        • Computes linear solution for state variables + observed variables
    • data_filtering (for period 1):
      • - INPUTS: data, ys, coeff_trends, StartPeriod, EndPeriod

        - OUTPUTS: centered_data for subperiod

    • Kalman filter initialization
      • - INPUTS: Sigma_e T R list_of_observed_variables

        - OUTPUTS: a0 P0 Z

        - Remark: Z is computed only for nonstationary models. mfs is computed once before these functions

        • Diffuse Kalman filter recursions takes place here ?
      LOOP on periods 1 to NP:
      • Kalman filter
        • - INPUTS: a0 Po Z T R centered_data Sigma_e H - OUTPUTS: log-likelihood, a(t|t-1), P(t|t-1)

          if period < NP:

          • parameter updates
          • reduced form
          • data_filtering
      END LOOP
    • priors evaluation

Additional Description Notes

Kalman

As change in parameters is not expected by the agents, the solution is very simple, we simply change the values of the system matrices in the Kalman filter within each sub-sample.

However, it would be too complicated to write a Kalman filter routine with changing matrices, so we prefer repeat the basic steps of the current implementation of DsgeLikelihood for each sub-sample during which all parameters remain unchanged.

The consistency of the transition from one sub-period to the next is insured by the proper initialization of initial state (a0) and initial covariance matrix (P0), that are taken from the last value of the previous sub-sample.

Likelihood Calculation

The likelihood (posterior) for the entire sample is simply computed as the sum of the likelihood for each sub-sample (weighted for the length of the sub-sample?).

From an estimation point of view, the changing parameters are treated as different parameters, so in the prior, constant parameters count for one, and each different values of a parameter count each for one as well.

Therefore, the value of log prior is not computed in the loop but only once at the end of DsgeLikelihood for all parameters.

Because we compute the likelihood (posterior) for the entire sample, introducing changing parameters doesn't modify the way the optimizers or the MCMC procedures calls DsgeLikelihood.

See also

C++ Estimation and DsgeLikelihood Design

DynareWiki: EstimationModule (last edited 2011-07-05 09:43:21 by SébastienVillemot)