do(10000) * tally(~Diabetes, data = resample(nhanes.samp.adult),
format = "proportion") -> bootsConfidence Intervals
Goal: Create or evaluate a mathematical model for some random variable(s), using a sample of its (their) values.
Model for a random variable: A distribution with some parameters.
We have a model that we think may work, and we want to test it against our data.
We want to see whether the model is consistent with the data.
Use a sample to find an estimate for one parameter of the model.
Requires no previous knowledge of the parameter, although we may have to make some assumptions about the model.
We have one sample, and we want to use it to estimate a population parameter.
Suppose I use the sample mean to estimate the population mean.
That’s called a point estimate
We think that most of the time the estimate will be pretty good.
What does most of the time mean?
What does pretty good mean?
There is often going to be some difference between the sample statistic and the population parameter.
This is called a sampling error.
How big can this error get?
General principle: the distribution of the sampling error has the same shape as the sampling distribution of the statistic, but is centered at 0.
Also, the sampling distribution of the statistic will have approximately the same shape as the bootstrap distribution.
We saw that bootstrap distributions are generally bell shaped.
Most samples will have small sampling error.
There will be a few samples with large sampling error.
We do not know if our sample has small or large sampling error.
What we can ask is:
Assuming our sample is one of the good ones, how far from our sample statistic can the population parameter be?
This is called the margin of error.
How do we pick the middle 95% (or whatever other confidence level we want) of the samples?
Get the bootstrap distribution:
do(10000) * tally(~Diabetes, data = resample(nhanes.samp.adult),
format = "proportion") -> bootsVisualize 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
We are 95% confident that the interval between 0.052 and 0.148 contains the true proportion of the US adults who have diabetes.
If we instead choose \(L = 90\%\):
qdata(~Yes, c(0.05, 0.95), data = boots) 5% 95%
0.05925926 0.14074074
We are 90% confident that the interval between 0.059 and 0.141 contains the true proportion of the US adults who have diabetes.
Let’s try \(L = 80\%\):
qdata(~Yes, c(0.1, 0.9), data = boots) 10% 90%
0.06666667 0.13333333
We are 80% confident that the interval between 0.067 and 0.133 contains the true proportion of the US adults who have diabetes.
If this range is narrow, we have a sharp estimate.
If this range is wide, we have an estimate that is not so good.
The correct interpretation:
The method illustrated for computing a 95% confidence interval will produce an interval that (on average) contains the true population mean for 95 samples out of 100.
The remaining 5 samples out of 100 will be “incorrect”, that is, it will not contain the population mean.
Unfortunately, we do not know whether a particular interval contains the population mean.
Accuracy is given by the confidence level. This tells you how likely you are to “hit the target”.
Precision is determined by the width of the interval. This tells you how precisely is the target determined when you hit it.
If you want to increase the accuracy, you have to decrease the precision, and vice versa.