If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Confidence interval simulation

Confidence interval simulation.

Want to join the conversation?

  • blobby green style avatar for user James Cage
    Is the simulation software available to students? If so, can you share a link? Thanks -
    (13 votes)
    Default Khan Academy avatar avatar for user
  • leaf red style avatar for user caseyfranklin027
    does anyone have a link to the simulation? The one I found doesn't work at all
    (3 votes)
    Default Khan Academy avatar avatar for user
  • male robot johnny style avatar for user Mohamed Ibrahim
    Can we calculate the confidence level, even when the distribution of the proportions is not normal ( there are fewer than 10 expected successes) ?
    (4 votes)
    Default Khan Academy avatar avatar for user
    • blobby green style avatar for user daniella
      Yes, you can calculate a confidence interval even when the distribution of the proportions is not normal, but the method may differ. Normally, the approximation to a normal distribution is valid when both np and n(1-p) are greater than 10. If this condition isn't met (fewer than 10 expected successes or failures), alternative methods such as the exact binomial confidence interval or using transformations like the Wilson score interval or the Agresti-Coull interval should be considered. These methods adjust for the skewness and discreteness of the binomial distribution especially in cases of small sample sizes or extreme proportions.
      (1 vote)
  • blobby green style avatar for user Georgia  Poole
    I'm reading a scientific article with results formatted as follows
    mean = 7·7 (SD = 5·4), placebo 9·0 (6·0); effect size -1·2, (95% CI -2·3, -0·1), p = 0·037)
    How do I interpret this?
    (3 votes)
    Default Khan Academy avatar avatar for user
    • blobby green style avatar for user daniella
      The scientific article presents its results in a specific format indicating the effect of a treatment compared to a placebo. Here's how to interpret the data:

      Mean = 7.7 (SD = 5.4): This indicates the average result of the treatment group is 7.7, with a standard deviation (SD) of 5.4. The standard deviation shows variability around the mean, where a larger SD indicates more spread in the data.

      Placebo 9.0 (6.0): The placebo group's mean result is 9.0 with a standard deviation of 6.0, again indicating variability around this mean.

      Effect size -1.2, (95% CI -2.3, -0.1): The treatment resulted in an average decrease of 1.2 units compared to the placebo. The 95% confidence interval (CI) from -2.3 to -0.1 suggests that, with 95% confidence, the true effect size lies within this range. The fact that the interval does not include 0 supports the claim that the treatment has a statistically significant effect (the treatment effect is likely not due to chance).

      p = 0.037: This p-value indicates that there is a 3.7% probability that the observed effect (or an even more extreme effect) could occur if the null hypothesis (no true difference between treatment and placebo) were true. Since the p-value is less than 0.05, the results are typically considered statistically significant, rejecting the null hypothesis in favor of the alternative that there is a difference between treatment and placebo effects.
      (1 vote)
  • blobby green style avatar for user Joshua Towns
    this was very helpful
    (2 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user ju lee
    why is standard error of sample proportion and confidence interval useful?
    (2 votes)
    Default Khan Academy avatar avatar for user
    • sneak peak green style avatar for user S.M.Deepak
      The standard error (otherwise called as confidence interval) of sample proportion is used to estimate population proportion. If you find the 99% confidence interval (0.45 to 0.66 for example) from a sample proportion, it says that the population proportion is between that interval (0.45 to 0.66).
      (1 vote)
  • blobby green style avatar for user vsimone5088
    Is there a notes version of this topic some where? I cant follow along well enough to take notes on this, and if there isnt one, could you please make one?
    (2 votes)
    Default Khan Academy avatar avatar for user
    • blobby green style avatar for user daniella
      Confidence Intervals (CI):

      Purpose: Estimate the range within which a population parameter (like a mean or proportion) lies based on sample data.

      Calculation:
      For Proportions: CI = p-hat ± Z*(standard error), where Z depends on the confidence level (e.g., 1.96 for 95% CI).

      Standard Error for Proportions: SE = sqrt[p-hat(1 - p-hat)/n].

      Interpretation: If the process of taking samples and calculating CIs were repeated indefinitely, approximately 95% (for a 95% CI) of these intervals would contain the true population parameter.

      Assumptions for Normal Approximation: np and n(1-p) should both be >10 for the normal approximation to be valid. If not, consider alternative methods like exact binomial or Wilson score intervals.
      (1 vote)
  • leaf orange style avatar for user PTNLemay
    Suppose we wanted a different confidence interval, like 80% or 99%. What would we change in our formula? The methodology we've seen so far seems locked in at 95%.
    (1 vote)
    Default Khan Academy avatar avatar for user
    • leafers ultimate style avatar for user Sergey Korotkov
      95% confidence interval means that you go 2 SE's (standard errors) below and 2 SE's above your sample mean. In another way - you are constructing an interval between z-scores of -2 and 2 (remember the empirical rule, or 68-95-99.7 rule). If you want to construct an interval for any other percentage you should find z-values, difference of which will give you desired percentage. Simplified formula is [sample mean - z-score * SE; sample mean + z-score * SE].
      (2 votes)
  • purple pi teal style avatar for user Tridib Roy Chowdhury
    This is not correct. The size of the horizontal bars should change depending on the phat. Is that not how we derived SE in the previous video (erroneously I feel).
    Why are the horizionatal confidence bars same size -- looks like it was based on the std.dev of population which we claimed in the previous video we do not know.
    (1 vote)
    Default Khan Academy avatar avatar for user
    • blobby green style avatar for user Joe
      The intervals are not the same length. Take a screenshot of the video when the intervals are displayed and measure a few of them and you'll see they vary. Not by much, but look at it this way: 0.6 * 0.4 = 0.24, while 0.5 * 0.5 = 0.25. That's not much of a difference, especially after you plug into the standard error formula.
      (2 votes)
  • aqualine sapling style avatar for user RainyDAZE
    I know that you can use 80% as a confidence level but why would you because it does not have the, uh, ability to, um, get most of the confidence interval? Sorry if that's confusing.
    Also wouldn't it just be better to use a 100% confidence level?
    (1 vote)
    Default Khan Academy avatar avatar for user

Video transcript

- [Instructor] 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 here we're dealing with a gumball machine where a certain proportion of the gumballs are going to be green. And so let's say we can set that on it. 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. And so let's say they take samples of 50 at a time, and so 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, what, how confident are we that the, a certain range around that estimate actually contains the true population proportion? And so if we look at this tab right over here, that's what confidence intervals are good for. And in a previous video, we talked about how you calculate the confidence interval. What we wanna do is say, well, there's a 95% chance, and we get that from this confidence level, and 95% is the confidence level people typically use. And so there's a 95% 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 are 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 a standard error, which we've done in previous videos. And so this is two standard errors to the right and two standard errors to the left of our sample proportion. And our confidence interval is this entire interval, going from this left point to this right point. And as we draw more samples, you can see it's not obvious, but our intervals change depending on what our actual sample proportion is. Because 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 does our confidence interval, does it actually contain the true parameter? So let me just draw out 25 samples at a time. And so you can see here that right now, 93% of our, for 93% of our samples, did our confidence interval actually contain our population parameter. And 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. And so once again, we did all that math in the previous video, but here you can see that confidence intervals calculated the way that we calculated them, actually do a pretty good job of what they claim to do. That if we calculate a confidence interval based on a confidence level of 95%, that it is indeed the case that roughly 95% of the time, the true parameter, the population proportion will be contained in that interval. And 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% 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%, 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.