Skip to contents

Create a ddf object for the binomial distribution with the given parameters.

Usage

bin(n, p)

Source

This function uses stats::dbinom() to calculate the distribution efficiently.

Arguments

n

An integer, the number of trials.

p

A number between 0 and 1, the success probability for each trial.

Value

A ddf distribution as described above.

Details

The binomial distribution with parameters \(n\) and \(p\) models the number of successes when conducting \(n\) independent experiments with each one being distributed according to the Bernoulli distribution with success probability \(p\) (see also bernoulli()).

It has support \(\{0, \dots, n\}\) on which its probability mass function is given by $$p(k) = \binom{n}{k} p^k (1-p)^{n-k}.$$

See also

Examples

# How often a six can be expected when
# throwing a six-sided dice thrice
bin(3, 1 / 6)
#> Binomial distribution with parameters n = 3 and p = 0.166666666666667 
#> 
#> Support:
#> [1] 0 1 2 3
#> 
#> Probabilities:
#> [1] 0.57870370 0.34722222 0.06944444 0.00462963