.. |newpage| raw:: latex \newpage .. |cr| raw:: latex \hspace{0.0mm} Boost: Bernoulli distribution ------------------------------------------------------------------------------- The following functions return the pmf, cdf, qtf or boost class of the Bernoulli distribution The Bernoulli distribution is a discrete distribution of the outcome of a single trial with only two results, 0 (failure) or 1 (success), with a probability of success p. The Bernoulli distribution is the simplest building block on which other discrete distributions of sequences of independent Bernoulli trials can be based. The Bernoulli is the binomial distribution (k = 1, p) with only one trial. The domain of the random variable is 0 and 1, and the useful supported range is only 0 or 1. The support interval for `k` is `{0, 1}`, and `0 \le q \le 1`. The Bernoulli distribution is implemented here as a strict discrete distribution. If a generalised version, allowing k to be any real, is required then the binomial distribution with a single trial should be used, for example: binomial_distribution(1, 0.25) !!! The following references need to be updated: !!! See also Wikipedia :cite:p:`WikipediaDis31`, MathWorld :cite:p:`WolframDis31`, BoostMath :cite:p:`BoostDis31` . |cr| .. _Ctx_BernoulliPmf: .. method:: Ctx.bernoulli_pmf(k, p) where ``Ctx`` is ``Math53`` or ``CtxBoost``. Returns `\text{pmf}(x)`, the value of the probability mass function (:ref:`Pmf `) of the Bernoulli distribution. It is calculated using the relation `\text{pmf}(k) = 1 - p` for `k = 0`, else `p`. The following example shows both forms of the syntax: .. code-block:: pycon >>> from xlcalcnet import * >>> a = 0; b = 1; t = 0.3; x = 0.6; >>> print ("BernoulliPdf(x, a, b): ", BernoulliPdf(x, a, b)) >>> print ("dist_bernoulli(a, b).pdf(x): ", dist_bernoulli(a, b).pdf(x)) 6.3563523462564525615615615614561356E+00 |cr| .. _Ctx_BernoulliCdf: .. method:: Ctx.bernoulli_cdf(k, p) where ``Ctx`` is ``Math53`` or ``CtxBoost``. Returns `\text{cdf}(x)`, the value of the cumulative distribution function (:ref:`Cdf `) of the Bernoulli distribution. It is calculated using the relation `\text{cdf}(k) = 1 - p` for `k = 0`, else `1`. The following example shows both forms of the syntax: .. code-block:: pycon >>> from xlcalcnet import * >>> a = 0; b = 1; t = 0.3; x = 0.6; >>> print ("BernoulliCdf(x, a, b): ", BernoulliCdf(x, a, b)) >>> print ("dist_bernoulli(a, b).cdf(x): ", dist_bernoulli(a, b).cdf(x)) 6.3563523462564525615615615614561356E+00 |cr| .. _Ctx_BernoulliQtf: .. method:: Ctx.bernoulli_qtf(q, p) where ``Ctx`` is ``Math53`` or ``CtxBoost``. Returns `\text{qtf}(q)`, the value of the quantile function (:ref:`Qtf `) of the Bernoulli distribution. It is calculated using the relation `\text{qtf}(k) = 0` for `k \le (1-p)`, else `1`. The following example shows both forms of the syntax: .. code-block:: pycon >>> from xlcalcnet import * >>> a = 0; b = 1; t = 0.3; q = 0.6; >>> print ("BernoulliQtf(q, a, b): ", BernoulliQtf(q, a, b)) >>> print ("dist_bernoulli(a, b).qtf(q): ", dist_bernoulli(a, b).qtf(q)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: CtxBoost.dist_bernoulli(p) Returns an ``dist_bernoulli`` object, which gives access to the functions descibed below: .. code-block:: pycon >>> from xlcalcnet import SReal, FReal, ereal, QReal, CReal, OReal >>> a = 0; b = 1; >>> Ctx = SReal >>> dist_bernoulli = Ctx.dist_bernoulli(a, b) >>> print ("Dist.qtf(q=0.5): ", Dist.qtf(q=0.5)) 6.3563523462564525615615615614561356E+00 .. method:: dist_bernoulli.pmf(x) Returns `\text{pdf}(x)`, the value of the probability density function of the Bernoulli distribution. See :ref:`Ctx.BernoulliPmf ` for formulas and examples. .. method:: dist_bernoulli.cdf(x) Returns `\text{cdf}(x)`, the value of the cumulative distribution function of the Bernoulli distribution. See :ref:`Ctx.BernoulliCdf ` for formulas and examples. .. method:: dist_bernoulli.qtf(q) Returns `\text{qtf}(q)`, the value of the quantile function of the Bernoulli distribution. See :ref:`Ctx.BernoulliQtf ` for formulas and examples. |cr| .. method:: dist_bernoulli.sf(x) Returns `\text{sf}(x)`, the value of the survival function (:ref:`Sf `) of the Bernoulli distribution. It is calculated using the relation `\text{sf}(k) = p` for `k = 0`, else `0`. .. code-block:: pycon >>> # continued from above >>> print ("Dist.sf(x=0.5): ", Dist.qtf(x=0.5)) 6.3563523462564525615615615614561356E+00 .. method:: dist_bernoulli.isf(q) Returns `\text{isf}(q)`, the value of the inverse survival function (:ref:`Isf `) of the Bernoulli distribution. It is calculated using the relation `\text{qtf}(k) = 1` for `k \le (1-p)`, else `0`. .. code-block:: pycon >>> # continued from above >>> print ("Dist.isf(x=0.5): ", Dist.isf(x=0.5)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.hf(x) Returns `\text{hazard}(x)`, the value of the hazard function (:ref:`Hf `) of the Bernoulli distribution. .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.chf(x) Returns `\text{chf}(x)`, the value of the cumulative hazard function (:ref:`Chf `) of the Bernoulli distribution. .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.mode() Returns the :ref:`mode ` of the Bernoulli distribution, which is `0` if `(p < 0.5)` else `1`. .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.median() Returns the :ref:`median ` of the Bernoulli distribution. Calculated as `\displaystyle tbd`. .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.mean() Returns the :ref:`mean ` (expected value) of the Bernoulli distribution, which is `p`. .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.variance() Returns the :ref:`variance ` of the Bernoulli distribution. Calculated as `\displaystyle p (1-p)`. .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.stdev() Returns the :ref:`standard deviation ` of the Bernoulli distribution. Calculated as `\displaystyle \sqrt{p (1-p)}`. .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.skewness() Returns the :ref:`skewness ` of the Bernoulli distribution. Calculated as `\displaystyle (1-2p)/\sqrt{p(1-p)}`. .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.kurtosis() Returns the 'proper' :ref:`kurtosis ` (normalized fourth moment) of the Bernoulli distribution. Calculated as `\displaystyle 3+(1-6p(1-p))/(p(1-p))`. .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.kurtosis_excess() Returns the :ref:`kurtosis excess ` of the Bernoulli distribution. Calculated as `\displaystyle (1-6p(1-p))/(p(1-p))`. .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.support_lower_endpoint() Returns the :ref:`support ` of the Bernoulli distribution as a tuple (left, right). .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.support_upper_endpoint() Returns the :ref:`support ` of the Bernoulli distribution as a tuple (left, right). .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.range_lower_endpoint() Returns the valid :ref:`range ` of the Bernoulli distribution as a tuple (left, right). .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00 |cr| .. method:: dist_bernoulli.range_upper_endpoint() Returns the valid :ref:`range ` of the Bernoulli distribution as a tuple (left, right). .. code-block:: pycon >>> from xlcalcnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00