Chapter page 29 / 3821 Inference for comparing paired means
English

21  Inference for comparing paired means

In Chapter 20 analysis was done to compare the average population value across two different groups. Recall that one of the important conditions in doing a two-sample analysis is that the two groups are independent. Here, independence across groups means that knowledge of the observations in one group does not change what we would expect to happen in the other group. But what happens if the groups are dependent? Sometimes dependency is not something that can be addressed through a statistical method. However, a particular dependency, pairing, can be modeled quite effectively using many of the same tools we have already covered in this text.

Paired data represent a particular type of experimental structure where the analysis is somewhat akin to a one-sample analysis (see Chapter 19) but has other features that resemble a two-sample analysis (see Chapter 20). As with a two-sample analysis, quantitative measurements are made on each of two different levels of the explanatory variable. However, because the observational unit is paired across the two groups, the two measurements are subtracted such that only the difference is retained. Table 21.1 presents some examples of studies where paired designs were implemented.

Table 21.1: Examples of studies where a paired design is used to measure the difference in the measurement over two conditions.
Observational unit Comparison groups Measurement Value of interest
Car Smooth Turn vs Quick Spin amount of tire tread after 1,000 miles difference in tread
Textbook UCLA vs Amazon price of new text difference in price
Individual person Pre-course vs Post-course exam score difference in score

Paired data.

Two sets of observations are paired if each observation in one set has a special correspondence or connection with exactly one observation in the other dataset.

It is worth noting that if mathematical modeling is chosen as the analysis tool, paired data inference on the difference in measurements will be identical to the one-sample mathematical techniques described in Chapter 19. However, recall from Chapter 19 that with pure one-sample data, the computational tools for hypothesis testing are not easy to implement and were not presented (although the bootstrap was presented as a computational approach for constructing a one sample confidence interval). With paired data, the randomization test fits nicely with the structure of the experiment and is presented here.

21.1 Randomization test for the mean paired difference

Consider an experiment done to measure whether tire brand Smooth Turn or tire brand Quick Spin has longer tread wear (in cm). That is, after 1,000 miles on a car, which brand of tires has more tread, on average?

21.1.1 Observed data

The observed data represent 25 tread measurements (in cm) taken on 25 tires of Smooth Turn and 25 tires of Quick Spin. The study used a total of 25 cars, so on each car, one tire was of Smooth Turn and one was of Quick Spin. The mean tread for the Quick Spin tires was 0.308 cm and the mean tread for the Smooth Turn tires was 0.310 cm. Figure 21.1 presents the observed data, calculations on tread remaining (in cm).

The Smooth Turn manufacturer looks at the box plots and says:

Clearly the tread on Smooth Turn tires is higher, on average, than the tread on Quick Spin tires after 1,000 miles of driving.

The Quick Spin manufacturer is skeptical and retorts:

But with only 25 cars, it seems that the variability in road conditions (sometimes one tire hits a pothole, etc.) could be what leads to the small difference in average tread amount.

Box plots of the amount of tire tread for each of the two brands of tires with data values superimposed over the box plots. Each superimposed dot represents a car that drove with both types of tires. A grey line connects each car across the two box plots indicating that Smooth Turn has more tire wear than Quick Spin.
Figure 21.1: Box plots of the tire tread data (in cm) and the brand of tire from which the original measurements came.

We’d like to be able to systematically distinguish between what the Smooth Turn manufacturer sees in the plot and what the Quick Spin manufacturer sees in the plot. Fortunately for us, we have an excellent way to simulate the natural variability (from road conditions, etc.) that can lead to tires being worn at different rates.

21.1.2 Variability of the statistic

A randomization test will identify whether the differences seen in the box plot of the original data in Figure 21.1 could have happened just by chance variability. As before, we will simulate the variability in the study under the assumption that the null hypothesis is true. In this study, the null hypothesis is that average tire tread wear is the same across Smooth Turn and Quick Spin tires.

  • \(H_0: \mu_{diff} = 0,\) the average tread wear is the same for the two tire brands.
  • \(H_A: \mu_{diff} \ne 0,\) the average tread wear is different across the two tire brands.

When observations are paired, the randomization process randomly assigns the tire brand to each of the observed tread values. Note that in the randomization test for the two-sample mean setting (see Section 20.1) the explanatory variable was also randomly assigned to the responses. The change in the paired setting, however, is that the assignment happens within an observational unit (here, a car). Remember, if the null hypothesis is true, it will not matter which brand is put on which tire because the overall tread wear will be the same across pairs.

Figure 21.2 and Figure 21.3 show that the random assignment of group (tire brand) happens within a single car. That is, every single car will still have one tire of each type. In the first randomization, it just so happens that the 4th car’s tire brands were swapped and the 5th car’s tire brands were not swapped.

Line plot connecting the tread for the 4th car in the dataset. The first plot is the original data and the second plot is the permuted data where the groups happened to get permuted randomly.
Figure 21.2: The 4th car: the tire brand was randomly permuted, and in the randomization calculation, the measurements (in cm) ended up in different groups.
Line plot connecting the tread for the 5th car in the dataset. The first plot is the original data and the second plot is the permuted data where the groups happened to stay connected to the original measurements.
Figure 21.3: The 5th car: the tire brand was randomly permuted to stay the same! In the randomization calculation, the measurements (in cm) ended up in the original groups.

We can put the shuffled assignments for all the cars into one plot as seen in Figure 21.4 (b).

Line plot connecting the tread for the all of the cars in the dataset. The first plot is the original data and the second plot is the permuted data where some of the brands are connect to the original tread measurements and some of the brands have been swapped across the two tread measurements, within a car.
(a) Brand of tire is the original brand.
Line plot connecting the tread for the all of the cars in the dataset. The first plot is the original data and the second plot is the permuted data where some of the brands are connect to the original tread measurements and some of the brands have been swapped across the two tread measurements, within a car.
(b) Brand of tire is the shuffled brand assignment.
Figure 21.4: Tire tread (in cm) by brand, original and shuffled. As evidenced by the colors, some of the cars kept their original tire assignments and some cars swapped the tire assignments.

The next step in the randomization test is to sort the brands so that the assigned brand value on the x-axis aligns with the assigned group from the randomization. Figure 21.5 (a) shows the same randomized groups, as seen in Figure 21.4 (b) previously. However, Figure 21.5 (b) sorts the randomized groups so that we can measure the variability across groups as compared to the variability within groups.

Scatterplot of tread on the y axis and tire brand on the x axis. The left panel has the observed tread values matched to the original tire brand for the x axis location. The observations are colored based on the permuted tire brand assigned in the randomization. The right panel has the tread values matched to the permuted tire brand, so some observations have swapped orientation. The observations are also colored by the permuted tire brand assigned in the randomization. In the right panel, the two tire brands seem equivalent with respect to tire wear.
(a) Randomized brand assignment
Scatterplot of tread on the y axis and tire brand on the x axis. The left panel has the observed tread values matched to the original tire brand for the x axis location. The observations are colored based on the permuted tire brand assigned in the randomization. The right panel has the tread values matched to the permuted tire brand, so some observations have swapped orientation. The observations are also colored by the permuted tire brand assigned in the randomization. In the right panel, the two tire brands seem equivalent with respect to tire wear.
(b) Randomized brand assignment sorted by brand.
Figure 21.5: Tire tread (in cm) by brand.

Figure 21.6 presents a second randomization of the data. Notice that the two observations from the same car are linked with a grey line; some of the tread values have been randomly assigned to the other tire brand, while some are still connected to their original tire brands.

Box plots and scatterplot with tire brand on the x-axis and tire tread on the y-axis. The points are assigned to the x-axis brand given by the permutation, but the plot differs from previous figures in that it is a second permutation of the brands. Again, the two permuted brands seem equivalent with respect to tire wear.
Figure 21.6: A second randomization where the brand is randomly swapped (or not) across the two tread wear measurements (in cm) from the same car.

Figure 21.7 presents yet another randomization of the data. Again, the same observations are linked by a grey line, and some of the tread values have been randomly assigned to the opposite tire brand than they were originally (while some are still connected to their original tire brands).

Box plots and scatterplot with tire brand on the x-axis and tire tread on the y-axis. The points are assigned to the x-axis brand given by the permutation, but the plot differs from previous figures in that it is a second permutation of the brands. The additional permutation demonstrates that the box plots continue to change for each permutation yet the tire tread is equivalent across the permuted groups.
Figure 21.7: An additional randomization where the brand is randomly swapped (or not) across the two tread wear measurements (in cm) from the same car.

21.1.3 Observed statistic vs. null statistics

By repeating the randomization process, we can create a distribution of the average of the differences in tire treads, as seen in Figure 21.8. As expected (because the differences were generated under the null hypothesis), the center of the histogram is zero. A line has been drawn at the observed difference which is well outside the majority of the null differences simulated from natural variability by mixing up which the tire received Smooth Turn and which received Quick Spin. Because the observed statistic is so far away from the natural variability of the randomized differences, we are convinced that there is a difference between Smooth Turn and Quick Spin. Our conclusion is that the extra amount of average tire tread in Smooth Turn is due to more than just natural variability: we reject \(H_0\) and conclude that \(\mu_{ST} \ne \mu_{QS}.\)

Histogram of the average difference in tire wear, Quick Spin minus Smooth Turn over 1000 different permutations. The histogram is centered at 0 and spreads to approximately -0.0025 and 0.0025. A red line at approximately 0.002 indicates the observed difference in average trend from the original data.
Figure 21.8: Histogram of 1,000 mean differences with tire brand randomly assigned across the two tread measurements (in cm) per pair.

21.2 Bootstrap confidence interval for the mean paired difference

For both the bootstrap and the mathematical models applied to paired data, the analysis is virtually identical to the one-sample approach given in Chapter 19. The key to working with paired data (for bootstrapping and mathematical approaches) is to consider the measurement of interest to be the difference in measured values across the pair of observations.

21.2.1 Observed data

In an earlier edition of this textbook, we found that Amazon prices were, on average, lower than those of the UCLA Bookstore for UCLA courses in 2010. It’s been several years, and many stores have adapted to the online market, so we wondered, how is the UCLA Bookstore doing today?

We sampled 201 UCLA courses. Of those, 68 required books could be found on Amazon. A portion of the dataset from these courses is shown in Table 21.2, where prices are in US dollars.

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

Table 21.2: Four cases from the ucla_textbooks_f18 dataset.
subject course_num bookstore_new amazon_new price_diff
American Indian Studies M10 48.0 47.5 0.52
Anthropology 2 14.3 13.6 0.71
Arts and Architecture 10 13.5 12.5 0.97
Asian M60W 49.3 55.0 -5.69

Each textbook has two corresponding prices in the dataset: one for the UCLA Bookstore and one for Amazon. When two sets of observations have this special correspondence, they are said to be paired.

21.2.2 Variability of the statistic

Following the example of bootstrapping the one-sample statistic, the observed differences can be bootstrapped in order to understand the variability of the average difference from sample to sample. Remember, the differences act as a single value to bootstrap. That is, the original dataset would include the list of 68 price differences, and each resample will also include 68 price differences (some repeated through the bootstrap resampling process). The bootstrap procedure for paired differences is quite similar to the procedure applied to the one-sample statistic case in Section 19.1.

In Figure 21.9, two 99% confidence intervals for the difference in the cost of a new book at the UCLA bookstore compared with Amazon have been calculated. The bootstrap percentile confidence interval is computed using the 0.5 percentile and 99.5 percentile bootstrapped differences and is found to be ($0.25, $7.87).

Using the histogram of bootstrapped difference in means, estimate the standard error of the mean of the sample differences, \(\bar{x}_{diff}.\)1

The bootstrap SE interval is found by computing the SE of the bootstrapped differences \((SE_{\overline{x}_{diff}} = \$1.64)\) and the normal multiplier of \(z^{\star} = 2.58.\) The averaged difference is \(\bar{x} = \$3.58.\) The 99% confidence interval is: \(\$3.58 \pm 2.58 \times \$ 1.64 = (\$-0.65, \$7.81).\)

The confidence intervals seem to indicate that the UCLA bookstore price is, on average, higher than the Amazon price, as the majority of the confidence interval is positive. However, if the analysis required a strong degree of certainty (e.g., 99% confidence), and the bootstrap SE interval was most appropriate (given a second course in statistics the nuances of the methods can be investigated), the results of which bookseller is higher are not well determined (because the bootstrap SE interval overlaps zero). That is, the 99% bootstrap SE interval gives potential for UCLA bookstore to be lower, on average, than Amazon (because of the possible negative values for the true mean difference in price).

Histogram showing the distribution of the average bootstrapped difference of price, UCLA minus Amazon. The center of the distribution is given at approximately $3.75. Two bootstrap intervals are given. The percentile interval is approximately $0.25 to $8.50. The SE interval is approximately -$0.50 to $7.75.
Figure 21.9: Bootstrap distribution for the average difference in new book price at the UCLA bookstore versus Amazon. 99% confidence intervals are superimposed using blue dashed (bootstrap percentile interval) and red dotted (bootstrap SE interval) lines.

21.3 Mathematical model for the mean paired difference

Thinking about the differences as a single observation on an observational unit changes the paired setting into the one-sample setting. The mathematical model for the one-sample case is covered in Section 19.2.

21.3.1 Observed data

To analyze paired data, it is often useful to look at the difference in outcomes of each pair of observations. In the textbook data, we look at the differences in prices, which is represented as the price_difference variable in the dataset. Here the differences are taken as

\[\text{UCLA Bookstore price} - \text{Amazon price}\]

It is important that we always subtract using a consistent order; here Amazon prices are always subtracted from UCLA prices. The first difference shown in Table 21.2 is computed as \(47.97 - 47.45 = 0.52.\) Similarly, the second difference is computed as \(14.26 - 13.55 = 0.71,\) and the third is \(13.50 - 12.53 = 0.97.\) A histogram of the differences is shown in Figure 21.10.

 

Histogram of the differences in prices for each book samples, UCLA minus Amazon. The prices differences range from -$10 to $80 with a strong right skew.
Figure 21.10: Histogram of the differences in prices for each book sampled.

21.3.2 Variability of the statistic

To analyze a paired dataset, we simply analyze the differences. Table 21.3 provides the data summaries from the textbook data. Note that instead of reporting the prices separately for UCLA and Amazon, the summary statistics are given by the mean of the differences, the standard deviation of the differences, and the total number of pairs (i.e., differences). The parameter of interest is also a single value, \(\mu_{diff},\) so we can use the same \(t\)-distribution techniques we applied in Section 19.2 directly onto the observed differences.

Table 21.3: Summary statistics for the 68 price differences.
n Mean SD
68 3.58 13.4

Set up a hypothesis test to determine whether, on average, there is a difference between Amazon’s price for a book and the UCLA bookstore’s price. Also, check the conditions for whether we can move forward with the test using the \(t\)-distribution.


We are considering two scenarios:

  • \(H_0:\) \(\mu_{diff} = 0.\) There is no difference in the average textbook prices.

  • \(H_A:\) \(\mu_{diff} \neq 0.\) There is a difference in average prices.

Next, we check the independence and normality conditions. This is a simple random sample, so assuming the textbooks are independent seems reasonable. While there are some outliers, \(n = 68\) and none of the outliers are particularly extreme, so the normality of \(\bar{x}\) is satisfied. With these conditions satisfied, we can move forward with the \(t\)-distribution.

21.3.3 Observed statistic vs. null statistics

As mentioned previously, the methods applied to a difference will be identical to the one-sample techniques. Therefore, the full hypothesis test framework is presented as guided practices.

The test statistic for assessing a paired mean is a T.

The T score is a ratio of how the sample mean difference varies from zero as compared to how the observations vary.

\[T = \frac{\bar{x}_{diff} - 0 }{s_{diff}/\sqrt{n_{diff}}}\]

When the null hypothesis is true and the conditions are met, T has a t-distribution with \(df = n_{diff} - 1.\)

Conditions:

  • Independently sampled pairs.
  • Large samples and no extreme outliers.

Complete the hypothesis test started in the previous Example.


To compute the test compute the standard error associated with \(\bar{x}_{diff}\) using the standard deviation of the differences \((s_{diff} = 13.42)\) and the number of differences \((n_{diff} = 68):\)

\[SE_{\bar{x}_{diff}} = \frac{s_{diff}}{\sqrt{n_{diff}}} = \frac{13.42}{\sqrt{68}} = 1.63\]

The test statistic is the T score of \(\bar{x}_{diff}\) under the null hypothesis that the true mean difference is 0:

\[T = \frac{\bar{x}_{diff} - 0}{SE_{\bar{x}_{diff}}} = \frac{3.58 - 0}{1.63} = 2.20\]

To visualize the p-value, the sampling distribution of \(\bar{x}_{diff}\) is drawn as though \(H_0\) is true, and the p-value is represented by the two shaded tails in the figure below. The degrees of freedom is \(df = 68 - 1 = 67.\) Using statistical software, we find the one-tail area of 0.0156.

Doubling this area gives the p-value: 0.0312. Because the p-value is less than 0.05, we reject the null hypothesis. The data provide evidence that Amazon prices are different, on average, than the UCLA Bookstore prices for UCLA courses.

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

Margin of error for \(\bar{x}_{diff}.\)

The margin of error is \(t^\star_{df} \times s_{diff}/\sqrt{n_{diff}}\) where \(t^\star_{df}\) is calculated from a specified percentile on the t-distribution with df degrees of freedom.

Create a 95% confidence interval for the average price difference between books at the UCLA bookstore and books on Amazon.


Conditions have already been verified and the standard error computed in a previous Example.
To find the confidence interval, identify \(t^{\star}_{67}\) using statistical software or the \(t\)-table \((t^{\star}_{67} = 2.00),\) and plug it, the point estimate, and the standard error into the confidence interval formula:

\[ \begin{aligned} \text{point estimate} \ &\pm \ t^{\star}_{67} \ \times \ SE \\ 3.58 \ &\pm \ 2.00 \ \times \ 1.63 \\ (0.32 \ &, \ 6.84) \end{aligned} \]

We are 95% confident that the UCLA Bookstore is, on average, between $0.32 and $6.84 more expensive than Amazon for UCLA course books.

We have convincing evidence that Amazon is, on average, less expensive. How should this conclusion affect UCLA student buying habits? Should UCLA students always buy their books on Amazon?2

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

21.4 Chapter review

21.4.1 Summary

Like the two independent sample procedures in Chapter 20, the paired difference analysis can be done using a t-distribution. The randomization test applied to the paired differences is slightly different, however. Note that when randomizing under the paired setting, each null statistic is created by randomly assigning the group to a numerical outcome within the individual observational unit. The procedure for creating a confidence interval for the paired difference is almost identical to the confidence intervals created in Chapter 19 for a single mean.

21.4.2 Terms

The terms introduced in this chapter are presented in Table 21.4. 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 21.4: Terms introduced in this chapter.
bootstrap CI paired difference paired difference CI T score paired difference
paired data paired difference t-test

21.5 Exercises

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

  1. Air quality. Air quality measurements were collected in a random sample of 25 country capitals in 2013, and then again in the same cities in 2014. We would like to use these data to compare average air quality between the two years. Should we use a paired or non-paired test? Explain your reasoning.
  1. True / False: paired. Determine if the following statements are true or false. If false, explain.

    1. In a paired analysis we first take the difference of each pair of observations, and then we do inference on these differences.

    2. Two datasets of different sizes cannot be analyzed as paired data.

    3. Consider two sets of data that are paired with each other. Each observation in one dataset has a natural correspondence with exactly one observation from the other dataset.

    4. Consider two sets of data that are paired with each other. Each observation in one dataset is subtracted from the average of the other dataset’s observations.

  1. Paired or not? I. In each of the following scenarios, determine if the data are paired.

    1. Compare pre- (beginning of semester) and post-test (end of semester) scores of students.

    2. Assess gender-related salary gap by comparing salaries of randomly sampled men and women.

    3. Compare artery thicknesses at the beginning of a study and after 2 years of taking Vitamin E for the same group of patients.

    4. Assess effectiveness of a diet regimen by comparing the before and after weights of subjects.

  1. Paired or not? II. In each of the following scenarios, determine if the data are paired.

    1. We would like to know if Intel’s stock and Southwest Airlines’ stock have similar rates of return. To find out, we take a random sample of 50 days, and record Intel’s and Southwest’s stock on those same days.

    2. We randomly sample 50 items from Target stores and note the price for each. Then we visit Walmart and collect the price for each of those same 50 items.

    3. A school board would like to determine whether there is a difference in average SAT scores for students at one high school versus another high school in the district. To check, they take a simple random sample of 100 students from each high school.

  1. Sample size and pairing. Determine if the following statement is true or false, and if false, explain your reasoning: If comparing means of two groups with equal sample sizes, always use a paired test.
  1. High School and Beyond, randomization test. The National Center of Education Statistics conducted a survey of high school seniors, collecting test data on reading, writing, and several other subjects. Here we examine a simple random sample of 200 students from this survey.

    Side-by-side box plots of reading and writing scores as well as a histogram of the differences in scores are shown below. Also provided below is a histogram of randomized averages of paired differences of scores (read - write), with the observed difference (\(\bar{x}_{read-write} = -0.545\)) marked with a red vertical line. The randomization distribution was produced by doing the following 1000 times: for each student, the two scores were randomly assigned to either read or write, and the average was taken across all students in the sample.3

    1. Is there a clear difference in the average reading and writing scores?

    2. Are the reading and writing scores of each student independent of each other?

    3. Create hypotheses appropriate for the following research question: is there an evident difference in the average scores of students in the reading and writing exam?

    4. Is the average of the observed difference in scores \((\bar{x}_{read-write} = -0.545)\) consistent with the distribution of randomized average differences? Explain.

    5. Do these data provide convincing evidence of a difference between the average scores on the two exams? Estimate the p-value from the randomization test, and conclude the hypothesis test using words like “score on reading test” and “score on writing test.”

  1. Global warming, randomization test. Let’s consider a limited set of climate data, examining temperature differences in 1950 vs 2022. We sampled 26 locations in the US from the National Oceanic and Atmospheric Administration’s (NOAA) historical data, where the data was available for both years of interest. (NOAA 2023) The data are not a random sample, but they are selected to be a representative sample across the land area of the lower 48 United States. Using the hottest day of the year as a measure can make the results susceptible to outliers. Instead, to get a sense for how hot a year was, we calculate the 90\(^{th}\) percentile; that is, we find the maximum temperature on the day that was hotter than 90% of the days that year. We want to know: is the 90\(^{th}\) percentile high temperature greater in 2022 or in 1950? The difference in 90\(^{th}\) percentile high temperature (high temperature for 2022 - high temperature for 1950) was calculated for each of the 26 locations. The average of the 26 differences was 2.52\(^\circ\)F with a standard deviation of 2.95\(^\circ\)F. We are interested in determining whether these data provide strong evidence that the 90\(^{th}\) percentile high temperature is higher in 2022 than in 1950.4

     

    1. Create hypotheses appropriate for the following research question: is there an evident difference in the 90\(^{th}\) percentile high temp across the two years (1950 and 2022)?

    2. Is the average of the observed difference in scores \((\bar{x}_{2022-1950} = 2.53\)^\(F)\) consistent with the distribution of randomized average differences? Explain.

     

    1. Do these data provide convincing evidence of a difference between the 90\(^{th}\) percentile high temperature? Estimate the p-value from the randomization test, and conclude the hypothesis test using words like “90\(^{th}\) percentile high temperature in 1950” and “90\(^{th}\) percentile high temperature in 2022.”
  1. High School and Beyond, bootstrap interval. We considered the differences between the reading and writing scores of a random sample of 200 students who took the High School and Beyond Survey. The mean and standard deviation of the differences are \(\bar{x}_{read-write} = -0.545\) and \(s_{read-write}\) = 8.887 points. The bootstrap distribution below was produced by bootstrapping from the sample of differences in reading and writing scores 1,000 times.

     

    1. Find an approximate 95% bootstrap percentile confidence interval for the true average difference in scores (read - write).

    2. Find an approximate 95% bootstrap SE confidence interval for the true average difference in scores (read - write).

     

    1. Interpret both confidence intervals using words like “population” and “score”.

    2. From the confidence intervals calculated above, does it appear that there is a discernible difference in reading and writing scores, on average?

  1. Global warming, bootstrap interval. We considered the change in the 90\(^{th}\) percentile high temperature in 1950 versus 2022 at 26 sampled locations from the NOAA database. (NOAA 2023) The mean and standard deviation of the reported differences are 2.53\(^\circ\)F and 2.95\(^\circ\)F.

    1. Calculate a 90% bootstrap percentile confidence interval for the average difference of 90\(^{th}\) percentile high temperature between 1950 and 2022.

    2. Calculate a 90% bootstrap SE confidence interval for the average difference of 90\(^{th}\) percentile high temperature between 1950 and 2022.

    3. Interpret both intervals in context.

    4. Do the confidence intervals provide convincing evidence that there were hotter high temperatures in 2022 than in 1950 at NOAA stations? Explain your reasoning.

  1. High School and Beyond, mathematical test. We considered the differences between the reading and writing scores of a random sample of 200 students who took the High School and Beyond Survey.

    1. Create hypotheses appropriate for the following research question: is there an evident difference in the average scores of students in the reading and writing exam?

    2. Check the conditions required to complete this test.

    3. The average observed difference in scores is \(\bar{x}_{read-write} = -0.545\), and the standard deviation of the differences is \(s_{read-write} = 8.887\) points. Do these data provide convincing evidence of a difference between the average scores on the two exams?

    4. What type of error might we have made? Explain what the error means in the context of the application.

    5. Based on the results of this hypothesis test, would you expect a confidence interval for the average difference between the reading and writing scores to include 0? Explain your reasoning.

  1. Global warming, mathematical test. We considered the change in the 90\(^{th}\) percentile high temperature in 1950 versus 2022 at 26 sampled locations from the NOAA database. (NOAA 2023) The mean and standard deviation of the reported differences are 2.53\(^\circ\)F and 2.95\(^\circ\)F.

     

    1. Is there a relationship between the observations collected in 1950 and 2022? Or are the observations in the two groups independent? Explain your reasoning.

    2. Write hypotheses for this research in symbols and in words.

    3. Check the conditions required to complete this test.

     

    1. Calculate the test statistic and find the p-value.

    2. Use \(\alpha = 0.05\) to evaluate the test, and interpret your conclusion in context.

    3. What type of error might we have made? Explain in context what the error means.

    4. Based on the results of this hypothesis test, would you expect a confidence interval for the average difference between the 90\(^{th}\) percentile high temperture from 1950 to 2022 to include 0? Explain your reasoning.

  2. High school and beyond, mathematical interval. We considered the differences between the reading and writing scores of a random sample of 200 students who took the High School and Beyond Survey. The mean and standard deviation of the differences are \(\bar{x}_{read-write} = -0.545\) and \(s_{read-write}\) = 8.887 points.

    1. Calculate a 95% confidence interval for the average difference between the reading and writing scores of all students.

    2. Interpret this interval in context.

    3. Does the confidence interval provide convincing evidence that there is a real difference in the average scores? Explain.

  3. Global warming, mathematical interval. We considered the change in the 90\(^{th}\) percentile high temperature in 1950 versus 2022 at 26 sampled locations from the NOAA database. (NOAA 2023) The mean and standard deviation of the reported differences are 2.53\(^\circ\)F and 2.95\(^\circ\)F.

    1. Calculate a 90% confidence interval for the average difference of 90\(^{th}\) percentile high temperature between 1950 and 2022. We’ve already checked the conditions for you.

    2. Interpret the interval in context.

    3. Does the confidence interval provide convincing evidence that there were hotter high temperatures in 2022 than in 1950 at NOAA stations? Explain your reasoning.

  4. Possible paired randomized differences. Two observations were collected on each of five people. Which of the following could be a possible randomization of the paired differences given in the table below? If the set of values could not be a randomized set of differences, indicate why not.

     

    1. -2, 1, 1, 11, -2

    2. -4, 11, -2, 0, 1

    3. -2, 2, -11, 11, -2, 2, 0, 1, -1

    4. 0, -1, 2, -4, 11

    5. 4, -11, 2, 0, -1

     

    People
    1 2 3 4 5
    Observation 1 3 14 4 5 10
    Observation 2 7 3 6 5 9
    Difference -4 11 -2 0 1
  1. Study environment. In order to test the effects of listening to music while studying versus studying in silence, students agree to be randomized to two treatments (i.e., study with music or study in silence). There are two exams during the semester, so the researchers can either randomize the students to have one exam with music and one with silence (randomly selecting which exam corresponds to which study environment) or the researchers can randomize the students to one study habit for both exams.

    The researchers are interested in estimating the true population difference of exam score for those who listen to music while studying as compared to those who study in silence.

    1. Describe the experiment which is consistent with a paired designed experiment. How is the treatment assigned, and how are the data collected such that the observations are paired?

    2. Describe the experiment which is consistent with an indpenedent samples experiment. How is the treatment assigned, and how are the data collected such that the observations are independent?

  1. Friday the 13th, traffic. In the early 1990’s, researchers in the UK collected data on traffic flow on Friday the 13th with the goal of addressing issues of how superstitions regarding Friday the 13th affect human behavior and and whether Friday the 13th is an unlucky day. The histograms below show the distributions of numbers of cars passing by a specific intersection on Friday the 6th and Friday the 13th for many such date pairs. Also provided are some sample statistics, where the difference is the number of cars on the 6th minus the number of cars on the 13th.5 (Scanlon et al. 1993)

    n Mean SD
    sixth 10 128,385 7,259
    thirteenth 10 126,550 7,664
    diff 10 1,836 1,176
    1. Are there any underlying structures in these data that should be considered in an analysis? Explain.

    2. What are the hypotheses for evaluating whether the number of people out on Friday the 6\(^{\text{th}}\) is different than the number out on Friday the 13\(^{\text{th}}\)?

    3. Check conditions to carry out the hypothesis test from part (b) using mathematical models.

    4. Calculate the test statistic and the p-value.

    5. What is the conclusion of the hypothesis test?

    6. Interpret the p-value in this context.

    7. What type of error might have been made in the conclusion of your test? Explain.

  1. Friday the 13th, accidents. In the early 1990’s, researchers in the UK collected data the number of traffic accident related emergency room (ER) admissions on Friday the 13th with the goal of addressing issues of how superstitions regarding Friday the 13th affect human behavior and and whether Friday the 13th is an unlucky day. The histograms below show the distributions of numbers of ER admissions at specific emergency rooms on Friday the 6th and Friday the 13th for many such date pairs. Also provided are some sample statistics, where the difference is the ER admissions on the 6th minus the ER admissions on the 13th.(Scanlon et al. 1993)

    n Mean SD
    sixth 6 8 3
    thirteenth 6 11 4
    diff 6 -3 3
    1. Conduct a hypothesis test using mathematical models to evaluate if there is a difference between the average numbers of traffic accident related emergency room admissions between Friday the 6\(^{\text{th}}\) and Friday the 13\(^{\text{th}}\).

    2. Calculate a 95% confidence interval using mathematical models for the difference between the average numbers of traffic accident related emergency room admissions between Friday the 6\(^{\text{th}}\) and Friday the 13\(^{\text{th}}\).

    3. The conclusion of the original study states, “Friday 13th is unlucky for some. The risk of hospital admission as a result of a transport accident may be increased by as much as 52%. Staying at home is recommended.” Do you agree with this statement? Explain your reasoning.

  1. Forest management. Forest rangers wanted to better understand the rate of growth for younger trees in the park. They took measurements of a random sample of 50 young trees in 2009 and again measured those same trees in 2019. The data below summarize their measurements, where the heights are in feet.

    Year Mean SD n
    2009 12.0 3.5 50
    2019 24.5 9.5 50
    Difference 12.5 7.2 50

    Construct a 99% confidence interval for the average growth of (what had been) younger trees in the park over 2009-2019.


  1. The bootstrapped differences in sample means vary roughly from 0.7 to 7.5, a range of $6.80. Although the bootstrap distribution is not symmetric, we use the empirical rule (that with bell-shaped distributions, most observations are within two standard errors of the center), the standard error of the mean differences is approximately $1.70. You might note that the standard error calculation given in Section 21.3 is \(SE(\bar{x}_{diff}) = \sqrt{s^2_{diff}/n_{diff}} = \sqrt{13.4^2/68} = \$1.62\) (values from Section 21.3), very close to the bootstrap approximation.↩︎

  2. The average price difference is only mildly useful for this question. Examine the distribution shown in Figure 21.10. There are certainly a handful of cases where Amazon prices are far below the UCLA Bookstore’s, which suggests it is worth checking Amazon (and probably other online sites) before purchasing. However, in many cases the Amazon price is above what the UCLA Bookstore charges, and most of the time the price isn’t that different. Ultimately, if getting a book immediately from the bookstore is notably more convenient, e.g., to get started on reading or homework, it’s likely a good idea to go with the UCLA Bookstore unless the price difference on a specific book happens to be quite large. For reference, this is a very different result from what we (the authors) had seen in a similar dataset from 2010. At that time, Amazon prices were almost uniformly lower than those of the UCLA Bookstore’s and by a large margin, making the case to use Amazon over the UCLA Bookstore quite compelling at that time. Now we frequently check multiple websites to find the best price.↩︎

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

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

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

中文

21  比较配对均值的推断

第 20 分析的目的是比较两个不同组的总体平均值。回顾一下,进行两样本分析的一个重要条件是两组相互独立。这里,组间的独立性意味着了解其中一组的观测值不会改变我们对另一组结果的预期。但如果两组是 因变量的呢?有时依赖性是无法通过统计方法解决的。然而,有一种特殊的依赖性,即 配对,可以利用本教材中已经介绍的许多相同工具进行非常有效的建模。

配对数据代表一种特殊的实验结构,其分析在某种程度上类似于单样本分析(见 第 19),但又具有类似于两样本分析的其他特征(见 第 20)。与两样本分析一样,对解释变量的两个不同水平分别进行定量测量。然而,由于观测单元在两组之间是 配对 ,因此将两个测量值相减,只保留差值。 表 21.1 展示了一些采用配对设计的研究示例。

表 21.1:使用配对设计来测量两种条件下测量值差异的研究示例。
观测单元 比较组 测量 感兴趣的值
汽车 平滑转弯 vs 快速旋转 行驶1,000英里后的轮胎胎面深度 胎面深度差异
教科书 UCLA vs Amazon 新教科书的价格 价格差异
个人 课前 vs 课后 考试分数 分数差异

配对数据。

两组观测值是 配对 如果一个数据集中的每个观测值与另一个数据集中恰好一个观测值有特殊的对应关系或联系。

值得注意的是,如果选择数学建模作为分析工具,对测量值差异的配对数据推断将与 第 19中描述的单样本数学技术完全相同。然而,回顾 第 19 ,对于纯单样本数据,假设检验的计算工具并不容易实现,因此未予介绍(尽管自助法已被介绍为构建单样本置信区间的一种计算方法)。而对于配对数据,随机化检验与实验结构非常契合,因此在此予以介绍。

21.1 配对差值均值的随机化检验

考虑一项实验,用于测量轮胎品牌 Smooth Turn 和轮胎品牌 Quick Spin 哪个的胎面磨损(单位:cm)更长。也就是说,在汽车行驶 1,000 英里后,平均而言哪个品牌的轮胎剩余胎面更多?

21.1.1 观测数据

观测数据包括对 25 条 Smooth Turn 轮胎和 25 条 Quick Spin 轮胎测得的 25 个胎面测量值(单位:cm)。该研究共使用了 25 辆汽车,因此每辆车上有一条 Smooth Turn 轮胎和一条 Quick Spin 轮胎。Quick Spin 轮胎的平均胎面为 0.308 cm,Smooth Turn 轮胎的平均胎面为 0.310 cm。 图 21.1 展示了观测数据以及剩余胎面(单位:cm)的计算结果。

Smooth Turn 的制造商看着箱线图说:

显然,在行驶 1,000 英里后,Smooth Turn 轮胎的平均胎面高于 Quick Spin 轮胎的平均胎面。

Quick Spin 的制造商对此表示怀疑并反驳道:

但只有 25 辆车,路况的变异性(有时一条轮胎会撞到坑洼等)似乎可能才是导致平均胎面量出现微小差异的原因。

Box plots of the amount of tire tread for each of the two brands of tires with data values superimposed over the box plots. Each superimposed dot represents a car that drove with both types of tires. A grey line connects each car across the two box plots indicating that Smooth Turn has more tire wear than Quick Spin.
图 21.1:轮胎胎面数据(单位:cm)的箱线图,以及原始测量值所来自的轮胎品牌。

我们希望能够系统地区分 Smooth Turn 制造商在图中看到的内容与 Quick Spin 制造商在图中看到的内容。对我们来说幸运的是,我们有一种极好的方法来模拟自然变异性(来自路况等),这种变异性可能导致轮胎以不同的速率磨损。

21.1.2 统计量的变异性

随机化检验将确定 图 21.1 可能仅由随机变异造成。与之前一样,我们将在原假设为真的假设下模拟研究中的变异性。在本研究中,原假设是 Smooth Turn 和 Quick Spin 轮胎的平均胎面磨损相同。

  • \(H_0: \mu_{diff} = 0,\) 两个轮胎品牌的平均胎面磨损相同。
  • \(H_A: \mu_{diff} \ne 0,\) 两个轮胎品牌的平均胎面磨损不同。

当观测值成对出现时,随机化过程会将轮胎品牌随机分配给每个观测到的胎面值。注意,在两样本均值情形的随机化检验中(见 Section 20.1),解释变量 被随机分配给了响应变量。然而,配对情形的变化在于,分配发生在 之内 同一个观测单元(此处为一辆车)之内。请记住,如果原假设为真,那么哪个品牌装在哪个轮胎上并不重要,因为每对的总胎面磨损将是相同的。

图 21.2图 21.3 表明组别(轮胎品牌)的随机分配发生在同一辆车之内。也就是说,每辆车仍然各有一个每种类型的轮胎。在第一次随机化中,恰好第 4 辆车的轮胎品牌被交换了,而第 5 辆车的轮胎品牌没有被交换。

Line plot connecting the tread for the 4th car in the dataset. The first plot is the original data and the second plot is the permuted data where the groups happened to get permuted randomly.
图 21.2:第 4 辆车:轮胎品牌被随机置换,在随机化计算中,测量值(单位:cm)最终进入了不同的组。
Line plot connecting the tread for the 5th car in the dataset. The first plot is the original data and the second plot is the permuted data where the groups happened to stay connected to the original measurements.
图 21.3:第 5 辆车:轮胎品牌被随机置换后保持不变!在随机化计算中,测量值(单位:cm)最终进入了原来的组。

我们可以把所有汽车打乱后的分配放入一张图中,如 图 21.4 (b).

Line plot connecting the tread for the all of the cars in the dataset. The first plot is the original data and the second plot is the permuted data where some of the brands are connect to the original tread measurements and some of the brands have been swapped across the two tread measurements, within a car.
所示。
Line plot connecting the tread for the all of the cars in the dataset. The first plot is the original data and the second plot is the permuted data where some of the brands are connect to the original tread measurements and some of the brands have been swapped across the two tread measurements, within a car.
(a) 轮胎品牌为原始品牌。
(b) 轮胎品牌为打乱后的品牌分配。

随机化检验的下一步是对品牌进行排序,使 x 轴上分配的品牌值与随机化分配的组对齐。 图 21.5 (a) 展示了与之前 图 21.4 (b) 中相同的随机化分组。然而, 图 21.5 (b) 对随机化分组进行了排序,以便我们可以测量 组间 的变异性,并与 之内 组内变异性进行比较。

Scatterplot of tread on the y axis and tire brand on the x axis. The left panel has the observed tread values matched to the original tire brand for the x axis location. The observations are colored based on the permuted tire brand assigned in the randomization. The right panel has the tread values matched to the permuted tire brand, so some observations have swapped orientation. The observations are also colored by the permuted tire brand assigned in the randomization. In the right panel, the two tire brands seem equivalent with respect to tire wear.
(a) 随机化的品牌分配
Scatterplot of tread on the y axis and tire brand on the x axis. The left panel has the observed tread values matched to the original tire brand for the x axis location. The observations are colored based on the permuted tire brand assigned in the randomization. The right panel has the tread values matched to the permuted tire brand, so some observations have swapped orientation. The observations are also colored by the permuted tire brand assigned in the randomization. In the right panel, the two tire brands seem equivalent with respect to tire wear.
(b) 按品牌排序的随机化品牌分配。
图 21.5:按品牌划分的轮胎胎面(单位:cm)。

图 21.6 展示了数据的第二次随机化。请注意,来自同一辆车的两个观测值用灰线连接;一些胎面值被随机分配给了另一个轮胎品牌,而一些仍与其原始轮胎品牌相连。

Box plots and scatterplot with tire brand on the x-axis and tire tread on the y-axis. The points are assigned to the x-axis brand given by the permutation, but the plot differs from previous figures in that it is a second permutation of the brands. Again, the two permuted brands seem equivalent with respect to tire wear.
图 21.6:第二次随机化,其中品牌在同一辆车的两个胎面磨损测量值(单位:cm)之间被随机交换(或不交换)。

图 21.7 展示了数据的又一次随机化。同样,相同的观测值用灰线连接,一些胎面值被随机分配给了与原来相反的轮胎品牌(而一些仍与其原始轮胎品牌相连)。

Box plots and scatterplot with tire brand on the x-axis and tire tread on the y-axis. The points are assigned to the x-axis brand given by the permutation, but the plot differs from previous figures in that it is a second permutation of the brands. The additional permutation demonstrates that the box plots continue to change for each permutation yet the tire tread is equivalent across the permuted groups.
图 21.7:额外的随机化,其中品牌在同一辆车的两个胎面磨损测量值(单位:厘米)之间随机交换(或不交换)。

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

通过重复随机化过程,我们可以创建轮胎胎面差异平均值的分布,如 图 21.8所示。正如预期的那样(因为差异是在原假设下生成的),直方图的中心为零。在观察到的差异处画了一条线,该差异远超出了通过混淆哪个轮胎使用 Smooth Turn、哪个轮胎使用 Quick Spin 而从自然变异性中模拟出的大多数原假设差异。由于观察到的统计量与随机化差异的自然变异性相距甚远,我们确信 Smooth Turn 和 Quick Spin 之间存在差异。我们的结论是,Smooth Turn 平均轮胎胎面的额外数量不仅仅是自然变异性造成的:我们拒绝 \(H_0\) ,并得出结论认为 \(\mu_{ST} \ne \mu_{QS}.\)

Histogram of the average difference in tire wear, Quick Spin minus Smooth Turn over 1000 different permutations. The histogram is centered at 0 and spreads to approximately -0.0025 and 0.0025. A red line at approximately 0.002 indicates the observed difference in average trend from the original data.
图 21.8:1,000 个平均差异的直方图,其中轮胎品牌在每对的两个胎面测量值(单位:厘米)之间随机分配。

21.2 配对差异均值的自助法置信区间

对于应用于配对数据的自助法和数学模型,其分析与 第 19中给出的单样本方法几乎完全相同。处理配对数据(自助法和数学方法)的关键是将所关注的测量视为每对观测值之间测量值的差异。

21.2.1 观测数据

在本教科书的早期版本中,我们发现 2010 年 UCLA 课程的 Amazon 价格平均低于 UCLA Bookstore 的价格。已经过去多年,许多商店已经适应了在线市场,所以我们想知道,UCLA Bookstore 如今的表现如何?

我们抽样了 201 门 UCLA 课程。其中,68 门所需教材可以在 Amazon 上找到。这些课程数据集的一部分显示在 表 21.2中,价格以美元计。

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

表 21.2:来自 ucla_textbooks_f18 数据集的最后五行。
受试者 的四个案例。 course_num bookstore_new amazon_new
美洲印第安人研究 M10 48.0 47.5 0.52
人类学 2 14.3 13.6 0.71
艺术与建筑 10 13.5 12.5 0.97
亚洲 M60W 49.3 55.0 -5.69

在数据集中,每本教科书有两个对应的价格:一个是UCLA书店的价格,一个是亚马逊的价格。当两组观测值具有这种特殊对应关系时,它们被称为 配对.

21.2.2 统计量的变异性

遵循对单样本统计量进行自助法(bootstrap)的示例,观测到的 差异 可以进行自助法重抽样,以了解样本之间平均差异的变异性。请记住,差异作为一个单一值进行自助法重抽样。也就是说,原始数据集将包含68个价格差异的列表,每次重抽样也将包含68个价格差异(其中一些通过自助法重抽样过程重复出现)。配对差异的自助法程序与 第19.1节.

图 21.9中应用于单样本统计量情形的程序非常相似,我们已经计算了UCLA书店与亚马逊新书价格差异的两个99%置信区间。自助法百分位置信区间使用0.5百分位和99.5百分位的自助法差异计算得出,结果为($0.25, $7.87)。

使用自助法均值差异的直方图,估计样本差异均值的标准误, \(\bar{x}_{diff}.\)1

自助法SE区间通过计算自助法差异的标准误 \((SE_{\overline{x}_{diff}} = \$1.64)\) 以及正态乘数 \(z^{\star} = 2.58.\) 平均差为 \(\bar{x} = \$3.58.\) 99%置信区间为: \(\$3.58 \pm 2.58 \times \$ 1.64 = (\$-0.65, \$7.81).\)

置信区间似乎表明UCLA书店的价格平均高于Amazon的价格,因为置信区间的大部分为正值。然而,如果分析需要较高的确定性程度(例如99%的置信度),且自助法SE区间是最合适的(鉴于统计学第二门课程可以研究这些方法的细微差别),那么哪个书商价格更高的结果并不能很好地确定(因为自助法SE区间与零重叠)。也就是说,99%自助法SE区间给出了UCLA书店价格平均低于Amazon的可能性(因为真实平均价格差可能为负值)。

Histogram showing the distribution of the average bootstrapped difference of price, UCLA minus Amazon. The center of the distribution is given at approximately $3.75. Two bootstrap intervals are given. The percentile interval is approximately $0.25 to $8.50. The SE interval is approximately -$0.50 to $7.75.
图21.9:UCLA书店与Amazon新书平均价格差的自助法分布。图中叠加了99%置信区间,蓝色虚线(自助法百分位区间)和红色点线(自助法SE区间)。

21.3 平均配对差的数学模型

将差值视为观测单元上的单个观测值,会把配对设置转变为单样本设置。单样本情形的数学模型在 第 19.2 节.

21.3.1 观测数据

中介绍。要分析配对数据,通常有用的方法是查看每对观测值结果的差值。在教科书数据中,我们查看价格的差值,在数据集中表示为 price_difference 变量。这里的差值取为

\[\text{UCLA Bookstore price} - \text{Amazon price}\]

重要的是,我们始终按照一致的顺序进行相减;这里始终用UCLA价格减去Amazon价格。 表 21.2 总平方和 \(47.97 - 47.45 = 0.52.\) 中显示的第一个差值计算为 \(14.26 - 13.55 = 0.71,\) 类似地,第二个差值计算为 \(13.50 - 12.53 = 0.97.\) 第三个是 图 21.10.

 

Histogram of the differences in prices for each book samples, UCLA minus Amazon. The prices differences range from -$10 to $80 with a strong right skew.
差值的直方图如

21.3.2 统计量的变异性

所示。 图21.10:每本抽样书籍价格差的直方图。 表 21.3 要分析配对数据集,我们只需分析差值即可。 \(\mu_{diff},\) 提供了教科书数据的汇总信息。请注意,汇总统计量不是分别报告UCLA和Amazon的价格,而是给出差值的均值、差值的标准差以及配对(即差值)的总数。感兴趣的参数也是单个值,即 μdiff,因此我们可以使用相同的 \(t\)-我们在 中应用的分布技术, 第 19.2 节 直接作用于观察到的差异上。

表 21.3:68 个价格差的汇总统计量。
n 平均数 标准差
68 3.58 13.4

建立一个假设检验,以确定平均而言亚马逊的图书价格与 UCLA 书店的价格是否存在差异。同时,检查是否可以使用 检验继续进行检验的条件。 \(t\)分布。


我们考虑两种情形:

  • \(H_0:\) \(\mu_{diff} = 0.\) 教科书的平均价格没有差异。

  • \(H_A:\) \(\mu_{diff} \neq 0.\) 平均价格存在差异。

接下来,我们检查独立性和正态性条件。这是一个简单随机样本,因此假设教科书相互独立似乎是合理的。虽然存在一些离群值, \(n = 68\) 且没有特别极端的离群值,因此 的正态性条件得到满足。在这些条件都满足的情况下,我们可以继续进行 \(\bar{x}\) 如前所述,应用于差值的方法与单样本技术完全相同。因此,完整的假设检验框架将以引导练习的形式呈现。 \(t\)分布。

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

评估配对均值的检验统计量是 T。

T 分数是一个比值,衡量样本均值差相对于零的偏离程度与观测值变异程度的比较。

独立抽样的配对。

\[T = \frac{\bar{x}_{diff} - 0 }{s_{diff}/\sqrt{n_{diff}}}\]

当原假设为真且条件满足时,T 服从自由度为 \(df = n_{diff} - 1.\)

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

  • 完成上一个示例中开始的假设检验。
  • 的 t 分布。

要计算该检验,需计算与 相关的标准误。


为完成检验,使用差值的标准差 \((s_{diff} = 13.42)\) 和差值数量 \((n_{diff} = 68)\),计算与 \(\bar{x}_{diff}\) 对应的标准误:

\[SE_{\bar{x}_{diff}} = \frac{s_{diff}}{\sqrt{n_{diff}}} = \frac{13.42}{\sqrt{68}} = 1.63\]

检验统计量是 \(\bar{x}_{diff}\) 的 T 分数,原假设为真实平均差为 0:

\[T = \frac{\bar{x}_{diff} - 0}{SE_{\bar{x}_{diff}}} = \frac{3.58 - 0}{1.63} = 2.20\]

为了将 p 值可视化,将 \(\bar{x}_{diff}\) 的抽样分布绘制成 \(H_0\) 为真的情形,p 值由下图中两个阴影尾部表示。自由度为 \(df = 68 - 1 = 67.\) 使用统计软件,我们得到单尾面积为 0.0156。

将该面积乘以 2 得到 p 值:0.0312。由于 p 值小于 0.05,我们拒绝原假设。数据提供了证据,表明对于 UCLA 的课程教材,Amazon 的价格平均而言与 UCLA Bookstore 的价格不同。

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

误差幅度(针对 \(\bar{x}_{diff}.\)

误差幅度为 \(t^\star_{df} \times s_{diff}/\sqrt{n_{diff}}\) ,其中 \(t^\star_{df}\) 由自由度为 df 的t分布上的指定分位数计算得出。

为 UCLA Bookstore 与 Amazon 书籍的平均价格差构建一个 95% 置信区间。


条件已在前面验证过,标准误也在之前的示例中计算得出。
为了求置信区间,使用统计软件或 \(t\) 分布表确定 \(t^{\star}_{67}\)\(t^{\star}_{67} = 2.00\)),再将其与点估计值、标准误代入置信区间公式:

\[ \begin{aligned} \text{point estimate} \ &\pm \ t^{\star}_{67} \ \times \ SE \\ 3.58 \ &\pm \ 2.00 \ \times \ 1.63 \\ (0.32 \ &, \ 6.84) \end{aligned} \]

我们有 95% 的把握认为,对于 UCLA 的课程教材,UCLA Bookstore 平均而言比 Amazon 贵 0.32 美元至 6.84 美元。

我们有令人信服的证据表明,亚马逊平均而言价格更低。这一结论应如何影响加州大学洛杉矶分校(UCLA)学生的购书习惯?UCLA 学生是否应该总是在亚马逊上购买教材?2

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

21.4 本章复习

21.4.1 小结

第 20中的两个独立样本方法类似,配对差值分析也可以使用 t 分布来完成。然而,应用于配对差值的随机化检验略有不同。请注意,在配对设置下进行随机化时,每个原假设统计量都是通过将组别随机分配给每个观测单元的数值结果 之内 来构造的。为配对差值构造置信区间的过程与 第 19 中为单个均值构造置信区间的过程几乎完全相同。

21.4.2 术语

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

表 21.4:本章介绍的术语。
bootstrap CI 配对差值 配对差值 CI T score 配对差值
配对数据 配对差值 t 检验

21.5 练习

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

  1. 空气质量。 2013 年,我们在随机抽取的 25 个国家首都收集了空气质量测量数据,随后在 2014 年又对相同的城市进行了收集。我们希望使用这些数据比较两年之间的平均空气质量。我们应该使用配对检验还是非配对检验?请解释你的理由。
  1. 判断 / 错误:配对。 判断以下陈述是对还是错。如果是错的,请解释。

    1. 在配对分析中,我们首先计算每对观测值之间的差值,然后对这些差值进行推断。

    2. 两个大小不同的数据集不能作为配对数据进行分析。

    3. 考虑两组相互配对的数据。一个数据集中的每个观测值与另一个数据集中恰好一个观测值存在自然对应关系。

    4. 考虑两组相互配对的数据。一个数据集中的每个观测值减去另一个数据集观测值的平均值。

  1. 是否配对?I. 在以下每个情境中,判断数据是否配对。

    1. 比较学生的前测(学期初)和后测(学期末)成绩。

    2. 通过比较随机抽取的男性和女性的工资来评估与性别相关的工资差距。

    3. 比较同一组患者研究开始时和服用维生素E 2年后的动脉厚度。

    4. 通过比较受试者前后的体重来评估饮食方案的有效性。

  1. 是否配对?II. 在以下每个情境中,判断数据是否配对。

    1. 我们想知道英特尔的股票和西南航空的股票是否具有相似的回报率。为了找出答案,我们随机抽取50天,并记录这些天英特尔和西南航空的股票情况。

    2. 我们从Target商店随机抽取50件商品并记录每件商品的价格。然后我们访问沃尔玛,收集同样这50件商品的价格。

    3. 某学校董事会想确定学区内一所高中与另一所高中的学生平均SAT成绩是否存在差异。为了进行检验,他们从每所高中各抽取了100名学生的简单随机样本。

  1. 样本量与配对。 判断以下陈述是真是假,如果为假,请解释你的理由:在比较样本量相等的两组均值时,总是应使用配对检验。
  1. High School and Beyond(高中及以后),随机化检验。 美国国家教育统计中心对高中毕业班学生进行了一项调查,收集了阅读、写作以及其他几个科目的测试数据。这里我们检验来自该调查的200名学生的简单随机样本。

    下方展示了阅读和写作成绩的并排箱线图,以及成绩差异的直方图。下方还提供了配对成绩差异(阅读 - 写作)的随机化平均值的直方图,观测到的差异(\(\bar{x}_{read-write} = -0.545\))用红色竖线标出。该随机化分布通过以下步骤重复1000次得到:对每名学生,将两个成绩随机分配给阅读或写作,然后对样本中所有学生取平均值。3

    1. 阅读和写作的平均成绩是否存在明显差异?

    2. 每名学生的阅读成绩和写作成绩是否相互独立?

    3. 针对以下研究问题建立适当的假设:学生在阅读和写作考试中的平均成绩是否存在明显差异?

    4. 观测到的分数差异的平均值 \((\bar{x}_{read-write} = -0.545)\) 是否与随机化平均差异的分布一致?请解释。

    5. 这些数据是否提供了两门考试平均成绩存在差异的有说服力的证据?根据随机化检验估计p值,并使用诸如“阅读考试成绩”和“写作考试成绩”之类的词语对假设检验作出结论。

  1. 全球变暖,随机化检验。 让我们考虑一组有限的气候数据,考察1950年与2022年的温度差异。我们从美国国家海洋和大气管理局(NOAA)的历史数据中抽取了美国的26个地点作为样本,这些地点在两个目标年份的数据均可用。 (NOAA 2023) 这些数据并非随机样本,但它们被选取为覆盖美国本土48州陆地面积的代表性样本。使用一年中最热的一天作为衡量标准可能使结果容易受异常值影响。相反,为了了解某一年有多热,我们计算第90\(^{th}\) 百分位数;也就是说,我们找出该年比当年90%的日子都热的那一天的最高气温。我们想知道:第90\(^{th}\) 百分位最高气温在2022年更高还是在1950年更高?我们为26个地点分别计算了第90\(^{th}\) 百分位最高气温的差异(2022年最高气温 - 1950年最高气温)。这26个差异的平均值为2.52\(^\circ\)°F,标准差为2.95\(^\circ\)°F。我们想确定这些数据是否提供了强有力的证据,表明2022年的第90\(^{th}\) 百分位最高气温高于1950年。4

     

    1. 为以下研究问题创建适当的假设:两个年份(1950年和2022年)之间的第90\(^{th}\) 百分位最高气温是否存在明显差异?

    2. 观测到的分数差异的平均值 \((\bar{x}_{2022-1950} = 2.53\)^\(F)\) 是否与随机化平均差异的分布一致?请解释。

     

    1. 这些数据是否提供了令人信服的证据,表明第90\(^{th}\) 百分位最高气温存在差异?请根据随机化检验估计p值,并使用诸如“1950年的第90\(^{th}\) 百分位最高气温”和“2022年的第90\(^{th}\) 百分位最高气温”之类的措辞对假设检验下结论。
  1. High School and Beyond,自助法区间。 我们考虑了参加“高中及以后”调查的 200 名学生随机样本的阅读和写作成绩之间的差异。这些差异的均值和标准差为 \(\bar{x}_{read-write} = -0.545\)\(s_{read-write}\) = 8.887 分。下面的自助法(bootstrap)分布是通过从阅读和写作成绩差异的样本中进行 1,000 次自助抽样得到的。

     

    1. 求真实平均成绩差异(阅读 - 写作)的近似 95% 自助法百分位置信区间。

    2. 求真实平均成绩差异(阅读 - 写作)的近似 95% 自助法标准误(SE)置信区间。

     

    1. 使用诸如“总体”和“成绩”之类的词语解释这两个置信区间。

    2. 根据上面计算出的置信区间,平均而言,阅读和写作成绩之间是否存在可辨识的差异?

  1. 全球变暖,自助法区间。 我们考虑了从NOAA数据库中抽取的26个采样地点在1950年与2022年之间90\(^{th}\) 百分位高温的变化。 (NOAA 2023) 报告的差异的均值和标准差分别为 2.53\(^\circ\)F 和 2.95\(^\circ\)F。

    1. 计算 1950 年与 2022 年之间 90\(^{th}\) 1950年至2022年间的高温百分位数。

    2. 计算 1950 年与 2022 年之间 90\(^{th}\) 1950年至2022年间的高温百分位数。

    3. 在具体情境中解释这两个区间。

    4. 这些置信区间是否提供了令人信服的证据,表明2022年NOAA站点的高温比1950年更热?请解释你的理由。

  1. “高中及以后”调查,数学测试。 我们考虑了参加“高中及以后”调查的200名学生的随机样本的阅读和写作成绩之间的差异。

    1. 针对以下研究问题建立适当的假设:学生在阅读和写作考试中的平均成绩是否存在明显差异?

    2. 检查完成该检验所需的条件。

    3. 观察到的平均成绩差异为 \(\bar{x}_{read-write} = -0.545\),差异的标准差为 \(s_{read-write} = 8.887\) 分。这些数据是否提供了令人信服的证据,表明两项考试的平均成绩存在差异?

    4. 我们可能犯了哪种类型的错误?请解释该错误在此应用情境中的含义。

    5. 基于该假设检验的结果,你是否预期阅读和写作平均成绩差异的置信区间会包含0?请解释你的理由。

  1. 全球变暖,数学测试。 我们考虑了从NOAA数据库中抽取的26个采样地点在1950年与2022年之间90\(^{th}\) 百分位高温的变化。 (NOAA 2023) 报告的差异的均值和标准差分别为 2.53\(^\circ\)F 和 2.95\(^\circ\)F。

     

    1. 1950 年和 2022 年收集的观测值之间是否存在关联?还是说两组观测值是相互独立的?请解释你的理由。

    2. 用符号和文字写出这项研究的假设。

    3. 检查完成该检验所需的条件。

     

    1. 计算检验统计量并求出 p 值。

    2. 使用 \(\alpha = 0.05\) 来评估该检验,并结合上下文解释你的结论。

    3. 我们可能犯了哪种类型的错误?请结合上下文解释该错误的含义。

    4. 根据这个假设检验的结果,你是否预期 1950 年至 2022 年平均差异(90\(^{th}\) 百分位高温)的置信区间会包含 0?请解释你的理由。

  2. 高中及以后,数学区间。 我们考虑了参加“高中及以后”调查的 200 名学生随机样本的阅读和写作成绩之间的差异。这些差异的均值和标准差为 \(\bar{x}_{read-write} = -0.545\)\(s_{read-write}\) = 8.887 分。

    1. 计算所有学生阅读和写作成绩平均差异的 95% 置信区间。

    2. 结合上下文解释这个区间。

    3. 置信区间是否提供了令人信服的证据,表明平均分数存在真实差异?请解释。

  3. 全球变暖,数学区间。 我们考虑了从NOAA数据库中抽取的26个采样地点在1950年与2022年之间90\(^{th}\) 百分位高温的变化。 (NOAA 2023) 报告的差异的均值和标准差分别为 2.53\(^\circ\)F 和 2.95\(^\circ\)F。

    1. 计算1950年与2022年之间90\(^{th}\) 百分位高温平均差异的90%置信区间。我们已经为你检查了条件。

    2. 结合上下文解释该区间。

    3. 置信区间是否提供了令人信服的证据,表明NOAA站点2022年的高温比1950年更热?请解释你的理由。

  4. 可能的配对随机化差异。 对五个人中的每一个人收集了两次观测。以下哪一项可能是下表中给出的配对差异的一种随机化?如果这组数值不可能是随机化的差异集合,请说明原因。

     

    1. -2, 1, 1, 11, -2

    2. -4, 11, -2, 0, 1

    3. -2, 2, -11, 11, -2, 2, 0, 1, -1

    4. 0, -1, 2, -4, 11

    5. 4, -11, 2, 0, -1

     

    人员
    1 2 3 4 5
    观测1 3 14 4 5 10
    观测值 2 7 3 6 5 9
    差值 -4 11 -2 0 1
  1. 学习环境。 为了检验学习时听音乐与在安静环境中学习的效果差异,学生们同意被随机分配到两种处理(即听音乐学习或在安静环境中学习)。学期中有两次考试,因此研究者既可以将学生随机分配为一次考试听音乐学习、一次考试安静学习(随机选择哪次考试对应哪种学习环境),也可以将学生随机分配为两次考试都采用同一种学习习惯。

    研究者感兴趣的是估计边听音乐边学习的学生与在安静环境中学习的学生考试分数的真实总体差异。

    1. 描述与配对设计实验相一致的实验。处理是如何分配的?数据是如何收集的,使得观测值是配对的?

    2. 描述与独立样本实验相一致的实验。处理是如何分配的?数据是如何收集的,使得观测值是独立的?

  1. 13号星期五与交通。 20世纪90年代初,英国的研究人员收集了13号星期五的交通流量数据,目的是研究关于13号星期五的迷信如何影响人类行为,以及13号星期五是否是一个不吉利的日子。下面的直方图显示了许多此类日期对中,6号星期五和13号星期五经过某个特定路口的汽车数量分布。同时还提供了一些样本统计量,其中差异是6号的汽车数量减去13号的汽车数量。5 (Scanlon et al. 1993)

    n 平均数 标准差
    sixth 10 128,385 7,259
    thirteenth 10 126,550 7,664
    diff 10 1,836 1,176
    1. 这些数据中是否存在在分析中应当考虑的潜在结构?请解释。

    2. 评估6号星期五外出的人数\(^{\text{th}}\) 是否与13号星期五外出的人数不同的假设是什么\(^{\text{th}}\)?

    3. 使用数学模型检验从 (b) 部分进行假设检验的条件。

    4. 计算检验统计量和 p 值。

    5. 假设检验的结论是什么?

    6. 在此情境下解释 p 值的含义。

    7. 在你的检验结论中可能犯了哪种类型的错误?请解释。

  1. 13号星期五与事故。 20世纪90年代初,英国的研究人员收集了13号星期五与交通事故相关的急诊室(ER)入院人数的数据,目的是探讨关于13号星期五的迷信如何影响人类行为,以及13号星期五是否真的是不吉利的一天。下面的直方图显示了多个此类日期对中,特定急诊室在6号星期五和13号星期五的急诊入院人数的分布。同时提供了一些样本统计量,其中差值定义为6号的急诊入院人数减去13号的急诊入院人数。(Scanlon et al. 1993)

    n 平均数 标准差
    sixth 6 8 3
    thirteenth 6 11 4
    diff 6 -3 3
    1. 使用数学模型进行假设检验,以评估6号星期五与13号星期五之间交通事故相关急诊室平均入院人数是否存在差异。\(^{\text{th}}\) 和13号星期五之间有所不同\(^{\text{th}}\).

    2. 使用数学模型计算95%置信区间,用于估计6号星期五与13号星期五之间交通事故相关急诊室平均入院人数的差异。\(^{\text{th}}\) 和13号星期五之间有所不同\(^{\text{th}}\).

    3. 原始研究的结论指出:“13号星期五对某些人来说是不吉利的。因交通事故而入院的风险可能增加多达52%。建议待在家里。”你同意这一说法吗?请解释你的理由。

  1. 森林管理。 护林员希望更好地了解公园中较年轻树木的生长速度。他们在2009年对50棵随机抽取的幼树进行了测量,并在2019年再次测量了这些相同的树木。下面的数据总结了他们的测量结果,其中高度以英尺为单位。

    年份 平均数 标准差 n
    2009 12.0 3.5 50
    2019 24.5 9.5 50
    差值 12.5 7.2 50

    为公园中(曾经的)较年轻树木在2009-2019年间的平均生长量构建99%置信区间。


  1. 自助法样本均值差异大致在0.7到7.5之间变化,范围为$6.80。尽管自助法分布不对称,我们仍使用经验法则(即对于钟形分布,大多数观测值位于中心两个标准误之内),均值差异的标准误约为$1.70。你可能会注意到, Section 21.3 在学生每周外出超过两个晚上时为 \(SE(\bar{x}_{diff}) = \sqrt{s^2_{diff}/n_{diff}} = \sqrt{13.4^2/68} = \$1.62\) 中给出的标准误计算结果(数值来自 Section 21.3)与自助法近似值非常接近。↩︎

  2. 平均价格差异对这个问题只有很小的参考价值。请查看 图 21.10中所示的分布。确实有少数几个案例中亚马逊的价格远低于UCLA书店,这表明在购买之前值得查看亚马逊(可能还有其他在线网站)。然而,在许多情况下,亚马逊的价格高于UCLA书店的售价,而且大多数时候价格差异并不大。最终,如果直接从书店立即拿到书明显更方便,例如为了开始阅读或做作业,那么选择UCLA书店可能是明智的,除非某本特定书籍的价格差异恰好非常大。作为参考,这与我们(作者)在2010年一个类似数据集中看到的结果大不相同。当时,亚马逊的价格几乎一律低于UCLA书店,而且差距很大,这使得当时选择亚马逊而非UCLA书店的理由非常有说服力。现在我们经常查看多个网站以找到最优惠的价格。↩︎

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

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

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