The principles of simple linear regression lay the foundation for more sophisticated regression models used in a wide range of challenging settings. In Chapter 9, we explore multiple regression, which introduces the possibility of more than one predictor in a linear model, and logistic regression, a technique for predicting categorical outcomes with two levels.
Multiple regression extends simple two-variable regression to the case that still has one response but many predictors (denoted , , , ...). The method is motivated by scenarios where many variables may be simultaneously connected to an output.
We will consider data about loans from the peer-to-peer lender, Lending Club, which is a data set we first encountered in Chapters 1 and 2. The loan data includes terms of the loan as well as information about the borrower. The outcome variable we would like to better understand is the interest rate assigned to the loan. For instance, all other characteristics held constant, does it matter how much debt someone already has? Does it matter if their income has been verified? Multiple regression will help us answer these and other questions.
The data set loans includes results from 10,000 loans, and we’ll be looking at a subset of the available variables, some of which will be new from those we saw in earlier chapters. The first six observations in the data set are shown in Figure 9.1, and descriptions for each variable are shown in Figure 9.2. Notice that the past bankruptcy variable (bankruptcy) is an indicator variable, where it takes the value 1 if the borrower had a past bankruptcy in their record and 0 if not. Using an indicator variable in place of a category name allows for these variables to be directly used in regression. Two of the other variables are categorical (income_ver and issued), each of which can take one of a few different non-numerical values; we’ll discuss how these are handled in the model in Section 9.1.1.
| interest_rate | income_ver | debt_to_income | credit_util | bankruptcy | term | issued | credit_checks | |
|---|---|---|---|---|---|---|---|---|
| 1 | 14.07 | verified | 18.01 | 0.55 | 0 | 60 | Mar2018 | 6 |
| 2 | 12.61 | not | 5.04 | 0.15 | 1 | 36 | Feb2018 | 1 |
| 3 | 17.09 | source_only | 21.15 | 0.66 | 0 | 36 | Feb2018 | 4 |
| 4 | 6.72 | not | 10.16 | 0.20 | 0 | 36 | Jan2018 | 0 |
| 5 | 14.07 | verified | 57.96 | 0.75 | 0 | 36 | Mar2018 | 7 |
| 6 | 6.72 | not | 6.46 | 0.09 | 0 | 36 | Jan2018 | 6 |
loans data set.| variable | description |
|---|---|
interest_rate |
Interest rate for the loan. |
income_ver |
Categorical variable describing whether the borrower’s income source and amount have been verified, with levels verified, source_only, and not. |
debt_to_income |
Debt-to-income ratio, which is the percentage of total debt of the borrower divided by their total income. |
credit_util |
Of all the credit available to the borrower, what fraction are they utilizing. For example, the credit utilization on a credit card would be the card’s balance divided by the card’s credit limit. |
bankruptcy |
An indicator variable for whether the borrower has a past bankruptcy in her record. This variable takes a value of 1 if the answer is “yes” and 0 if the answer is “no”. |
term |
The length of the loan, in months. |
issued |
The month and year the loan was issued, which for these loans is always during the first quarter of 2018. |
credit_checks |
Number of credit checks in the last 12 months. For example, when filing an application for a credit card, it is common for the company receiving the application to run a credit check. |
loans data set.Indicator and categorical variables as predictors
Let’s start by fitting a linear regression model for interest rate with a single predictor indicating whether or not a person has a bankruptcy in their record: Results of this model are shown in Figure 9.3.
| Estimate | Std. Error | t value | Pr(t) | |
| (Intercept) | 12.3380 | 0.0533 | 231.49 | 0.0001 |
| bankruptcy | 0.7368 | 0.1529 | 4.82 | 0.0001 |
Example 9.1
Interpret the coefficient for the past bankruptcy variable in the model. Is this coefficient significantly different from 0?
The bankruptcy variable takes one of two values: 1 when the borrower has a bankruptcy in their history and 0 otherwise. A slope of 0.74 means that the model predicts a 0.74% higher interest rate for those borrowers with a bankruptcy in their record. (See Section 8.2.8 for a review of the interpretation for two-level categorical predictor variables.) Examining the regression output in Figure 9.3, we can see that the p-value for bankruptcy is very close to zero, indicating there is strong evidence the coefficient is different from zero when using this simple one-predictor model.
Suppose we had fit a model using a 3-level categorical variable, such as income_ver. The output from software is shown in Figure 9.4. This regression output provides multiple rows for the income_ver variable. Each row represents the relative difference for each level of income_ver. However, we are missing one of the levels: not (for not verified). The missing level is called the reference level, and it represents the default level that other levels are measured against.
| Estimate | Std. Error | t value | Pr(t) | |
| (Intercept) | 11.0995 | 0.0809 | 137.18 | 0.0001 |
| income_ver | 1.4160 | 0.1107 | 12.79 | 0.0001 |
| income_ver | 3.2543 | 0.1297 | 25.09 | 0.0001 |
Example 9.2
How would we write an equation for this regression model?
The equation for the regression model may be written as a model with two predictors: We use the notation to represent indicator variables for when the categorical variable takes a particular value. For example, would take a value of 1 if income_ver was source_only for a loan, and it would take a value of 0 otherwise. Likewise, would take a value of 1 if income_ver took a value of verified and 0 if it took any other value.
The notation used in Example 9.2 may feel a bit confusing. Let’s figure out how to use the equation for each level of the income_ver variable.
Example 9.3
Using the model from Example 9.2, compute the average interest rate for borrowers whose income source and amount are both unverified.
When income_ver takes a value of not, then both indicator functions in the equation from Example 9.2 are set to zero: The average interest rate for these borrowers is 11.1%. Because the not level does not have its own coefficient and it is the reference value, the indicators for the other levels for this variable all drop out.
Example 9.4
Using the model from Example 9.2, compute the average interest rate for borrowers whose income source is verified but the amount is not.
When income_ver takes a value of source_only, then the corresponding variable takes a value of 1 while the other () is 0: The average interest rate for these borrowers is 12.52%.
Guided Practice 9.5
Compute the average interest rate for borrowers whose income source and amount are both verified.1
Predictors with several categories
When fitting a regression model with a categorical variable that has levels where , software will provide a coefficient for of those levels. For the last level that does not receive a coefficient, this is the reference level, and the coefficients listed for the other levels are all considered relative to this reference level.
Guided Practice 9.6
Interpret the coefficients in the income_ver model.2
The higher interest rate for borrowers who have verified their income source or amount is surprising. Intuitively, we’d think that a loan would look less risky if the borrower’s income has been verified. However, note that the situation may be more complex, and there may be confounding variables that we didn’t account for. For example, perhaps lender require borrowers with poor credit to verify their income. That is, verifying income in our data set might be a signal of some concerns about the borrower rather than a reassurance that the borrower will pay back the loan. For this reason, the borrower could be deemed higher risk, resulting in a higher interest rate. (What other confounding variables might explain this counter-intuitive relationship suggested by the model?)
Guided Practice 9.7
How much larger of an interest rate would we expect for a borrower who has verified their income source and amount vs a borrower whose income source has only been verified?3
Including and assessing many variables in a model
The world is complex, and it can be helpful to consider many factors at once in statistical modeling. For example, we might like to use the full context of borrower to predict the interest rate they receive rather than using a single variable. This is the strategy used in multiple regression. While we remain cautious about making any causal interpretations using multiple regression on observational data, such models are a common first step in gaining insights or providing some evidence of a causal connection.
We want to construct a model that accounts not only for any past bankruptcy or whether the borrower had their income source or amount verified, but simultaneously accounts for all the variables in the data set: income_ver, debt_to_income, credit_util, bankruptcy, term, issued, and credit_checks. This equation represents a holistic approach for modeling all of the variables simultaneously. Notice that there are two coefficients for income_ver and also two coefficients for issued, since both are 3-level categorical variables.
We estimate the parameters , , , ..., in the same way as we did in the case of a single predictor. We select , , , ..., that minimize the sum of the squared residuals: where and represent the observed interest rates and their estimated values according to the model, respectively. 10,000 residuals are calculated, one for each observation. We typically use a computer to minimize the sum of squares and compute point estimates, as shown in the sample output in Figure 9.5. Using this output, we identify the point estimates of each , just as we did in the one-predictor case.
| Estimate | Std. Error | t value | Pr(t) | |
| (Intercept) | 1.9251 | 0.2102 | 9.16 | 0.0001 |
| income_ver | 0.9750 | 0.0991 | 9.83 | 0.0001 |
| income_ver | 2.5374 | 0.1172 | 21.65 | 0.0001 |
| debt_to_income | 0.0211 | 0.0029 | 7.18 | 0.0001 |
| credit_util | 4.8959 | 0.1619 | 30.24 | 0.0001 |
| bankruptcy | 0.3864 | 0.1324 | 2.92 | 0.0035 |
| term | 0.1537 | 0.0039 | 38.96 | 0.0001 |
| issued | 0.0276 | 0.1081 | 0.26 | 0.7981 |
| issued | -0.0397 | 0.1065 | -0.37 | 0.7093 |
| credit_checks | 0.2282 | 0.0182 | 12.51 | 0.0001 |
interest_rate is the outcome and the variables listed are the predictors.Multiple regression model
A multiple regression model is a linear model with many predictors. In general, we write the model as when there are predictors. We always estimate the parameters using statistical software.
Example 9.8
Write out the regression model using the point estimates from Figure 9.5. How many predictors are there in this model?
The fitted model for the interest rate is given by: If we count up the number of predictor coefficients, we get the effective number of predictors in the model: . Notice that the issued categorical predictor counts as two, once for the two levels shown in the model. In general, a categorical predictor with different levels will be represented by terms in a multiple regression model.
Guided Practice 9.9
What does , the coefficient of variable credit_util, represent? What is the point estimate of ?4
Example 9.10
Compute the residual of the first observation in Figure 9.1 on Section 9.1 using the equation identified in Guided Practice 9.8.
To compute the residual, we first need the predicted value, which we compute by plugging values into the equation from Example 9.8. For example, takes a value of 0, takes a value of 1 (since the borrower’s income source and amount were verified), debt_to_income was 18.01, and so on. This leads to a prediction of . The observed interest rate was 14.07%, which leads to a residual of .
Example 9.11
We estimated a coefficient for bankruptcy in Section 9.1.1 of with a standard error of when using simple linear regression. Why is there a difference between that estimate and the estimated coefficient of 0.39 in the multiple regression setting?
If we examined the data carefully, we would see that some predictors are correlated. For instance, when we estimated the connection of the outcome interest_rate and predictor bankruptcy using simple linear regression, we were unable to control for other variables like whether the borrower had her income verified, the borrower’s debt-to-income ratio, and other variables. That original model was constructed in a vacuum and did not consider the full context. When we include all of the variables, underlying and unintentional bias that was missed by these other variables is reduced or eliminated. Of course, bias can still exist from other confounding variables.
Example 9.11 describes a common issue in multiple regression: correlation among predictor variables. We say the two predictor variables are collinear (pronounced as co-linear) when they are correlated, and this collinearity complicates model estimation. While it is impossible to prevent collinearity from arising in observational data, experiments are usually designed to prevent predictors from being collinear.
Guided Practice 9.12
The estimated value of the intercept is 1.925, and one might be tempted to make some interpretation of this coefficient, such as, it is the model’s predicted price when each of the variables take value zero: income source is not verified, the borrower has no debt (debt-to-income and credit utilization are zero), and so on. Is this reasonable? Is there any value gained by making this interpretation?5
Adjusted as a better tool for multiple regression
We first used in Section 8.2 to determine the amount of variability in the response that was explained by the model: where represents the residuals of the model and the outcomes. This equation remains valid in the multiple regression framework, but a small enhancement can make it even more informative when comparing models.
Guided Practice 9.13
The variance of the residuals for the model given in Guided Practice 9.8 is 18.53, and the variance of the total price in all the auctions is 25.01. Calculate for this model.6
This strategy for estimating is acceptable when there is just a single variable. However, it becomes less helpful when there are many variables. The regular is a biased estimate of the amount of variability explained by the model when applied to a new sample of data. To get a better estimate, we use the adjusted .
Adjusted as a tool for model assessment
The adjusted is computed as where is the number of cases used to fit the model and is the number of predictor variables in the model. Remember that a categorical predictor with levels will contribute to the number of variables in the model.
Because is never negative, the adjusted will be smaller – often times just a little smaller – than the unadjusted . The reasoning behind the adjusted lies in the degrees of freedom associated with each variance, which is equal to for the multiple regression context. If we were to make predictions for new data using our current model, we would find that the unadjusted would tend to be slightly overly optimistic, while the adjusted formula helps correct this bias.
Guided Practice 9.14
There were auctions in the loans data set and predictor variables in the model. Use , , and the variances from Guided Practice 9.13 to calculate for the interest rate model.7
Guided Practice 9.15
Suppose you added another predictor to the model, but the variance of the errors didn’t go down. What would happen to the ? What would happen to the adjusted ?8
Adjusted could have been used in Chapter 8. However, when there is only predictors, adjusted is very close to regular , so this nuance isn’t typically important when the model has only one predictor.
Exercises
Exercise 9.1
Baby weights, Part I. The Child Health and Development Studies investigate a range of topics. One study considered all pregnancies between 1960 and 1967 among women in the Kaiser Foundation Health Plan in the San Francisco East Bay area. 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 ounces, based on the smoking status of the mother. 9
| Estimate | Std. Error | t value | Pr(t) | |
|---|---|---|---|---|
| (Intercept) | 123.05 | 0.65 | 189.60 | 0.0000 |
| smoke | -8.94 | 1.03 | -8.65 | 0.0000 |
The variability within the smokers and non-smokers are about equal and the distributions are symmetric. With these conditions satisfied, it is reasonable to apply the model. (Note that we don’t need to check linearity since the predictor has only two levels.)
Write the equation of the regression model.
Interpret the slope in this context, and calculate the predicted birth weight of babies born to smoker and non-smoker mothers.
Is there a statistically significant relationship between the average birth weight and smoking?
Exercise 9.2
Baby weights, Part II. Exercise 9.1 introduces a data set on birth weight of babies. Another variable we consider is parity, which is 1 if the child is the first born, and 0 otherwise. The summary table below shows the results of a linear regression model for predicting the average birth weight of babies, measured in ounces, from parity.
| Estimate | Std. Error | t value | Pr(t) | |
|---|---|---|---|---|
| (Intercept) | 120.07 | 0.60 | 199.94 | 0.0000 |
| parity | -1.93 | 1.19 | -1.62 | 0.1052 |
Write the equation of the regression model.
Interpret the slope in this context, and calculate the predicted birth weight of first borns and others.
Is there a statistically significant relationship between the average birth weight and parity?
Exercise 9.3
Baby weights, Part III. We considered the variables smoke and parity, one at a time, in modeling birth weights of babies in Exercises 9.1 and 9.2. A more realistic approach to modeling infant weights is to consider all possibly related variables at once. Other variables of interest include length of pregnancy in days (gestation), mother’s age in years (age), mother’s height in inches (height), and mother’s pregnancy weight in pounds (weight). Below are three observations from this data set.
| bwt | gestation | parity | age | height | weight | smoke | |
|---|---|---|---|---|---|---|---|
| 1 | 120 | 284 | 0 | 27 | 62 | 100 | 0 |
| 2 | 113 | 282 | 0 | 33 | 64 | 135 | 0 |
| 1236 | 117 | 297 | 0 | 38 | 65 | 129 | 0 |
The summary table below shows the results of a regression model for predicting the average birth weight of babies based on all of the variables included in the data set.
| Estimate | Std. Error | t value | Pr(t) | |
|---|---|---|---|---|
| (Intercept) | -80.41 | 14.35 | -5.60 | 0.0000 |
| gestation | 0.44 | 0.03 | 15.26 | 0.0000 |
| parity | -3.33 | 1.13 | -2.95 | 0.0033 |
| age | -0.01 | 0.09 | -0.10 | 0.9170 |
| height | 1.15 | 0.21 | 5.63 | 0.0000 |
| weight | 0.05 | 0.03 | 1.99 | 0.0471 |
| smoke | -8.40 | 0.95 | -8.81 | 0.0000 |
Write the equation of the regression model that includes all of the variables.
Interpret the slopes of
gestationandagein this context.The coefficient for
parityis different than in the linear model shown in Exercise 9.2. Why might there be a difference?Calculate the residual for the first observation in the data set.
The variance of the residuals is 249.28, and the variance of the birth weights of all babies in the data set is 332.57. Calculate the and the adjusted . Note that there are 1,236 observations in the data set.
Exercise 9.4
Absenteeism, Part I. Researchers interested in the relationship between absenteeism from school and certain demographic characteristics of children collected data from 146 randomly sampled students in rural New South Wales, Australia, in a particular school year. Below are three observations from this data set.
| eth | sex | lrn | days | |
|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 2 |
| 2 | 0 | 1 | 1 | 11 |
| 146 | 1 | 0 | 0 | 37 |
The summary table below shows the results of a linear regression model for predicting the average number of days absent based on ethnic background (eth: 0 - aboriginal, 1 - not aboriginal), sex (sex: 0 - female, 1 - male), and learner status (lrn: 0 - average learner, 1 - slow learner). 10
| Estimate | Std. Error | t value | Pr(t) | |
|---|---|---|---|---|
| (Intercept) | 18.93 | 2.57 | 7.37 | 0.0000 |
| eth | -9.11 | 2.60 | -3.51 | 0.0000 |
| sex | 3.10 | 2.64 | 1.18 | 0.2411 |
| lrn | 2.15 | 2.65 | 0.81 | 0.4177 |
Write the equation of the regression model.
Interpret each one of the slopes in this context.
Calculate the residual for the first observation in the data set: a student who is aboriginal, male, a slow learner, and missed 2 days of school.
The variance of the residuals is 240.57, and the variance of the number of absent days for all students in the data set is 264.17. Calculate the and the adjusted . Note that there are 146 observations in the data set.
Exercise 9.5
GPA. A survey of 55 Duke University students asked about their GPA, number of hours they study at night, number of nights they go out, and their gender. Summary output of the regression model is shown below. Note that male is coded as 1.
| Estimate | Std. Error | t value | Pr(t) | |
|---|---|---|---|---|
| (Intercept) | 3.45 | 0.35 | 9.85 | 0.00 |
| studyweek | 0.00 | 0.00 | 0.27 | 0.79 |
| sleepnight | 0.01 | 0.05 | 0.11 | 0.91 |
| outnight | 0.05 | 0.05 | 1.01 | 0.32 |
| gender | -0.08 | 0.12 | -0.68 | 0.50 |
Calculate a 95% confidence interval for the coefficient of gender in the model, and interpret it in the context of the data.
Would you expect a 95% confidence interval for the slope of the remaining variables to include 0? Explain
Exercise 9.6
Cherry trees. 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.11
| Estimate | Std. Error | t value | Pr(t) | |
|---|---|---|---|---|
| (Intercept) | -57.99 | 8.64 | -6.71 | 0.00 |
| height | 0.34 | 0.13 | 2.61 | 0.01 |
| diameter | 4.71 | 0.26 | 17.82 | 0.00 |
Calculate a 95% confidence interval for the coefficient of height, and interpret it in the context of the data.
One tree in this sample is 79 feet tall, has a diameter of 11.3 inches, and is 24.2 cubic feet in volume. Determine if the model overestimates or underestimates the volume of this tree, and by how much.
Notes
When
income_vertakes a value ofverified, then the corresponding variable takes a value of 1 while the other () is 0: The average interest rate for these borrowers is 14.35%. ↩Each of the coefficients gives the incremental interest rate for the corresponding level relative to the
notlevel, which is the reference level. For example, for a borrower whose income source and amount have been verified, the model predicts that they will have a 3.25% higher interest rate than a borrower who has not had their income source or amount verified. ↩Relative to the
notcategory, theverifiedcategory has an interest rate of 3.25% higher, while thesource_onlycategory is only 1.42% higher. Thus,verifiedborrowers will tend to get an interest rate about higher thansource_onlyborrowers. ↩represents the change in interest rate we would expect if someone’s credit utilization was 0 and went to 1, all other factors held even. The point estimate is . ↩
Many of the variables do take a value 0 for at least one data point, and for those variables, it is reasonable. However, one variable never takes a value of zero:
term, which describes the length of the loan, in months. Iftermis set to zero, then the loan must be paid back immediately; the borrower must give the money back as soon as she receives it, which means it is not a real loan. Ultimately, the interpretation of the intercept in this setting is not insightful. ↩. ↩
. While the difference is very small, it will be important when we fine tune the model in the next section. ↩
The unadjusted would stay the same and the adjusted would go down. ↩
Child Health and Development Studies, Baby weights data set. ↩
W. N. Venables and B. D. Ripley. Modern Applied Statistics with S. Springer. Data can also be found in the R MASS package. 2002. ↩
Hand, D.J. A handbook of small data sets. Chapman & Hall/CRC. 1994. ↩