Home > matlab > lpdfgam.m

lpdfgam

PURPOSE ^

Evaluates the logged GAMMA PDF at x.

SYNOPSIS ^

function [ldens,Dldens,D2ldens] = lpdfgam(x,a,b);

DESCRIPTION ^

 Evaluates the logged GAMMA PDF at x.

 INPUTS     
    x     [double]  m*n matrix of locations,
    a     [double]  m*n matrix or scalar, First GAMMA distribution parameters, 
    b     [double]  m*n matrix or scalar, Second GAMMA distribution parameters, 

 OUTPUTS
    ldens [double]  m*n matrix of logged GAMMA densities evaluated at x.
     
        
 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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