Chapter page 28 / 3820 Inference for comparing two independent means
English

20  Inference for comparing two independent means

We now extend the methods from Chapter 19 to apply confidence intervals and hypothesis tests to differences in population means that come from two groups, Group 1 and Group 2: \(\mu_1 - \mu_2.\)

In our investigations, we’ll identify a reasonable point estimate of \(\mu_1 - \mu_2\) based on the sample, and you may have already guessed its form: \(\bar{x}_1 - \bar{x}_2.\) Then we’ll look at the inferential analysis in three different ways: using a randomization test, applying bootstrapping for interval estimates, and, if we verify that the point estimate can be modeled using a normal distribution, we compute the estimate’s standard error and apply the mathematical framework.

In this section we consider a difference in two population means, \(\mu_1 - \mu_2,\) under the condition that the data are not paired. Just as with a single sample, we identify conditions to ensure we can use the \(t\)-distribution with a point estimate of the difference, \(\bar{x}_1 - \bar{x}_2,\) and a new standard error formula.

The details for working through inferential problems in the two independent means setting are strikingly similar to those applied to the two independent proportions setting. We first cover a randomization test where the observations are shuffled under the assumption that the null hypothesis is true. Then we bootstrap the data (with no imposed null hypothesis) to create a confidence interval for the true difference in population means, \(\mu_1 - \mu_2.\) The mathematical model, here the \(t\)-distribution, is able to describe both the randomization test and the bootstrapping as long as the conditions are met.

The inferential tools are applied to three different data contexts: determining whether stem cells can improve heart function, exploring the relationship between pregnant women’s smoking habits and birth weights of newborns, and exploring whether there is convincing evidence that one variation of an exam is harder than another variation. This section is motivated by questions like “Is there convincing evidence that newborns from mothers who smoke have a different average birth weight than newborns from mothers who do not smoke?”

20.1 Randomization test for the difference in means

An instructor decided to run two slight variations of the same exam. Prior to passing out the exams, they shuffled the exams together to ensure each student received a random version. Anticipating complaints from students who took Version B, they would like to evaluate whether the difference observed in the groups is so large that it provides convincing evidence that Version B was more difficult (on average) than Version A.

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

20.1.1 Observed data

Summary statistics for how students performed on these two exams are shown in Table 20.1 and plotted in Figure 20.1.

Table 20.1: Summary statistics of scores for each exam version.
Group n Mean SD Min Max
A 58 75.1 13.9 44 100
B 55 72.0 13.8 38 100
Box plot of exam score broken down by version of exam.
Figure 20.1: Exam scores for students given one of two different exams.

Construct hypotheses to evaluate whether the observed difference in sample means, \(\bar{x}_A - \bar{x}_B=3.1,\) is likely to have happened due to chance, if the null hypothesis is true. We will later evaluate these hypotheses using \(\alpha = 0.01.\)1

Before moving on to evaluate the hypotheses in the previous Guided Practice, let’s think carefully about the dataset. Are the observations across the two groups independent? Are there any concerns about outliers?2

20.1.2 Variability of the statistic

In Chapter 11, the variability of the statistic (previously: \(\hat{p}_1 - \hat{p}_2)\) was visualized after shuffling the observations across the two treatment groups many times. The shuffling process implements the null hypothesis model (that there is no effect of the treatment). In the exam example, the null hypothesis is that exam A and exam B are equally difficult, so the average scores across the two tests should be the same. If the exams were equally difficult, due to natural variability, we would sometimes expect students to do slightly better on exam A \((\bar{x}_A > \bar{x}_B)\) and sometimes expect students to do slightly better on exam B \((\bar{x}_B > \bar{x}_A).\) The question at hand is: does \(\bar{x}_A - \bar{x}_B=3.1\) indicate that exam A is easier than exam B.

Figure 20.2 shows the process of randomizing the exam to the observed exam scores. If the null hypothesis is true, then the score on each exam should represent the true student ability on that material. It shouldn’t matter whether they were given exam A or exam B. By reallocating which student got which exam, we are able to understand how the difference in average exam scores changes due only to natural variability. There is only one iteration of the randomization process in Figure 20.2, leading to one simulated difference in average scores.

Four panels representing four different orientations of a toy dataset of 9 exam scores. The first panel provides the observed data; 4 of the exams were version A and the average score was 77.25; 5 of the exams were version B and the average score was 75.8, a difference of 1.45. The second panel shows the shuffled reassignment of the exam versions (4 of the scores are randomly reassigned to A, 5 of the scores are randomly reassigned to B). The third panel shows which score is connected with which new reassigned version of the exam. And the fourth panel sorts the exams so that version A exams are together and version B exams are together. In the randomly reassigned versions, the average score for version A is 74.25 and the average score for version B is 78.2, a difference of -3.95.
Figure 20.2: The version of the test (A or B) is randomly allocated to the test scores, under the null assumption that the tests are equally difficult.

Building on Figure 20.2, Figure 20.3 shows the values of the simulated statistics \(\bar{x}_{1, sim} - \bar{x}_{2, sim}\) over 1,000 random simulations. We see that, just by chance, the difference in scores can range anywhere from -10 points to +10 points.

Histogram of differences in means, calculated from 1,000 different randomizations of the exam types.
Figure 20.3: Histogram of differences in means, calculated from 1,000 different randomizations of the exam types.

20.1.3 Observed statistic vs. null statistics

The goal of the randomization test is to assess the observed data, here the statistic of interest is \(\bar{x}_A - \bar{x}_B=3.1.\) The randomization distribution allows us to identify whether a difference of 3.1 points is more than one would expect by natural variability of the scores if the two tests were equally difficult. By plotting the value of 3.1 on Figure 20.4, we can measure how different or similar 3.1 is to the randomized differences which were generated under the null hypothesis.

Histogram of differences in means, calculated from 1,000 different randomizations of the exam types. The observed difference of 3.1 points is plotted as a vertical line, and the area more extreme than 3.1 is shaded to represent the p-value.
Figure 20.4: Histogram of differences in means, calculated from 1,000 different randomizations of the exam types. The observed difference of 3.1 points is plotted as a vertical line, and the area more extreme than 3.1 is shaded to represent the p-value.

Approximate the p-value depicted in Figure 20.4, and provide a conclusion in the context of the case study.


Using software, we can find the number of shuffled differences in means that are less than the observed difference (of 3.14) is 900 (out of 1,000 randomizations). So 10% of the simulations are larger than the observed difference. To get the p-value, we double the proportion of randomized differences which are larger than the observed difference, p-value = 0.2.

Previously, we specified that we would use \(\alpha = 0.01.\) Since the p-value is larger than \(\alpha,\) we do not reject the null hypothesis. That is, the data do not convincingly show that one exam version is more difficult than the other, and the teacher should not be convinced that they should add points to the Version B exam scores.

The large p-value and consistency of \(\bar{x}_A - \bar{x}_B=3.1\) with the randomized differences leads us to not reject the null hypothesis. Said differently, there is no evidence to think that one of the tests is easier than the other. One might be inclined to conclude that the tests have the same level of difficulty, but that conclusion would be wrong. The hypothesis testing framework is set up only to reject a null claim, it is not set up to validate a null claim. As we concluded, the data are consistent with exams A and B being equally difficult, but the data are also consistent with exam A being 3.1 points “easier” than exam B. The data are not able to adjudicate on whether the exams are equally hard or whether one of them is slightly easier. Indeed, conclusions where the null hypothesis is not rejected often seem unsatisfactory. However, in this case, the teacher and class are probably all relieved that there is no evidence to demonstrate that one of the exams is more difficult than the other.

20.2 Bootstrap confidence interval for the difference in means

Before providing a full example working through a bootstrap analysis on actual data, we return to the fictional Awesome Auto example as a way to visualize the two sample bootstrap setting. Consider an expanded scenario where the research question centers on comparing the average price of a car at one Awesome Auto franchise (Group 1) to the average price of a car at a different Awesome Auto franchise (Group 2). The process of bootstrapping can be applied to each Group separately, and the differences of means recalculated each time. Figure 20.5 visually describes the bootstrap process when interest is in a statistic computed on two separate samples. The analysis proceeds as in the one sample case, but now the (single) statistic of interest is the difference in sample means. That is, a bootstrap resample is done on each of the groups separately, but the results are combined to have a single bootstrapped difference in means. Repetition will produce \(k\) bootstrapped differences in means, and the histogram will describe the natural sampling variability associated with the difference in means.

Samples are shown as separately coming from two independent, large, unknown populations. Directly from each of the two observed samples, bootstrap resamples can be taken (with replacement). Bootstrap resample 1 from sample 1 is compared to bootstrap resample 1 from sample 2 by comparing the difference in bootstrapped averages. A histogram of differences in bootstrapped averages displays the differences ranging from roughly -20000 dollars to +10000 dollars.
Figure 20.5: For the two group comparison, the bootstrap resampling is done separately on each group, but the statistic is calculated as a difference. The set of k differences is then analyzed as the statistic of interest with conclusions drawn on the parameter of interest.

In the following sections, we leave the fictional setting of Awesome Auto and apply the bootstrap method to actual datasets investigating whether embryonic stem cells help improve heart function and later to investigate characteristics of births. Note that the fictional setting allowed us to visualize the bootstrap method because we had samples of size five. The visualization was important in understanding how the bootstrap method works. However, the bootstrap relies heavily on the sample being an outstanding proxy for the population, and five observations are almost never enough to truly represent the nuances of a full population. To that end, we apply bootstrap methods with much larger sample sizes, as seen in the 1000 random samples provided in the births data.

20.2.1 Observed data

Does treatment using embryonic stem cells (ESCs) help improve heart function following a heart attack? Table 20.2 contains summary statistics for an experiment to test ESCs in sheep that had a heart attack. Each of these sheep was randomly assigned to the ESC or control group, and the change in their hearts’ pumping capacity was measured in the study. (Ménard et al. 2005) Figure 20.8 provides histograms of the two datasets. A positive value corresponds to increased pumping capacity, which generally suggests a stronger recovery. Our goal will be to identify a 95% confidence interval for the effect of ESCs on the change in heart pumping capacity relative to the control group.

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

Table 20.2: Summary statistics of the embryonic stem cell study.
Group n Mean SD
ESC 9 3.50 5.17
Control 9 -4.33 2.76

The point estimate of the difference in the heart pumping variable is straightforward to find: it is the difference in the sample means.

\[\bar{x}_{esc} - \bar{x}_{control}\ =\ 3.50 - (-4.33)\ =\ 7.83\]

20.2.2 Variability of the statistic

As we saw in Section 17.2, we will use bootstrapping to estimate the variability associated with the difference in sample means when taking repeated samples. In a method akin to two proportions, a separate sample is taken with replacement from each group (here ESCs and control), the sample means are calculated, and their difference is taken. The entire process is repeated multiple times to produce a bootstrap distribution of the difference in sample means (without the null hypothesis assumption).

Figure 20.6 displays the variability of the differences in means with the 90% percentile and SE confidence intevals super imposed.

Histogram of differences in means after 1,000 bootstrap samples from each of the two groups. The observed difference is plotted as a black vertical line at 7.83. The blue dashed and red dotted lines provide the bootstrap percentile and boostrap SE confidence intervals, respectively, for the difference in true population means.
Figure 20.6: Histogram of differences in means after 1,000 bootstrap samples from each of the two groups. The observed difference is plotted as a black vertical line at 7.83. The blue dashed and red dotted lines provide the bootstrap percentile and bootstrap SE confidence intervals, respectively, for the difference in true population means.

Using the histogram of bootstrapped difference in means, estimate the standard error of the differences in sample means, \(\bar{x}_{ESC} - \bar{x}_{Control}.\)3

Choose one of the bootstrap confidence intervals for the true difference in average pumping capacity, \(\mu_{ESC} - \mu_{Control}.\) Does the interval show that there is a difference across the two treatments?


Because neither of the 90% intervals (either percentile or SE) above overlap zero (note that zero is never one of the bootstrapped differences so 95% and 99% intervals would have given the same conclusion!), we conclude that the ESC treatment is substantially better with respect to heart pumping capacity than the control.

Because the study is a randomized controlled experiment, we can conclude that it is the treatment (ESC) which is causing the change in pumping capacity.

20.3 Mathematical model for testing the difference in means

Every year, the US releases to the public a large dataset containing information on births recorded in the country. This dataset has been of interest to medical researchers who are studying the relation between habits and practices of expectant mothers and the birth of their children. We will work with a random sample of 1,000 cases from the dataset released in 2014.

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

20.3.1 Observed data

Four cases from this dataset are represented in Table 20.3. We are particularly interested in two variables: weight and smoke. The weight variable represents the weights of the newborns and the smoke variable describes which mothers smoked during pregnancy.

Table 20.3: Four cases from the births14 dataset. The empty cells indicate missing data.
fage mage weeks visits gained weight sex habit
34 34 37 14 28 6.96 male nonsmoker
36 31 41 12 41 8.86 female nonsmoker
37 36 37 10 28 7.51 female nonsmoker
16 38 29 6.19 male nonsmoker

We would like to know, is there convincing evidence that newborns from mothers who smoke have a different average birth weight than newborns from mothers who do not smoke? We will use data from this sample to try to answer this question.

Set up appropriate hypotheses to evaluate whether there is a relationship between a mother smoking and average birth weight.


The null hypothesis represents the case of no difference between the groups.

  • \(H_0:\) There is no difference in average birth weight for newborns from mothers who did and did not smoke. In statistical notation: \(\mu_{n} - \mu_{s} = 0,\) where \(\mu_{n}\) represents non-smoking mothers and \(\mu_s\) represents mothers who smoked.
  • \(H_A:\) There is some difference in average newborn weights from mothers who did and did not smoke \((\mu_{n} - \mu_{s} \neq 0).\)

Table 20.4 displays sample statistics from the data. We can see that the average birth weight of babies born to smoker moms is lower than those born to nonsmoker moms.

Table 20.4: Summary statistics for the births14 dataset.
Habit n Mean SD
nonsmoker 867 7.27 1.23
smoker 114 6.68 1.60

20.3.2 Variability of the statistic

We check the two conditions necessary to model the difference in sample means using the \(t\)-distribution.

  • Because the data come from a simple random sample, the observations are independent, both within and between samples.
  • With both groups over 30 observations, we inspect the data in Figure 20.7 for any particularly extreme outliers and find none.

Since both conditions are satisfied, the difference in sample means may be modeled using a \(t\)-distribution.

The left panel represents birth weights for infants whose mothers smoked during pregnancy. The right panel represents the birth weights for infants whose mothers who did not smoke during pregnancy.
Figure 20.7: The left panel represents birth weights for infants whose mothers smoked during pregnancy. The right panel represents the birth weights for infants whose mothers who did not smoke during pregnancy.

The summary statistics in Table 20.4 may be useful for this Guided Practice. What is the point estimate of the population difference, \(\mu_{n} - \mu_{s}\)?4

20.3.3 Observed statistic vs. null statistics

The test statistic for comparing two means is a T.

The T score is a ratio of how the groups differ as compared to how the observations within a group vary.

\[T = \frac{(\bar{x}_1 - \bar{x}_2) - 0}{\sqrt{s_1^2/n_1 + s_2^2/n_2}}\]

When the null hypothesis is true and the conditions are met, T has a t-distribution with \(df = min(n_1 - 1, n_2 -1).\)

Conditions:

  • Independent observations within and between groups.
  • Large samples and no extreme outliers.

Compute the standard error of the point estimate for the average difference between the weights of babies born to nonsmoker and smoker mothers.5

Complete the hypothesis test started in the previous Example and Guided Practice on births14 dataset and research question. Use a discernibility level of \(\alpha=0.05.\) For reference, \(\bar{x}_{n} - \bar{x}_{s} = 0.59,\) \(SE = 0.16,\) and the sample sizes were \(n_n = 867\) and \(n_s = 114.\)


We can find the test statistic for this test using the previous information:

\[T = \frac{\ 0.59 - 0\ }{0.16} = 3.69\]

We find the single tail area using software. We’ll use the smaller of \(n_n - 1 = 866\) and \(n_s - 1 = 113\) as the degrees of freedom: \(df = 113.\) The one tail area is roughly 0.00017; doubling this value gives the two-tail area and p-value, 0.00034.

The p-value is smaller than the discernibility level, 0.05, so we reject the null hypothesis. The data provide statistically discernible evidence of a difference in the average weights of babies born to mothers who smoked during pregnancy and those who did not.

This result is likely not surprising. We all know that smoking is bad for you and you’ve probably also heard that smoking during pregnancy is not just bad for the mother but also for the baby as well. In fact, some in the tobacco industry actually had the audacity to tout that as a benefit of smoking:

It’s true. The babies born from women who smoke are smaller, but they’re just as healthy as the babies born from women who do not smoke. And some women would prefer having smaller babies. - Joseph Cullman, Philip Morris’ Chairman of the Board on CBS’ Face the Nation, Jan 3, 1971

Furthermore, health differences between babies born to mothers who smoke and those who do not are not limited to weight differences.6

A small note on the power of the independent t-test (recall the discussion of power in Section 14.4). It turns out that the independent t-test given here is often less powerful than the paired t-test discussed in Section 21.3. That said, depending on how the data are collected, we don’t always have a mechanism for pairing the data and reducing the inherent variability across observations.

20.4 Mathematical model for estimating the difference in means

20.4.1 Observed data

As with hypothesis testing, for the question of whether we can model the difference using a \(t\)-distribution, we’ll need to check new conditions. Like the 2-proportion cases, we will require a more robust version of independence so we are confident the two groups are also independent. Secondly, we also check for normality in each group separately, which in practice is a check for outliers.

Using the \(t\)-distribution for a difference in means.

The \(t\)-distribution can be used for inference when working with the standardized difference of two means if

  • Independence (extended). The data are independent within and between the two groups, e.g., the data come from independent random samples or from a randomized experiment.
  • Normality. We check the outliers for each group separately.

The standard error may be computed as

\[SE = \sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}\]

The official formula for the degrees of freedom is quite complex and is generally computed using software, so instead you may use the smaller of \(n_1 - 1\) and \(n_2 - 1\) for the degrees of freedom if software isn’t readily available.

Recall that the margin of error is defined by the standard error. The margin of error for \(\bar{x}_1 - \bar{x}_2\) can be directly obtained from \(SE(\bar{x}_1 - \bar{x}_2).\)

Margin of error for \(\bar{x}_1 - \bar{x}_2.\)

The margin of error is \(t^\star_{df} \times \sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}\) where \(t^\star_{df}\) is calculated from a specified percentile on the t-distribution with df degrees of freedom.

20.4.2 Variability of the statistic

Can the \(t\)-distribution be used to make inference using the point estimate, \(\bar{x}_{esc} - \bar{x}_{control} = 7.83\)?


First, we check for independence. Because the sheep were randomized into the groups, independence within and between groups is satisfied.

Figure 20.8 does not reveal any clear outliers in either group. (The ESC group does look a bit more variable, but this is not the same as having clear outliers.)

With both conditions met, we can use the \(t\)-distribution to model the difference of sample means.

Histograms for the difference in heart pumping function after a heart attack for both the treatment group (ESC, which received the embryonic stem cell treatment) and the control group (which did not receive the treatment).
Figure 20.8: Histograms for the difference in heart pumping function after a heart attack for both the treatment group (ESC, which received the embryonic stem cell treatment) and the control group (which did not receive the treatment).

Generally, we use statistical software to find the appropriate degrees of freedom, or if software isn’t available, we can use the smaller of \(n_1 - 1\) and \(n_2 - 1\) for the degrees of freedom, e.g., if using a \(t\)-table to find tail areas. For transparency in the Examples and Guided Practice, we’ll use the latter approach for finding \(df\); in the case of the ESC example, this means we’ll use \(df = 8.\)

Calculate a 95% confidence interval for the effect of ESCs on the change in heart pumping capacity of sheep after they’ve suffered a heart attack.


We will use the sample difference and the standard error that we computed earlier:

\[ \begin{aligned} \bar{x}_{esc} - \bar{x}_{control} &= 7.83 \\ SE &= \sqrt{\frac{5.17^2}{9} + \frac{2.76^2}{9}} = 1.95 \end{aligned} \]

Using \(df = 8,\) we can identify the critical value of \(t^{\star}_{8} = 2.31\) for a 95% confidence interval. Finally, we can enter the values into the confidence interval formula:

\[ \begin{aligned} \text{point estimate} \ &\pm\ t^{\star} \times SE \\ 7.83 \ &\pm\ 2.31\times 1.95 \\ (3.32 \ &, \ 12.34) \end{aligned} \]

We are 95% confident that the heart pumping function in sheep that received embryonic stem cells is between 3.32% and 12.34% higher than for sheep that did not receive the stem cell treatment.

20.5 Chapter review

20.5.1 Summary

In this chapter we extended the single mean inferential methods to questions of differences in means. You may have seen parallels from the chapters that extended a single proportion (Chapter 16) to differences in proportions (Chapter 17). When considering differences in sample means (indeed, when considering many quantitative statistics), we use the t-distribution to describe the sampling distribution of the T score (the standardized difference in sample means). Ideas of confidence level and type of error which might occur from a hypothesis test conclusion are similar to those seen in other chapters (see Chapter 14).

20.5.2 Terms

The terms introduced in this chapter are presented in Table 20.5. If you’re not sure what some of these terms mean, we recommend you go back in the text and review their definitions. You should be able to easily spot them as bolded text.

Table 20.5: Terms introduced in this chapter.
difference in means SE difference in means t-CI
point estimate T score t-test

20.6 Exercises

Answers to odd-numbered exercises can be found in Appendix A.20.

  1. Experimental baker. A baker working on perfecting their bagel recipe is experimenting with active dry (AD) and instant (I) yeast. They bake a dozen bagels with each type of yeast and score each bagel on a scale of 1 to 10 on how well the bagels rise. They come up with the following set of hypotheses for evaluating whether there is a difference in the average rise of bagels baked with active dry and instant yeast. What is wrong with the hypotheses as stated?

    \[H_0: \bar{x}_{AD} \leq \bar{x}_{I} \quad \quad H_A: \bar{x}_{AD} > \bar{x}_{I}\]

  1. Fill in the blanks. We use a ___ to evaluate if data provide convincing evidence of a difference between two population means and we use a ___ to estimate this difference.
  1. Diamonds, randomization test. The prices of diamonds go up as the carat weight increases, but the increase is not smooth. For example, the difference between the size of a 0.99 carat diamond and a 1 carat diamond is undetectable to the naked human eye, but the price of a 1 carat diamond tends to be much higher than the price of a 0.99 carat diamond. We have two random samples of diamonds: 23 0.99 carat diamonds and 23 1 carat diamonds. In order to be able to compare equivalent units, we first divide the price for each diamond by 100 times its weight in carats. That is, for a 0.99 carat diamond, we divide the price by 99 and for a 1 carat diamond, we divide it by 100. Then, we randomize the carat weight to the price values in order simulate the null distribution of differences in average prices of 0.99 carat and 1 carat diamonds. The null distribution (with 1,000 randomized differences) is shown below and depicts the distribution of differences in sample means (of price per carat) if there really was no difference in the population from which these diamonds came.7 (Wickham 2016)

    Using the randomization distribution, conduct a hypothesis test to evaluate if there is a difference between the prices per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat. Make sure to state your hypotheses clearly and interpret your results in context of the data. (Wickham 2016)

  1. Lizards running, randomization test. In order to assess physiological characteristics of common lizards, data on top speeds (in m/sec) measured on a laboratory race track for two species of lizards: Western fence lizard (Sceloporus occidentalis) and Sagebrush lizard (Sceloporus graciosus). The original observed difference in lizard speeds is \(\bar{x}_{Western fence} - \bar{x}_{Sagebrush} = 0.7 \mbox{m/sec}.\) The histogram below shows the distribution of average differences when speed has been randomly allocated across lizard species 1,000 times. Using the randomization distribution, conduct a hypothesis test to evaluate if there is a difference between the average speed of the Western fence lizard as compared to the Sagebrush lizard. Make sure to state your hypotheses clearly and interpret your results in context of the data.8 (Adolph 1987)

  1. Diamonds, bootstrap interval. We have data on two random samples of diamonds: 23 0.99 carat diamonds and 23 1 carat diamonds. Provided below is a histogram of bootstrap differences in means of price per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat. (Wickham 2016)

    1. Using the bootstrap distribution, create a (rough) 95% bootstrap percentile confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat.

    2. Using the bootstrap distribution, create a (rough) 95% bootstrap SE confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat. Note that the standard error of the bootstrap distribution is 4.64.

  1. Lizards running, bootstrap interval. We have data on top speeds (in m/sec) measured on a laboratory race track for two species of lizards: Western fence lizard (Sceloporus occidentalis) and Sagebrush lizard (Sceloporus graciosus). The bootstrap distribution below describes the variability of difference in means captured from 1,000 bootstrap samples of the lizard data. (Adolph 1987)

    1. Using the bootstrap distribution, create a (rough) 90% percentile bootrap confidence interval for the true population difference in average speed of the Western fence lizard as compared with Sagebrush lizard.

    2. Using the bootstrap distribution, create a (rough) 90% bootstrap SE confidence interval for the true population difference in average speed of the Western fence lizard as compared with Sagebrush lizard.

  1. Weight loss. You are reading an article in which the researchers have created a 95% confidence interval for the difference in average weight loss for two diets. They are 95% confident that the true difference in average weight loss over 6 months for the two diets is somewhere between (1 lb, 25 lbs). The authors claim that, “therefore diet A (\(\bar{x}_A\) = 20 lbs average loss) results in a much larger average weight loss as compared to diet B (\(\bar{x}_B\) = 7 lbs average loss).” Comment on the authors’ claim.
  1. Possible randomized means. Data were collected on data from two groups (A and B). There were 3 measurements taken on Group A and two measurements in Group B.

    Group Measurement 1 Measurement 2 Measurement 3
    A 1 15 5
    B 7 3

    If the data are (repeatedly) randomly allocated across the two conditions, provide the following: (1) the values which are assigned to group A, (2) the values which are assigned to group B, and (3) the difference in averages \((\bar{x}_A - \bar{x}_B)\) for each of the following:

    1. When the randomized difference in averages is as large as possible.

    2. When the randomized difference in averages is as small as possible (a big in magnitude negative number).

    3. When the randomized difference in averages is as close to zero as possible.

    4. When the observed values are randomly assigned to the two groups, to which of the previous parts would you expect the difference in means to fall closest? Explain your reasoning.

  1. Diamonds, mathematical test. We have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat. Each sample has 23 diamonds. Sample statistics for the price per carat of diamonds in each sample are provided below. Conduct a hypothesis test using a mathematical model to evaluate if there is a difference between the prices per carat of diamonds that weigh 0.99 carats and diamonds that weigh 1 carat Make sure to state your hypotheses clearly, check relevant conditions, and interpret your results in context of the data. (Wickham 2016)

    Mean SD n
    0.99 carats $44.51 $13.32 23
    1 carat $57.20 $18.19 23

  1. A/B testing. A/B testing is a user experience research methodology where two variants of a page are shown to users at random. A company wants to evaluate whether users will spend more time, on average, on Page A or Page B using an A/B test. Two user experience designers at the company, Lucie and Müge, are tasked with conducting the analysis of the data collected. They agree on how the null hypothesis should be set: on average, users spend the same amount of time on Page A and Page B. Lucie believes that Page B will provide a better experience for users and hence wants to use a one-tailed test, Müge believes that a two-tailed test would be a better choice. Which designer do you agree with, and why?

  2. Diamonds, mathematical interval. We have data on two random samples of diamonds: one with diamonds that weigh 0.99 carats and one with diamonds that weigh 1 carat. Each sample has 23 diamonds. Sample statistics for the price per carat of diamonds in each sample are provided below. Assuming that the conditions for conducting inference using a mathematical model are satisfied, construct a 95% confidence interval for the true population difference in prices per carat of diamonds that weigh 0.99 carats and 1 carat. (Wickham 2016)

    Mean SD n
    0.99 carats $44.51 $13.32 23
    1 carat $57.20 $18.19 23
  1. True / False: comparing means. Determine if the following statements are true or false, and explain your reasoning for statements you identify as false.

    1. As the degrees of freedom increases, the \(t\)-distribution approaches normality.

    2. If a 95% confidence interval for the difference between two population means contains 0, a 99% confidence interval calculated based on the same two samples will also contain 0.

    3. If a 95% confidence interval for the difference between two population means contains 0, a 90% confidence interval calculated based on the same two samples will also contain 0.

  2. Difference of means. We collect two random samples from two different populations In each part below, consider the sample means \(\bar{x}_1\) and \(\bar{x}_2\) that we might observe from these two samples.

    Mean Standard deviation Sample size
    Population 1 15 20 50
    Population 2 20 10 30
    1. What is the associated mean and standard deviation of \(\bar{x}_1\)?

    2. What is the associated mean and standard deviation of \(\bar{x}_2\)?

    3. Calculate and interpret the mean and standard deviation associated with the difference in sample means for the two groups, \(\bar{x}_2 - \bar{x}_1\).

    4. How are the standard deviations from parts (a), (b), and (c) related?

  1. Mindfulness intervention for nurses. In order to address extremely challenging and stressful situations for intensive care unit nurses, researchers ran a mindfulness-based intervention (MBI) study on 60 nurses working in three hospitals in El-Beheira, Egypt. The participants were randomly allocated to one of the two groups: the treatment group (MBI) received 8 MBI sessions and the control group received no intervention. The nurses’ emotional exhaustion was measured using 9 items from a questionnaire of the Maslach Burnout Inventory-Human Services Survey for Medical Personnel; the questions are recorded on a Likert scale where 0 indicated “Never” and 6 indicates “Every day”. Nurses in the treatment group had an emotional exhaustion score of 15.47, with a standard deviation of 4.44, and nurses in the control group had an emotional exhaustion score of 32.43, with a standard deviation of 8.87. Do these data provide convincing evidence that the emotional exhaustion decrease is different for the patients in the treatment group compared to the control group? Assume that conditions for conducting inference using mathematical models are satisfied. (Othman et al. 2023)
  1. Chicken diet: horsebean vs. linseed. Chicken farming is a multi-billion dollar industry, and any methods that increase the growth rate of young chicks can reduce consumer costs while increasing company profits, possibly by millions of dollars. An experiment was conducted to measure and compare the effectiveness of various feed supplements on the growth rate of chickens. Newly hatched chicks were randomly allocated into six groups, and each group was given a different feed supplement. In this exercise we consider chicks that were fed horsebean and linseed. Below are some summary statistics from this dataset along with box plots showing the distribution of weights by feed type.9 (McNeil 1977)

    Horsebean Linseed
    Mean 160.2 218.8
    SD 38.6 52.2
    n 10.0 12.0

    1. Describe the distributions of weights of chickens that were fed horsebean and linseed.

    2. Do these data provide strong evidence that the average weights of chickens that were fed linseed and horsebean are different? Use a 5% discernibility level.

    3. What type of error might we have committed? Explain.

    4. Would your conclusion change if we used \(\alpha = 0.01\)?

  1. Fuel efficiency in the city. Each year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year. Below are summary statistics on fuel efficiency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2021. Do these data provide strong evidence of a difference between the average fuel efficiency of cars with manual and automatic transmissions in terms of their average city mileage?10 (US DOE EPA 2021)

    CITY Mean SD n
    Automatic 17.4 3.44 25
    Manual 22.7 4.58 25

  1. Chicken diet: casein vs. soybean. Casein is a common weight gain supplement for humans. Does it have an effect on chickens? An experiment was conducted to measure and compare the effectiveness of various feed supplements on the growth rate of chickens. Newly hatched chicks were randomly allocated into six groups, and each group was given a different feed supplement. In this exercise we consider chicks that were fed casein and soybean. Assume that the conditions for conducting inference using mathematical models are met, and using the data provided below, test the hypothesis that the average weight of chickens that were fed casein is different than the average weight of chickens that were fed soybean. If your hypothesis test yields a statistically discernible result, discuss whether the higher average weight of chickens can be attributed to the casein diet. (McNeil 1977)

    Feed type Mean SD n
    casein 323.58 64.43 12
    soybean 246.43 54.13 14
  1. Fuel efficiency on the highway. Each year the US Environmental Protection Agency (EPA) releases fuel economy data on cars manufactured in that year. Below are summary statistics on fuel efficiency (in miles/gallon) from random samples of cars with manual and automatic transmissions manufactured in 2021. Do these data provide strong evidence of a difference between the average fuel efficiency of cars with manual and automatic transmissions in terms of their average highway mileage? (US DOE EPA 2021)

    HIGHWAY Mean SD n
    Automatic 23.7 3.90 25
    Manual 30.9 5.13 25

  1. Gaming, distracted eating, and intake. A group of researchers who are interested in the possible effects of distracting stimuli during eating, such as an increase or decrease in the amount of food consumption, monitored food intake for a group of 44 patients who were randomized into two equal groups. The treatment group ate lunch while playing solitaire, and the control group ate lunch without any added distractions. Patients in the treatment group ate 52.1 grams of biscuits, with a standard deviation of 45.1 grams, and patients in the control group ate 27.1 grams of biscuits, with a standard deviation of 26.4 grams. Do these data provide convincing evidence that the average food intake (measured in amount of biscuits consumed) is different for the patients in the treatment group compared to the control group? Assume that conditions for conducting inference using mathematical models are satisfied. (Oldham-Cooper et al. 2011)
  1. Gaming, distracted eating, and recall. A group of researchers who are interested in the possible effects of distracting stimuli during eating, such as an increase or decrease in the amount of food consumption, monitored food intake for a group of 44 patients who were randomized into two equal groups. The 22 patients in the treatment group who ate their lunch while playing solitaire were asked to do a serial-order recall of the food lunch items they ate. The average number of items recalled by the patients in this group was 4. 9, with a standard deviation of 1.8. The average number of items recalled by the patients in the control group (no distraction) was 6.1, with a standard deviation of 1.8. Do these data provide strong evidence that the average numbers of food items recalled by the patients in the treatment and control groups are different? Assume that conditions for conducting inference using mathematical models are satisfied. (Oldham-Cooper et al. 2011)

  1. \(H_0:\) the exams are equally difficult, on average. \(\mu_A - \mu_B = 0.\) \(H_A:\) one exam was more difficult than the other, on average. \(\mu_A - \mu_B \neq 0.\)↩︎

  2. Since the exams were shuffled, the “treatment” in this case was randomly assigned, so independence within and between groups is satisfied. The summary statistics suggest the data are roughly symmetric about the mean, and the min/max values do not suggest any outliers of concern.↩︎

  3. The point estimate of the population difference (\(\bar{x}_{ESC} - \bar{x}_{Control}\)) is 7.83.↩︎

  4. The point estimate of the population difference (\(\bar{x}_{n} - \bar{x}_{s}\)) is 0.59.↩︎

  5. \(SE(\bar{x}_{n} - \bar{x}_{s}) = \sqrt{s^2_{n}/ n_{n} + s^2_{s}/n_{s}} = \sqrt{1.23^2/867 + 1.60^2/114} = 0.16\)↩︎

  6. You can watch an episode of John Oliver on Last Week Tonight to explore the present day offenses of the tobacco industry. Please be aware that there is some adult language.↩︎

  7. The diamonds data used in this exercise can be found in the ggplot2 R package.↩︎

  8. The lizard_run data used in this exercise can be found in the openintro R package.↩︎

  9. The chickwts data used in this exercise can be found in the datasets R package.↩︎

  10. The epa2021 data used in this exercise can be found in the openintro R package.↩︎

中文

20  比较两个独立均值的推断

我们现在将 第 19 中的方法加以扩展,将置信区间和假设检验应用于来自两组(第 1 组和第 2 组)的总体均值差异: \(\mu_1 - \mu_2.\)

在我们的研究中,我们将基于样本确定 \(\mu_1 - \mu_2\) 的一个合理的点估计,你可能已经猜到了它的形式: \(\bar{x}_1 - \bar{x}_2.\) 然后我们将以三种不同的方式进行推断分析:使用随机化检验、应用自助法进行区间估计,以及如果我们验证了点估计可以用正态分布建模,我们就计算该估计的标准误并应用数学框架。

在本节中,我们考虑两个总体均值的差异 \(\mu_1 - \mu_2,\) ,其条件是数据不是配对的。正如单样本的情形一样,我们确定一些条件,以确保我们可以将 \(t\)分布与差异的点估计 \(\bar{x}_1 - \bar{x}_2,\) 以及一个新的标准误公式结合使用。

在两个独立均值情形下处理推断问题的细节,与两个独立比例情形下所应用的方法极为相似。我们首先介绍随机化检验,其中在原假设为真的假设下对观测值进行打乱。然后我们对数据进行自助法抽样(不施加原假设),以构建总体均值真实差异 \(\mu_1 - \mu_2.\) 的置信区间。数学模型,此处为 \(t\)分布,只要满足条件,就能够同时描述随机化检验和自助法。

这些推断工具应用于三种不同的数据情境:确定干细胞能否改善心脏功能,探索孕妇吸烟习惯与新生儿出生体重之间的关系,以及探索是否有令人信服的证据表明某一版本的考试比另一版本更难。本节的动机来自诸如“是否有令人信服的证据表明吸烟母亲的新生儿平均出生体重与不吸烟母亲的新生儿不同?”这样的问题。

20.1 均值差异的随机化检验

一位教师决定对同一场考试进行两个略有不同的版本。在发放试卷之前,他们将试卷混在一起洗牌,以确保每个学生都随机收到一个版本。由于预料到参加版本 B 考试的学生会抱怨,他们想评估两组之间观察到的差异是否大到足以提供令人信服的证据,表明版本 B(平均而言)比版本 A 更难。

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

20.1.1 观测数据

学生在两次考试中表现的汇总统计量显示在 表 20.1 中,并绘制在 图 20.1.

表 20.1:每个考试版本分数的汇总统计量。
组别 n 平均数 标准差 最小值 最大值
A 58 75.1 13.9 44 100
B 55 72.0 13.8 38 100
Box plot of exam score broken down by version of exam.
图 20.1:参加两个不同考试之一的学生的考试分数。

构建假设以评估观察到的样本均值差异 \(\bar{x}_A - \bar{x}_B=3.1,\) 在原假设为真时是否可能因偶然而发生。我们稍后将使用 \(\alpha = 0.01.\)1

在继续评估上一个引导练习中的假设之前,让我们仔细思考一下这个数据集。两组之间的观测是否独立?是否存在对异常值的担忧?2

20.1.2 统计量的变异性

第 11 章,该统计量的变异性(之前: \(\hat{p}_1 - \hat{p}_2)\) )是在将观测值在两个处理组之间多次打乱后进行可视化的。打乱过程实现了原假设模型(即处理没有效果)。在考试示例中,原假设是考试 A 和考试 B 难度相同,因此两次考试的平均分数应该相同。如果两次考试难度相同, 由于自然变异性,我们有时会预期学生在考试 A 上表现稍好 \((\bar{x}_A > \bar{x}_B)\) ,有时会预期学生在考试 B 上表现稍好 \((\bar{x}_B > \bar{x}_A).\) 眼下的问题是:是否 \(\bar{x}_A - \bar{x}_B=3.1\) 表明考试A比考试B更容易。

图 20.2 展示了将考试随机分配到观测到的考试分数的过程。如果原假设为真,那么每场考试的分数应该代表学生在该材料上的真实能力。无论他们拿到的是考试A还是考试B,结果都不应有差别。通过重新分配哪位学生拿到哪场考试,我们能够理解考试平均分之差仅由自然变异引起时会如何变化。在图20.1中只有一次随机化过程的迭代,从而得到一个模拟的平均分之差。 图 20.2图20.2:在考试难度相同的原假设下,将考试版本(A或B)随机分配给考试分数。

Four panels representing four different orientations of a toy dataset of 9 exam scores. The first panel provides the observed data; 4 of the exams were version A and the average score was 77.25; 5 of the exams were version B and the average score was 75.8, a difference of 1.45. The second panel shows the shuffled reassignment of the exam versions (4 of the scores are randomly reassigned to A, 5 of the scores are randomly reassigned to B). The third panel shows which score is connected with which new reassigned version of the exam. And the fourth panel sorts the exams so that version A exams are together and version B exams are together. In the randomly reassigned versions, the average score for version A is 74.25 and the average score for version B is 78.2, a difference of -3.95.
展示了模拟统计量

基于 图 20.2, 图 20.3 在1,000次随机模拟中的取值。我们看到,仅凭偶然机会,分数之差可以在-10分到+10分之间的任何位置。 \(\bar{x}_{1, sim} - \bar{x}_{2, sim}\) 图20.3:由1,000次不同的考试类型随机化计算得到的均值之差的直方图。

Histogram of differences in means, calculated from 1,000 different randomizations of the exam types.
随机化检验的目标是评估观测数据,此处关注的统计量是

20.1.3 观测统计量与零假设统计量的对比

随机化分布使我们能够判断3.1分的差异是否超出了在两场考试难度相同的情况下由分数自然变异所能预期的范围。通过在图20.3上标出3.1的值,我们可以衡量3.1与在原假设下生成的随机化差异有多大不同或相似。 \(\bar{x}_A - \bar{x}_B=3.1.\) 图20.4:由1,000次不同的考试类型随机化计算得到的均值之差的直方图。观测到的3.1分差异用一条竖线标出,比3.1更极端的区域用阴影表示,即p值。 图 20.4近似计算图20.4中描绘的p值,并结合案例研究的背景给出结论。

Histogram of differences in means, calculated from 1,000 different randomizations of the exam types. The observed difference of 3.1 points is plotted as a vertical line, and the area more extreme than 3.1 is shaded to represent the p-value.
利用软件,我们可以找到均值之差的洗牌差异小于观测差异(3.14)的数量为900(1,000次随机化中)。因此10%的模拟结果大于观测差异。为了得到p值,我们将大于观测差异的随机化差异比例加倍,p值 = 0.2。

之前,我们已明确将使用 图 20.4由于p值大于


null

,我们无法拒绝原假设。 \(\alpha = 0.01.\) 由于p值大于显著性水平,我们没有足够的证据拒绝原假设。 \(\alpha,\) 我们不拒绝原假设。也就是说,数据并不能令人信服地表明其中一个版本的考试比另一个更难,因此老师不应确信需要给 B 版考试的分数加分。

较大的 p 值以及 \(\bar{x}_A - \bar{x}_B=3.1\) 与随机化差异的一致性使我们 不拒绝原假设。换句话说,没有证据表明其中一份试卷比另一份更容易。人们可能倾向于得出两份试卷难度相同的结论,但这个结论是错误的。假设检验框架的设立只是为了拒绝原假设,而不是为了验证原假设。正如我们所总结的,数据与试卷 A 和 B 难度相同相一致,但数据也与试卷 A 比试卷 B “容易” 3.1 分相一致。数据无法判定两份试卷是否同样难,或者其中一份是否稍微容易一些。事实上,不拒绝原假设的结论往往看起来不尽如人意。然而,在这个案例中,老师和学生可能都松了一口气,因为没有证据表明其中一份试卷比另一份更难。

20.2 均值差异的自助法置信区间

在提供一个基于真实数据进行自助法分析的完整示例之前,我们回到虚构的 Awesome Auto 示例,以直观展示两个样本的自助法设置。考虑一个扩展场景:研究问题聚焦于比较一家 Awesome Auto 加盟店(组 1)的汽车平均价格与另一家 Awesome Auto 加盟店(组 2)的汽车平均价格。自助法可以分别应用于 每个 组,并每次重新计算均值之差。 图 20.5 直观描述了当关注的是基于两个独立样本计算的统计量时的自助法过程。分析过程与单样本情形相同,只是现在(单一的)关注统计量是 样本均值之差。也就是说,对每个组分别进行自助法重抽样,但将结果合并为一个单一的自助法均值之差。重复该过程将产生 \(k\) 个自助法均值之差,直方图将描述与均值之差相关的自然抽样变异性。

Samples are shown as separately coming from two independent, large, unknown populations. Directly from each of the two observed samples, bootstrap resamples can be taken (with replacement). Bootstrap resample 1 from sample 1 is compared to bootstrap resample 1 from sample 2 by comparing the difference in bootstrapped averages. A histogram of differences in bootstrapped averages displays the differences ranging from roughly -20000 dollars to +10000 dollars.
图 20.5:对于两组比较,自助法重抽样分别在每个组上进行,但统计量按差值计算。随后将这 k 个差值的集合作为关注统计量进行分析,并针对关注参数得出结论。

在接下来的章节中,我们将离开虚构的 Awesome Auto 场景,把自助法应用于真实数据集,研究胚胎干细胞是否有助于改善心脏功能,之后还将用于研究新生儿出生的特征。请注意,虚构场景之所以让我们能够直观展示自助法,是因为我们的样本量为 5。这种可视化对于理解自助法的工作原理非常重要。然而,自助法在很大程度上依赖于样本能够出色地代表总体,而 5 个观测值几乎永远不足以真正代表完整总体的细微差别。为此,我们在样本量大得多的情形下应用自助法,例如新生儿出生数据中提供的 1000 个随机样本。

20.2.1 观测数据

使用胚胎干细胞(ESCs)进行治疗是否有助于改善心脏病发作后的心脏功能? 表 20.2 包含一项测试ESC(胚胎干细胞)对患有心脏病的绵羊疗效的实验的汇总统计。每只绵羊被随机分配到ESC组或对照组,研究中测量了它们心脏泵血能力的变化。 (Ménard等人 2005) 图 20.8 给出了两个数据集的直方图。正值对应于泵血能力的提高,这通常表明恢复得更好。我们的目标是确定ESC相对于对照组对心脏泵血能力变化影响的95%置信区间。

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

表 20.2:胚胎干细胞研究的汇总统计。
组别 n 平均数 标准差
ESC 9 3.50 5.17
对照组 9 -4.33 2.76

心脏泵血变量差异的点估计很容易求得:即样本均值之差。

\[\bar{x}_{esc} - \bar{x}_{control}\ =\ 3.50 - (-4.33)\ =\ 7.83\]

20.2.2 统计量的变异性

正如我们在 第 17.2 节中看到的,我们将使用自助法(bootstrap)来估计在重复抽样时与样本均值之差相关的变异性。在类似于两个比例的方法中,从每组(此处为ESC组和对照组)有放回地抽取一个 独立的 样本,计算样本均值,并求其差值。整个过程重复多次,以生成样本均值之差的自助分布(不包含 零假设假设)。

图 20.6 展示了均值之差的变异性,并叠加了90%百分位数置信区间和SE置信区间。

Histogram of differences in means after 1,000 bootstrap samples from each of the two groups. The observed difference is plotted as a black vertical line at 7.83. The blue dashed and red dotted lines provide the bootstrap percentile and boostrap SE confidence intervals, respectively, for the difference in true population means.
图 20.6:从两组各进行1,000次自助抽样后均值之差的直方图。观测到的差异以黑色竖线绘制在7.83处。蓝色虚线和红色点线分别给出了真实总体均值之差的自助百分位数置信区间和自助SE置信区间。

使用自助均值之差的直方图,估计样本均值之差的标准误, \(\bar{x}_{ESC} - \bar{x}_{Control}.\)3

为真实平均泵血能力之差选择一个自助置信区间, \(\mu_{ESC} - \mu_{Control}.\) 该区间是否显示两种处理之间存在差异?


由于上面的两个90%区间(无论是百分位数还是SE)都不包含零(注意零从来不是自助法差值之一,因此95%和99%区间也会得出相同的结论!),我们得出结论:ESC处理在心脏泵血能力方面明显优于对照组。

由于该研究是一项随机对照实验,我们可以得出结论:正是处理(ESC)导致了泵血能力的变化。

20.3 用于检验均值差异的数学模型

每年,美国都会向公众发布一个大型数据集,其中包含该国记录的出生信息。该数据集一直受到医学研究人员的关注,他们正在研究准母亲的习惯和做法与其孩子出生之间的关系。我们将使用2014年发布数据集中1,000个案例的随机样本。

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

20.3.1 观测数据

该数据集中的四个案例呈现在 表 20.3中。我们特别关注两个变量: weightsmoke。而 weight 变量表示新生儿的体重, smoke 变量描述哪些母亲在怀孕期间吸烟。

表 20.3:来自 births14 数据集的四个案例。空白单元格表示缺失数据。
fage mage weeks visits gained weight sex habit
34 34 37 14 28 6.96 男性 习惯
36 31 41 12 41 8.86 女性 习惯
37 36 37 10 28 7.51 女性 习惯
16 38 29 6.19 男性 习惯

我们想知道,是否有令人信服的证据表明吸烟母亲所生新生儿的平均出生体重与不吸烟母亲所生新生儿的平均出生体重不同?我们将使用该样本中的数据来尝试回答这个问题。

建立适当的假设来评估母亲吸烟与平均出生体重之间是否存在关系。


原假设代表两组之间没有差异的情形。

  • \(H_0:\) 吸烟母亲与不吸烟母亲所生新生儿的平均出生体重没有差异。用统计符号表示为: \(\mu_{n} - \mu_{s} = 0,\) ,其中 \(\mu_{n}\) 代表不吸烟的母亲, \(\mu_s\) 代表吸烟的母亲。
  • \(H_A:\) 吸烟母亲与不吸烟母亲所生新生儿的平均出生体重存在某些差异 \((\mu_{n} - \mu_{s} \neq 0).\)

表 20.4 展示了数据的样本统计量。我们可以看到,吸烟母亲所生婴儿的平均出生体重低于不吸烟母亲所生婴儿的平均出生体重。

表 20.4: births14 数据集的最后五行。
的汇总统计量 n 平均数 标准差
习惯 867 7.27 1.23
不吸烟者 114 6.68 1.60

20.3.2 统计量的变异性

吸烟者 \(t\)分布。

  • 我们检验使用该方法对样本均值之差进行建模所需的两个条件: 独立性。样本均值之差的分布可以建模的条件之一是两组观测值相互独立。我们将在下面对此进行讨论。样本量/偏度条件。其次,样本量应足够大(每组 n ≥ 30),以便样本均值之差的分布近似正态。由于每组样本量为 150,该条件也满足。在满足这些条件的情况下,我们可以将样本均值之差建模为: 其中 μns − μs 表示不吸烟母亲与吸烟母亲所生新生儿平均出生体重之差。由于两组样本量较大且相互独立,样本均值之差的标准误可估计为: SE = sqrt(s²ns/nns + s²s/ns) = sqrt(18.1²/150 + 18.1²/150) ≈ 2.09 将样本均值之差除以其标准误,可得到检验统计量: Z = (x̄ns − x̄s − 0)/SE = (34.1 − 33.7)/2.09 ≈ 0.19 该 Z 统计量对应的 p 值约为 0.85,远大于显著性水平 0.05。因此,我们没有足够的证据拒绝原假设,即没有令人信服的证据表明吸烟母亲与不吸烟母亲所生新生儿的平均出生体重存在差异。
  • 由于两组的观测值都超过30个,我们检查 图 20.7 中的数据是否存在特别极端的异常值,结果没有发现。

由于两个条件都满足,样本均值之差可以用 \(t\)分布。

The left panel represents birth weights for infants whose mothers smoked during pregnancy. The right panel represents the birth weights for infants whose mothers who did not smoke during pregnancy.
图 20.7:左图表示孕期吸烟母亲所生婴儿的出生体重。右图表示孕期不吸烟母亲所生婴儿的出生体重。

中的汇总统计量可能对本引导练习有用。总体差异的点估计是多少, 表 20.4 比较两个均值的检验统计量是 T。 \(\mu_{n} - \mu_{s}\)?4

20.3.3 观测统计量与零假设统计量的对比

T 分数是组间差异与组内观测值变异之比。

组内和组间观测值相互独立。

\[T = \frac{(\bar{x}_1 - \bar{x}_2) - 0}{\sqrt{s_1^2/n_1 + s_2^2/n_2}}\]

当原假设为真且条件满足时,T 服从自由度为 \(df = min(n_1 - 1, n_2 -1).\)

F 统计量是各组之间差异程度(MSG)与组内观测值变异程度(MSE)的比值。

  • 计算不吸烟母亲与吸烟母亲所生婴儿平均体重之差的点估计的标准误。
  • 的 t 分布。

5

数据集和研究问题上,完成上一个例题和引导练习中开始的假设检验。使用可辨识性水平 births14 作为参考, \(\alpha=0.05.\) 且样本量为 \(\bar{x}_{n} - \bar{x}_{s} = 0.59,\) \(SE = 0.16,\) 我们可以利用先前的信息求出该检验的检验统计量: \(n_n = 867\)\(n_s = 114.\)


我们使用软件求出单侧尾面积。我们将使用

\[T = \frac{\ 0.59 - 0\ }{0.16} = 3.69\]

中较小的那个 \(n_n - 1 = 866\)\(n_s - 1 = 113\) 作为自由度: \(df = 113.\) 单尾面积约为 0.00017;将该值加倍即得双尾面积和 p 值,0.00034。

p 值小于可辨别性水平 0.05,因此我们拒绝原假设。数据提供了具有统计学可辨别性的证据,表明孕期吸烟的母亲与不吸烟的母亲所生婴儿的平均体重存在差异。

这个结果可能并不令人惊讶。我们都知道吸烟有害健康,你可能也听说过孕期吸烟不仅对母亲有害,对婴儿也有害。事实上,烟草行业的一些人竟然厚颜无耻地将其宣传为吸烟的一项 好处

这是真的。吸烟女性所生的婴儿更小,但他们和不吸烟女性所生的婴儿一样健康。而且有些女性更愿意生较小的婴儿。 —— Joseph Cullman,菲利普莫里斯公司董事长,于 CBS 《面对国家》节目,1971 年 1 月 3 日

此外,吸烟母亲与不吸烟母亲所生婴儿之间的健康差异不仅限于体重差异。6

关于独立 t 检验功效的一点小提示(回顾 第 14.4 节中关于功效的讨论)。事实证明,这里给出的独立 t 检验的功效通常低于 Section 21.3中讨论的配对 t 检验。话虽如此,取决于数据收集的方式,我们并不总是有办法对数据进行配对以降低观测之间固有的变异性。

20.4 估计均值差异的数学模型

20.4.1 观测数据

与假设检验一样,对于能否用 \(t\)-分布,我们需要检查新的条件。与两比例的情形类似,我们要求一个更稳健的独立性版本,以便确信两组之间也是独立的。其次,我们还要分别检验每一组的正态性,实际上就是检查离群值。

使用 \(t\)-分布来处理均值差异。

\(t\)-分布可用于对两个均值的标准化差异进行推断,前提是

  • 独立性 (扩展版)。数据在两组内部以及两组之间都是独立的,例如,数据来自独立的随机样本或随机化实验。
  • 正态性。我们分别检查每一组的离群值。

标准误可按如下方式计算:

\[SE = \sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}\]

自由度的官方公式相当复杂,通常需要用软件计算,因此如果无法使用软件,你可以改用 \(n_1 - 1\)\(n_2 - 1\) 中较小者作为自由度。

回忆一下,误差幅度由标准误差定义。 \(\bar{x}_1 - \bar{x}_2\) 的误差幅度可以直接从 \(SE(\bar{x}_1 - \bar{x}_2).\)

误差幅度(针对 \(\bar{x}_1 - \bar{x}_2.\)

误差幅度为 \(t^\star_{df} \times \sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}\) ,其中 \(t^\star_{df}\) 由自由度为 df 的t分布上的指定分位数计算得出。

20.4.2 统计量的变异性

能否使用 \(t\)-分布基于点估计 \(\bar{x}_{esc} - \bar{x}_{control} = 7.83\)?


进行推断?

图 20.8 首先,我们检查独立性。由于绵羊是被随机分配到各组的,组内和组间的独立性都得到满足。

并未显示任何一组存在明显的离群值。(ESC 组看起来确实变异稍大,但这与存在明显离群值并不相同。) \(t\)-分布来对样本均值之差进行建模。

Histograms for the difference in heart pumping function after a heart attack for both the treatment group (ESC, which received the embryonic stem cell treatment) and the control group (which did not receive the treatment).
图 20.8:心脏病发作后心脏泵血功能变化(治疗组(ESC,接受胚胎干细胞治疗)与对照组(未接受治疗))的直方图。

通常,我们使用统计软件来找到合适的自由度;如果没有软件,我们可以使用两者中较小的一个作为自由度,例如,在使用 \(n_1 - 1\)\(n_2 - 1\) 表查找尾部面积时。为了在例题和引导练习中保持透明,我们将使用后一种方法来求 \(t\);在 ESC 例子中,这意味着我们将使用 \(df\)计算胚胎干细胞(ESC)对绵羊心脏病发作后心脏泵血能力变化的 95% 置信区间。 \(df = 8.\)

我们将使用之前计算出的样本差值和标准误:


我们可以确定

\[ \begin{aligned} \bar{x}_{esc} - \bar{x}_{control} &= 7.83 \\ SE &= \sqrt{\frac{5.17^2}{9} + \frac{2.76^2}{9}} = 1.95 \end{aligned} \]

使用 \(df = 8,\) 在 95% 置信区间下的临界值。最后,将数值代入置信区间公式: \(t^{\star}_{8} = 2.31\) 我们有 95% 的把握认为,接受胚胎干细胞治疗的绵羊的心脏泵血功能比未接受干细胞治疗的绵羊高 3.32% 至 12.34%。

\[ \begin{aligned} \text{point estimate} \ &\pm\ t^{\star} \times SE \\ 7.83 \ &\pm\ 2.31\times 1.95 \\ (3.32 \ &, \ 12.34) \end{aligned} \]

在本章中,我们将单均值的推断方法扩展到了均值差异的问题。你可能已经看到了与之前章节的相似之处,即从单一比例(

20.5 本章复习

20.5.1 小结

)扩展到比例差异(第 16)的章节。在考虑样本均值差异时(实际上,在考虑许多定量统计量时),我们使用 t 分布来描述 T 分数(标准化的样本均值之差)的抽样分布。置信水平的概念以及假设检验结论可能产生的错误类型与其他章节中看到的类似(参见第 17表 20.5:本章介绍的术语。 第 14).

20.5.2 术语

本章中介绍的术语列于 表 20.5。如果您不确定其中一些术语的含义,我们建议您回到正文中复习它们的定义。您应该能够很容易地发现它们是 粗体文本.

均值之差
均值差异 均值之差的标准误 t置信区间
点估计 T 分数 t 检验

20.6 练习

奇数编号习题的答案见 附录 A.20.

  1. 实验面包师。 一位面包师正在完善其贝果配方,试验活性干酵母(AD)和速发酵母(I)。他们用每种酵母各烤了12个贝果,并按贝果的膨胀程度以1到10的量表对每个贝果进行评分。为了评估用活性干酵母和速发酵母烤制的贝果的平均膨胀程度是否存在差异,他们提出了以下一组假设。这些假设的表述有什么问题?

    \[H_0: \bar{x}_{AD} \leq \bar{x}_{I} \quad \quad H_A: \bar{x}_{AD} > \bar{x}_{I}\]

  1. 填空。 我们使用___来评估数据是否提供了两个总体均值之间存在差异的有力证据,并使用___来估计这一差异。
  1. 钻石,随机化检验。 钻石的价格随克拉重量增加而上涨,但这种上涨并不平滑。例如,0.99克拉钻石与1克拉钻石的大小差异肉眼无法察觉,但1克拉钻石的价格往往远高于0.99克拉钻石的价格。我们有两个钻石随机样本:23颗0.99克拉钻石和23颗1克拉钻石。为了能够比较等价单位,我们首先将每颗钻石的价格除以其克拉重量的100倍。也就是说,对于0.99克拉的钻石,我们将价格除以99;对于1克拉的钻石,我们将价格除以100。然后,我们将克拉重量随机分配到价格值上,以模拟0.99克拉和1克拉钻石平均价格之差的零分布。零分布(含1,000个随机化差值)如下所示,它描绘了当这些钻石所来自的总体确实不存在差异时,样本均值(每克拉价格)之差的分布。7 (Wickham 2016)

    利用随机化分布,进行假设检验以评估重量为0.99克拉的钻石与重量为1克拉的钻石的每克拉价格是否存在差异。请确保清晰地陈述你的假设,并结合数据背景解释你的结果。 (Wickham 2016)

  1. 蜥蜴奔跑,随机化检验。 为了评估常见蜥蜴的生理特征,在实验室赛道上测量了两种蜥蜴的最高速度(单位:米/秒):西部篱蜥(Sceloporus occidentalis)和灌木蜥(Sceloporus graciosus)。原始观测到的蜥蜴速度之差为 \(\bar{x}_{Western fence} - \bar{x}_{Sagebrush} = 0.7 \mbox{m/sec}.\) 下面的直方图显示了将速度在蜥蜴物种间随机分配1,000次后平均差值的分布。利用该随机化分布,进行假设检验以评估西部篱蜥与灌木蜥的平均速度是否存在差异。请确保清晰地陈述你的假设,并结合数据背景解释你的结果。8 (Adolph 1987)

  1. 钻石,自助法区间。 我们有两个钻石随机样本的数据:23颗0.99克拉的钻石和23颗1克拉的钻石。下面提供的是重量为0.99克拉的钻石与重量为1克拉的钻石每克拉价格均值之差的自助法(bootstrap)差异直方图。 (Wickham 2016)

    1. 利用自助法分布,为重量0.99克拉与1克拉钻石的真实总体每克拉价格差异创建一个(粗略的)95%自助法百分位置信区间。

    2. 利用自助法分布,为重量0.99克拉与1克拉钻石的真实总体每克拉价格差异创建一个(粗略的)95%自助法标准误(SE)置信区间。注意,自助法分布的标准误为4.64。

  1. 蜥蜴奔跑,自助法区间。 我们有两种蜥蜴在实验室赛道上测得的最高速度(单位:米/秒)的数据:西部强棱蜥(Sceloporus occidentalis)和灌木蜥(Sceloporus graciosus)。下面的自助法分布描述了从蜥蜴数据的1,000个自助法样本中捕获的均值差异的变异性。 (Adolph 1987)

    1. 利用自助法分布,为西部强棱蜥与灌木蜥相比的真实总体平均速度差异创建一个(粗略的)90%百分位自助法置信区间。

    2. 利用自助法分布,为西部强棱蜥与灌木蜥相比的真实总体平均速度差异创建一个(粗略的)90%自助法标准误(SE)置信区间。

  1. 减重。 你正在阅读一篇文章,其中研究人员为两种饮食的平均减重差异创建了一个95%置信区间。他们有95%的把握认为,两种饮食在6个月内的真实平均减重差异介于(1磅,25磅)之间。作者声称,“因此饮食A(\(\bar{x}_A\) = 平均减重20磅)相比饮食B(\(\bar{x}_B\) = 平均减重7磅)产生大得多的平均减重。”请对作者的说法进行评论。
  1. 可能的随机化均值。 收集了来自两组(A和B)的数据。A组有3个测量值,B组有2个测量值。

    组别 测量值1 测量 2 测量 3
    A 1 15 5
    B 7 3

    如果将数据(重复地)随机分配到两个条件中,请提供以下内容:(1) 分配到 A 组的数值,(2) 分配到 B 组的数值,以及 (3) 平均值之差 \((\bar{x}_A - \bar{x}_B)\) 针对以下每种情况:

    1. 当随机分配得到的平均值之差尽可能大时。

    2. 当随机分配得到的平均值之差尽可能小时(一个绝对值很大的负数)。

    3. 当随机分配得到的平均值之差尽可能接近零时。

    4. 当观测值被随机分配到两组时,你预期平均值之差会最接近前面哪一部分的结果?请解释你的理由。

  1. 钻石,数学检验。 我们有两个钻石随机样本的数据:一个样本包含重量为 0.99 克拉的钻石,另一个样本包含重量为 1 克拉的钻石。每个样本各有 23 颗钻石。下面提供了每个样本中钻石每克拉价格的样本统计量。请使用数学模型进行假设检验,以评估重量为 0.99 克拉的钻石与重量为 1 克拉的钻石的每克拉价格是否存在差异。务必清楚地陈述你的假设,检查相关条件,并结合数据的实际背景解释你的结果。 (Wickham 2016)

    平均数 标准差 n
    0.99 克拉 $44.51 $13.32 23
    1 克拉 $57.20 $18.19 23

  1. A/B 测试。 A/B 测试是一种用户体验研究方法,将页面的两个版本随机展示给用户。一家公司想通过 A/B 测试评估用户平均在页面 A 还是页面 B 上花费更多时间。该公司的两位用户体验设计师 Lucie 和 Müge 负责对收集到的数据进行分析。他们一致同意原假设的设定方式:平均而言,用户在页面 A 和页面 B 上花费的时间相同。Lucie 认为页面 B 会为用户提供更好的体验,因此想使用单尾检验;Müge 认为双尾检验是更好的选择。你同意哪位设计师的观点,为什么?

  2. 钻石,数学区间。 我们有两组钻石的随机样本数据:一组是重量为0.99克拉的钻石,另一组是重量为1克拉的钻石。每个样本有23颗钻石。下面提供了每个样本中钻石每克拉价格的样本统计量。假设使用数学模型进行推断的条件均满足,请为重量为0.99克拉和1克拉的钻石每克拉价格的真实总体差异构建一个95%置信区间。 (Wickham 2016)

    平均数 标准差 n
    0.99 克拉 $44.51 $13.32 23
    1 克拉 $57.20 $18.19 23
  1. 判断对错:均值比较。 判断以下陈述是对还是错,并对你认为是错误的陈述解释理由。

    1. 随着自由度的增加, \(t\)-分布趋近于正态分布。

    2. 如果两个总体均值之差的95%置信区间包含0,那么基于相同两个样本计算的99%置信区间也将包含0。

    3. 如果两个总体均值之差的95%置信区间包含0,那么基于相同两个样本计算的90%置信区间也将包含0。

  2. 均值之差。 我们从两个不同的总体中收集两个随机样本。在下面的每一部分中,考虑我们可能从这两个样本中观察到的样本均值 \(\bar{x}_1\)\(\bar{x}_2\)

    平均数 标准差 样本量
    总体1 15 20 50
    总体2 20 10 30
    1. 其相关的均值和标准差是多少? \(\bar{x}_1\)?

    2. 其相关的均值和标准差是多少? \(\bar{x}_2\)?

    3. 计算并解释与两组样本均值之差相关的均值和标准差, \(\bar{x}_2 - \bar{x}_1\).

    4. (a)、(b) 和 (c) 部分中的标准差之间有什么关系?

  1. 针对护士的正念干预。 为了应对重症监护室护士面临的极具挑战性和压力的情况,研究人员对在埃及布海拉省三家医院工作的 60 名护士开展了一项基于正念的干预(MBI)研究。参与者被随机分配到两组之一:干预组(MBI)接受 8 次 MBI 课程,而对照组不接受任何干预。护士的情绪衰竭程度使用 Maslach 职业倦怠量表-人际服务版医务人员调查问卷中的 9 个条目进行测量;问题采用李克特量表记录,其中 0 表示“从不”,6 表示“每天”。干预组护士的情绪衰竭得分为 15.47,标准差为 4.44;对照组护士的情绪衰竭得分为 32.43,标准差为 8.87。这些数据是否提供了令人信服的证据,表明干预组患者的情绪衰竭降幅与对照组相比有所不同?假设使用数学模型进行推断的条件均已满足。 (Othman 等人,2023)
  1. 鸡饲料:豆科干草 vs. 亚麻籽。 养鸡业是一个价值数十亿美元的产业,任何能提高雏鸡生长速度的方法都可以在降低消费者成本的同时增加公司利润,可能高达数百万美元。有人进行了一项实验,以测量和比较各种饲料补充剂对鸡生长速度的效果。刚孵出的雏鸡被随机分配到六个组,每组给予不同的饲料补充剂。在本练习中,我们考虑喂食豆科干草和亚麻籽的雏鸡。下面是该数据集的一些汇总统计量,以及按饲料类型显示体重分布的箱线图。9 (McNeil 1977)

    豆科干草 亚麻籽
    平均数 160.2 218.8
    标准差 38.6 52.2
    n 10.0 12.0

    1. 描述喂食豆科干草和亚麻籽的鸡的体重分布。

    2. 这些数据是否提供了强有力的证据,表明喂食亚麻籽和豆科干草的鸡的平均体重不同?使用 5% 的显著性水平。

    3. 我们可能犯了哪种类型的错误?请解释。

    4. 如果我们使用 \(\alpha = 0.01\)?

  1. 城市燃油效率。 每年美国环境保护署(EPA)都会发布当年生产的汽车的燃油经济性数据。以下是2021年生产的手动挡和自动挡汽车随机样本的燃油效率(单位:英里/加仑)汇总统计。这些数据是否提供了有力证据,表明手动挡和自动挡汽车在城市平均里程方面的平均燃油效率存在差异?10 (美国能源部/环保署 2021)

    城市 平均数 标准差 n
    自动挡 17.4 3.44 25
    手动挡 22.7 4.58 25

  1. 鸡饲料:酪蛋白 vs. 大豆。 酪蛋白是一种常见的人类增重补充剂。它对鸡有影响吗?有人进行了一项实验,以测量和比较各种饲料补充剂对鸡生长速度的效果。刚孵出的雏鸡被随机分配到六个组,每组给予不同的饲料补充剂。在本练习中,我们考虑喂食酪蛋白和大豆的雏鸡。假设使用数学模型进行推断的条件已满足,并使用下面提供的数据,检验喂食酪蛋白的鸡的平均体重与喂食大豆的鸡的平均体重不同的假设。如果你的假设检验得出具有统计学可辨识性的结果,请讨论鸡的平均体重较高是否可以归因于酪蛋白饮食。 (McNeil 1977)

    饲料类型 平均数 标准差 n
    酪蛋白 323.58 64.43 12
    大豆 246.43 54.13 14
  1. 高速公路上的燃油效率。 每年美国环境保护署(EPA)都会发布当年生产的汽车的燃油经济性数据。以下是2021年生产的手动挡和自动挡汽车随机样本的燃油效率(单位:英里/加仑)汇总统计。这些数据是否提供了有力证据,表明手动挡和自动挡汽车在高速公路平均里程方面的平均燃油效率存在差异? (美国能源部/环保署 2021)

    高速公路 平均数 标准差 n
    自动挡 23.7 3.90 25
    手动挡 30.9 5.13 25

  1. 玩游戏、分心进食与摄入量。 一组对进食期间干扰性刺激可能产生的影响(例如食物摄入量的增加或减少)感兴趣的研究人员,监测了44名被随机分为两个等量组的患者的食物摄入量。处理组在玩纸牌游戏的同时吃午餐,对照组在没有任何额外干扰的情况下吃午餐。处理组患者吃了52.1克饼干,标准差为45.1克;对照组患者吃了27.1克饼干,标准差为26.4克。这些数据是否提供了令人信服的证据,表明处理组患者的平均食物摄入量(以饼干消耗量衡量)与对照组不同?假设使用数学模型进行推断的条件已满足。 (Oldham-Cooper et al. 2011)
  1. 游戏、分心进食与回忆。 一组研究人员对进食期间干扰刺激可能产生的影响(例如食物摄入量的增加或减少)感兴趣,他们对44名被随机分为两个等组的患者的食物摄入情况进行了监测。治疗组22名患者在玩纸牌游戏时吃午餐,随后被要求按顺序回忆他们所吃的午餐食物。该组患者平均回忆起4.9种食物,标准差为1.8。对照组(无干扰)患者平均回忆起6.1种食物,标准差为1.8。这些数据是否提供了有力证据,表明治疗组和对照组患者平均回忆的食物种类数不同?假设使用数学模型进行推断的条件已满足。 (Oldham-Cooper et al. 2011)

  1. \(H_0:\) 两场考试平均难度相同。 \(\mu_A - \mu_B = 0.\) \(H_A:\) 其中一场考试平均难度更高。 \(\mu_A - \mu_B \neq 0.\)↩︎

  2. 由于试卷是随机打乱分发的,本例中的“处理”是随机分配的,因此组内和组间的独立性均得到满足。汇总统计量表明数据大致对称地分布于均值附近,且最小值/最大值未显示任何值得关注的离群值。↩︎

  3. 总体差异(\(\bar{x}_{ESC} - \bar{x}_{Control}\))的点估计值为 7.83。↩︎

  4. 总体差异(\(\bar{x}_{n} - \bar{x}_{s}\))的点估计值为 0.59。↩︎

  5. \(SE(\bar{x}_{n} - \bar{x}_{s}) = \sqrt{s^2_{n}/ n_{n} + s^2_{s}/n_{s}} = \sqrt{1.23^2/867 + 1.60^2/114} = 0.16\)↩︎

  6. 您可以在 Last Week Tonight 上观看约翰·奥利弗的一期节目,以了解当今烟草行业的种种劣行。请注意节目中包含一些成人语言。↩︎

  7. diamonds 本练习中使用的数据可在 ggplot2 R 包中找到。↩︎

  8. lizard_run 本练习中使用的数据可在 openintro R 包中找到。↩︎

  9. chickwts 本练习中使用的数据可在 datasets R 包中找到。↩︎

  10. epa2021 本练习中使用的数据可在 openintro R 包中找到。↩︎