File: prior_bounds.m

package info (click to toggle)
dynare 4.6.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 74,896 kB
  • sloc: cpp: 98,057; ansic: 28,929; pascal: 13,844; sh: 5,947; objc: 4,236; yacc: 4,215; makefile: 2,583; lex: 1,534; fortran: 877; python: 647; ruby: 291; lisp: 152; xml: 22
file content (164 lines) | stat: -rw-r--r-- 5,980 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
function bounds = prior_bounds(bayestopt, prior_trunc)

%@info:
%! @deftypefn {Function File} {@var{bounds} =} prior_bounds (@var{bayesopt},@var{option})
%! @anchor{prior_bounds}
%! @sp 1
%! Returns bounds for the prior densities. For each estimated parameter the lower and upper bounds
%! are such that the defined intervals contains a probability mass equal to 1-2*@var{option}.prior_trunc. The
%! default value for @var{option}.prior_trunc is 1e-10 (set in @ref{global_initialization}).
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item bayestopt
%! Matlab's structure describing the prior distribution (initialized by @code{dynare}).
%! @item option
%! Matlab's structure describing the options (initialized by @code{dynare}).
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item bounds
%! A structure with two fields lb and up (p*1 vectors of doubles, where p is the number of estimated parameters) for the lower and upper bounds.
%! @end table
%! @sp 2
%! @strong{This function is called by:}
%! @sp 1
%! @ref{get_prior_info}, @ref{dynare_estimation_1}, @ref{dynare_estimation_init}
%! @sp 2
%! @strong{This function calls:}
%! @sp 1
%! None.
%! @end deftypefn
%@eod:


% function bounds = prior_bounds(bayestopt)
% computes bounds for prior density.
%
% INPUTS
%    bayestopt  [structure]  characterizing priors (shape, mean, p1..p4)
%
% OUTPUTS
%    bounds     [double]      structure specifying prior bounds (lb and ub fields)
%
% SPECIAL REQUIREMENTS
%    none

% Copyright (C) 2003-2017 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.

pshape = bayestopt.pshape;
p3 = bayestopt.p3;
p4 = bayestopt.p4;
p6 = bayestopt.p6;
p7 = bayestopt.p7;

bounds.lb = zeros(length(p6),1);
bounds.ub = zeros(length(p6),1);

for i=1:length(p6)
    switch pshape(i)
      case 1
        if prior_trunc == 0
            bounds.lb(i) = p3(i);
            bounds.ub(i) = p4(i);
        else
            bounds.lb(i) = betainv(prior_trunc,p6(i),p7(i))*(p4(i)-p3(i))+p3(i);
            bounds.ub(i) = betainv(1-prior_trunc,p6(i),p7(i))*(p4(i)-p3(i))+p3(i);
        end
      case 2
        if prior_trunc == 0
            bounds.lb(i) = p3(i);
            bounds.ub(i) = Inf;
        else
            try
                bounds.lb(i) = gaminv(prior_trunc,p6(i),p7(i))+p3(i);
                bounds.ub(i) = gaminv(1-prior_trunc,p6(i),p7(i))+p3(i);
            catch
                % Workaround for ticket #161, see http://savannah.gnu.org/bugs/?52569
                if isoctave
                    error(['Due to a computational limitation in Octave, the prior bounds cannot be computed. You must either use prior_trunc=0 or choose other values for mean and/or variance of your prior on ' bayestopt.name{i} ', or use another shape'])
                else
                    rethrow(lasterror)
                end
            end
        end
      case 3
        if prior_trunc == 0
            bounds.lb(i) = -Inf;
            bounds.ub(i) = Inf;
        else
            bounds.lb(i) = norminv(prior_trunc,p6(i),p7(i));
            bounds.ub(i) = norminv(1-prior_trunc,p6(i),p7(i));
        end
      case 4
        if prior_trunc == 0
            bounds.lb(i) = p3(i);
            bounds.ub(i) = Inf;
        else
            try
                bounds.lb(i) = 1/sqrt(gaminv(1-prior_trunc, p7(i)/2, 2/p6(i)))+p3(i);
                bounds.ub(i) = 1/sqrt(gaminv(prior_trunc, p7(i)/2, 2/p6(i)))+p3(i);
            catch
                % Workaround for ticket #161, see http://savannah.gnu.org/bugs/?52569
                if isoctave
                    error(['Due to a computational limitation in Octave, the prior bounds cannot be computed. You must either use prior_trunc=0 or choose other values for mean and/or variance of your prior on ' bayestopt.name{i} ', or use another shape'])
                else
                    rethrow(lasterror)
                end
            end
        end
      case 5
        if prior_trunc == 0
            bounds.lb(i) = p6(i);
            bounds.ub(i) = p7(i);
        else
            bounds.lb(i) = p6(i)+(p7(i)-p6(i))*prior_trunc;
            bounds.ub(i) = p7(i)-(p7(i)-p6(i))*prior_trunc;
        end
      case 6
        if prior_trunc == 0
            bounds.lb(i) = p3(i);
            bounds.ub(i) = Inf;
        else
            try
                bounds.lb(i) = 1/gaminv(1-prior_trunc, p7(i)/2, 2/p6(i))+p3(i);
                bounds.ub(i) = 1/gaminv(prior_trunc, p7(i)/2, 2/p6(i))+ p3(i);
            catch
                % Workaround for ticket #161, see http://savannah.gnu.org/bugs/?52569
                if isoctave
                    error(['Due to a computational limitation in Octave, the prior bounds cannot be computed. You must either use prior_trunc=0 or choose other values for mean and/or variance of your prior on ' bayestopt.name{i} ', or use another shape'])
                else
                    rethrow(lasterror)
                end
            end
        end
      case 8
        if prior_trunc == 0
            bounds.lb(i) = p3(i);
            bounds.ub(i) = Inf;
        else
            bounds.lb(i) = p3(i)+wblinv(prior_trunc,p6(i),p7(i));
            bounds.ub(i) = p3(i)+wblinv(1-prior_trunc,p6(i),p7(i));
        end
      otherwise
        error(sprintf('prior_bounds: unknown distribution shape (index %d, type %d)', i, pshape(i)));
    end
end