forked from PeterKDunn/SRM-Textbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
21-CIs-More.Rmd
executable file
·385 lines (288 loc) · 14.6 KB
/
21-CIs-More.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# More about CIs {#AboutCIs}
```{r, child = if (knitr::is_html_output()) {'./introductions/21-CIs-More-HTML.Rmd'} else {'./introductions/21-CIs-More-LaTeX.Rmd'}}
```
## General comments
The previous chapter discussed forming confidence intervals (CI) for one proportion.
We will also study CIs in other contexts.
This chapter discusses some principles that apply to *all* CIs.
CIs are formed for the unknown *population* parameter (such as the population proportion $p$), based on a *sample* statistic (such as the sample proportion $\hat{p}$).
Most CIs have the form
\[
\text{Statistic} \pm (\text{Multiplier} \times \text{standard error}),
\]
where $(\text{Multiplier} \times \text{standard error})$ is called the *margin of error*.
For an *approximate* 95% CI, the *multiplier* is 2 (from the [68--95--99.7 rule](#def:EmpiricalRule)).
The statistical conditions should always be checked to see if the CI is (at least approximately) statistically valid.
## Interpreting a CI {#CIInterpretation}
Interpreting CIs correctly is tricky.
The *correct* interpretation (Definition \@ref(def:ConfidenceInterval)) of a 95% CI is the following:
> *If* samples were repeatedly taken many times, and the 95% confidence interval computed for each sample, 95% of these confidence intervals formed would contain the population [*parameter*](#def:Parameter).
This is the idea shown in
`r if (knitr::is_latex_output()) {
'Fig. \\@ref(fig:RollDiceCIFig).'
} else {
'the animation in Sect. \\@ref(ConfIntPUnknownP).'
}`
In practice, this definition is unsatisfying, since we only ever have *one* sample.
And since the value of the parameter is unknown (after all, we went to the bother of taking a sample so we could *estimate* the value of the parameter), we don't know if *our* CI from our single sample includes the population parameter or not.
A reasonable alternative interpretation for a 95% CI is:
> The confidence interval gives a range of values of the unknown parameter that could plausibly (with 95% confidence) have given rise to our observed value of the statistic.
Or we might say that:
> There is a 95% chance that our computed CI straddles the value of the population parameter.
These alternatives are not absolutely correct, but are reasonable and common interpretations.
Commonly, the CI is described as having a 95% chance of containing the population [parameter](#StatisticsAndParameters).
This is not strictly correct, but is a common and a convenient paraphrase for the correct interpretation above.
I use this analogy:
Most people say the sun rises in the east.
This is incorrect: the sun doesn't *rise* at all.
It *appears* to rise in the east because the earth rotates on its axis.
But almost everyone says that the 'sun rises in the east', and for most circumstances this is a fine and convenient paraphrase of the situation, even though technically incorrect.
Similarly, most people interpret a CI as an interval with a certain chance of containing the value of the population parameter, even though it is technically incorrect.
::: {.importantBox .important data-latex="{iconmonstr-warning-8-240.png}"}
All *confidence intervals* tell us something about the unknown *population parameter*, based on what we learn from the imperfect sample statistic.
:::
<div style="float:right; width: 222x; border: 1px; padding:10px">
<img src="Illustrations/tin-1568095_640.jpg" width="200px"/>
</div>
::: {.example #EnergyDrinks name="Energy drinks in Canadian youth"}
In Example \@ref(exm:CanadianEnergyDrinks), the approximate 95% CI was from 0.192 to 0.236.
The correct interpretation is:
> If we took many samples of 1516 Canadian youth, and computed the approximate 95% CI for each one, about 95% of those CIs would contain the population proportion.
We don't know if *our* CI from a single sample includes the value of $p$, however.
We might say:
> This 95% CI is likely to straddle the actual value of $p$.
or
> The range of values of $p$ that could plausibly (with 95% confidence) have produced $\hat{p} = 0.241$ is between 0.192 and 0.236.
In practice, the CI is usually interpreted as:
> There is a 95% chance that the population proportion of Canadian youth who have experienced sleeping difficulties after consuming energy drinks is between 0.192 to 0.236.
This is not strictly correct, but is a commonly-used paraphrase, and sufficient for our use.
:::
::: {.thinkBox .think data-latex="{iconmonstr-light-bulb-2-240.png}"}
In Example \@ref(exm:KoalasCrossingRoads) about koalas crossing roads, the approximate 95% CI was from 0.130 to 0.209.
What is the correct interpretation of this CI?\label{thinkBox:InterpretationKoala}
`r if (knitr::is_latex_output()) '<!--'`
`r webexercises::hide()`
The correct interpretation is:
> If we took many similar samples, about 95% of these would contain the population proportion
We might also say this:
> There is a 95% chance that this CI we computed straddles the population proportion.
In practice, most people think of it like this (even though it is not strictly correct):
> There is a 95% chance that the population proportion is between 0.130 and 0.209.
`r webexercises::unhide()`
`r if (knitr::is_latex_output()) '-->'`
:::
## Validity and confidence intervals {#ValidityCIs}
When constructing confidence intervals, certain *statistical validity conditions* must be true; these ensure that the sampling distribution is sufficiently close to a normal distribution for the [68--95--99.7 rule](#def:EmpiricalRule) rule to apply.
If these conditions are *not* met, the sampling distribution may not be close to an approximate normal distribution, so the 68--95--99.7 rule (on which the CI is based) may not be appropriate, and the CI itself may be inappropriate.
Of course, if the statistical validity conditions are close to be satisfied, then the resulting confidence interval will still be reasonably useful.
In addition to the statistical validity condition, the *internal validity* and *external validity* of the study should be discussed (Fig. \@ref(fig:ValiditiesCI)).
Regarding *external validity*, all the CI computations in this book assume a *simple random sample*.
If the sample is from a [*random* sampling method](#RandomSamples), but not from a [*simple random sample*](#SRS), then methods exist for producing CIs that are externally valid, but are more complicated than those described in this book.
If the sample is a [non-random sample](#NonRandomSamples), then the CI may be reasonable for the quite specific population that *is* represented by the sample;
however, the sample probably does not represent the more general population that is probably intended.
*Externally validity* requires that a study is also internally valid.
*Internal validity* can only be discussed if details are known about the study design.
```{r ValiditiesCI, fig.cap="Four types of validities for studies.", fig.align="center", fig.height=4, out.width="75%"}
par( mar = c(0.15, 0.15, 0.15, 0.15))
ValidityColours <- viridis::viridis(8) # alpha = 0.4)
TypeCol <- ValidityColours[6]
ConditionCol <- ValidityColours[7]
ImplicationCol <- ValidityColours[8]
openplotmat()
pos <- array(NA,
dim = c(12, 2))
pos[1, ] <- c(0.25, 0.85) # External
pos[2, ] <- c(0.45, 0.85) # Internal
pos[3, ] <- c(0.65, 0.85) # Statistical
pos[4, ] <- c(0.85, 0.85) # Ecological
pos[5, ] <- c(0.25, 0.50) # EX: conditions
pos[6, ] <- c(0.45, 0.50) # IN: conditions
pos[7, ] <- c(0.65, 0.50) # ST: conditions
pos[8, ] <- c(0.85, 0.50) # ECO: conditions
pos[9, ] <- c(0.25, 0.085) # EX: upshot
pos[10, ] <- c(0.45, 0.085) # IN: upshot
pos[11, ] <- c(0.65, 0.085) # ST: upshot
pos[12, ] <- c(0.85, 0.085) # ECO: upshot
textplain( mid = c(0.07, pos[1, 2]),
lab = "Type:",
adj = c(0.5, 1))
textplain( mid = c(0.07, pos[5, 2]),
lab = "Condition:",
adj = c(0.5, 1))
textplain( mid = c(0.07, pos[9, 2]),
lab = "Implication:",
adj = c(0.5, 1))
straightarrow(from = pos[1, ], to = pos[5, ],
lwd = 2,
lcol = "black",
lty = 1)
straightarrow(from = pos[2, ], to = pos[6, ],
lwd = 2,
lcol = "black",
lty = 1)
straightarrow(from = pos[3, ], to = pos[7, ],
lwd = 2,
lcol = "black",
lty = 1)
straightarrow(from = pos[4, ], to = pos[8, ],
lwd = 2,
lcol = "black",
lty = 1)
straightarrow(from = pos[5, ], to = pos[9, ],
lwd = 2,
lcol = "black",
lty = 3)
straightarrow(from = pos[6, ], to = pos[10, ],
lwd = 2,
lcol = "black",
lty = 3)
straightarrow(from = pos[7, ], to = pos[11, ],
lwd = 2,
lcol = "black",
lty = 3)
straightarrow(from = pos[8, ], to = pos[12, ],
lwd = 2,
lcol = "black",
lty = 3)
textrect( pos[1, ],
lab = "External\n validity",
radx = 0.09,
rady = 0.10,
shadow.size = 0,
box.col = TypeCol,
lcol = TypeCol)
textrect( pos[2, ],
lab = "Internal\n validity",
radx = 0.09,
rady = 0.10,
shadow.size = 0,
box.col = TypeCol,
lcol = TypeCol)
textrect( pos[3, ],
lab = "Statistical\n validity",
radx = 0.09,
rady = 0.10,
shadow.size = 0,
box.col = TypeCol,
lcol = TypeCol)
textrect( pos[4, ],
lab = "Ecological\n validity",
radx = 0.09,
rady = 0.10,
shadow.size = 0,
box.col = TypeCol,
lcol = TypeCol)
textrect( pos[5, ],
lab = "Random\n samples",
radx = 0.09,
rady = 0.10,
shadow.size = 0,
box.col = ConditionCol,
lcol = ConditionCol)
textrect( pos[6, ],
lab = "Study is\n well-designed",
radx = 0.09,
rady = 0.10,
shadow.size = 0,
box.col = ConditionCol,
lcol = ConditionCol)
textrect( pos[7, ],
lab = "Specific\n conditions",
radx = 0.09,
rady = 0.10,
shadow.size = 0,
box.col = ConditionCol,
lcol = ConditionCol)
textrect( pos[8, ],
lab = "Study like\nreal world",
radx = 0.09,
rady = 0.10,
shadow.size = 0,
box.col = ConditionCol,
lcol = ConditionCol)
textrect( pos[9, ],
lab = "Sample\n represents\n population",
radx = 0.09,
rady = 0.150,
adj = c(0.5, 0.25),
shadow.size = 0,
box.col = ImplicationCol,
lcol = ImplicationCol)
textrect( pos[10, ],
lab = c("Within-sample\n conclusions\n are sound"),
radx = 0.09,
rady = 0.150,
adj = c(0.5, 0.25),
shadow.size = 0,
box.col = ImplicationCol,
lcol = ImplicationCol)
textrect( pos[11, ],
lab = "Statistical\n methods\n appropriate",
radx = 0.09,
rady = 0.150,
adj = c(0.5, 0.25),
shadow.size = 0,
box.col = ImplicationCol,
lcol = ImplicationCol)
textrect( pos[12, ],
lab = "Results\n seen in\n real world",
radx = 0.09,
rady = 0.150,
adj = c(0.5, 0.25),
shadow.size = 0,
box.col = ImplicationCol,
lcol = ImplicationCol)
```
In addition, CIs also require that the sample size is less than about 10% of the population size; this is almost always the case.
<iframe src="https://learningapps.org/watch?v=paixpst9c22" style="border:0px;width:100%;height:600px" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>
## Quick revision exercises {#Chap21-QuickReview}
::: {.webex-check .webex-box}
1. True or false: CIs *always* have 95% confidence.\tightlist
`r if( knitr::is_html_output() ) {torf(answer = FALSE )}`
1. True or false: The statistical validity conditions concern *generalisability* of the results.
`r if( knitr::is_html_output() ) {torf(answer = FALSE )}`
1. True or false: CIs are intervals in which the value of a *population* parameter will always lie.
`r if( knitr::is_html_output() ) {torf(answer = FALSE )}`
1. True or false: All other things being equal, a 95% CI is *wider* than a 90% CI.
`r if( knitr::is_html_output() ) {torf(answer = TRUE )}`
1. The 'multiplier times the standard error' is called the
`r if( knitr::is_html_output() ) {longmcq( c(
"CI",
answer = "margin of error",
"sampling variation"
) )} else {'________.'}`
1. A CI gives an interval which we are fairly sure (but not certain) that includes the value of the
`r if( knitr::is_html_output() ) {longmcq( c(
"Sample statistic",
answer = "Population parameter",
"Population sample"
) )} else {'________.'}`
:::
## Exercises {#AboutCIsExercises}
Selected answers are available in Sect. \@ref(AboutCIsAnswer).
::: {.exercise #AboutCIsInterpretation}
A researcher was computing a 95% CI for a single proportion to estimate the proportion of trees with apple scab [@hirst1962epidemiology], and found that $\hat{p} = 0.314$ and $\text{s.e.}(\hat{p}) = 0.091$.
What would be wrong with the following conclusion?
> The approximate 95% CI for the sample proportion is between 0.223 and 0.405.
:::
::: {.exercise #AboutCIsInterpretation2}
A researcher was computing a 95% CI for a single proportion to estimate the proportion of trees with apple scab [@hirst1962epidemiology], and found that $\hat{p} = 0.314$ and $\text{s.e.}(\hat{p}) = 0.091$.
What would be wrong with the following conclusion?
> This CI means we are 95% confident that between 22.3 and 40.5 trees are infected with apple scab.
:::
<!-- QUICK REVIEW ANSWERS -->
`r if (knitr::is_html_output()) '<!--'`
::: {.EOCanswerBox .EOCanswer data-latex="{iconmonstr-check-mark-14-240.png}"}
**Answers to in-chapter questions:**
- Sect. \ref{thinkBox:InterpretationKoala}: The correct interpretation is: "If we took many similar samples, about 95% of these would contain the population proportion."
We might also say this: "There is a 95% chance that this CI we computed straddles the population proportion."
In practice, most people think of it like this (even though it is not strictly correct): "There is a 95% chance that the population proportion is between 0.130 and 0.209."
- \textbf{\textit{Quick Revision} questions:}
**1.** False.
**2.** False.
**3.** False.
**4.** True.
**5.** Margin of error.
**6.** Population parameter.
:::
`r if (knitr::is_html_output()) '-->'`