[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: binomial normal cdf
From: |
Ted Harding |
Subject: |
RE: binomial normal cdf |
Date: |
Tue, 28 Jul 1998 00:31:03 +0100 (BST) |
On 27-Jul-98 Dimitrie O. Paun wrote:
> I am looking for a Octave/Matlab function that can return the binomial
> normal cdf. Does anyone has such a beast?
For the binomial probability function try
function P=binompdf(n,p)
# For integer n, real p (0 <= p <= 1),
# returns the entire binomial distribution on (0,1,2,...,n)
# as a column vector.
if (( p<0 ) | ( p>1) )
error ( "p is out of range" );
endif
if ( p == 0 )
P = zeros(n+1,1); P(1) = 1;
elseif ( p == 1 )
P = zeros(n+1,1); P(n+1) = 1;
else
r = (0:n)';
P = exp(lgamma(n+1)-lgamma(r+1)-lgamma(n-r+1)+r*log(p)+(n-r)*log(1-p));
P = P/sum(P);
endif
endfunction
and for the binomial CDF try
function P=binomCDF(n,p)
# For integer n, real p (0 <= p <= 1),
# returns the entire binomial cumulative distribution on (0,1,2,...,n)
# as a column vector.
P = cumsum(binompdf(n,p));
endfunction
For the Normal CDF try
function p = normCDF(x);
# function p = normCDF(x) = int from (-inf) to x of normpdf(t) dt
s=sqrt(2);
p=0.5*(1 + erf(x/s));
endfunction
I don't know what would be meant by "binomial normal CDF" unless one of the
above.
Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Date: 28-Jul-98 Time: 00:31:03
--------------------------------------------------------------------