comparison rDiff/src/tests/calcl_nbin_pdf.m @ 0:0f80a5141704

version 0.3 uploaded
author vipints
date Thu, 14 Feb 2013 23:38:36 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0f80a5141704
1 function [RET]=calcl_nbin_pdf(VAL,R,P)
2 %uses formula used by matlab for compatability
3
4 RET=zeros(size(VAL,1),size(VAL,2));
5 IDX=VAL==round(VAL);
6 %RET(IDX) = exp(gammaln(R+VAL(IDX))-gammaln(VAL(IDX)+1)-gammaln(R)+R*log(P)+VAL(IDX)*log1p(-P));
7
8
9 nk = (gammaln(R + VAL(IDX)) - gammaln(VAL(IDX) + 1) - gammaln(R));
10 RET(IDX) = nk + (R.*log(P)) + (VAL(IDX).*log(1 - P));
11 RET(IDX) = exp(RET(IDX));