<?xml version="1.0" encoding="UTF-8"?>

<!--
 *
 * This help file was generated from distfun_binopdf.sci using help_from_sci().
 *
 -->

<refentry version="5.0-subset Scilab" xml:id="distfun_binopdf" xml:lang="en"
          xmlns="http://docbook.org/ns/docbook"
          xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg"
          xmlns:ns3="http://www.w3.org/1999/xhtml"
          xmlns:mml="http://www.w3.org/1998/Math/MathML"
          xmlns:scilab="http://www.scilab.org"
          xmlns:db="http://docbook.org/ns/docbook">

  <refnamediv>
    <refname>distfun_binopdf</refname>
    <refpurpose>Binomial PDF</refpurpose>
  </refnamediv>


<refsynopsisdiv>
   <title>Calling Sequence</title>
   <synopsis>
   y = distfun_binopdf(x,N,pr)
   
   </synopsis>
</refsynopsisdiv>

<refsection>
   <title>Parameters</title>
   <variablelist>
   <varlistentry><term>x :</term>
      <listitem><para> a matrix of doubles, the number of successes. x belongs to the set {0,1,2,3,...,N}</para></listitem></varlistentry>
   <varlistentry><term>N :</term>
      <listitem><para> a matrix of doubles , the total number of binomial trials. N belongs to the set {1,2,3,4,.......}</para></listitem></varlistentry>
   <varlistentry><term>pr :</term>
      <listitem><para> a matrix of doubles, the probability of success in a Bernoulli trial. pr in [0,1].</para></listitem></varlistentry>
   <varlistentry><term>y :</term>
      <listitem><para> a matrix of doubles, the probability density.</para></listitem></varlistentry>
   </variablelist>
</refsection>

<refsection>
   <title>Description</title>
   <para>
Computes the probability distribution function of
the Binomial distribution function.
   </para>
   <para>
Any scalar input argument is expanded to a matrix of doubles
of the same size as the other input arguments.
   </para>
   <para>
The function definition is:
   </para>
   <para>
<latex>
\begin{eqnarray}
f(x,N,pr) = \binom{N}{x} p_r^x (1-p_r)^{N-x}
\end{eqnarray}
</latex>
   </para>
   <para>
Analysis of the random variable.
   </para>
   <para>
Assume that we perform a Bernoulli trial, where
the probability of success is pr and the probability
of failure is 1-pr.
Each time we make the experiment, we replace the
ball in the urn, i.e. this is an experiment with
replacement.
We repeat this experiment N times.
Let X be the number of successes.
Then the random variable X has a binomial distribution with parameters
N and pr.
   </para>
   <para>
Instead, when the sampling is done without replacement,
the hypergeometric distribution must be
considered.
However, when X is much smaller than N, then
the binomial distribtion is a good approximation.
   </para>
   <para>
</para>
</refsection>

<refsection>
   <title>Examples</title>
   <programlisting role="example"><![CDATA[
// Check with x scalar, N scalar, pr scalar
y = distfun_binopdf(0,200,0.02)
expected = 0.0175879

// Check with expanded x
computed = distfun_binopdf([5 15],100,0.05)
expected = [0.1800178 0.0000988]

// Check with expanded N
computed = distfun_binopdf(5,[50 100],0.05)
expected = [0.0658406 0.1800178]

// Check with two arguments expanded
computed = distfun_binopdf([5 10],[50 100],0.05)
expected = [0.0658406 0.0167159]

// Check with all the arguments expanded
computed = distfun_binopdf([5 10],[50 100],[0.05 0.1])
expected = [0.0658406 0.1318653]

// Check y = distfun_binopdf(x,N,pr) with large value of N
computed = distfun_binopdf(2,1000,0.5)
expected = 4.66165177442386078D-296

// Plot the function
scf();
N1 = 20;
x = 0:N1;
y1 = distfun_binopdf(x,N1,0.5);
plot(x,y1,"bo-")
N2 = 20;
x = 0:N2;
y2 = distfun_binopdf(x,N2,0.7);
plot(x,y2,"go-")
N3 = 40;
x = 0:N3;
y3 = distfun_binopdf(x,N3,0.5);
plot(x,y3,"ro-")
legend(["pr=0.5, N=20","pr=0.7, N=20","pr=0.5, N=40"]);
xtitle("Binomial PDF","x","P(X=x)")

   ]]></programlisting>
</refsection>

<refsection>
   <title>Bibliography</title>
   <para>http://en.wikipedia.org/wiki/Binomial_distribution</para>
   <para>http://forge.scilab.org/index.php/p/specfun/source/tree/HEAD/macros/specfun_nchoosek.sci</para>
   <para>Boost C++ librairies, Binomial Coefficients, 2006 , 2007, 2008, 2009, 2010 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno Lalande, Johan Råde, Gautam Sewani and Thijs van den Berg</para>
</refsection>

<refsection>
   <title>Authors</title>
   <simplelist type="vert">
   <member>Copyright (C) 2012 - Prateek Papriwal</member>
   <member>Copyright (C) 2012 - Michael Baudin</member>
   </simplelist>
</refsection>
</refentry>
