Learn R Programming

distr6 (version 1.3.6)

Bernoulli: Bernoulli Distribution Class

Description

Mathematical and statistical functions for the Bernoulli distribution, which is commonly used to model a two-outcome scenario.

Value

Returns an R6 object inheriting from class SDistribution.

Constructor

Bernoulli$new(prob = 0.5, qprob = NULL, decorators = NULL, verbose = FALSE)

Constructor Arguments

Argument Type Details
prob numeric probability of success.
qprob numeric probability of failure.

decorators Decorator decorators to add functionality. See details.

Constructor Details

The Bernoulli distribution is parameterised with prob or qprob as a number between 0 and 1. These are related via, $$qprob = 1 - prob$$ If qprob is given then prob is ignored.

Public Variables

Variable Return
name Name of distribution.
short_name Id of distribution.
description Brief description of distribution.

Public Methods

Accessor Methods Link
decorators decorators
traits traits
valueSupport valueSupport
variateForm variateForm
type type
properties properties
support support
symmetry symmetry
sup sup
inf inf
dmax dmax
dmin dmin
skewnessType skewnessType
kurtosisType kurtosisType

Statistical Methods Link pdf(x1, ..., log = FALSE, simplify = TRUE) pdf cdf(x1, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE) cdf quantile(p, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE) quantile.Distribution rand(n, simplify = TRUE) rand mean() mean.Distribution variance() variance stdev() stdev prec() prec cor() cor skewness() skewness kurtosis(excess = TRUE) kurtosis entropy(base = 2) entropy mgf(t) mgf cf(t) cf pgf(z) pgf median() median.Distribution iqr() iqr mode(which = "all") mode

Parameter Methods Link parameters(id) parameters getParameterValue(id, error = "warn") getParameterValue setParameterValue(..., lst = NULL, error = "warn") setParameterValue

Validation Methods Link liesInSupport(x, all = TRUE, bound = FALSE) liesInSupport liesInType(x, all = TRUE, bound = FALSE) liesInType

Representation Methods Link strprint(n = 2) strprint print(n = 2) print summary(full = T) summary.Distribution

Details

The Bernoulli distribution parameterised with probability of success, \(p\), is defined by the pmf, $$f(x) = p, \ if \ x = 1$$$$f(x) = 1 - p, \ if \ x = 0$$ for \(p \ \in \ [0,1]\).

The distribution is supported on \(\{0,1\}\).

References

McLaughlin, M. P. (2001). A compendium of common probability distributions (pp. 2014-01). Michael P. McLaughlin.

See Also

listDistributions for all available distributions. Binomial for a generalisation of the Bernoulli distribution.

Examples

Run this code
# NOT RUN {
# Can be parameterised with probability of success or failure
Bernoulli$new(prob = 0.2)
Bernoulli$new(qprob = 0.3)

x = Bernoulli$new(verbose = TRUE) # Default is with prob = 0.5

# Update parameters
# When any parameter is updated, all others are too!
x$setParameterValue(qprob = 0.3)
x$parameters()

# d/p/q/r
x$pdf(5)
x$cdf(5)
x$quantile(0.42)
x$rand(4)

# Statistics
x$mean()
x$variance()

summary(x)

# }

Run the code above in your browser using DataLab