1. The normal distribution
So far in this course, we've been exploring the binomial distribution, the result of flipping a coin multiple times and counting the number of heads. In this chapter we're going to introduce three other important probability distributions, and see how they each connect to the theme of flipping coins.
You'll not only add these distributions to your statistical toolbox, but also see how the principles we've learned about working with random variables and simulation are important far beyond the binomial.
2. Flipping 10 coins
So far you've often looked at a binomial where each draw is made up of ten flips of a coin that has a 50% chance of heads. That would look like this distribution: a histogram where the most common value is 5.
3. Flipping 1000 coins
Now imagine that instead of flipping 10 or 20 fair coins in each draw, we flipped 1000. Now the distribution of the number of heads is centered around 500. Notice that the distribution is now taking on a sort of symmetrical "bell curve" shape.
4. Flipping 1000 coins
This is because when you draw from the binomial with a very large size (that is, many coins)- the result approximates a normal distribution. Approximations from one distribution to another are important in probability since they let you make connections between statistical tools.
You'll sometimes hear a normal distribution referred to as a Gaussian distribution, or a bell curve. It's famous because many distributions in nature take up this shape, such as measurement errors in scientific experiments, and because its mathematical properties are well understood. Many of the courses on the DataCamp platform show how the normal distribution can be used in statistical inference.
5. Normal distribution has mean and standard deviation
While the binomial is defined in terms of parameters size and p-that is, the number of coins and their probability of heads-the normal is defined based on two other parameters: the mean and the standard deviation. Mathematically, we usually represent the mean as the Greek letter "mu", and standard deviation as the Greek letter sigma.
In chapters 1 and 2 we introduced the concept of variance, the average squared distance from the mean. The standard deviation is the square root of the variance. While R defines the normal using the standard deviation, some other statisticians choose to define the normal distribution in terms of the variance. It's not that important which you choose, because if you know one-you know the other. You can square the standard deviation to get the variance, or take the square root of the variance to get the standard deviation.
6. Normal approximation to the binomial
Because the normal is defined in terms of the mean and variance, this makes it easy to find the normal approximation to a particular binomial distribution.
For example, we could create a sample of 100,000 draws from the binomial distribution with size 1000 each and a probability of point-5. In Chapter 1 you learned how to compute the expected value and variance from these parameters. The expected value is the size, 1000, times the probability, point-5, and the variance is the size times the probability times 1 minus the probability, point-5. Since we want the standard deviation, we can take the square root of the variance.
We can then simulate from the normal using these parameters. We do this with the rnorm function, rather than rbinom. The first argument is the number of draws, The second is the mean, the same as the expected value of the binomial, and the third is the desired standard deviation.
7. Comparing histograms
Now that we've simulated one hundred thousand draws from the binomial and from the corresponding normal, we'd like to compare them to see if the normal really is a good approximation.
This course focuses on probability rather than visualization, so rather than have you build the graph yourself, we've provided a simple function: "compare_histograms", to which you simply provide the two simulated vectors. You'll notice the two histograms look very similar, confirming that this normal distribution is a good approximation to the binomial. You'll try some other comparisons in the exercises, including comparing the cumulative density between the two distributions.
8. Let's practice!