Introduction to Statistics in R
Maggie Matsui
Content Developer, DataCamp
rbinom(# of trials, # of coins, # probability of heads/success)
1
= head, 0
= tails
rbinom(1, 1, 0.5)
1
rbinom(1, 1, 0.5)
0
rbinom(8, 1, 0.5)
1 0 0 1 0 0 1 0
rbinom(1, 8, 0.5)
3
rbinom(10, 3, 0.5)
2 0 1 0 1 1 3 3 3 1
rbinom(10, 3, 0.25)
1 1 0 0 1 1 1 1 2 1
Probability distribution of the number of successes in a sequence of independent trials
E.g. Number of heads in a sequence of coin flips
Described by $n$ and $p$
$P(\text{heads} = 7)$
# dbinom(num heads, num trials, prob of heads)
dbinom(7, 10, 0.5)
0.1171875
$P(\text{heads} \le 7)$
pbinom(7, 10, 0.5)
0.9453125
$P(\text{heads} > 7)$
pbinom(7, 10, 0.5, lower.tail = FALSE)
0.0546875
1 - pbinom(7, 10, 0.5)
0.0546875
$\text{Expected value} = n \times p$
Expected number of heads out of 10 flips $= 10 \times 0.5 = 5$
The binomial distribution is a probability distribution of the number of successes in a sequence of independent trials
The binomial distribution is a probability distribution of the number of successes in a sequence of independent trials
Probabilities of second trial are altered due to outcome of the first
If trials are not independent, the binomial distribution does not apply!
Introduction to Statistics in R