2017-05-16 12:42:01 +02:00
|
|
|
function [ldens,Dldens,D2ldens] = lpdfgbeta(x,a,b,aa,bb)
|
2017-05-16 15:10:20 +02:00
|
|
|
% Evaluates the logged BETA PDF at x.
|
2008-01-11 16:45:52 +01:00
|
|
|
%
|
2017-05-16 15:10:20 +02:00
|
|
|
% INPUTS
|
2021-01-22 15:45:51 +01:00
|
|
|
% x [double] m*n matrix of locations,
|
2017-05-16 15:10:20 +02:00
|
|
|
% a [double] m*n matrix of First BETA distribution parameters,
|
|
|
|
% b [double] m*n matrix of Second BETA distribution parameters,
|
|
|
|
% aa [double] m*n matrix of lower bounds for (generalized) distribution,
|
2014-01-28 18:41:07 +01:00
|
|
|
% bb [double] m*n matrix of upper bounds for (generalized) distribution
|
2009-04-06 16:38:37 +02:00
|
|
|
%
|
2017-05-16 15:10:20 +02:00
|
|
|
% OUTPUTS
|
2021-01-22 15:45:51 +01:00
|
|
|
% ldens [double] m*n matrix of logged (generalized) BETA densities.
|
|
|
|
% Dldens [double] m*n matrix of first derivatives of logged (generalized) BETA densities.
|
|
|
|
% D2ldens [double] m*n matrix of second derivatives of logged matrix of logged (generalized) BETA densities.
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2008-01-11 16:45:52 +01:00
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
2008-08-01 14:40:33 +02:00
|
|
|
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2003-2021 Dynare Team
|
2008-08-01 14:40:33 +02:00
|
|
|
%
|
|
|
|
% 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
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2008-01-11 16:45:52 +01:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
ldens = -Inf( size(x) ) ;
|
|
|
|
idx = find( (x-aa)>0 & (x-bb)<0 ) ;
|
|
|
|
|
|
|
|
if length(a)==1
|
|
|
|
ldens(idx) = -betaln(a,b) + (a-1)*log(x(idx)-aa) + (b-1)*log(bb-x(idx)) - (a+b-1)*log(bb-aa) ;
|
|
|
|
else
|
|
|
|
ldens(idx) = -betaln(a(idx),b(idx)) + (a(idx)-1).*log(x(idx)-aa(idx)) + (b(idx)-1).*log(bb(idx)-x(idx)) - (a(idx)+b(idx)-1).*log(bb(idx)-aa(idx));
|
2011-11-05 10:32:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
if nargout >1
|
2021-01-22 15:45:51 +01:00
|
|
|
Dldens = ldens ;
|
2011-11-05 10:32:37 +01:00
|
|
|
if length(a)==1
|
|
|
|
Dldens(idx) = (a-1)./(x(idx)-aa) - (b-1)./(bb-x(idx)) ;
|
|
|
|
else
|
|
|
|
Dldens(idx) = (a(idx)-1)./(x(idx)-aa(idx)) - (b(idx)-1)./(bb(idx)-x(idx));
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
if nargout == 3
|
2021-01-22 15:45:51 +01:00
|
|
|
D2ldens = ldens ;
|
2011-11-05 10:32:37 +01:00
|
|
|
if length(a)==1
|
2011-11-07 09:17:56 +01:00
|
|
|
D2ldens(idx) = -(a-1)./(x(idx)-aa).^2 - (b-1)./(bb-x(idx)).^2 ;
|
2011-11-05 10:32:37 +01:00
|
|
|
else
|
2011-11-07 09:17:56 +01:00
|
|
|
D2ldens(idx) = -(a(idx)-1)./(x(idx)-aa(idx)).^2 - (b(idx)-1)./(bb(idx)-x(idx)).^2;
|
2011-11-05 10:32:37 +01:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|