Chapter page 22 / 3815 Applications: Foundations
English

15  Applications: Foundations

15.1 Recap: Foundations

In the foundations of inference chapters, we have provided three different methods for statistical inference. We will continue to build on all three of the methods throughout the text, and by the end, you should have an understanding of the similarities and differences between them. Meanwhile, it is important to note that the methods are designed to mimic variability with data, and we know that variability can come from different sources (e.g., random sampling vs. random allocation, see Figure 2.8). In Table 15.1, we have summarized some of the ways the inferential procedures feature specific sources of variability. We hope that you refer back to the table often as you dive more deeply into inferential ideas in future chapters.

Table 15.1: Summary and comparison of randomization, bootstrapping, and mathematical models as inferential statistical methods.
Answer
Question Randomization Bootstrapping Mathematical models
What does it do? Shuffles the explanatory variable to mimic the natural variability found in a randomized experiment Resamples (with replacement) from the observed data to mimic the sampling variability found by collecting data from a population Uses theory (primarily the Central Limit Theorem) to describe the hypothetical variability resulting from either repeated randomized experiments or random samples
What is the random process described? Randomized experiment Random sampling from a population Randomized experiment or random sampling
What other random processes can be approximated? Can also be used to describe random sampling in an observational model Can also be used to describe random allocation in an experiment Can also be used to describe random sampling in an observational model or random allocation in an experiment
What is it best for? Hypothesis testing (can also be used for confidence intervals, but not covered in this text) Confidence intervals (can also be used for bootstrap hypothesis testing for one proportion as well) Quick analyses through, for example, calculating a Z score
What physical object represents the simulation process? Shuffling cards Pulling marbles from a bag with replacement Not applicable

You might have noticed that the word distribution is used throughout this part (and will continue to be used in future chapters). A distribution always describes variability, but sometimes it is worth reflecting on what is varying. Typically the distribution either describes how the observations vary or how a statistic varies. But even when describing how a statistic varies, there is a further consideration with respect to the study design, e.g., does the statistic vary from random sample to random sample or does it vary from random allocation to random allocation? The methods presented in this text (and used in science generally) are typically used interchangeably across ideas of random samples or random allocations of the treatment. Often, the two different analysis methods will give equivalent conclusions. The most important thing to consider is how to contextualize the conclusion in terms of the problem. See Figure 2.8 to confirm that your conclusions are appropriate.

Below, we synthesize the different types of distributions discussed throughout the text. Reading through the different definitions and solidifying your understanding will help as you come across these distributions in future chapters and you can always return back here to refresh your understanding of the differences between the various distributions.

Distributions.

  • A data distribution describes the shape, center, and variability of the observed data.

    This can also be referred to as the sample distribution but we’ll avoid that phrase as it sounds too much like sampling distribution, which is different.

  • A population distribution describes the shape, center, and variability of the entire population of data.

    Except in very rare circumstances of very small, very well-defined populations, this is never observed.

  • A sampling distribution describes the shape, center, and variability of all possible values of a sample statistic from samples of a given sample size from a given population.

    Since the population is never observed, it’s never possible to observe the true sampling distribution either. However, when certain conditions hold, the Central Limit Theorem tells us what the sampling distribution is.

  • A randomization distribution describes the shape, center, and variability of all possible values of a sample statistic from random allocations of the treatment variable.

    We computationally generate the randomization distribution, though usually, it’s not feasible to generate the full distribution of all possible values of the sample statistic, so we instead generate a large number of them. Almost always, by randomly allocating the treatment variable, the randomization distribution describes the null hypothesis, i.e., it is centered at the null hypothesized value of the parameter.

  • A bootstrap distribution describes the shape, center, and variability of all possible values of a sample statistic from resamples of the observed data.

    We computationally generate the bootstrap distribution, though usually, it’s not feasible to generate all possible resamples of the observed data, so we instead generate a large number of them. Since bootstrap distributions are generated by randomly resampling from the observed data, they are centered at the sample statistic. Bootstrap distributions are most often used for estimation, i.e., we base confidence intervals off of them.

15.2 Case study: Malaria vaccine

In this case study, we consider a new malaria vaccine called PfSPZ. In the malaria study, volunteer patients were randomized into one of two experiment groups: 14 patients received an experimental vaccine and 6 patients received a placebo vaccine. Nineteen weeks later, all 20 patients were exposed to a drug-sensitive strain of the malaria parasite; the motivation of using a drug-sensitive strain here is for ethical considerations, allowing any infections to be treated effectively.

The malaria data can be found in the openintro R package.

The results are summarized in Table 15.2, where 9 of the 14 treatment patients remained free of signs of infection while all of the 6 patients in the control group showed some baseline signs of infection.

Table 15.2: Summary results for the malaria vaccine experiment.
Treatment Infection No infection Total
placebo 6 0 6
vaccine 5 9 14
Total 11 9 20

Is this an observational study or an experiment? What implications does the study type have on what can be inferred from the results?1

15.2.1 Variability within data

In this study, a smaller proportion of patients who received the vaccine showed signs of an infection (35.7% versus 100%). However, the sample is very small, and it is unclear whether the difference provides convincing evidence that the vaccine is effective.

Statisticians and data scientists are sometimes called upon to evaluate the strength of evidence. When looking at the rates of infection for patients in the two groups in this study, what comes to mind as we try to determine whether the data show convincing evidence of a real difference?


The observed infection rates (35.7% for the treatment group versus 100% for the control group) suggest the vaccine may be effective. However, we cannot be sure if the observed difference represents the vaccine’s efficacy or if there is no treatment effect and the observed difference is just from random chance. Generally there is a little bit of fluctuation in sample data, and we wouldn’t expect the sample proportions to be exactly equal, even if the truth was that the infection rates were independent of getting the vaccine. Additionally, with such small samples, perhaps it’s common to observe such large differences when we randomly split a group due to chance alone!

This example is a reminder that the observed outcomes in the data sample may not perfectly reflect the true relationships between variables since there is random noise. While the observed difference in rates of infection is large, the sample size for the study is small, making it unclear if this observed difference represents efficacy of the vaccine or whether it is simply due to chance. We label these two competing claims, \(H_0\) and \(H_A\):

  • \(H_0\): Independence model. The variables are independent. They have no relationship, and the observed difference between the proportion of patients who developed an infection in the two groups, 64.3%, was due to chance.

  • \(H_A\): Alternative model. The variables are not independent. The difference in infection rates of 64.3% was not due to chance. Here (because an experiment was done), if the difference in infection rate is not due to chance, it was the vaccine that affected the rate of infection.

What would it mean if the independence model, which says the vaccine had no influence on the rate of infection, is true? It would mean 11 patients were going to develop an infection no matter which group they were randomized into, and 9 patients would not develop an infection no matter which group they were randomized into. That is, if the vaccine did not affect the rate of infection, the difference in the infection rates was due to chance alone in how the patients were randomized.

Now consider the alternative model: infection rates were influenced by whether a patient received the vaccine or not. If this was true, and especially if this influence was substantial, we would expect to see some difference in the infection rates of patients in the groups.

We choose between these two competing claims by assessing if the data conflict so much with \(H_0\) that the independence model cannot be deemed reasonable. If this is the case, and the data support \(H_A,\) then we will reject the notion of independence and conclude the vaccine was effective.

15.2.2 Simulating the study

We’re going to implement simulation under the setting where we will pretend we know that the malaria vaccine being tested does not work. Ultimately, we want to understand if the large difference we observed in the data is common in these simulations that represent independence. If it is common, then maybe the difference we observed was purely due to chance. If it is very uncommon, then the possibility that the vaccine was helpful seems more plausible.

Table 15.2 shows that 11 patients developed infections and 9 did not. For our simulation, we will suppose the infections were independent of the vaccine and we were able to rewind back to when the researchers randomized the patients in the study. If we happened to randomize the patients differently, we may get a different result in this hypothetical world where the vaccine does not influence the infection. Let’s complete another randomization using a simulation.

In this simulation, we take 20 notecards to represent the 20 patients, where we write down “infection” on 11 cards and “no infection” on 9 cards. In this hypothetical world, we believe each patient that got an infection was going to get it regardless of which group they were in, so let’s see what happens if we randomly assign the patients to the treatment and control groups again. We thoroughly shuffle the notecards and deal 14 into a pile and 6 into a pile. Finally, we tabulate the results, which are shown in Table 15.3.

Table 15.3: Simulation results, where any difference in infection ratio is purely due to chance.
treatment placebo vaccine Total
infection 4 7 11
no infection 2 7 9
Total 6 14 20

How does this compare to the observed 64.3% difference in the actual data?2

15.2.3 Independence between treatment and outcome

We computed one possible difference under the independence model in the previous Guided Practice, which represents one difference due to chance, assuming there is no vaccine effect. While in this first simulation, we physically dealt out notecards to represent the patients, it is more efficient to perform the simulation using a computer.

Repeating the simulation on a computer, we get another difference due to chance: \[ \frac{2}{6{}} - \frac{9}{14} = -0.310 \]

And another: \[ \frac{3}{6{}} - \frac{8}{14} = -0.071\]

And so on until we repeat the simulation enough times to create a distribution of differences that could have occurred if the null hypothesis was true.

Figure 15.1 shows a stacked plot of the differences found from 100 simulations, where each dot represents a simulated difference between the infection rates (control rate minus treatment rate).

A stacked dot plot of differences from 100 simulations produced under the independence mode, $H_0,$ where in these simulations infections are unaffected by the vaccine. Two of the 100 simulations had a difference of at least 64.3%, the difference observed in the study.
Figure 15.1: A stacked dot plot of differences from 100 simulations produced under the independence mode, \(H_0,\) where in these simulations infections are unaffected by the vaccine. Two of the 100 simulations had a difference of at least 64.3%, the difference observed in the study.

Note that the distribution of these simulated differences is centered around 0. We simulated these differences assuming that the independence model was true, and under this condition, we expect the difference to be near zero with some random fluctuation, where near is pretty generous in this case since the sample sizes are so small in this study.

How often would you observe a difference of at least 64.3% (0.643) according to Figure 15.1? Often, sometimes, rarely, or never?


It appears that a difference of at least 64.3% due to chance alone would only happen about 2% of the time according to Figure 15.1. Such a low probability indicates a rare event.

The difference of 64.3% being a rare event suggests two possible interpretations of the results of the study:

  • \(H_0\): Independence model. The vaccine has no effect on infection rate, and we just happened to observe a difference that would only occur on a rare occasion.

  • \(H_A\): Alternative model. The vaccine has an effect on infection rate, and the difference we observed was actually due to the vaccine being effective at combating malaria, which explains the large difference of 64.3%.

Based on the simulations, we have two options. (1) We conclude that the study results do not provide strong evidence against the independence model. That is, we do not have sufficiently strong evidence to conclude the vaccine had an effect in this clinical setting. (2) We conclude the evidence is sufficiently strong to reject \(H_0\) and assert that the vaccine was useful. When we conduct formal studies, usually we reject the notion that we just happened to observe a rare event. So in the vaccine case, we reject the independence model in favor of the alternative. That is, we are concluding the data provide strong evidence that the vaccine provides some protection against malaria in this clinical setting.

One field of statistics, statistical inference, is built on evaluating whether such differences are due to chance. In statistical inference, data scientists evaluate which model is most reasonable given the data. Errors do occur, just like rare events, and we might choose the wrong model. While we do not always choose correctly, statistical inference gives us tools to control and evaluate how often decision errors occur.

15.3 Interactive R tutorials

Navigate the concepts you’ve learned in this part in R using the following self-paced tutorials. All you need is your browser to get started!

You can also access the full list of tutorials supporting this book here.

15.4 R labs

Further apply the concepts you’ve learned in this part in R with computational labs that walk you through a data analysis case study.

You can also access the full list of labs supporting this book here.


  1. The study is an experiment, as patients were randomly assigned an experiment group. Since this is an experiment, the results can be used to evaluate a causal relationship between the malaria vaccine and whether patients showed signs of an infection.↩︎

  2. \(4 / 6 - 7 / 14 = 0.167\) or about 16.7% in favor of the vaccine. This difference due to chance is much smaller than the difference observed in the actual groups.↩︎

中文

15  应用:基础

15.1 回顾:基础知识

在统计推断基础的章节中,我们提供了三种不同的统计推断方法。我们将在全书继续围绕这三种方法展开,到最后,你应该能理解它们之间的相似与不同之处。同时,需要注意的是,这些方法旨在模拟数据中的变异性,而我们知道变异性可能来自不同的来源(例如,随机抽样与随机分配,参见 图 2.8)。在 表 15.1中,我们总结了推断方法体现特定变异性来源的一些方式。希望你今后在更深入学习推断相关概念时,能经常回顾该表。

表 15.1:随机化、自助法和数学模型作为推断统计方法的总结与比较。
答案
问题 随机化 自助法 数学模型
它的作用是什么? 打乱解释变量以模拟随机化实验中出现的自然变异性 从观测数据中进行有放回的重抽样,以模拟从总体中收集数据时出现的抽样变异性 利用理论(主要是中心极限定理)来描述由重复的随机化实验或随机样本所产生的假设变异性
所描述的随机过程是什么? 随机化实验 从总体中随机抽样 随机化实验或随机抽样
还可以近似哪些其他随机过程? 也可用于描述观察模型中的随机抽样 也可用于描述实验中的随机分配 也可用于描述观察模型中的随机抽样或实验中的随机分配
它最适合用于什么? 假设检验(也可用于置信区间,但本教材未涉及) 置信区间(也可用于单一比例的自助法假设检验) 快速分析,例如计算 Z 分数
什么实物可以代表这一模拟过程? 洗牌 有放回地从袋中抽取弹珠 不适用

你可能已经注意到,这个词 分布 在本部分中反复出现(并将在后续章节中继续使用)。分布总是描述变异性,但有时值得思考一下 什么 在变化。通常,分布要么描述观测值如何变化,要么描述统计量如何变化。但即使在描述统计量如何变化时,还需要考虑研究设计,例如,该统计量是随随机样本而变化,还是随随机分配而变化?本书中介绍的方法(以及科学界普遍使用的方法)通常在随机样本和随机分配处理这两种概念之间互换使用。通常,这两种不同的分析方法会给出等效的结论。最重要的是如何结合具体问题来解释结论。参见 图 2.8 以确认你的结论是否恰当。

下面,我们综合了全书讨论的不同类型的分布。通读这些不同的定义并巩固你的理解,将有助于你在后续章节中遇到这些分布时更好地理解,你也可以随时回到这里温习各种分布之间的区别。

分布。

  • 一个 数据分布 描述 观测数据.

    的形状、中心和变异性。 这也可以称为 样本分布(sample distribution), 但我们将避免使用这个短语,因为它听起来太像抽样分布(sampling distribution),而两者是不同的。

  • 一个 总体分布 描述整个数据的形状、中心和变异性。 数据总体.

    除了极少数非常小且定义非常明确的总体的特殊情况外,这种情况从未被观察到。

  • 一个 抽样分布 描述来自对观测数据进行再抽样的 样本统计量 的所有可能取值的形状、中心和变异性。

    由于总体从未被观察到,因此也不可能观察到真实的抽样分布。然而,当某些条件成立时,中心极限定理会告诉我们抽样分布是什么样的。

  • 一个 随机化分布 描述来自对观测数据进行再抽样的 样本统计量 的所有可能取值的形状、中心和变异性。

    我们通过计算生成随机化分布,但通常无法生成样本统计量所有可能取值的完整分布,因此我们改为生成大量的取值。几乎总是如此,通过随机分配处理变量,随机化分布描述了原假设,即它以参数的原假设值为中心。

  • 一个 自助抽样分布 描述来自对观测数据进行再抽样的 样本统计量 的所有可能取值的形状、中心和变异性。

    我们通过计算生成自助抽样分布,但通常无法生成观测数据的所有可能再抽样,因此我们改为生成大量的再抽样。由于自助抽样分布是通过从观测数据中随机再抽样生成的,它们以样本统计量为中心。自助抽样分布最常用于估计,即我们基于它们构建置信区间。

15.2 案例研究:疟疾疫苗

在本案例研究中,我们考虑一种名为 PfSPZ 的新型疟疾疫苗。在这项疟疾研究中,志愿患者被随机分配到两个实验组之一:14 名患者接种了实验性疫苗,6 名患者接种了安慰剂疫苗。十九周后,所有 20 名患者都暴露于一种对药物敏感的疟疾寄生虫株;这里使用对药物敏感的寄生虫株是出于伦理考虑,以便任何感染都能得到有效治疗。

malaria 数据可以在 openintro R 包中找到。

结果总结在 表 15.2中,14 名接受疫苗的患者中有 9 名未出现感染迹象,而对照组的 6 名患者全部显示出一些基线感染迹象。

表 15.2:疟疾疫苗实验的结果汇总。
治疗 感染 未感染 总计
安慰剂 6 0 6
疫苗 5 9 14
总计 11 9 20

这是一项观察性研究还是实验?研究类型对从结果中能推断出什么有何影响?1

15.2.1 数据内部的变异性

在这项研究中,接种疫苗的患者中出现感染迹象的比例较小(35.7% 对 100%)。然而,样本非常小,尚不清楚这一差异是否提供了 令人信服的证据 证明该疫苗有效。

统计学家和数据科学家有时会被要求评估证据的强度。当我们观察本研究中两组患者的感染率时,在试图确定数据是否显示出真实差异的令人信服的证据时,我们会想到什么?


观察到的感染率(治疗组为 35.7%,对照组为 100%)表明疫苗可能是有效的。然而,我们无法确定观察到的差异是否代表疫苗的效力,还是不存在治疗效果,观察到的差异只是随机偶然造成的。一般来说,样本数据会有一些波动,我们不会期望样本比例 恰好 相等,即使事实是感染率与是否接种疫苗无关。此外,在如此小的样本下,当我们仅凭随机机会将一组人随机分组时,观察到如此大的差异也许很常见!

这个例子提醒我们,数据样本中观察到的结果可能无法完美反映变量之间的真实关系,因为存在 随机噪声。虽然观察到的感染率差异很大,但该研究的样本量很小,因此尚不清楚这一观察到的差异究竟代表疫苗的有效性,还是仅仅由偶然因素造成。我们将这两种相互竞争的说法分别标记为: \(H_0\)\(H_A\):

  • \(H_0\): 独立性模型。 变量是相互独立的。它们之间没有关系,两组中发生感染的患者比例之间观察到的 64.3% 的差异是由偶然因素造成的。

  • \(H_A\): 备择模型。 变量 独立。64.3% 的感染率差异并非由偶然因素造成。这里(因为进行了实验),如果感染率的差异不是由偶然因素造成的,那就是疫苗影响了感染率。

如果独立性模型——即疫苗对感染率没有影响——是正确的,那意味着什么?那意味着有 11 名患者 无论被随机分到哪一组都会发生感染,而有 9 名患者 无论被随机分到哪一组都不会发生感染。也就是说,如果疫苗没有影响感染率,那么感染率之间的差异仅仅是由于患者随机分组时的偶然因素造成的。

现在考虑备择模型:感染率受到患者是否接种疫苗的影响。如果这是真的,尤其是当这种影响相当显著时,我们预期会看到两组患者的感染率存在一些差异。

我们通过评估数据是否与其中一种说法存在严重冲突来在这两种相互竞争的说法之间做出选择。 \(H_0\) 独立性模型不能被认为是合理的。如果是这种情况,且数据支持 \(H_A,\) 那么我们将拒绝独立性的概念,并得出疫苗有效的结论。

15.2.2 模拟该研究

我们将实施 模拟 ,设定为我们假装已知正在测试的疟疾疫苗确实 有效。最终,我们想了解在数据中观察到的大差异在这些代表独立性的模拟中是否常见。如果常见,那么我们观察到的差异可能纯粹是偶然造成的。如果非常罕见,那么疫苗有帮助的可能性就显得更为合理。

表 15.2 显示有11名患者发生了感染,9名未感染。在我们的模拟中,我们假设感染与疫苗无关,并且我们能够 倒回 到研究人员对研究中的患者进行随机分组的时候。如果我们碰巧以不同的方式对患者进行随机分组,在这个疫苗不影响感染的假设世界中,我们可能会得到不同的结果。让我们通过模拟再进行一次 随机化

在这个 模拟中,我们取20张卡片来代表20名患者,在11张卡片上写下“感染”,在9张卡片上写下“未感染”。在这个假设世界中,我们认为每位感染的患者无论属于哪个组都会感染,所以让我们看看如果再次将患者随机分配到治疗组和对照组会发生什么。我们彻底洗牌这些卡片,将14张分成一堆,6张分成一堆。最后,我们统计结果,结果如 表 15.3.

表 15.3:模拟结果,其中感染比例的任何差异纯粹是偶然造成的。
治疗 安慰剂 疫苗 总计
感染 4 7 11
未感染 2 7 9
总计 6 14 20

这与实际数据中观察到的64.3%的差异相比如何?2

15.2.3 处理与结果之间的独立性

在之前的引导练习中,我们计算了独立性模型下一种可能的差异,它代表在假设疫苗无效的情况下由偶然造成的一种差异。虽然在第一次模拟中,我们是用实体卡片来代表患者的,但使用计算机进行模拟会更高效。

在计算机上重复模拟,我们得到另一个由偶然造成的差异: \[ \frac{2}{6{}} - \frac{9}{14} = -0.310 \]

再来一次: \[ \frac{3}{6{}} - \frac{8}{14} = -0.071\]

如此继续,直到我们重复模拟足够多的次数,以创建一个 如果零假设为真时可能出现的差异分布.

图 15.1 展示了100次模拟所得差异的堆叠点图,其中每个点代表一次模拟的感染率差异(对照组感染率减去处理组感染率)。

A stacked dot plot of differences from 100 simulations produced under the independence mode, $H_0,$ where in these simulations infections are unaffected by the vaccine. Two of the 100 simulations had a difference of at least 64.3%, the difference observed in the study.
图15.1:在独立性模型下由100次模拟产生的差异的堆叠点图, \(H_0,\) 在这些模拟中,感染不受疫苗影响。100次模拟中有2次的差异至少为64.3%,即研究中观察到的差异。

请注意,这些模拟差异的分布以0为中心。我们在假设独立性模型为真的条件下模拟了这些差异,在这种条件下,我们预期差异接近零并带有一些随机波动,其中 接近 在这里是一个相当宽松的说法,因为该研究的样本量非常小。

根据 图 15.1,你观察到至少 64.3%(0.643)差异的频率是多少?是经常、有时、很少,还是从不?


看起来,仅由偶然产生至少 64.3% 的差异,根据 图 15.1,大约只有 2% 的时间会发生。如此低的概率表明这是一个罕见事件。

64.3% 的差异是一个罕见事件,这提示对研究结果有两种可能的解释:

  • \(H_0\): 独立性模型。 疫苗对感染率没有影响,我们只是碰巧观察到了一个只在罕见情况下才会出现的差异。

  • \(H_A\): 备择模型。 疫苗对感染率有影响,我们观察到的差异实际上是由于疫苗在抗击疟疾方面有效,这解释了 64.3% 的巨大差异。

基于模拟,我们有两个选择。(1)我们得出结论:研究结果没有提供反对独立性模型的有力证据。也就是说,我们没有足够有力的证据得出疫苗在该临床环境中有效的结论。(2)我们得出结论:证据足够有力,可以拒绝 \(H_0\) ,并断言疫苗是有用的。当我们进行正式研究时,通常会拒绝“我们只是碰巧观察到了一个罕见事件”这一说法。因此在疫苗的例子中,我们拒绝独立性模型而支持备择模型。也就是说,我们得出的结论是:数据提供了有力证据,表明疫苗在该临床环境中对疟疾有一定的保护作用。

统计学的一个领域——统计推断,就是建立在评估这类差异是否由偶然造成的之上的。在统计推断中,数据科学家根据数据评估哪个模型最合理。错误确实会发生,就像罕见事件一样,我们可能会选择错误的模型。虽然我们并不总是能做出正确的选择,但统计推断为我们提供了控制和评估决策错误发生频率的工具。

15.3 交互式 R 教程

使用以下自学教程在 R 中探索你在本部分所学的概念。你只需要一个浏览器即可开始!

您还可以访问支持本书的完整教程列表 这里.

15.4 R 实验课

通过引导您逐步完成数据分析案例研究的计算实验,在 R 中进一步应用您在本部分学到的概念。

您还可以访问支持本书的完整实验列表 这里.


  1. 该研究是一项实验,因为患者被随机分配到实验组。由于这是一项实验,其结果可用于评估疟疾疫苗与患者是否出现感染迹象之间的因果关系。↩︎

  2. \(4 / 6 - 7 / 14 = 0.167\) 即约 16.7% 支持疫苗。这种由偶然造成的差异远小于在实际组中观察到的差异。↩︎