Home > matlab > lpdfgbeta.m

lpdfgbeta

PURPOSE ^

Evaluates the logged BETA PDF at x.

SYNOPSIS ^

function [ldens,Dldens,D2ldens] = lpdfgbeta(x,a,b,aa,bb);

DESCRIPTION ^

 Evaluates the logged BETA PDF at x. 

 INPUTS 
    x     [double]  m*n matrix of loactions,
    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, 
    bb    [double]  m*n matrix of upper bounds. 

 OUTPUTS 
    ldens [double]  m*n matrix of logged (generalized) BETA densities.
        
 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ldens,Dldens,D2ldens] = lpdfgbeta(x,a,b,aa,bb);
0002 % Evaluates the logged BETA PDF at x.
0003 %
0004 % INPUTS
0005 %    x     [double]  m*n matrix of loactions,
0006 %    a     [double]  m*n matrix of First BETA distribution parameters,
0007 %    b     [double]  m*n matrix of Second BETA distribution parameters,
0008 %    aa    [double]  m*n matrix of lower bounds,
0009 %    bb    [double]  m*n matrix of upper bounds.
0010 %
0011 % OUTPUTS
0012 %    ldens [double]  m*n matrix of logged (generalized) BETA densities.
0013 %
0014 % SPECIAL REQUIREMENTS
0015 %    none
0016 
0017 % Copyright (C) 2003-2009 Dynare Team
0018 %
0019 % This file is part of Dynare.
0020 %
0021 % Dynare is free software: you can redistribute it and/or modify
0022 % it under the terms of the GNU General Public License as published by
0023 % the Free Software Foundation, either version 3 of the License, or
0024 % (at your option) any later version.
0025 %
0026 % Dynare is distributed in the hope that it will be useful,
0027 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0028 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0029 % GNU General Public License for more details.
0030 %
0031 % You should have received a copy of the GNU General Public License
0032 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0033 
0034 ldens = -Inf( size(x) ) ;
0035 idx = find( (x-aa)>0 & (x-bb)<0 ) ;
0036 
0037 if length(a)==1
0038     ldens(idx) = -betaln(a,b) + (a-1)*log(x(idx)-aa) + (b-1)*log(bb-x(idx)) - (a+b-1)*log(bb-aa) ;
0039 else
0040     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));
0041 end
0042 
0043 
0044 if nargout >1 
0045     if length(a)==1
0046         Dldens(idx) = (a-1)./(x(idx)-aa) - (b-1)./(bb-x(idx)) ;
0047     else
0048         Dldens(idx) = (a(idx)-1)./(x(idx)-aa(idx)) - (b(idx)-1)./(bb(idx)-x(idx));
0049     end
0050 end
0051 
0052 
0053 if nargout == 3 
0054     if length(a)==1
0055         D2ldens(idx) = -(a-1)./(x(idx)-aa).^2 - (b-1)./(bb-x(idx)).^2 ;
0056     else
0057         D2ldens(idx) = -(a(idx)-1)./(x(idx)-aa(idx)).^2 - (b(idx)-1)./(bb(idx)-x(idx)).^2;
0058     end
0059 end

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005