$$P(x)=\frac{N!}{x!(N-x)!}\pi^x(1-\pi)^{N-x} $$
For people who are not used to mathematical formulas, this might already look intimidating. However, all we need to know right now is that this formula gives us the probability of getting x heads $P{(x)}$ (i.e. the number of ways we get x heads divided by N tosses):
Note that $\pi$ in the above formula is not the one we might know from geometry but it is simply the Greek letter for p denoting a probability here.
In this case, it is the probability of either event, heads or tails, happening on each toss so it is 50% or 0.5.
We can fill this in for the example above:
$$P(55)=\frac{100!}{55!(100-55)!}0.5^{55}(1-0.5)^{100-55}$$
Translating this formula into `R` syntax we get the following:
`factorial(100)/(factorial(55)*factorial(100-55))*0.5^55*(1-0.5)^(100-55)` = `r round(factorial(100)/(factorial(55)*factorial(100-55))*0.5^55*(1-0.5)^(100-55),2)`
However, before we said that we do not need the probability of _exactly_ 55 heads but everything that is _at least 55_. In order to answer our question how often we get _at least_ 55 heads, we could repeat the above calculation with all values from 55 up until 100 and add up the probabilities that we get.
For example we could do this with a for-loop:
```{r p_binom_manual}
# first we write a function that calculates the probability for each number so we can call it in a loop
pbinom2 <- function(N, x, p){
factorial(N)/(factorial(x)*factorial(N-x))*p^x*(1-p)^(N-x)
}
tosses_55to100 <- c(55:100) # we define the amount of heads that we want to check for (all bigger than or equal to 55)
probs <- c() # we will make an empty collection that we will add the results for each number of heads to
for(i in tosses_55to100){
probs <- append(probs, pbinom2(100,i,.5))
}
print(probs[1:10])
```
Now we got all the probabilities for each of the amounts of heads that we are interested in.
By summing them up we get what we need - the probability of getting at least 55 heads in 100 tosses, `sum(probs)` = `r round(sum(probs), 2)` or `r round(sum(probs), 2)*100` percent.