<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE MAN SYSTEM "../../manrev.dtd">
<MAN>
  <LANGUAGE>eng</LANGUAGE>
  <TITLE>binomial</TITLE>
  <TYPE>Scilab Function</TYPE>
  <DATE>April 1993</DATE>
  <SHORT_DESCRIPTION name="binomial"> binomial distribution probabilities</SHORT_DESCRIPTION>
  <CALLING_SEQUENCE>
    <CALLING_SEQUENCE_ITEM>pr=binomial(p,n)  </CALLING_SEQUENCE_ITEM>
  </CALLING_SEQUENCE>
  <PARAM>
    <PARAM_INDENT>
      <PARAM_ITEM>
        <PARAM_NAME>pr</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: row vector with n+1 components</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>p</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: real number in [0,1]</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>n</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: an integer &gt;= 1</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
    </PARAM_INDENT>
  </PARAM>
  <DESCRIPTION>
    <P><VERB>pr=binomial(p,n)</VERB> returns the binomial probability vector, i.e. 
    <VERB>pr(k+1)</VERB> is the probability of <VERB>k</VERB> success in <VERB>n</VERB> independent 
    Bernouilli trials with probability of success <VERB>p</VERB>. In other words :
    <VERB>pr(k+1) = probability(X=k)</VERB> , with X a random variable following the B(n,p) 
    distribution, and numerically :</P>
    <VERBATIM>
<![CDATA[
            / n \  k      n-k       / n \       n!
 pr(k+1) =  |   | p  (1-p)    with  |   |  = ---------
            \ k /                   \ k /    k! (n-k)!
   ]]>
    </VERBATIM>
  </DESCRIPTION>
  <EXAMPLE>
<![CDATA[
// first example
n=10;p=0.3; xbasc(); plot2d3(0:n,binomial(p,n));

// second example 
n=50;p=0.4;
mea=n*p; sigma=sqrt(n*p*(1-p));
x=( (0:n)-mea )/sigma;
xbasc()
plot2d(x, sigma*binomial(p,n));
deff('y=Gauss(x)','y=1/sqrt(2*%pi)*exp(-(x.^2)/2)')
plot2d(x, Gauss(x), style=2);

// by binomial formula (Caution if big n)
function pr=binomial2(p,n)
x=poly(0,'x');pr=coeff((1-p+x)^n).*horner(x^(0:n),p);
endfunction
p=1/3;n=5;
binomial(p,n)-binomial2(p,n)

// by Gamma function: gamma(n+1)=n! (Caution if big n)
p=1/3;n=5;
Cnks=gamma(n+1)./(gamma(1:n+1).*gamma(n+1:-1:1));
x=poly(0,'x');
pr=Cnks.*horner(x.^(0:n).*(1-x)^(n:-1:0),p);
pr-binomial(p,n)
 ]]>
  </EXAMPLE>
  <SEE_ALSO>
    <SEE_ALSO_ITEM>
      <LINK>cdfbin</LINK>
    </SEE_ALSO_ITEM>
    <SEE_ALSO_ITEM>
      <LINK>grand</LINK>
    </SEE_ALSO_ITEM>
  </SEE_ALSO>
</MAN>
