# R - Binomial Distribution

## Function

### Density

The binomial distribution with size = n and prob = p has density

````p(x) = choose(n, x) p^x (1-p)^(n-x)`
```

for x = 0, …, n

where:

### Cumulative

To find the probability of having k or less correct answers, we can plot a cumulative distribution.

``````plot(pbinom(0:40, size=20, prob=0.5) )
plot(pbinom(0:40, size=20, prob=0.7) )
plot(pbinom(0:40, size=40, prob=0.5) )```
```

## Example

### Biased coin

The (Probability|Statistics) - Binomial Distribution example of the Binomial Distribution in R

``````require(graphics)
dbinom(0:5, size=6, prob=0.3)```
```
````[1] 0.117649 0.302526 0.324135 0.185220 0.059535 0.010206`
```

where:

• 0:5 is a vector representing k (the trial index)
• size is n, the number of trial
• prob is the probability of a success trial