In this page, we’ll discuss the Bernoulli distribution.
The Bernoulli distribution is the probability distribution of Bernoulli trial, which only has 2 outcomes (eg: success or failure, win or lose).
Mathematically, Bernoulli distribution is described as below.
k: outcome
Bernoulli distribution is simple to create. We’ll create a distribution of P(x=0) = 0.4 and P(x=1) = 0.6 in this page.
barplot(names.arg = 0:1, height = dbinom(0:1, size = 1, p = 0.6), xlab = 'X', ylab = 'Probability')
As you see above, the probability of X0 is 0.4, and the probability of X1 is 0.6.
Binomial distribution is a distribution of multiple Bernoulli trials.
Mathematically, binomial distribution is described as below.
x: the number of success
p: the probability of success
n: the number of Bernoulli trial
Let’s create a binomial distribution based on the above Bernoulli distribution (100 trials).
dist_1 <- dbinom(x = 1:100, size = 100, prob = 0.6)
plot(dist_1, type= "h")
The above plot is the expected distribution of 100 Bernoulli trials with the probability of winning 0.6. Now let’s see how the distribution changes with respect to the probability of winning.
x <- 1:100
dist_1 <- dbinom(x, size = 100, prob = 0.6)
plot(dist_1, type= "h", ylim=c(0,0.14))
lines (dbinom(x, size = 100, prob = 0.3), type ="h",col = rgb(0,1,0, 0.7))
lines (dbinom(x, size = 100, prob = 0.9), type ="h",col = rgb(0,0,1, 0.7))
legend("bottomleft", legend = c("0.3, 0.6, 0.9,"), title = "probablity of winning")
You may have noticed that the shape of binomial distribution varies with respect to p.