Chapter page 34 / 3825 Inference for linear regression with multiple predictors
English

25  Inference for linear regression with multiple predictors

In Chapter 8, the least squares regression method was used to estimate linear models which predicted a particular response variable given more than one explanatory variable. Here, we discuss whether each of the variables individually is a statistically discernible predictor of the outcome or whether the model might be just as strong without that variable. That is, as before, we apply inferential methods to ask whether a variable could have come from a population where the particular coefficient at hand was zero. If one of the linear model coefficients is truly zero (in the population), then the estimate of the coefficient (using least squares) will vary around zero. The inference task at hand is to decide whether the coefficient’s difference from zero is large enough to decide that the data cannot possibly have come from a model where the true population coefficient is zero. Both the derivations from the mathematical model and the randomization model are beyond the scope of this book, but we are able to calculate p-values using statistical software. We will discuss interpreting p-values in the multiple regression setting and note some scenarios where careful understanding of the context and the relationship between variables is important. We use cross-validation as a method for independent assessment of the multiple linear regression model.

25.1 Multiple regression output from software

Recall the loans data from Chapter 8.

The loans_full_schema data can be found in the openintro R package. Based on the data in this dataset we have created two new variables: credit_util which is calculated as the total credit utilized divided by the total credit limit and bankruptcy which turns the number of bankruptcies to an indicator variable (0 for no bankruptcies and 1 for at least 1 bankruptcy). We will refer to this modified dataset as loans.

Now, our goal is to create a model where interest_rate can be predicted using the variables debt_to_income, term, and credit_checks. As you learned in Chapter 8, least squares can be used to find the coefficient estimates for the linear model. The unknown population model can be written as:

\[ \begin{aligned} E[\texttt{interest\_rate}] = \beta_0 &+ \beta_1\times \texttt{debt\_to\_income} \\ &+ \beta_2 \times \texttt{term}\\ &+ \beta_3 \times \texttt{credit\_checks}\\ \end{aligned} \]

Table 25.1: Summary of a linear model for predicting interest rate based on debt_to_income, term, and credit_checks. Each of the variables has its own coefficient estimate as well as a p-value.
term estimate std.error statistic p.value
(Intercept) 4.31 0.20 22.1 <0.0001
debt_to_income 0.04 0.00 13.3 <0.0001
term 0.16 0.00 37.9 <0.0001
credit_checks 0.25 0.02 12.8 <0.0001

The estimated equation for the regression model may be written as a model with three predictor variables:

\[ \widehat{\texttt{interest\_rate}} = 4.31 + 0.041 \times \texttt{debt\_to\_income} + 0.16 \times \texttt{term} + 0.25 \times \texttt{credit\_checks} \]

Not only does Table 25.1 provide the estimates for the coefficients, it also provides information on the inference analysis (i.e., hypothesis testing) which is the focus of this chapter.

In Chapter 24, you learned that the hypothesis test for a linear model with one predictor1 can be written as:

if only one predictor, \(H_0: \beta_1 = 0.\)

That is, if the true population slope is zero, the p-value measures how likely it would be to select data which produced the observed slope (\(b_1\)) value.

With multiple predictors, the hypothesis is similar, however, it is now conditioned on each of the other variables remaining in the model.

if multiple predictors, \(H_0: \beta_i = 0\) given other variables in the model

Using the example above and focusing on each of the variable p-values (here we won’t discuss the p-value associated with the intercept), we can write out the three different hypotheses:

  • \(H_0: \beta_1 = 0\), given term and credit_checks are included in the model
  • \(H_0: \beta_2 = 0\), given debt_to_income and credit_checks are included in the model
  • \(H_0: \beta_3 = 0\), given debt_to_income and term are included in the model

The very low p-values from the software output tell us that each of the variables acts as an important predictor in the model, despite the inclusion of the other two. Consider the p-value on \(H_0: \beta_1 = 0\). The low p-value says that it would be extremely unlikely to see data that produce a coefficient on debt_to_income as large as 0.041 if the true relationship between debt_to_incomeand interest_rate was non-existent (i.e., if \(\beta_1 = 0\)) and the model also included term and credit_checks. You might have thought that the value 0.041 is a small number (i.e., close to zero), but in the units of the problem, 0.041 turns out to be far away from zero, it’s all about context! The p-values on term and on credit_checks are interpreted similarly.

Sometimes a set of predictor variables can impact the model in unusual ways, often due to the predictor variables themselves being correlated.

25.2 Multicollinearity

In practice, there will almost always be some degree of correlation between the explanatory variables in a multiple regression model. For regression models, it is important to understand the entire context of the model, particularly for correlated variables. Our discussion will focus on interpreting coefficients (and their signs) in relationship to other variables as well as the discernibility (i.e., the p-value) of each coefficient.

Consider an example where we would like to predict how much money is in a coin dish based only on the number of coins in the dish. We ask 26 students to tell us about their individual coin dishes, collecting data on the total dollar amount, the total number of coins, and the total number of low coins.2 The number of low coins is the number of coins minus the number of quarters (a quarter is the largest commonly used US coin, at US$0.25). Figure 25.1 illustrates a sample of U.S. coins, their total worth (total_amount), the total number_of_coins, and the number_of_low_coins.

Graphic of five pennies, three nickles, two dimes, and six quarters. A summary table indicates that there are 16 total coins, 10 of which are considered low coins. The total amount of money is one dollar and ninety cents.
Figure 25.1: A sample of coins with 16 total coins, 10 low coins, and a net worth of $1.90.

The collected data is given in Figure 25.2 and shows that the total_amount of money is more highly correlated with the total number_of_coins than it is with the number_of_low_coins. We also note that the total number_of_coins and the number_of_low_coins are positively correlated.

Two scatterplots, both with total amount of money on the y-axis. The left plot has total number of coins on the x-axis. The right plot has number of low coins on the x-axis. Both plots show positive correlation, but the total number of coins plot is more strongly correlated than the number of low coins plot.
(a) Total number of coins on the x-axis.
Two scatterplots, both with total amount of money on the y-axis. The left plot has total number of coins on the x-axis. The right plot has number of low coins on the x-axis. Both plots show positive correlation, but the total number of coins plot is more strongly correlated than the number of low coins plot.
(b) Number of low coins on the x-axis.
Figure 25.2: Two plots describing the total amount of money (USD) as a function of the total number of coins or low coins. As you might expect, the total amount of money is more highly positively correlated with the total number of coins than with the number of low coins.

Using the total number_of_coins as the predictor variable, Table 25.2 provides the least squares estimate of the coefficient is 0.13. For every additional coin in the dish, we would predict that the student had US$0.13 more. The \(b_1 = 0.13\) coefficient has a small p-value associated with it, suggesting we would not have seen data like this if number_of_coins and total_amount of money were not linearly related.

\[\widehat{\texttt{total\_amount}} = 0.55 + 0.13 \times \texttt{number\_of\_coins}\]

Table 25.2: Linear model output predicting the total amount of money based on the total number of coins.
term estimate std.error statistic p.value
(Intercept) 0.55 0.44 1.23 0.2301
number_of_coins 0.13 0.02 5.54 <0.0001

Using number_of_low_coins as the predictor variable, Table 25.3 provides the least squares estimate of the coefficient is 0.02. For every additional low coin in the dish, we would predict that the student had US$0.02 more. The \(b_1 = 0.02\) coefficient has a large p-value associated with it, suggesting we could easily have seen data like ours even if the number_of_low_coins and total_amount of money are not at all linearly related.

\[\widehat{\texttt{total\_amount}} = 2.28 + 0.02 \times \texttt{number\_of\_low\_coins}\]

Table 25.3: Linear model output predicting the total amount of money based on the number of low coins.
term estimate std.error statistic p.value
(Intercept) 2.28 0.58 3.9 0.0
number_of_low_coins 0.02 0.05 0.4 0.7

Come up with an example of two observations that have the same number of low coins but the number of total coins differs by one. What is the difference in total amount?


Two samples of coins with the same number of low coins (3), but a different number of total coins (4 vs 5) and a different total amount ($0.41 vs $0.66).

A set of four coins is shown: one of each penny, nickle, dime, and quarter. One quarter is then added to create a set of five coins -- one penny, one nickle, one dime, and two quarters. The two sets of coins have the same number of low coins but a different number of total coins.

Come up with an example of two observations that have the same total number of coins but a different number of low coins. What is the difference in total amount?


Two samples of coins with the same total number of coins (4), but a different number of low coins (3 vs 4) and a different total amount ($0.41 vs $0.17).

A set of four coins is shown: one of each penny, nickle, dime, and quarter. The quarter is then replaced with a penny to create a new set of four coins -- two pennies, one nickle, and one dime. The two sets of coins have the same number of total coins but a different number of low coins.

Using both the total number_of_coins and the number_of_low_coins as predictor variables, Table 25.4 provides the least squares estimates of both coefficients as 0.21 and -0.16. Now, with two variables in the model, the interpretation is more nuanced.

  • A coefficient interpretation always indicates a change in one variable while keeping the other variable(s) constant.
    For every additional coin in the dish while the number_of_low_coins stays constant, we would predict that the student had US$0.21 more. Re-considering the phrase “every additional coin in the dish while the number of low coins stays constant” makes us realize that each increase is a single additional quarter (larger samples sizes would have led to a \(b_1\) coefficient closer to 0.25 because of the deterministic relationship described here).
  • For every additional low coin in the dish while the total number_of_coins stays constant, we would predict that the student had US$0.16 less. Re-considering the phrase “every additional low coin in the dish while the number of total coins stays constant” makes us realize that a quarter is being swapped out for a penny, nickel, or dime.

Considering the coefficients across Table 25.2, Table 25.3, and Table 25.4 within the context and knowledge we have of US coins allows us to understand the correlation between variables and why the signs of the coefficients would change depending on the model. Note also, however, that the p-value for the number_of_low_coins coefficient changed from Table 25.3 to Table 25.4. It makes sense that the variable describing the number_of_low_coins provides more information about the total_amount of money when it is part of a model which also includes the total number_of_coins than it does when it is used as a single variable in a simple linear regression model.

\[ \begin{aligned} \widehat{\texttt{total\_amount}} = 0.80 &+ 0.21 \times \texttt{number\_of\_coins} \\ &- 0.16 \times \texttt{number\_of\_low\_coins} \end{aligned} \]

Table 25.4: Linear model output predicting the total amount of money based on both the total number of coins and the number of low coins.
term estimate std.error statistic p.value
(Intercept) 0.80 0.30 2.65 0.0142
number_of_coins 0.21 0.02 9.89 <0.0001
number_of_low_coins -0.16 0.03 -5.51 <0.0001

When working with multiple regression models, interpreting the model coefficients is not always as straightforward as it was with the coin example. However, we encourage you to always think carefully about the variables in the model, consider how they might be correlated among themselves, and work through different models to see how using different sets of variables might produce different relationships for predicting the response variable of interest.

Multicollinearity.

Multicollinearity happens when the predictor variables are correlated within themselves. When the predictor variables themselves are correlated, the coefficients in a multiple regression model can be difficult to interpret.

Although diving into the details are beyond the scope of this text, we will provide one more reflection about multicollinearity. If the predictor variables have some degree of correlation, it can be quite difficult to interpret the value of the coefficient or evaluate whether the variable is a statistically discernible predictor of the outcome. However, even a model that suffers from high multicollinearity will likely lead to unbiased predictions of the response variable. So if the task at hand is only to do prediction (and not to interpret coefficients), multicollinearity is likely to not cause you substantial problems.

25.3 Cross-validation for prediction error

In Section 25.1, p-values were calculated on each of the model coefficients. The p-value gives a sense of which variables are important to the model; however, a more extensive treatment of variable selection is warranted in a follow-up course or textbook. Here, we use cross-validation prediction error to focus on which variable(s) are important for predicting the response variable of interest. In general, linear models are also used to make predictions of individual observations. In addition to model building, cross-validation provides a method for generating predictions that are not overfit to the particular dataset at hand. We continue to encourage you to take up further study on the topic of cross-validation, as it is among the most important ideas in modern data analysis, and we are only able to scratch the surface here.

Cross-validation is a computational technique which removes some observations before a model is run, then assesses the model accuracy on the held-out sample. By removing some observations, we provide ourselves with an independent evaluation of the model (that is, the removed observations do not contribute to finding the parameters which minimize the least squares equation). Cross-validation can be used in many different ways (as an independent assessment), and here we will just scratch the surface with respect to one way the technique can be used to compare models. See Figure 25.3 for a visual representation of the cross-validation process.

A square represents the original observed data which has been partitioned into four triangular segments. From the original partition, four different settings are considered. The first setting is such that the red, green, and yellow triangular representations of the data are used to build the model; the blue triangular representation of the data is heldout and used for independent model prediction. The second setting is such that the blue, green, and yellow triangular representations of the data are used to build the model; the red triangular representation of the data is heldout and used for independent model prediction. The third setting is such that the red, blue, and yellow triangular representations of the data are used to build the model; the green triangular representation of the data is heldout and used for independent model prediction. The fourth setting is such that the red, green, and blue triangular representations of the data are used to build the model; the yellow triangular representation of the data is held out and used for independent model prediction.
Figure 25.3: The dataset is broken into k folds (here k = 4). One at a time, a model is built using k-1 of the folds, and predictions are calculated on the single held out sample which will be completely independent of the model estimation.

The penguins data can be found in the palmerpenguins R package.

Our goal in this section is to compare two different regression models which both seek to predict the mass of an individual penguin in grams. The observations of three different penguin species include measurements on body size and sex. The data were collected by Dr. Kristen Gorman and the Palmer Station, Antarctica LTER as part of the Long Term Ecological Research Network. (Gorman et al. 2014) Although not exactly aligned with this research project, you might be able to imagine a setting where the dimensions of the penguin are known (through, for example, aerial photographs) but the mass is not known. The first model predicts body_mass_g by using only the bill_length_mm, a variable denoting the length of a penguin’s bill, in mm. The second model predicts body_mass_g by using bill_length_mm, bill_depth_mm, flipper_length_mm, sex, and species.

Prediction error.

The predicted error (also previously called the residual) is the difference between the observed value and the predicted value (from the regression model).

\[\text{prediction error}_i = e_i = y_i - \hat{y}_i\]

The presentation below (see the comparison of Figure 25.5 and Figure 25.7) shows that the model with more variables predicts body_mass_g with much smaller errors (predicted minus actual body mass) than the model which uses only bill_length_g. We have deliberately used a model that intuitively makes sense (the more body measurements, the more predictable mass is). However, in many settings, it is not obvious which variables or which models contribute most to accurate predictions. Cross-validation is one way to get accurate independent predictions with which to compare different models.

25.3.1 Comparing two models to predict body mass in penguins

The question we will seek to answer is whether the predictions of body_mass_g are substantially better when bill_length_mm, bill_depth_mm, flipper_length_mm, sex, and species are used in the model, as compared with a model on bill_length_mm only.

We refer to the model given with only bill_length_mm as the smaller model. It is seen in Table 25.5 with coefficient estimates of the parameters as well as standard errors and p-values. We refer to the model given with bill_length_mm, bill_depth_mm, flipper_length_mm, sex, and species as the larger model. It is seen in Table 25.6 with coefficient estimates of the parameters as well as standard errors and p-values. Given what we know about high correlations between body measurements, it is somewhat unsurprising that all of the variables have low p-values, suggesting that each variable is a statistically discernible predictor of body_mass_g, given all other variables in the model. However, in this section, we will go beyond the use of p-values to consider independent predictions of body_mass_g as a way to compare the smaller and larger models.

The smaller model:

\[ \begin{aligned} E[\texttt{body\_mass\_g}] &= \ \beta_0 + \beta_1 \times \texttt{bill\_length\_mm}\\ \widehat{\texttt{body\_mass\_g}} &= \ 362.31 + 87.42 \times \texttt{bill\_length\_mm}\\ \end{aligned} \]

Table 25.5: Least squares estimates for the smaller regression model predicting body_mass_g from bill_length_mm.
term estimate std.error statistic p.value
(Intercept) 362.3 283.4 1.28 0.2019
bill_length_mm 87.4 6.4 13.65 <0.0001

The larger model:

\[ \begin{aligned} E[\texttt{body\_mass\_g}] = \beta_0 &+ \beta_1 \times \texttt{bill\_length\_mm} \\ &+ \beta_2 \times \texttt{bill\_depth\_mm} \\ &+ \beta_3 \times \texttt{flipper\_length\_mm} \\ &+ \beta_4 \times \texttt{sex}\_{male} \\ &+ \beta_5 \times \texttt{species}\_{Chinstrap} \\ &+ \beta_6 \times \texttt{species}\_{Gentoo}\\ \widehat{\texttt{body\_mass\_g}} = -1460.99 &+ 18.20 \times \texttt{bill\_length\_mm} \\ &+ 67.22 \times \texttt{bill\_depth\_mm} \\ &+ 15.95 \times \texttt{flipper\_length\_mm} \\ &+ 389.89 \times \texttt{sex}\_{male} \\ &- 251.48 \times \texttt{species}\_{Chinstrap} \\ &+ 1014.63 \times \texttt{species}\_{Gentoo}\\ \end{aligned} \]

Table 25.6: Least squares estimates of the larger regression model predicting body_mass_g from bill_length_mm, bill_depth_mm, flipper_length_mm, sex, and species.
term estimate std.error statistic p.value
(Intercept) -1461.0 571.31 -2.56 0.011
bill_length_mm 18.2 7.11 2.56 0.0109
bill_depth_mm 67.2 19.74 3.40 7e-04
flipper_length_mm 15.9 2.91 5.48 <0.0001
sexmale 389.9 47.85 8.15 <0.0001
speciesChinstrap -251.5 81.08 -3.10 0.0021
speciesGentoo 1014.6 129.56 7.83 <0.0001

In order to compare the smaller and larger models in terms of their ability to predict penguin mass, we need to build models that can provide independent predictions based on the penguins in the holdout samples created by cross-validation. To reiterate, each of the predictions that (when combined together) will allow us to distinguish between the smaller and larger are independent of the data which were used to build the model. In this example, using cross-validation, we remove one quarter of the data before running the least squares calculations. Then the least squares model is used to predict the body_mass_g of the penguins in the holdout sample. Here we use a 4-fold cross-validation (meaning that one quarter of the data is removed each time) to produce four different versions of each model (other times it might be more appropriate to use 2-fold or 10-fold or even run the model separately after removing each individual data point one at a time).

Figure 25.4 displays how a model is fit to 3/4 of the data (note the slight differences in coefficients as compared to Table 25.5), and then predictions are made on the holdout sample.

The left panel shows the linear model predicting body mass in grams using bill length in mm; the model was built using the red, green, and yellow triangular sections of the observed data. The right panel shows a scatterplot of the prediction error versus the fitted values for the set of observations in the blue triangular section of the observed data. The prediction errors range from roughly -1,000 grams to +1,000 grams.
Figure 25.4: The smaller model. The coefficients are estimated using the least squares model on 3/4 of the dataset with only a single predictor variable. Predictions are made on the remaining 1/4 of the observations. The y-axis in the scatterplot represents the residual, true observed value minus the predicted value. Note that the predictions are independent of the estimated model coefficients.

By repeating the process for each holdout quarter sample, the residuals from the model can be plotted against the predicted values. We see that the predictions are scattered which shows a good model fit but that the prediction errors vary \(\pm\) 1,000 g of the true body mass.

One quarter at a time, the data were removed from the model building, and the body mass of the removed penguins was predicted. The least squares regression model was fit independently of the removed penguins. The predictions of body mass are based on bill length only. The x-axis represents the predicted value, the y-axis represents the error, the difference between predicted value and actual value). Four different scatterplots are provided, one for each set of predictions (on a quarter of the dataset). All four sets of error values are centered around zero with most observations between -500 and + 500. Virtually all errors are between -1,000 and +1,000.
Figure 25.5: The smaller model. One quarter at a time, the data were removed from the model building, and the body mass of the removed penguins was predicted. The least squares regression model was fit independently of the removed penguins. The predictions of body mass are based on bill length only. The x-axis represents the predicted value, the y-axis represents the error, the difference between predicted value and actual value.

The cross-validation SSE is the sum of squared error associated with the predictions. Let \(\hat{y}_{cv,i}\) be the prediction for the \(i^{th}\) observation where the \(i^{th}\) observation was in the hold-out fold and the other three folds were used to create the linear model. For the model using only bill_length_mm to predict body_mass_g, the CV SSE is 141,552,822.

Cross-validation SSE.

The prediction error from the cross-validated model can be used to calculate a single numerical summary of the model. The cross-validation SSE is the sum of squared cross-validation prediction errors.

\[\mbox{CV SSE} = \sum_{i=1}^n (\hat{y}_{cv,i} - y_i)^2\]

The same process is repeated for the larger number of explanatory variables. Note that the coefficients estimated for the first cross-validation model (in Figure 25.6) are slightly different from the estimates computed on the entire dataset (seen in Table 25.6). Figure 25.6 displays the cross-validation process for the multivariable model with a full set of residual plots given in Figure 25.7. Note that the residuals are mostly within \(\pm\) 500g, providing much more precise predictions for the independent body mass values of the individual penguins.

The left panel shows the linear model predicting body mass in grams using bill length, bill depth, flipper length, sex, and species; the model was built using the red, green, and yellow triangular sections of the observed data. The right panel shows a scatterplot of the prediction error versus the fitted values for the set of observations in the blue triangular section of the observed data. The prediction errors range from roughly -500 grams to +500 grams.
Figure 25.6: The larger model. The coefficients are estimated using the least squares model on 3/4 of the dataset with the five specified predictor variables. Predictions are made on the remaining 1/4 of the observations. The y-axis in the scatterplot represents the residual, true observed value minus the predicted value. Note that the predictions are independent of the estimated model coefficients.
One quarter at a time, the data were removed from the model building, and the body mass of the removed penguins was predicted. The least squares regression model was fit independently of the removed penguins. The predictions of body mass are based on the set of five variables described in the larger model. The x-axis represents the predicted value, the y-axis represents the error, the  difference between predicted value and actual value. Four different scatterplots are provided, one for each set of predictions (on a quarter of the dataset). All four sets of error values are centered around zero virtually all errors are between -500 and + 500.
Figure 25.7: The larger model. One quarter at a time, the data were removed from the model building, and the body mass of the removed penguins was predicted. The least squares regression model was fit independently of the removed penguins. The predictions of body mass are based on the set of five variables described in Table 25.6. The x-axis represents the predicted value, the y-axis represents the error, the difference between predicted value and actual value.

Figure 25.5 shows that the independent predictions are centered around the true values (i.e., errors are centered around zero), but that the predictions can be as much as 1,000 g off when using only bill_length_mm to predict body_mass_g. On the other hand, when using bill_length_mm, bill_depth_mm, flipper_length_mm, sex, and species to predict body_mass_g, the prediction errors seem to be about half as big, as seen in Figure 25.7. For the model using bill_length_mm, bill_depth_mm, flipper_length_mm, sex, and species to predict body_mass_g, the CV SSE is 27,728,698 (as compared to a CV SSE of 141,552,822 for the smaller model). Consistent with visually comparing the two sets of residual plots, the sum of squared prediction errors is smaller for the model which uses more predictor variables. The model with more predictor variables seems like the better model (according to the cross-validated prediction errors criteria).

We have provided a very brief overview to and example of using cross-validation. Cross-validation is a computational approach to model building and model validation as an alternative to reliance on p-values. While p-values have a role to play in understanding model coefficients, throughout this text, we have continued to present computational methods that broaden statistical approaches to data analysis. Cross-validation will be used again in Chapter 26 with logistic regression. We encourage you to consider both standard inferential methods (such as p-values) and computational approaches (such as cross-validation) as you build and use multivariable models of all varieties.

25.4 Chapter review

25.4.1 Summary

Building on the modeling ideas from Chapter 8, we have now introduced methods for evaluating coefficients (based on p-values) and evaluating models (cross-validation). There are many important aspects to consider when working with multiple variables in a single model, and we have only glanced at a few topics. Remember, multicollinearity can make coefficient interpretation difficult. A topic not covered in this text but important for multiple regression models is interaction, and we hope that you learn more about how variables work together as you continue to build up your modeling skills.

25.4.2 Terms

The terms introduced in this chapter are presented in Table 25.7. 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 25.7: Terms introduced in this chapter.
cross-validation multicollinearity prediction error
inference on multiple linear regression multiple predictors predictor

25.5 Exercises

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

  1. GPA, mathematical interval. A survey of 55 Duke University students asked about their GPA (gpa), number of hours they study weekly (studyweek), number of hours they sleep nightly (sleepnight), and whether they go out more than two nights a week (out_mt2). We use these data to build a model predicting GPA from the other variables. Summary of the model is shown below. Note that out_mt2 is 1 if the student goes out more than two nights a week, and 0 otherwise.3

    term estimate std.error statistic p.value
    (Intercept) 3.508 0.347 10.114 <0.0001
    studyweek 0.002 0.004 0.400 0.6908
    sleepnight 0.000 0.047 0.008 0.994
    out_mt2 0.151 0.097 1.551 0.127
    1. Calculate a 95% confidence interval for the coefficient of out_mt2 (go out more than two night a week) in the model, and interpret it in the context of the data.

    2. Would you expect a 95% confidence interval for the slope of the remaining variables to include 0? Explain your reasoning.

  1. Tourism spending. The Association of Turkish Travel Agencies reports the number of foreign tourists visiting Turkey and tourist spending by year. Three plots are provided: scatterplot showing the relationship between these two variables along with the least squares fit, residuals plot, and histogram of residuals.4

    1. Describe the relationship between number of tourists and spending.

    2. What are the predictor and the outcome variables?

    3. Why might we want to fit a regression line to these data?

    4. Do the data meet the LINE conditions required for fitting a least squares line? Use the scatterplot, the residuals plot, and the histogram to answer this question.

  1. Cherry trees, collinear predictors. Timber yield is approximately equal to the volume of a tree, however, this value is difficult to measure without first cutting the tree down. Instead, other variables, such as height and diameter, may be used to predict a tree’s volume and yield. Researchers wanting to understand the relationship between these variables for black cherry trees collected data from 31 such trees in the Allegheny National Forest, Pennsylvania. Height is measured in feet, diameter in inches (at 54 inches above ground), and volume in cubic feet.5 (Hand 1994) The plots below display the distribution of each of these variables (on the diagonal) as well as provide information on the pairwise correlations between them.

    Also provided below are three regression model outputs: volume vs. diam, volume vs. height, and volume vs. height + diam.

    term estimate std.error statistic p.value
    (Intercept) -36.94 3.365 -11.0 <0.0001
    diam 5.07 0.247 20.5 <0.0001
    term estimate std.error statistic p.value
    (Intercept) -87.12 29.273 -2.98 0.006
    height 1.54 0.384 4.02 0.000
    term estimate std.error statistic p.value
    (Intercept) -57.988 8.638 -6.71 <0.0001
    height 0.339 0.130 2.61 0.0145
    diam 4.708 0.264 17.82 <0.0001
    1. There are three variables described in the figure, and each is paired with each other to create three different scatterplots. Rate the pairwise relationships from most correlated to least correlated.

    2. When using only one variable to model a tree’s volume, is diameter a discernible predictor? Is height a discernible predictor? Explain your reasoning.

    3. When using both diameter and height to predict a tree’s volume, are both predictors still discernible? Explain your reasoning.

  1. GPA, collinear predictors. In this exercise we work with data from a survey of 55 Duke University students who were asked about their GPA, number of hours they sleep nightly, and number of nights they go out each week. The plots below display the distributions of each of these variables (on the diagonal) as well as their pairwise relationships and correlation coefficients.

    Also provided below are three regression model outputs: gpa vs. out, gpa vs. sleepnight, and gpa vs. out + sleepnight.

    term estimate std.error statistic p.value
    (Intercept) 3.504 0.106 33.011 <0.0001
    out 0.045 0.046 0.998 0.3229
    term estimate std.error statistic p.value
    (Intercept) 3.46 0.318 10.874 <0.0001
    sleepnight 0.02 0.045 0.445 0.6583
    term estimate std.error statistic p.value
    (Intercept) 3.483 0.320 10.888 <0.0001
    out 0.044 0.050 0.886 0.3796
    sleepnight 0.003 0.048 0.072 0.9432
    1. There are three variables described in the figure, and each is paired with each other to create three different scatterplots. Rate the pairwise relationships from most correlated to least correlated.

    2. When using only one variable to model gpa, is out a discernible predictor? Is sleepnight a discernible predictor? Explain your reasoning.

    3. When using both out and sleepnight to predict gpa in a multiple regression model, are either of the variables discernible? Explain your reasoning.

  1. Movie returns. A FiveThirtyEight.com article reports that “Horror movies get nowhere near as much draw at the box office as the big-time summer blockbusters or action/adventure movies, but there’s a huge incentive for studios to continue pushing them out. The return-on-investment potential for horror movies is absurd.” To investigate how the return-on-investment (ROI) compares between genres and how this relationship has changed over time, an introductory statistics student fit a linear regression model to predict the ratio of gross revenue of movies to the production costs from genre and release year for 1,070 movies released between 2000 and 2018. Using the plots given below, determine if this regression model is appropriate for these data. In particular, use the residual plot to check the LINE conditons. (FiveThirtyEight 2015)

  1. Difficult encounters. A study was conducted at a university outpatient primary care clinic in Switzerland to identify factors associated with difficult doctor-patient encounters. The data consist of 527 patient encounters, conducted by the 27 medical residents employed at the clinic. After each encounter, the attending physician completed two questionnaires: the Difficult Doctor Patient Relationship Questionnaire (DDPRQ-10) and the Patient’s Vulnerability Grid (PVG). A higher score on the DDPRQ-10 indicates a more difficult encounter. The maximum possible score is 60 and encounters with score 30 and higher are considered difficult. A model was fit to predict DDPRQ-10 score from features of the attending physician: age, sex (male or not), and years of training.

    term estimate std.error statistic p.value
    (Intercept) 30.594 2.886 10.601 <0.0001
    age -0.016 0.104 -0.157 0.876
    sexMale -0.535 0.781 -0.686 0.494
    yrs_train 0.096 0.215 0.445 0.656
    1. The intercept of the model is 30.594. What is the age, sex, and years of training of a physician whom this model would predict to have a DDPRQ-10 score of 30.594.

    2. Is there evidence of a discernible association between DDPRQ-10 score and any of the physician features?

  1. Baby’s weight, mathematical test. US Department of Health and Human Services, Centers for Disease Control and Prevention collect information on births recorded in the country. The data used here are a random sample of 1,000 births from 2014. Here, we study the relationship between smoking and weight of the baby. The variable smoke is coded 1 if the mother is a smoker, and 0 if not. The summary table below shows the results of a linear regression model for predicting the average birth weight of babies, measured in pounds, based on the smoking status of the mother.6 (ICPSR 2014)

    term estimate std.error statistic p.value
    (Intercept) -3.82 0.57 -6.73 <0.0001
    weeks 0.26 0.01 18.93 <0.0001
    mage 0.02 0.01 2.53 0.0115
    sexmale 0.37 0.07 5.30 <0.0001
    visits 0.02 0.01 2.09 0.0373
    habitsmoker -0.43 0.13 -3.41 7e-04

    Also shown below are a series of diagnostics plots.

    1. Determine if the conditions for doing inference based on mathematical models with these data are met using the diagnostic plots above. If not, describe how to proceed with the analysis.

    2. Using the regression output, evaluate whether the true slope of habit (i.e., whether the mother is a smoker) is different than 0, given the other variables in the model. State the null and alternative hypotheses, report the p-value (using a mathematical model), and state your conclusion.

  1. Baby’s weight, collinear predictors. In this exercise we study the relationship between the weight of the baby and two explanatory variables: number of weeks of gestation and number of pregnancy hospital visits. (ICPSR 2014) The plots below display the distributions of each of these variables (on the diagonal) as well as their pairwise relationships and correlation coefficients.

    Also provided below are three regression model outputs: weight vs. weeks, weight vs. visits, and weight vs. weeks + visits.

    term estimate std.error statistic p.value
    (Intercept) -0.83 1.76 -0.47 0.6395
    weeks 0.21 0.05 4.70 <0.0001
    term estimate std.error statistic p.value
    (Intercept) 6.56 0.36 18.36 <0.0001
    visits 0.08 0.03 2.61 0.0105
    term estimate std.error statistic p.value
    (Intercept) -0.44 1.78 -0.25 0.81
    weeks 0.19 0.05 4.00 0.00
    visits 0.04 0.03 1.26 0.21
    1. There are three variables described in the figure, and each is paired with each other to create three different scatterplots. Rate the pairwise relationships from most correlated to least correlated.

    2. When using only one variable to model the baby’s weight, is weeks a discernible predictor? Is visits a discernible predictor? Explain your reasoning.

    3. When using both visits and weeks to predict the baby’s weight, are both predictors still discernible? Explain your reasoning.

  1. Baby’s weight, cross-validation. Using a random sample of 1,000 US births from 2014, we study the relationship between the weight of the baby and various explanatory variables. (ICPSR 2014) The plots below display prediction errors associated with two different models designed to predict weight of baby at birth; one model uses 7 predictors, one model uses 2 predictors. Using 4-fold cross-validation, the data were split into 4 folds. Three of the folds estimate the \(\beta_i\) parameters using \(b_i\), and the model is applied to the held out fold for prediction. The process was repeated 4 times (each time holding out one of the folds).

    \[ \begin{aligned} E[\texttt{weight}] = \beta_0 &+ \beta_1\times \texttt{fage} + \beta_2\times \texttt{mage} + \beta_3 \times \texttt{mature} + \beta_4 \times \texttt{weeks} \\ &+ \beta_5 \times \texttt{visits} + \beta_6 \times \texttt{gained} + \beta_7 \times \texttt{habit}\\ E[\texttt{weight}] = \beta_0 &+ \beta_1\times \texttt{weeks} + \beta_2\times \texttt{mature} \end{aligned} \]

    1. In the first graph, note the point at roughly (predicted = 11 and error = -4). Estimate the observed and predcited value for that observation.

    2. Using the same point, describe which cross-validation fold(s) were used to build its prediction model.

    3. For the plot on the top, for one of the cross-validation folds, how many coefficients were estimated in the linear model? For the plot on the bottom, for one of the cross-validation folds, how many coefficients were estimated in the linear model?

    4. Do the values of the residuals (along the y-axis, not the x-axis) seem markedly different for the two models? Explain your reasoning.

  1. RailTrail, cross-validation. The Pioneer Valley Planning Commission (PVPC) collected data north of Chestnut Street in Florence, MA for ninety days from April 5, 2005 to November 15, 2005. Data collectors set up a laser sensor, with breaks in the laser beam recording when a rail-trail user passed the data collection station.7 The plots below display prediction errors associated with two different models designed to predict the volume of riders on the RailTrail; one model uses 6 predictors, one model uses 2 predictors. Using 3-fold cross-validation, the data were split into 3 folds. Three of the folds estimate the \(\beta_i\) parameters using \(b_i\), and the model is applied to the held out fold for prediction. The process was repeated 4 times (each time holding out one of the folds).

    \[ \begin{aligned} E[\texttt{volume}] = \beta_0 &+ \beta_1 \times \texttt{hightemp} + \beta_2 \times \texttt{lowtemp} + \beta_3 \times \texttt{spring}\\ &+ \beta_4 \times \texttt{weekday} + \beta_5 \times \texttt{cloudcover}+ \beta_6 \times \texttt{precip} \\ E[\texttt{volume}] = \beta_0 &+ \beta_1\times \texttt{hightemp} + \beta_2\times \texttt{precip} \end{aligned} \]

    1. In the second graph, note the point at roughly (predicted = 400 and error = 100). Estimate the observed and predcited value for that observation.

    2. Using the same point, describe which cross-validation fold(s) were used to build its prediction model.

    3. For the plot on the top, for one of the cross-validation folds, how many coefficients were estimated in the linear model? For the plot on the bottom, for one of the cross-validation folds, how many coefficients were estimated in the linear model?

    4. Do the values of the residuals (along the y-axis, not the x-axis) seem markedly different for the two models? Explain your reasoning.

  1. Baby’s weight, cross-validation for model selection. Using a random sample of 1,000 US births from 2014, we study the relationship between the weight of the baby and various explanatory variables. (ICPSR 2014) The plots below display prediction errors associated with two different models designed to predict weight of baby at birth; one model uses 7 predictors, one model uses 2 predictors. Using 4-fold cross-validation, the data were split into 4 folds. Three of the folds estimate the \(\beta_i\) parameters using \(b_i\), and the model is applied to the held out fold for prediction. The process was repeated 4 times, each time holding out one of the folds.

    \[ \begin{aligned} E[\texttt{weight}] = \beta_0 &+ \beta_1\times \texttt{fage} + \beta_2\times \texttt{mage}\\ &+ \beta_3 \times \texttt{mature} + \beta_4 \times \texttt{weeks}\\\ &+ \beta_5 \times \texttt{visits}+ \beta_6 \times \texttt{gained}\\ &+ \beta_7 \times \texttt{habit}\\ \end{aligned} \]

    \[ \begin{aligned} E[\texttt{weight}] = \beta_0 &+ \beta_1\times \texttt{weeks} + \beta_2\times \texttt{mature} \end{aligned} \]

    1. Using the spread of the points (in the y-direction), which model should be chosen for a final report on these data? Explain your reasoning.

    2. Using the summary statistic (CV SSE), which model should be chosen for a final report on these data? Explain your reasoning.

    3. Why would the model with more predictors fit the data less closely than the model with only two predictors?

  1. RailTrail, cross-validation for model selection. The Pioneer Valley Planning Commission (PVPC) collected data north of Chestnut Street in Florence, MA for ninety days from April 5, 2005 to November 15, 2005. Data collectors set up a laser sensor, with breaks in the laser beam recording when a rail-trail user passed the data collection station. The plots below display prediction errors associated with two different models designed to predict the volume of riders on the RailTrail; one model uses 6 predictors, one model uses 2 predictors. Using 3-fold cross-validation, the data were split into 3 folds. Three of the folds estimate the \(\beta_i\) parameters using \(b_i\), and the model is applied to the held out fold for prediction. The process was repeated 4 times, each time holding out one of the folds.

    \[ \begin{aligned} E[\texttt{volume}] = \beta_0 &+ \beta_1\times \texttt{hightemp} + \beta_2\times \texttt{lowtemp}\\ &+ \beta_3 \times \texttt{spring} + \beta_4 \times \texttt{weekday}\\\ &+ \beta_5 \times \texttt{cloudcover}+ \beta_6 \times \texttt{precip}\\ \end{aligned} \]

    \[ \begin{aligned} E[\texttt{volume}] = \beta_0 &+ \beta_1\times \texttt{hightemp} + \beta_2\times \texttt{precip} \end{aligned} \]

    1. Using the spread of the points (in the y-direction), which model should be chosen for a final report on these data? Explain your reasoning.

    2. Using the summary statistic (CV SSE), which model should be chosen for a final report on these data? Explain your reasoning.

    3. Why would the model with more predictors fit the data less closely than the model with only two predictors?


  1. In previous sections, the term explanatory variable was used instead of predictor. The words are synonymous and are used separately in the different sections to be consistent with how most analysts use them: explanatory variable for testing, predictor for modeling.↩︎

  2. In all honesty, this particular dataset is fabricated, and the original idea for the problem comes from Jeff Witmer at Oberlin College.↩︎

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

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

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

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

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

中文

25  多预测变量线性回归的推断

第 8中,我们使用最小二乘回归方法来估计线性模型,该模型在给定多个解释变量的情况下预测特定的响应变量。在这里,我们讨论每个变量本身是否是结果在统计上可辨识的预测因子,或者模型在没有该变量的情况下是否可能同样强。也就是说,与之前一样,我们应用推断方法来询问某个变量是否可能来自一个该特定系数为零的总体。如果某个线性模型系数在总体中确实为零,那么(使用最小二乘法得到的)系数估计值将在零附近波动。当前要进行的推断任务是判断该系数与零的差异是否足够大,以至于可以断定数据不可能来自真实总体系数为零的模型。从数学模型和随机化模型出发的推导都超出了本书的范围,但我们可以使用统计软件计算 p 值。我们将讨论在多元回归背景下如何解释 p 值,并指出一些需要对变量之间的背景和关系有仔细理解的情形。我们使用交叉验证作为对多元线性回归模型进行独立评估的方法。

25.1 软件输出的多元回归结果

回顾 loans R 包中的 第 8.

loans_full_schema 数据可以在 openintro 数据。基于该数据集中的数据,我们创建了两个新变量: credit_util ,其计算方式为已使用的总信用额度除以总信用限额;以及 bankruptcy ,它将破产次数转换为指示变量(0 表示没有破产,1 表示至少破产 1 次)。我们将把这个修改后的数据集称为 loans.

现在,我们的目标是创建一个模型,其中 interest_rate 可以使用变量 debt_to_income, termcredit_checks来预测。正如你在 第 8 章中学到的,最小二乘法可用于求出线性模型的系数估计值。未知的总体模型可以写为:

\[ \begin{aligned} E[\texttt{interest\_rate}] = \beta_0 &+ \beta_1\times \texttt{debt\_to\_income} \\ &+ \beta_2 \times \texttt{term}\\ &+ \beta_3 \times \texttt{credit\_checks}\\ \end{aligned} \]

表 25.1:基于 debt_to_income, termcredit_checks预测利率的线性模型汇总。每个变量都有自己的系数估计值和 p 值。
term 估计 的线性模型摘要 统计量 std.error
p.value 4.31 0.20 22.1 <0.0001
债务收入比 0.04 0.00 13.3 <0.0001
term 0.16 0.00 37.9 <0.0001
信用查询次数 0.25 0.02 12.8 <0.0001

回归模型的估计方程可以写成一个包含三个预测变量的模型:

\[ \widehat{\texttt{interest\_rate}} = 4.31 + 0.041 \times \texttt{debt\_to\_income} + 0.16 \times \texttt{term} + 0.25 \times \texttt{credit\_checks} \]

不仅 表 25.1 提供了系数的估计值,它还提供了推断分析(即假设检验)的信息,而这正是本章的重点。

第24章,你已经了解到,对于带有 一个预测变量1 的线性模型,其假设检验可以写成:

如果只有一个预测变量, \(H_0: \beta_1 = 0.\)

也就是说,如果真实总体斜率为零,则 p 值衡量的是选中能产生观测斜率(\(b_1\))值的数据的可能性有多大。

当有 多个预测变量时,假设类似,但现在的条件是模型中保留的其他每个变量保持不变。

如果有多个预测变量, \(H_0: \beta_i = 0\) 在给定模型中其他变量的条件下

使用上面的例子并关注每个变量的 p 值(这里我们不讨论与截距相关的 p 值),我们可以写出三个不同的假设:

  • \(H_0: \beta_1 = 0\), 给定 termcredit_checks 在给定
  • \(H_0: \beta_2 = 0\), 给定 debt_to_incomecredit_checks 在给定
  • \(H_0: \beta_3 = 0\), 给定 debt_to_incometerm 在给定

软件输出中极小的 p 值告诉我们,尽管模型中包含了另外两个变量,每个变量仍然是模型中重要的预测变量。考虑 \(H_0: \beta_1 = 0\)上的 p 值。较低的 p 值表明,如果 debt_to_incomedebt_to_income) 之间的真实关系是,并且模型中还包含 interest_rate 的系数至少达到 -1.91 那样远离 0(即 \(\beta_1 = 0\),那么看到数据产生一个高达 0.041 的 termcredit_checks系数将是极其不可能的。你可能认为 0.041 是一个很小的数值(即接近于零),但就问题的单位而言,0.041 实际上远离零,这完全取决于具体情境! termcredit_checks 上的 p 值也可以类似地解释。

有时,一组预测变量会以不同寻常的方式影响模型,这往往是由于预测变量本身之间存在相关性。

25.2 多重共线性

在实践中,多元回归模型中的解释变量之间几乎总会存在某种程度的相关性。对于回归模型来说,理解模型的整个背景非常重要,尤其是对于相关变量。我们的讨论将侧重于解释系数(及其符号)与其他变量之间的关系,以及每个系数的可辨别性(即 p 值)。

考虑一个例子,我们想仅根据盘子中硬币的数量来预测硬币盘中有多少钱。我们请 26 名学生介绍他们各自的硬币盘,收集了总金额、硬币总数和低面值硬币总数的数据。2 低面值硬币的数量是硬币总数减去 25 美分硬币的数量(25 美分硬币是美国常用的最大面值硬币,面值为 0.25 美元)。 图 25.1 展示了美国硬币的样本、它们的总价值(total_amount)、总 number_of_coins,而 number_of_low_coins.

Graphic of five pennies, three nickles, two dimes, and six quarters. A summary table indicates that there are 16 total coins, 10 of which are considered low coins. The total amount of money is one dollar and ninety cents.
图 25.1:一组硬币样本,共有 16 枚硬币,其中 10 枚为低面值硬币,总价值为 $1.90。

收集到的数据见 图 25.2 ,数据表明, total_amount 与总 number_of_coins 的相关性高于其与 number_of_low_coins的相关性。我们还注意到,总 number_of_coinsnumber_of_low_coins 呈正相关。

Two scatterplots, both with total amount of money on the y-axis. The left plot has total number of coins on the x-axis. The right plot has number of low coins on the x-axis. Both plots show positive correlation, but the total number of coins plot is more strongly correlated than the number of low coins plot.
(a) x 轴为硬币总数。
Two scatterplots, both with total amount of money on the y-axis. The left plot has total number of coins on the x-axis. The right plot has number of low coins on the x-axis. Both plots show positive correlation, but the total number of coins plot is more strongly correlated than the number of low coins plot.
(b) x 轴为低面值硬币数量。
图 25.2:两张图描述了总金额(美元)与硬币总数或低面值硬币数量的函数关系。正如你所预期的,总金额与硬币总数的正相关性高于其与低面值硬币数量的正相关性。

使用总 number_of_coins 作为预测变量, 表 25.2 给出的系数最小二乘估计值为 0.13。盘中每多一枚硬币,我们预测该学生多拥有 0.13 美元。 \(b_1 = 0.13\) 系数对应的 p 值很小,这表明如果 number_of_coinstotal_amount 与总金额之间不存在线性关系,我们不会看到这样的数据。

\[\widehat{\texttt{total\_amount}} = 0.55 + 0.13 \times \texttt{number\_of\_coins}\]

表 25.2:基于硬币总数预测总金额的线性模型输出。
term 估计 的线性模型摘要 统计量 std.error
p.value 0.55 0.44 1.23 0.2301
number_of_coins 0.13 0.02 5.54 <0.0001

使用 number_of_low_coins 作为预测变量, 表 25.3 给出的系数最小二乘估计为 0.02。盘中每多一枚低值硬币,我们预测该学生拥有的金额多 0.02 美元。 \(b_1 = 0.02\) 系数对应的 p 值很大,这表明即使金额与 number_of_low_coinstotal_amount 之间完全不存在线性关系,我们也很有可能看到类似我们这样的数据。

\[\widehat{\texttt{total\_amount}} = 2.28 + 0.02 \times \texttt{number\_of\_low\_coins}\]

表 25.3: 基于低值硬币数量预测总金额的线性模型输出。
term 估计 的线性模型摘要 统计量 std.error
p.value 2.28 0.58 3.9 0.0
number_of_low_coins 0.02 0.05 0.4 0.7

举一个例子:两个观测具有相同的低值硬币数量,但硬币总数相差一枚。总金额相差多少?


两份硬币样本具有相同的低值硬币数量(3 枚),但硬币总数不同(4 枚 vs 5 枚),总金额也不同($0.41 vs $0.66)。

A set of four coins is shown: one of each penny, nickle, dime, and quarter. One quarter is then added to create a set of five coins -- one penny, one nickle, one dime, and two quarters. The two sets of coins have the same number of low coins but a different number of total coins.

举一个例子:两个观测具有相同的硬币总数,但低值硬币数量不同。总金额相差多少?


两份硬币样本具有相同的硬币总数(4 枚),但低值硬币数量不同(3 枚 vs 4 枚),总金额也不同($0.41 vs $0.17)。

A set of four coins is shown: one of each penny, nickle, dime, and quarter. The quarter is then replaced with a penny to create a new set of four coins -- two pennies, one nickle, and one dime. The two sets of coins have the same number of total coins but a different number of low coins.

同时使用总的 number_of_coinsnumber_of_low_coins 作为预测变量, 表 25.4 给出的两个系数的最小二乘估计分别为 0.21 和 -0.16。现在模型中有两个变量,解释就更加细致了。

  • 系数的解释总是表示在保持其他变量不变的情况下,某一个变量的变化。
    盘中每多一枚硬币 whilenumber_of_low_coins 保持不变时,我们预测该学生会多出 0.21 美元。重新考虑“在 dish 中每增加一枚硬币 while 低值硬币的数量保持不变”这一表述,使我们意识到每次增加的是一枚 25 美分硬币(更大的样本量会使 \(b_1\) 系数更接近 0.25,因为这里存在确定性关系)。
  • 在 dish 中每增加一枚低值硬币 while 总数 number_of_coins 保持不变时,我们预测该学生会少 0.16 美元。重新考虑“在 dish 中每增加一枚低值硬币 while 硬币总数保持不变”这一表述,使我们意识到一枚 25 美分硬币被换成了一枚 1 美分、5 美分或 10 美分硬币。

结合我们对美国硬币的背景知识和了解来考虑 表 25.2, 表 25.3表 25.4 的系数,使我们能够理解变量之间的相关性,以及为什么系数的符号会随模型而变化。不过还要注意, number_of_low_coins 系数的 p 值从 表 25.3表 25.4变了。描述 number_of_low_coins 的变量提供了关于 total_amount 当它是模型的一部分时,该模型还包含总金额 number_of_coins 相比于它作为单一变量用于简单线性回归模型时的情况。

\[ \begin{aligned} \widehat{\texttt{total\_amount}} = 0.80 &+ 0.21 \times \texttt{number\_of\_coins} \\ &- 0.16 \times \texttt{number\_of\_low\_coins} \end{aligned} \]

表 25.4:基于硬币总数和低值硬币数量预测总金额的线性模型输出。
term 估计 的线性模型摘要 统计量 std.error
p.value 0.80 0.30 2.65 0.0142
number_of_coins 0.21 0.02 9.89 <0.0001
number_of_low_coins -0.16 0.03 -5.51 <0.0001

在使用多元回归模型时,解释模型系数并不总是像硬币示例中那样直接。然而,我们鼓励你始终仔细思考模型中的变量,考虑它们彼此之间可能存在的相关性,并尝试不同的模型,以了解使用不同的变量集如何产生不同的关系来预测感兴趣的响应变量。

多重共线性。

当预测变量彼此相关时,就会发生多重共线性。当预测变量自身之间存在相关性时,多元回归模型中的系数可能难以解释。

尽管深入探讨细节超出了本文的范围,我们将提供关于多重共线性的又一点思考。如果预测变量之间存在一定程度的相关性,解释系数的值或评估该变量是否是结果的统计上可辨识的预测因子可能会相当困难。然而,即使是受高多重共线性困扰的模型,也很可能对响应变量产生无偏的预测。因此,如果手头的任务只是进行预测(而不是解释系数),多重共线性很可能不会给你带来实质性的问题。

25.3 用于预测误差的交叉验证

第 25.1 节中,对每个模型系数都计算了 p 值。p 值可以让人了解哪些变量对模型很重要;然而,更全面的变量选择处理需要在后续课程或教科书中进行。在这里,我们使用 交叉验证 预测误差 来聚焦于哪些变量对预测感兴趣的响应变量很重要。一般来说,线性模型也用于对单个观测值进行预测。除了模型构建之外,交叉验证还提供了一种生成预测的方法,使预测不会对当前特定数据集过拟合。我们继续鼓励你进一步学习交叉验证这一主题,因为它是现代数据分析中最重要的思想之一,而我们在这里只能浅尝辄止。

交叉验证是一种计算技术,它在运行模型之前移除一些观测值,然后在留出的样本上评估模型准确性。通过移除一些观测值,我们为模型提供了一个独立的评估(即,被移除的观测值不参与寻找使最小二乘方程最小化的参数)。交叉验证可以以多种不同的方式使用(作为独立评估),在这里我们仅对其中一种可用于比较模型的方式浅尝辄止。参见 图 25.3 以了解交叉验证过程的可视化表示。

A square represents the original observed data which has been partitioned into four triangular segments. From the original partition, four different settings are considered. The first setting is such that the red, green, and yellow triangular representations of the data are used to build the model; the blue triangular representation of the data is heldout and used for independent model prediction. The second setting is such that the blue, green, and yellow triangular representations of the data are used to build the model; the red triangular representation of the data is heldout and used for independent model prediction. The third setting is such that the red, blue, and yellow triangular representations of the data are used to build the model; the green triangular representation of the data is heldout and used for independent model prediction. The fourth setting is such that the red, green, and blue triangular representations of the data are used to build the model; the yellow triangular representation of the data is held out and used for independent model prediction.
图 25.3:数据集被分成 k 折(此处 k = 4)。每次使用其中 k-1 折构建一个模型,并在单独留出的那一个样本上计算预测值,该样本与模型估计完全独立。

penguins 数据可以在 palmerpenguins R 包中找到。

本节的目标是比较两个不同的回归模型,它们都试图预测单只企鹅的体重(以克为单位)。对三个不同企鹅物种的观测包括体型和性别的测量数据。这些数据由 Kristen Gorman 博士南极洲帕尔默长期生态研究站(Palmer Station, Antarctica LTER) 收集,作为 长期生态研究网络(Long Term Ecological Research Network). (Gorman 等人 2014) 的一部分。虽然与该研究项目并不完全一致,但你可以想象这样一个场景:企鹅的体型尺寸是已知的(例如通过航空照片),但体重未知。第一个模型通过仅使用 body_mass_g (一个以毫米为单位表示企鹅喙长的变量)来预测 bill_length_mm。第二个模型通过使用 body_mass_g 来预测 bill_length_mm, bill_depth_mm, flipper_length_mm, sexspecies.

预测误差。

预测误差(之前也称为 残差)是观测值与预测值(来自回归模型)之间的差异。

\[\text{prediction error}_i = e_i = y_i - \hat{y}_i\]

下面的展示(参见 图 25.5图 25.7) 显示,包含更多变量的模型预测 body_mass_g 的误差(预测值减去实际体重)远小于仅使用 bill_length_g的模型。我们特意使用了一个直观上合理的模型(身体测量指标越多,体重就越可预测)。然而,在许多情况下,哪些变量或哪些模型对准确预测的贡献最大并不明显。交叉验证是获得准确的独立预测以比较不同模型的一种方法。

25.3.1 比较两个预测企鹅体重的模型

我们要寻求回答的问题是:与仅基于 body_mass_g 的模型相比,当模型中使用 bill_length_mm, bill_depth_mm, flipper_length_mm, sexspecies 时, bill_length_mm 的预测是否显著更好。

我们将仅包含 bill_length_mm 的模型称为 较小 模型。在 表 25.5 中可以看到该模型的参数系数估计值以及标准误和 p 值。我们将包含 bill_length_mm, bill_depth_mm, flipper_length_mm, sexspecies 的模型称为 较大 模型。在 表 25.6 以及参数的系数估计值、标准误和 p 值。鉴于我们对身体测量指标之间高度相关的了解,所有变量都具有较低的 p 值并不太令人意外,这表明每个变量都是 body_mass_g的统计上可辨识的预测因子(在控制模型中所有其他变量的情况下)。然而,在本节中,我们将超越仅使用 p 值来考虑对 body_mass_g 的独立预测,以此比较较小模型和较大模型。

较小的模型:

\[ \begin{aligned} E[\texttt{body\_mass\_g}] &= \ \beta_0 + \beta_1 \times \texttt{bill\_length\_mm}\\ \widehat{\texttt{body\_mass\_g}} &= \ 362.31 + 87.42 \times \texttt{bill\_length\_mm}\\ \end{aligned} \]

表 25.5:用 body_mass_g 表 25.6:用 bill_length_mm.
term 估计 的线性模型摘要 统计量 std.error
p.value 362.3 283.4 1.28 0.2019
预测 87.4 6.4 13.65 <0.0001

更大的模型:

\[ \begin{aligned} E[\texttt{body\_mass\_g}] = \beta_0 &+ \beta_1 \times \texttt{bill\_length\_mm} \\ &+ \beta_2 \times \texttt{bill\_depth\_mm} \\ &+ \beta_3 \times \texttt{flipper\_length\_mm} \\ &+ \beta_4 \times \texttt{sex}\_{male} \\ &+ \beta_5 \times \texttt{species}\_{Chinstrap} \\ &+ \beta_6 \times \texttt{species}\_{Gentoo}\\ \widehat{\texttt{body\_mass\_g}} = -1460.99 &+ 18.20 \times \texttt{bill\_length\_mm} \\ &+ 67.22 \times \texttt{bill\_depth\_mm} \\ &+ 15.95 \times \texttt{flipper\_length\_mm} \\ &+ 389.89 \times \texttt{sex}\_{male} \\ &- 251.48 \times \texttt{species}\_{Chinstrap} \\ &+ 1014.63 \times \texttt{species}\_{Gentoo}\\ \end{aligned} \]

bill_length_mm body_mass_g 表 25.6:用 bill_length_mm, bill_depth_mm, flipper_length_mm, sexspecies.
term 估计 的线性模型摘要 统计量 std.error
p.value -1461.0 571.31 -2.56 0.011
预测 18.2 7.11 2.56 0.0109
的较大回归模型的最小二乘估计 67.2 19.74 3.40 7e-04
bill_length_mm 15.9 2.91 5.48 <0.0001
sexmale 389.9 47.85 8.15 <0.0001
flipper_length_mm -251.5 81.08 -3.10 0.0021
sexmale 1014.6 129.56 7.83 <0.0001

speciesChinstrap speciesGentoo,我们需要构建能够基于交叉验证所创建的留出样本中的企鹅进行独立预测的模型。重申一下,每一个预测(当它们组合在一起时)将使我们能够区分较小和较大的模型,这些预测与用于构建模型的数据是相互独立的。在这个例子中,使用交叉验证,我们在运行最小二乘计算之前先移除四分之一的数据。然后用最小二乘模型来预测留出样本中企鹅的 body_mass_g 。这里我们使用4折交叉验证(即每次移除四分之一的数据)来生成每个模型的四个不同版本(其他情况下,使用2折或10折,甚至在每次移除单个数据点后分别运行模型可能更合适)。

图 25.4 展示了模型如何拟合3/4的数据(注意系数与 表 25.5相比略有差异),然后在留出样本上进行预测。

The left panel shows the linear model predicting body mass in grams using bill length in mm; the model was built using the red, green, and yellow triangular sections of the observed data. The right panel shows a scatterplot of the prediction error versus the fitted values for the set of observations in the blue triangular section of the observed data. The prediction errors range from roughly -1,000 grams to +1,000 grams.
图 25.4:较小的模型。系数仅使用数据集中3/4的数据、且只有一个预测变量的最小二乘模型进行估计。对剩余1/4的观测进行预测。散点图中的y轴表示残差,即真实观测值减去预测值。注意,预测与估计的模型系数是相互独立的。

通过对每个留出的四分之一样本重复这一过程,可以将模型的残差与预测值进行绘图。我们看到预测值分布分散,这表明模型拟合良好,但预测误差在真实体重的 \(\pm\) 1,000克范围内变化。

One quarter at a time, the data were removed from the model building, and the body mass of the removed penguins was predicted. The least squares regression model was fit independently of the removed penguins. The predictions of body mass are based on bill length only. The x-axis represents the predicted value, the y-axis represents the error, the difference between predicted value and actual value). Four different scatterplots are provided, one for each set of predictions (on a quarter of the dataset). All four sets of error values are centered around zero with most observations between -500 and + 500. Virtually all errors are between -1,000 and +1,000.
图 25.5:较小的模型。每次移除四分之一的数据用于模型构建之外,并对被移除企鹅的体重进行预测。最小二乘回归模型的拟合与被移除的企鹅相互独立。体重的预测仅基于嘴峰长度。x轴表示预测值,y轴表示误差,即预测值与实际值之间的差异。

交叉验证SSE是与预测相关的平方误差之和。设 \(\hat{y}_{cv,i}\) 为对第 \(i^{th}\) 个观测的预测,其中该 \(i^{th}\) 观测位于留出折中,而其他三个折用于创建线性模型。对于仅使用 bill_length_mm 来预测 body_mass_g的模型,CV SSE为141,552,822。

交叉验证SSE。

来自交叉验证模型的预测误差可用于计算该模型的单一数值汇总。交叉验证SSE是交叉验证预测误差的平方和。

\[\mbox{CV SSE} = \sum_{i=1}^n (\hat{y}_{cv,i} - y_i)^2\]

对更多的解释变量重复相同的过程。请注意,为第一个交叉验证模型估计的系数(在 图 25.6中)与在整个数据集上计算的估计值(见 表 25.6). 图 25.6 中)略有不同。 图 25.7展示了多变量模型的交叉验证过程,完整的残差图见 \(\pm\) 。请注意,残差大多在

The left panel shows the linear model predicting body mass in grams using bill length, bill depth, flipper length, sex, and species; the model was built using the red, green, and yellow triangular sections of the observed data. The right panel shows a scatterplot of the prediction error versus the fitted values for the set of observations in the blue triangular section of the observed data. The prediction errors range from roughly -500 grams to +500 grams.
500g 以内,为每只企鹅的独立体重值提供了精确得多的预测。
One quarter at a time, the data were removed from the model building, and the body mass of the removed penguins was predicted. The least squares regression model was fit independently of the removed penguins. The predictions of body mass are based on the set of five variables described in the larger model. The x-axis represents the predicted value, the y-axis represents the error, the  difference between predicted value and actual value. Four different scatterplots are provided, one for each set of predictions (on a quarter of the dataset). All four sets of error values are centered around zero virtually all errors are between -500 and + 500.
图 25.6:更大的模型。系数是使用最小二乘模型在数据集的 3/4 上、基于五个指定的预测变量估计的。预测是在其余 1/4 的观测上进行的。散点图中的 y 轴表示残差,即真实观测值减去预测值。请注意,这些预测与估计的模型系数是相互独立的。 表 25.6图 25.7:更大的模型。每次移除四分之一的数据,不将其用于模型构建,并预测被移除企鹅的体重。最小二乘回归模型是在独立于被移除企鹅的情况下拟合的。体重的预测基于

图 25.5 中描述的五个变量。x 轴表示预测值,y 轴表示误差,即预测值与实际值之间的差值。 bill_length_mm 来预测 body_mass_g来预测 bill_length_mm, bill_depth_mm, flipper_length_mm, sexspecies 来预测 body_mass_g来预测 图 25.7时,预测误差似乎小了一半左右,如 bill_length_mm, bill_depth_mm, flipper_length_mm, sexspecies 来预测 body_mass_g来预测 的模型,CV SSE 为 27,728,698(相比之下,较小模型的 CV SSE 为 141,552,822)。与对两组残差图的直观比较一致,使用更多预测变量的模型的预测误差平方和更小。根据交叉验证预测误差的标准,拥有更多预测变量的模型似乎是更好的模型。

我们已经提供了关于使用交叉验证的非常简短的概述和示例。交叉验证是一种用于模型构建和模型验证的计算方法,可作为依赖 p 值的替代方案。虽然 p 值在理解模型系数方面有其作用,但在本书中,我们持续介绍扩展统计分析方法的计算方法。交叉验证将在 第26章 中再次用于逻辑回归。我们鼓励您在构建和使用各种多变量模型时,同时考虑标准推断方法(如 p 值)和计算方法(如交叉验证)。

25.4 本章复习

25.4.1 小结

第 8 章的建模思想基础上,我们现在介绍了评估系数的方法(基于 p 值)和评估模型的方法(交叉验证)。在单个模型中使用多个变量时有许多重要方面需要考虑,而我们只是粗略地浏览了几个主题。请记住,多重共线性会使系数解释变得困难。本书未涉及但对多元回归模型很重要的一个主题是交互作用,我们希望您在继续提升建模技能的过程中,进一步了解变量之间如何协同工作。

25.4.2 术语

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

表 25.7:本章介绍的术语。
交叉验证 如果我们仔细检查数据,会发现某些预测变量之间存在 预测误差
多元线性回归的推断 多个预测变量 predictor

25.5 练习

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

  1. GPA,数学区间。 一项针对 55 名杜克大学学生的调查询问了他们的 GPA(gpa)、每周学习小时数(studyweek)、每晚睡眠小时数(sleepnight),以及他们是否每周外出超过两个晚上(out_mt2)。我们使用这些数据构建一个用其他变量预测 GPA 的模型。模型摘要如下所示。注意, out_mt2 在学生每周外出超过两个晚上时为 1 ,否则为 0。3

    term 估计 的线性模型摘要 统计量 std.error
    p.value 3.508 0.347 10.114 <0.0001
    studyweek 0.002 0.004 0.400 0.6908
    sleepnight 0.000 0.047 0.008 0.994
    out_mt2 0.151 0.097 1.551 0.127
    1. 计算模型中系数 out_mt2 (每周外出超过两个晚上)的95%置信区间,并结合数据背景对其进行解释。

    2. 你认为其余变量斜率的95%置信区间会包含0吗?请解释你的理由。

  1. 旅游支出。 土耳其旅行社协会按年份报告了访问土耳其的外国游客数量和游客支出。提供了三幅图:显示这两个变量之间关系及最小二乘拟合的散点图、残差图和残差直方图。4

    1. 描述游客数量与支出之间的关系。

    2. 哪个是预测变量,哪个是结果变量?

    3. 为什么我们可能想对这些数据拟合一条回归线?

    4. 这些数据是否满足拟合最小二乘直线所需的LINE条件?请利用散点图、残差图和直方图来回答这个问题。

  1. 黑樱桃树,共线性预测变量。 木材产量大致等于树木的体积,然而,如果不先砍倒树木,这个值很难测量。因此,可以使用其他变量(如高度和直径)来预测树木的体积和产量。想要了解这些变量之间关系的研究人员从宾夕法尼亚州阿勒格尼国家森林的31棵黑樱桃树中收集了数据。高度以英尺为单位测量,直径以英寸为单位(在离地54英寸处测量),体积以立方英尺为单位。5 (Hand 1994) 下面的图在对角线上显示了每个变量的分布,并提供了它们之间两两相关性的信息。

    下面还提供了三个回归模型的输出结果: volume 对比 diam, volume 对比 heightvolume 对比 height + diam.

    term 估计 的线性模型摘要 统计量 std.error
    p.value -36.94 3.365 -11.0 <0.0001
    diam 5.07 0.247 20.5 <0.0001
    term 估计 的线性模型摘要 统计量 std.error
    p.value -87.12 29.273 -2.98 0.006
    height 1.54 0.384 4.02 0.000
    term 估计 的线性模型摘要 统计量 std.error
    p.value -57.988 8.638 -6.71 <0.0001
    height 0.339 0.130 2.61 0.0145
    diam 4.708 0.264 17.82 <0.0001
    1. 图中描述了三个变量,每两个变量配对形成三个不同的散点图。请将这些两两关系按相关性从高到低排序。

    2. 当只用一个变量来建模树的高度的 volume建模时, diam是否是一个可辨识的预测变量? height 是否是一个可辨识的预测变量?请解释你的理由。

    3. 当同时使用 diameter 和 height 来预测树的高度的 volume时,两个预测变量是否仍然可以区分?请解释你的理由。

  1. GPA,共线性预测变量。 在本题中,我们使用一项对55名杜克大学学生的调查数据,调查询问了他们的GPA、每晚睡眠小时数以及每周外出的 out 晚数。下图展示了每个变量的分布(对角线上)以及它们的两两关系和相关系数。

    下面还提供了三个回归模型的输出结果: gpa 对比 out, gpa 对比 sleepnightgpa 对比 out + sleepnight.

    term 估计 的线性模型摘要 统计量 std.error
    p.value 3.504 0.106 33.011 <0.0001
    out 0.045 0.046 0.998 0.3229
    term 估计 的线性模型摘要 统计量 std.error
    p.value 3.46 0.318 10.874 <0.0001
    sleepnight 0.02 0.045 0.445 0.6583
    term 估计 的线性模型摘要 统计量 std.error
    p.value 3.483 0.320 10.888 <0.0001
    out 0.044 0.050 0.886 0.3796
    sleepnight 0.003 0.048 0.072 0.9432
    1. 图中描述了三个变量,每两个变量配对形成三个不同的散点图。请将这些两两关系按相关性从高到低排序。

    2. 当仅使用一个变量来建模 gpa建模时, out 是否是一个可辨识的预测变量? sleepnight 是否是一个可辨识的预测变量?请解释你的理由。

    3. 当同时使用 outsleepnight 来预测 gpa 时,这些变量中是否有任何一个具有可辨识性?请解释你的理由。

  1. 电影回报。 FiveThirtyEight.com 的一篇文章报道称:“恐怖电影在票房上的吸引力远不及大型暑期大片或动作/冒险电影,但制片厂仍有巨大的动力继续推出它们。恐怖电影的投资回报潜力是惊人的。”为了研究不同类型电影的投资回报率(ROI)有何差异,以及这种关系随时间如何变化,一位统计学入门课程的学生对 2000 年至 2018 年间发行的 1,070 部电影拟合了一个线性回归模型,以电影类型和发行年份来预测电影总收入与制作成本之比。利用下面给出的图,判断该回归模型是否适用于这些数据。特别地,请使用残差图检验 LINE 条件。 (FiveThirtyEight 2015)

  1. 困难的医患接诊。 瑞士一所大学门诊初级保健诊所开展了一项研究,旨在识别与困难的医患接诊相关的因素。数据包括527次患者接诊,由该诊所雇用的27名住院医师完成。每次接诊后,主治医师填写两份问卷:困难医患关系问卷(DDPRQ-10)和患者易感性量表(PVG)。DDPRQ-10得分越高表示接诊越困难。最高可能得分为60分,得分达到30分及以上的接诊被视为困难接诊。拟合了一个模型,根据主治医师的特征(年龄、性别(是否为男性)和受训年数)来预测DDPRQ-10得分。

    term 估计 的线性模型摘要 统计量 std.error
    p.value 30.594 2.886 10.601 <0.0001
    age -0.016 0.104 -0.157 0.876
    sexMale -0.535 0.781 -0.686 0.494
    yrs_train 0.096 0.215 0.445 0.656
    1. 该模型的截距为30.594。该模型预测DDPRQ-10得分为30.594的医生的年龄、性别和受训年数是多少?

    2. 是否有证据表明DDPRQ-10得分与医生的任何特征之间存在可辨识的关联?

  1. 婴儿体重与数学测验。 美国卫生与公众服务部下属的疾病控制与预防中心收集该国记录的出生信息。这里使用的数据是2014年1000例出生的随机样本。在此,我们研究吸烟与婴儿体重之间的关系。变量 smoke 在母亲为吸烟者时编码为1,否则为0。下面的汇总表显示了基于母亲吸烟状况预测婴儿平均出生体重(以磅为单位)的线性回归模型的结果。6 (ICPSR 2014)

    term 估计 的线性模型摘要 统计量 std.error
    p.value -3.82 0.57 -6.73 <0.0001
    weeks 0.26 0.01 18.93 <0.0001
    mage 0.02 0.01 2.53 0.0115
    sexmale 0.37 0.07 5.30 <0.0001
    visits 0.02 0.01 2.09 0.0373
    habitsmoker -0.43 0.13 -3.41 7e-04

    下面还展示了一系列诊断图。

    1. 使用上述诊断图,判断基于数学模型对这些数据进行推断的条件是否满足。如果不满足,请描述应如何继续进行分析。

    2. 利用回归输出结果,评估 habit 的真实斜率(即母亲是否为吸烟者)在模型中包含其他变量的情况下是否不同于 0。请写出原假设和备择假设,报告 p 值(使用数学模型),并给出你的结论。

  1. 婴儿体重,共线性预测变量。 在本练习中,我们研究婴儿体重与两个解释变量之间的关系:妊娠 weeks 数和产前检查 visits. (ICPSR 2014) 数。下图展示了这些变量各自的分布(对角线上)以及它们之间的两两关系和相关系数。

    下面还提供了三个回归模型的输出结果: weight 对比 weeks, weight 对比 visitsweight 对比 weeks + visits.

    term 估计 的线性模型摘要 统计量 std.error
    p.value -0.83 1.76 -0.47 0.6395
    weeks 0.21 0.05 4.70 <0.0001
    term 估计 的线性模型摘要 统计量 std.error
    p.value 6.56 0.36 18.36 <0.0001
    visits 0.08 0.03 2.61 0.0105
    term 估计 的线性模型摘要 统计量 std.error
    p.value -0.44 1.78 -0.25 0.81
    weeks 0.19 0.05 4.00 0.00
    visits 0.04 0.03 1.26 0.21
    1. 图中描述了三个变量,每两个变量配对形成三个不同的散点图。请将这些两两关系按相关性从高到低排序。

    2. 当仅使用一个变量来对婴儿的 weight建模时, weeks 是否是一个可辨识的预测变量? visits 是否是一个可辨识的预测变量?请解释你的理由。

    3. 当同时使用 visitsweeks 来预测婴儿的 weight时,两个预测变量是否仍然可以区分?请解释你的理由。

  1. 婴儿体重,交叉验证。 使用 2014 年美国 1,000 例新生儿的随机样本,我们研究婴儿体重与各种解释变量之间的关系。 (ICPSR 2014) 下面的图展示了两个不同模型的预测误差,这两个模型用于预测婴儿出生时的 weight ;一个模型使用 7 个预测变量,另一个模型使用 2 个预测变量。采用 4 折交叉验证,数据被分成 4 折。其中若干折用于估计 \(\beta_i\) 估计 \(b_i\),然后将模型应用于留出的那一折进行预测。该过程重复了 4 次(每次留出一折)。

    \[ \begin{aligned} E[\texttt{weight}] = \beta_0 &+ \beta_1\times \texttt{fage} + \beta_2\times \texttt{mage} + \beta_3 \times \texttt{mature} + \beta_4 \times \texttt{weeks} \\ &+ \beta_5 \times \texttt{visits} + \beta_6 \times \texttt{gained} + \beta_7 \times \texttt{habit}\\ E[\texttt{weight}] = \beta_0 &+ \beta_1\times \texttt{weeks} + \beta_2\times \texttt{mature} \end{aligned} \]

    1. 在第一张图中,注意大约位于(预测值 = 11,误差 = -4)的点。估计该观测值的观测值和预测值。

    2. 使用同一个点,描述构建其预测模型时使用了哪些交叉验证折。

    3. 对于上方的图,针对其中一个交叉验证折,线性模型中估计了多少个系数?对于下方的图,针对其中一个交叉验证折,线性模型中估计了多少个系数?

    4. 两个模型的残差值(沿 y 轴,而非 x 轴)看起来是否有明显差异?请解释你的理由。

  1. RailTrail,交叉验证。 先锋谷规划委员会(PVPC)于2005年4月5日至2005年11月15日的九十天里,在马萨诸塞州佛罗伦萨的栗树街以北收集数据。数据收集人员架设了一个激光传感器,当激光束被遮挡时,记录有铁路步道使用者经过数据收集站。7 下图显示了用于预测以下内容的两个不同模型所对应的预测误差: volume 的两个不同模型相关的预测误差;一个模型使用6个预测变量,另一个模型使用2个预测变量。采用3折交叉验证,数据被分成3折。其中各折使用 \(\beta_i\) 估计 \(b_i\),然后将模型应用于留出的那一折进行预测。该过程重复了 4 次(每次留出一折)。

    \[ \begin{aligned} E[\texttt{volume}] = \beta_0 &+ \beta_1 \times \texttt{hightemp} + \beta_2 \times \texttt{lowtemp} + \beta_3 \times \texttt{spring}\\ &+ \beta_4 \times \texttt{weekday} + \beta_5 \times \texttt{cloudcover}+ \beta_6 \times \texttt{precip} \\ E[\texttt{volume}] = \beta_0 &+ \beta_1\times \texttt{hightemp} + \beta_2\times \texttt{precip} \end{aligned} \]

    1. 在第二张图中,注意大约位于(预测值 = 400,误差 = 100)处的点。估计该观测值的观测值和预测值。

    2. 使用同一个点,描述构建其预测模型时使用了哪些交叉验证折。

    3. 对于上方的图,针对其中一个交叉验证折,线性模型中估计了多少个系数?对于下方的图,针对其中一个交叉验证折,线性模型中估计了多少个系数?

    4. 两个模型的残差值(沿 y 轴,而非 x 轴)看起来是否有明显差异?请解释你的理由。

  1. 婴儿体重,用于模型选择的交叉验证。 使用 2014 年美国 1,000 例新生儿的随机样本,我们研究婴儿体重与各种解释变量之间的关系。 (ICPSR 2014) 下面的图展示了两个不同模型的预测误差,这两个模型用于预测婴儿出生时的 weight ;一个模型使用 7 个预测变量,另一个模型使用 2 个预测变量。采用 4 折交叉验证,数据被分成 4 折。其中若干折用于估计 \(\beta_i\) 估计 \(b_i\)参数,然后将模型应用于留出的那一折进行预测。该过程重复了4次,每次留出一折。

    \[ \begin{aligned} E[\texttt{weight}] = \beta_0 &+ \beta_1\times \texttt{fage} + \beta_2\times \texttt{mage}\\ &+ \beta_3 \times \texttt{mature} + \beta_4 \times \texttt{weeks}\\\ &+ \beta_5 \times \texttt{visits}+ \beta_6 \times \texttt{gained}\\ &+ \beta_7 \times \texttt{habit}\\ \end{aligned} \]

    \[ \begin{aligned} E[\texttt{weight}] = \beta_0 &+ \beta_1\times \texttt{weeks} + \beta_2\times \texttt{mature} \end{aligned} \]

    1. 根据点的离散程度(y方向),在关于这些数据的最终报告中应选择哪个模型?请解释你的理由。

    2. 根据汇总统计量(CV SSE),在关于这些数据的最终报告中应选择哪个模型?请解释你的理由。

    3. 为什么预测变量较多的模型对数据的拟合程度反而不如只有两个预测变量的模型?

  1. RailTrail,用于模型选择的交叉验证。 先锋谷规划委员会(PVPC)于2005年4月5日至2005年11月15日的九十天里,在马萨诸塞州佛罗伦萨的栗树街以北收集了数据。数据收集人员架设了一台激光传感器,激光束的中断记录了铁路步道使用者经过数据收集站的时刻。下图显示了用于预测RailTrail上骑行者 volume 的两个不同模型相关的预测误差;一个模型使用6个预测变量,另一个模型使用2个预测变量。采用3折交叉验证,数据被分成3折。其中各折使用 \(\beta_i\) 估计 \(b_i\)参数,然后将模型应用于留出的那一折进行预测。该过程重复了4次,每次留出一折。

    \[ \begin{aligned} E[\texttt{volume}] = \beta_0 &+ \beta_1\times \texttt{hightemp} + \beta_2\times \texttt{lowtemp}\\ &+ \beta_3 \times \texttt{spring} + \beta_4 \times \texttt{weekday}\\\ &+ \beta_5 \times \texttt{cloudcover}+ \beta_6 \times \texttt{precip}\\ \end{aligned} \]

    \[ \begin{aligned} E[\texttt{volume}] = \beta_0 &+ \beta_1\times \texttt{hightemp} + \beta_2\times \texttt{precip} \end{aligned} \]

    1. 根据点的离散程度(y方向),在关于这些数据的最终报告中应选择哪个模型?请解释你的理由。

    2. 根据汇总统计量(CV SSE),在关于这些数据的最终报告中应选择哪个模型?请解释你的理由。

    3. 为什么预测变量较多的模型对数据的拟合程度反而不如只有两个预测变量的模型?


  1. 在前面的章节中,使用了术语 解释变量 而不是 predictor。这两个词是同义词,在不同章节中分别使用,以与大多数分析师的习惯保持一致:检验时用 explanatory variable(解释变量),建模时用 predictor(预测变量)。↩︎

  2. 坦白说,这个特定的数据集是虚构的,该问题的原始想法来自欧柏林学院的 Jeff Witmer。↩︎

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

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

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

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

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