STK++ 0.9.13

Binomial probability law. More...

#include <STK_Law_Binomial.h>

Inheritance diagram for STK::Law::Binomial:
Inheritance graph

Public Types

typedef IUnivLaw< IntegerBase
 

Public Member Functions

 Binomial (int n=1, Real const &prob=0.5)
 constructor
 
virtual ~Binomial ()
 destructor
 
int n () const
 
Real constprob () const
 
void setN (Integer n)
 
void setProb (Real const &prob)
 
virtual Integer rand () const
 
virtual Real pdf (Integer const &x) const
 compute the probability distribution function (density) Give the value of the pdf at the point x.
 
virtual Real lpdf (Integer const &x) const
 compute the log probability distribution function Give the value of the log-pdf at the point x.
 
virtual Real cdf (Real const &t) const
 compute the cumulative distribution function Give the probability that a Binomial random variate is less or equal to t.
 
virtual Integer icdf (Real const &p) const
 inverse cumulative distribution function The quantile is defined as the smallest value x such that F(x) >= p , where F is the cumulative distribution function.
 
- Public Member Functions inherited from STK::Law::IUnivLaw< Integer >
virtual ~IUnivLaw ()
 Virtual destructor.
 
virtual Real lcdf (Real const &t) const
 compute the lower tail log-cumulative distribution function Give the log-probability that a random variate is less or equal to t.
 
virtual Real cdfc (Real const &t) const
 calculate the complement of cumulative distribution function, called in statistics the survival function.
 
virtual Real lcdfc (Real const &t) const
 calculate the log-complement of cumulative distribution function Give the log-probability that a random variate is greater than t.
 
- Public Member Functions inherited from STK::Law::ILawBase
String constname () const
 

Static Public Member Functions

static Integer rand (int n, Real const &prob)
 
static Real pdf (Integer x, int n, Real const &prob)
 compute the probability distribution function (density) Give the value of the pdf at the point x.
 
static Real lpdf (Integer x, int n, Real const &prob)
 compute the log probability distribution function Give the value of the log-pdf at the point x.
 
static Real cdf (Real const &t, int n, Real const &prob)
 compute the cumulative distribution function Give the probability that a Binomial random variate is less or equal to t.
 
static Integer icdf (Real const &p, int n, Real const &prob)
 inverse cumulative distribution function The quantile is defined as the smallest value x such that F(x) >= p , where F is the cumulative distribution function.
 

Protected Attributes

int n_
 number of trials
 
Real prob_
 probability of success in a Bernoulli trial
 
- Protected Attributes inherited from STK::Law::ILawBase
String name_
 Name of the Law.
 

Additional Inherited Members

- Protected Member Functions inherited from STK::Law::IUnivLaw< Integer >
 IUnivLaw (String const &name)
 Constructor.
 
 IUnivLaw (IUnivLaw const &law)
 copy Constructor.
 
- Protected Member Functions inherited from STK::Law::ILawBase
 ILawBase (String const &name)
 Constructor.
 
 ~ILawBase ()
 destructor.
 

Detailed Description

Binomial probability law.

In probability theory and statistics, the Binomial distribution with parameters n and p is the discrete probability distribution of the number of successes in a sequence of n independent yes/no experiments, each of which yields success with probability p. A success/failure experiment is also called a Bernoulli experiment or Bernoulli trial. When n = 1, the binomial distribution is a Bernoulli distribution

In general, if the random variable X follows the binomial distribution with parameters n and p, we write $ X \sim B(n;p)$. The probability of getting exactly k successes in n trials is given by the probability mass function:

\[ f(k;n,p) = \mathbb{P}(X = k) = {n\choose k}p^k(1-p)^{n-k} \]

The binomial distribution is the basis for the popular binomial test of statistical significance.

Definition at line 64 of file STK_Law_Binomial.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ Binomial()

STK::Law::Binomial::Binomial ( int  n = 1,
Real const prob = 0.5 
)
inline

constructor

Parameters
probprobability of success in a Binomial trial
nthe number of trials

Definition at line 72 of file STK_Law_Binomial.h.

73 : Base(_T("Binomial")), n_(n), prob_(prob)
74 {
77 if (n<0) STKDOMAIN_ERROR_2ARG(Binomial::Binomial,prob,n,n must be >= 0);
78 }
#define STKDOMAIN_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:147
#define _T(x)
Let x unmodified.
Real const & prob() const
IUnivLaw< Integer > Base
Binomial(int n=1, Real const &prob=0.5)
constructor
Real prob_
probability of success in a Bernoulli trial
int n_
number of trials

References Binomial(), n(), prob(), and STKDOMAIN_ERROR_2ARG.

Referenced by Binomial().

◆ ~Binomial()

virtual STK::Law::Binomial::~Binomial ( )
inlinevirtual

destructor

Definition at line 80 of file STK_Law_Binomial.h.

80{}

Member Function Documentation

◆ cdf() [1/2]

Real STK::Law::Binomial::cdf ( Real const t) const
virtual

compute the cumulative distribution function Give the probability that a Binomial random variate is less or equal to t.

Parameters
ta real value
Returns
the value of the cdf

Implements STK::Law::IUnivLaw< Integer >.

Definition at line 69 of file STK_Law_Binomial.cpp.

70{
71 // trivial cases
73 return 0.;
74}
static Type NA()
Adding a Non Available (NA) special number.
static bool isNA(Type const &x)

References STK::Arithmetic< Type >::NA().

◆ cdf() [2/2]

Real STK::Law::Binomial::cdf ( Real const t,
int  n,
Real const prob 
)
static

compute the cumulative distribution function Give the probability that a Binomial random variate is less or equal to t.

Parameters
ta real value
n,probnumber of trial and probability of success
Returns
the value of the cdf

Definition at line 103 of file STK_Law_Binomial.cpp.

104{
105 return 0.;
106}

◆ icdf() [1/2]

int STK::Law::Binomial::icdf ( Real const p) const
virtual

inverse cumulative distribution function The quantile is defined as the smallest value x such that F(x) >= p , where F is the cumulative distribution function.

Parameters
pa probability number

Implements STK::Law::IUnivLaw< Integer >.

Definition at line 76 of file STK_Law_Binomial.cpp.

77{
78 // trivial cases
80 return 0.;
81}

References STK::Arithmetic< Type >::NA().

◆ icdf() [2/2]

int STK::Law::Binomial::icdf ( Real const p,
int  n,
Real const prob 
)
static

inverse cumulative distribution function The quantile is defined as the smallest value x such that F(x) >= p , where F is the cumulative distribution function.

Parameters
pa probability number
n,probnumber of trial and probability of success

Definition at line 108 of file STK_Law_Binomial.cpp.

109{
110 return 0.;
111}

◆ lpdf() [1/2]

Real STK::Law::Binomial::lpdf ( Integer const x) const
virtual

compute the log probability distribution function Give the value of the log-pdf at the point x.

Parameters
xa binary value
Returns
the value of the log-pdf

Reimplemented from STK::Law::IUnivLaw< Integer >.

Definition at line 62 of file STK_Law_Binomial.cpp.

63{
64 // trivial cases
66 // compute result
68}
Real binomial_lpdf_raw(Real const &x, Real const &n, Real const &p)
Compute the generalized binomial log-probability mass function.

References STK::Funct::binomial_lpdf_raw(), n_, STK::Arithmetic< Type >::NA(), and prob_.

◆ lpdf() [2/2]

Real STK::Law::Binomial::lpdf ( Integer  x,
int  n,
Real const prob 
)
static

compute the log probability distribution function Give the value of the log-pdf at the point x.

Parameters
xa binary value
n,probnumber of trial and probability of success
Returns
the value of the log-pdf

Definition at line 96 of file STK_Law_Binomial.cpp.

97{
98 // trivial cases
100 // compute result
101 return Funct::binomial_lpdf_raw(x, n, prob);
102}

References STK::Funct::binomial_lpdf_raw(), n(), STK::Arithmetic< Type >::NA(), and prob().

◆ n()

int STK::Law::Binomial::n ( ) const
inline
Returns
the number of trials

Definition at line 82 of file STK_Law_Binomial.h.

82{ return n_;}

References n_.

Referenced by Binomial(), lpdf(), pdf(), and setN().

◆ pdf() [1/2]

Real STK::Law::Binomial::pdf ( Integer const x) const
virtual

compute the probability distribution function (density) Give the value of the pdf at the point x.

Parameters
xa binary value
Returns
the value of the pdf

Implements STK::Law::IUnivLaw< Integer >.

Definition at line 54 of file STK_Law_Binomial.cpp.

55{
56 // trivial cases
58 // compute result
60}
Real binomial_pdf_raw(Real const &x, Real const &n, Real const &p)
Compute the generalized binomial probability mass function.

References STK::Funct::binomial_pdf_raw(), n_, STK::Arithmetic< Type >::NA(), and prob_.

◆ pdf() [2/2]

Real STK::Law::Binomial::pdf ( Integer  x,
int  n,
Real const prob 
)
static

compute the probability distribution function (density) Give the value of the pdf at the point x.

Parameters
xa binary value
n,probnumber of trial and probability of success
Returns
the value of the pdf

Definition at line 88 of file STK_Law_Binomial.cpp.

89{
90 // trivial cases
92 // compute result
93 return Funct::binomial_pdf_raw(x, n, prob);
94}

References STK::Funct::binomial_pdf_raw(), n(), STK::Arithmetic< Type >::NA(), and prob().

◆ prob()

Real const & STK::Law::Binomial::prob ( ) const
inline
Returns
the probability of success

Definition at line 84 of file STK_Law_Binomial.h.

84{ return prob_;}

References prob_.

Referenced by Binomial(), lpdf(), pdf(), and setProb().

◆ rand() [1/2]

int STK::Law::Binomial::rand ( ) const
virtual
Returns
a Integer random variate .

Implements STK::Law::IUnivLaw< Integer >.

Definition at line 49 of file STK_Law_Binomial.cpp.

50{
51 return 0;
52}

◆ rand() [2/2]

int STK::Law::Binomial::rand ( int  n,
Real const prob 
)
static
Parameters
n,probnumber of trial and probability of success
Returns
a Integer random variate.

Definition at line 83 of file STK_Law_Binomial.cpp.

84{
85 return 0;
86}

◆ setN()

void STK::Law::Binomial::setN ( Integer  n)
inline
Parameters
nthe number of trials to set

Definition at line 86 of file STK_Law_Binomial.h.

87 {
88 if (n<0) STKDOMAIN_ERROR_1ARG(Binomial::setN,n,n must be >= 0);
89 n_ = n;
90 }
#define STKDOMAIN_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:165
void setN(Integer n)

References n(), n_, setN(), and STKDOMAIN_ERROR_1ARG.

Referenced by setN().

◆ setProb()

void STK::Law::Binomial::setProb ( Real const prob)
inline
Parameters
probthe probability of success to set

Definition at line 92 of file STK_Law_Binomial.h.

93 {
96 prob_ = prob;
97 }
void setProb(Real const &prob)

References prob(), prob_, setProb(), and STKDOMAIN_ERROR_1ARG.

Referenced by setProb().

Member Data Documentation

◆ n_

int STK::Law::Binomial::n_
protected

number of trials

Definition at line 172 of file STK_Law_Binomial.h.

Referenced by lpdf(), n(), pdf(), and setN().

◆ prob_

Real STK::Law::Binomial::prob_
protected

probability of success in a Bernoulli trial

Definition at line 174 of file STK_Law_Binomial.h.

Referenced by lpdf(), pdf(), prob(), and setProb().


The documentation for this class was generated from the following files: