Math 132A

Confidence Intervals Examples

Example

What proportion of Americans have diabetes?

We used the nhanes.samp.adult data set, which includes the Diabetes variable:

tally(~Diabetes, data = nhanes.samp.adult, margin = TRUE)
Diabetes
   No   Yes Total 
  122    13   135 

The sample proportion of subjects with diabetes is \[\hat{p} = 0.0962963.\]

What does this tell us about the population proportion?

According to this sample, what are the plausible values of the population proportion?

Using Bootstrapping

  • Get the bootstrap distribution:

    do(10000) * tally(~Diabetes, data = resample(nhanes.samp.adult),
                      format = "proportion") -> boots
  • Visualize it

    gf_histogram(~Yes, data = boots)

  • Get the 95% CI:

    qdata(~Yes, c(0.025, 0.975), data = boots)
          2.5%      97.5% 
    0.05185185 0.14814815 

Conclusion

We are 95% confident that the interval between 0.052 and 0.148 contains the true proportion of the US adults who have diabetes.

Using the CLT

According to the CLT for proportions, the sampling distribution of sample proportions is approximately \[N\left(p, \sqrt{\frac{pq}{n}}\right).\]

It is contingent on the success-failure condition: \(np\) and \(nq\) must both be at least 10.

For confidence interval, we are sampling from the bootstrap population.

That is a fake population that is perfectly represented by the sample.

In this population, \(p\) is \(\hat{p}\) and \(q\) is \(\hat{q}\).

\(n\hat{p}\) is the actual number of successes in the sample.

\(n\hat{q}\) is the actual number of failures in the sample.

The Bootstrap Distribution

According to the CLT for proportions:

  • If the number of successes and the number of failures in the sample are both at least 10,
  • the bootstrap distribution of sample proportions obtained from that sample is approximately \[N\left(\hat{p}, \sqrt{\frac{\hat{p}\hat{q}}{n}}\right).\]
  • The mean is \(\hat{p}\).
  • The standard error is \[\sqrt{\frac{\hat{p}\hat{q}}{n}}.\]

Back to the Example

  • \(\hat{p} = 0.0962963\).
  • \(\hat{q} = 1 - \hat{p} = 0.9037037\).
  • \(n = 135\).
  • Number of successes: 13.
  • Number of failures: 122.
  • Standard error: \[SE = \sqrt{\frac{\hat{p}\hat{q}}{n}} = \sqrt{\frac{0.0962963\cdot 0.9037037}{135}} = 0.0253893.\]
  • Bootstrap distribution is approximately \(N(0.0962963, 0.0253893)\).

Confidence Interval

  • 95% of all values of a standard normal distribution are between \(-1.96\) and \(1.96\).

  • 95% of all values of \(N(0.0962963, 0.0253893)\) are between \[0.0962963 - 1.96\cdot 0.0253893 = 0.0465332\] and \[0.0962963 + 1.96\cdot 0.0253893 = 0.1460593.\]

  • Using R:

    qnorm(c(0.025, 0.975), mean = 0.0962963, sd = 0.0253893)
    [1] 0.04653419 0.14605841

Conclusion with CLT

We are 95% confident that the interval between 0.047 and 0.146 contains the true proportion of the US adults who have diabetes.

Comparison

Bootstrapping:

do(10000) * tally(~Diabetes, data = resample(nhanes.samp.adult),
                  format = "proportion") -> boots

qdata(~Yes, c(0.025, 0.975), data = boots)
      2.5%      97.5% 
0.05185185 0.14814815 

Central Limit Theorem:

phat <- prop(~Diabetes, success = "Yes", data = nhanes.samp.adult)
SE <- sqrt(phat*(1-phat)/135)

qnorm(c(0.025, 0.975), mean = 0.0962963, sd = 0.0253893)
[1] 0.04653419 0.14605841

Margin of Error

  • The middle 95% of values of a standard normal variable are between the 0.025 and 0.975 quantiles, which are approximately \(-1.96\) and \(1.96\).
  • The middle 95% of values of a normal variable with mean \(\mu\) and standard deviation \(\sigma\) are between the 0.025 and 0.975 quantiles, which are approximately \[\mu - 1.96\sigma\] and \[\mu + 1.96\sigma.\]
  • The \(1.96\) is called the critical \(z\)-score, often denoted \(z^\star\).
  • In confidence interval, \(\sigma = SE\), the standard error.
  • The quantity \(z^\star\cdot SE\) is called the margin of error.
  • The confidence interval is (point estimate - margin of error, point estimate + margin of error).

Margin of Error cont.

  • The margin of error is the half of the confidence interval length.
  • The margin of error tells you how “precise” your estimate is.
  • The confidence level tells you how “accurate” the process you used to calculate the interval is.
  • Increasing the confidence level makes the margin of error larger, thus decreasing precission.
  • Decreasing the confidence level makes the margin of error smaller, thus increasing precission.

Estimate of Mean

Using the same data set, we also found a confidence interval for the mean height of US adults. Let’s look at this example again.

favstats(~Height, data = nhanes.samp.adult)
 min     Q1 median    Q3   max     mean       sd   n missing
 140 162.55  168.5 177.8 191.3 169.4874 9.949473 135       0

We will find a 98% confidence interval for the population mean. We will use both bootstrapping and the Central Limit Theorem.

Bootstrapping

  • Get the bootstrap distribution:

    do(10000) * mean(~Height, data = resample(nhanes.samp.adult)) -> mean_boots
  • Visualize it

    gf_histogram(~mean, data = mean_boots)

  • Get the 98% CI:

    qdata(~mean, c(0.01, 0.99), data = mean_boots)
          1%      99% 
    167.5222 171.4505 

Conclusion

We are 98% confident that the interval between 167.52 cm and 171.45 cm contains the true mean height of all US adults.

Using the CLT

favstats(~Height, data = nhanes.samp.adult)
 min     Q1 median    Q3   max     mean       sd   n missing
 140 162.55  168.5 177.8 191.3 169.4874 9.949473 135       0
  • Sample mean \(\overline{x} = 169.4874074\).
  • Sample standard deviation \(s = 9.9494726\).
  • Sample size \(n = 135\).
  • Standard error \[SE = \frac{s}{\sqrt{n}} = \frac{9.9494726}{\sqrt{135}} = 0.8563143.\]
  • Quantiles of the T distribution:

    qt(c(.01, .99), df = 134)
    [1] -2.354498  2.354498
  • Critical \(t\)-score: \(t^\star = 2.3544981\).

  • Margin of error: \(t^\star\cdot SE = 2.3544981\cdot 0.8563143 = 2.0161903\).

Interval: \((\overline{x} - t^\star\cdot SE,\overline{x} + t^\star\cdot SE) = (169.4874074 - 2.0161903, 169.4874074 + 2.0161903) = (167.4712171, 171.5035977)\)

Conclusion

We are 98% confident that the interval between 167.47 cm and 171.5 cm contains the true mean height of all US adults.

Finding critical \(z\)-score :

  • We need to know \(\alpha = 1 - L\).

  • Left or lower CI: the area to the left of \(z^\star\) is \(\alpha\).

    With \(\alpha = 0.05\) (\(95\)% CI):

    qnorm(0.05)
    [1] -1.644854
  • Right or upper CI: the area to the left of \(z^\star\) is \(1 - \alpha\).

    With \(\alpha = 0.05\) (\(95\)% CI):

    qnorm(0.95)
    [1] 1.644854
  • Two-sided CI: the area to the left of \(z^\star\) is \(1 - \alpha/2\).

    With \(\alpha = 0.05\) (\(95\)% CI):

    qnorm(0.975)
    [1] 1.959964
  • Or use the normal distribution table.

Finding critical \(t\)-score :

  • We need \(\alpha = 1 - L\) and \(n\) for degrees of freedom. \(df = n - 1\)

  • Left or lower CI: the area to the left of \(t^\star\) is \(\alpha\).

    With \(\alpha = 0.05\) (\(95\)% CI) and \(n = 25\):

    qt(0.05, df = 24)
    [1] -1.710882
  • Right or upper CI: the area to the left of \(t^\star\) is \(1 - \alpha\).

    With \(\alpha = 0.05\) (\(95\)% CI) and \(n = 25\):

    qt(0.95, df = 24)
    [1] 1.710882
  • Two-sided CI: the area to the left of \(t^\star\) is \(1 - \alpha/2\).

    With \(\alpha = 0.05\) (\(95\)% CI) and \(n = 25\):

    qt(0.975, df = 24)
    [1] 2.063899

Using a table

Make the \(t^\star\) negative for left (lower) interval.

Another Example

In some places, rocks found in fields may contain geodes in them. In a sample of 25 rocks collected from a field, 11 of them contained a geode. Use this information to find a 75% confidence interval estimating the proportion of rocks that contain geodes in the field.

  • Is success-failure condition satisfied?
  • Sample size \(n\):
  • Sample proportion \(\hat{p}\):
  • Standard error \(SE\):
  • Critical \(z\)-score \(z^\star\):
  • Margin of error \(E\):
  • The confidence interval:
  • Formal conclusion:

Yet Another Example

In some places, it is possible to find pieces of rare natural glass called tektites. It is known that sizes of tektites are approximately normally distributed. A sample of 16 tektites collected from a field has a mean weight of 12 grams, with standard deviation 3 grams. Use this information to find a 90% confidence interval estimating the mean weight of tektites in the field.

  • Is the sample large enough? How do you know?
  • Sample size \(n\):
  • Sample mean \(\overline{x}\):
  • Standard error \(SE\):
  • Critical \(t\)-score \(t^\star\):
  • Margin of error \(E\):
  • The confidence interval:
  • Formal conclusion: