Confidence interval simulation | Confidence intervals | AP Statistics | Khan Academy
The goal of this video is to use this scratch pad on Khan Academy, that was written by Khan Academy user Charlotte Allen, in order to get a better intuitive sense of confidence intervals.
So, we're here; we're dealing with a gumball machine where a certain proportion of the gumballs are going to be green. Let's say we can set that, and let's make that 60% of the gumballs are green. But let's say someone else comes along, and they don't actually know the proportion of gumballs that are green, but they can take samples.
So, let's say they take samples of 50 at a time. They draw a sample; the sample proportion right over here actually just happened to be 0.6. But then they could draw another sample; this time the sample proportion is 0.52, or 52% of those 50 gumballs happened to be green.
Now, you could say, "All right, well, these are all different estimates, but for any given estimate, how confident are we that a certain range around that estimate actually contains the true population proportion?" If we look at this tab right over here, that's what confidence intervals are good for.
In a previous video, we talked about how you calculate the confidence interval. What we want to do is say, "Well, there's a 95 percent chance," and we get that from this confidence level. Generally, 95% is the confidence level people typically use.
So, there's a 95 percent chance that whatever our sample proportion is, that it's within two standard deviations of the true proportion, or that the true proportion is going to be contained in an interval that is two standard deviations on either side of our sample proportion. Well, if you don't know the true proportion, the way that you estimate the standard deviation is with the standard error, which we've done in previous videos.
This is two standard errors to the right and two standard errors to the left of our sample proportion. Our confidence interval is this entire interval, going from this left point to this right point. As we draw more samples, you can see—it’s not obvious—but our intervals change depending on what our actual sample proportion is. We use our sample proportion to calculate our confidence interval because we're assuming whoever's doing the sampling does not actually know the true population proportion.
Now, what's interesting here about this simulation is that we can see what percentage of the time our confidence interval actually contains the true parameter. So, let me just draw 25 samples at a time, and you can see here that right now, 93% of our samples did our confidence interval actually contain our population parameter.
We can keep sampling over here, and we can see the more samples that we take, it really is approaching that close to 95% of the time our confidence interval does indeed contain the true parameter. Once again, we did all this math in the previous video, but here, you can see that confidence intervals—calculated the way that we've calculated them—actually do a pretty good job of what they claim to do.
If we calculate a confidence interval based on a confidence level of 95 percent, it is indeed the case that roughly 95% of the time, the true parameter, the population proportion will be contained in that interval. I could just draw more and more and more samples, and we can actually see that happening.
Every now and then, for sure, you get a sample where even when you calculate your confidence interval, the true parameter—the true population proportion—is not contained. But that is the exception; that happens very infrequently. 95 percent of the time, your true population parameter is contained in that interval.
Now, another interesting thing to see is if we increase our sample size, our confidence interval is going to get narrower. So, if we increase our sample size, we'll just make it 200. Now, let's draw some samples—notice now our confidence intervals are narrower.
But still, because our confidence level, which was used to calculate these intervals, is still 95 percent, when we draw a bunch of samples, we are still going to get roughly 95% of the time our confidence intervals contain our true population proportion. But roughly 5% of the time, they don't.