Every problem in the chapter beside the book’s answer, a chapter at a time as you scroll.

Chapter 9: Multiple and logistic regression

28 problems · 9 figures

Guided Practice 9.5 §9.1 source ↗

Compute the average interest rate for borrowers whose income source and amount are both verified.

Answer

When income_ver takes a value of verified, then the corresponding variable takes a value of 1 while the other (𝚒𝚗𝚌𝚘𝚖𝚎_𝚟𝚎𝚛source_only⁠) is 0:

rateˆ=11.10+1.42×0+3.25×1=14.35

The average interest rate for these borrowers is 14.35%.

Guided Practice 9.6 §9.1 source ↗

Interpret the coefficients in the income_ver model.

Answer

Each of the coefficients gives the incremental interest rate for the corresponding level relative to the not level, 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.

Guided Practice 9.7 §9.1 source ↗

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?

Answer

Relative to the not category, the verified category has an interest rate of 3.25% higher, while the source_only category is only 1.42% higher. Thus, verified borrowers will tend to get an interest rate about 3.25%−1.42%=1.83% higher than source_only borrowers.

Guided Practice 9.10 §9.1 source ↗

What does β4⁠, the coefficient of variable credit_util, represent? What is the point estimate of β4⁠?

Answer

β4 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 b4=4.90%⁠.

Guided Practice 9.13 §9.1 source ↗

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?

Answer

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. If term is 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.

Guided Practice 9.14 §9.1 source ↗

The variance of the residuals for the model given in Guided Practice 9.9 is 18.53, and the variance of the total price in all the auctions is 25.01. Calculate R2 for this model.

Guided Practice 9.9 in the book ↗

Write out the regression model using the point estimates from Figure 9.5. How many predictors are there in this model?

Answer. The fitted model for the interest rate is given by:

𝚛𝚊𝚝𝚎ˆ=1.925+0.975×𝚒𝚗𝚌𝚘𝚖𝚎_𝚟𝚎𝚛source_only+2.537×𝚒𝚗𝚌𝚘𝚖𝚎_𝚟𝚎𝚛verified+0.021×𝚍𝚎𝚋𝚝_𝚝𝚘_𝚒𝚗𝚌𝚘𝚖𝚎 +4.896×𝚌𝚛𝚎𝚍𝚒𝚝_𝚞𝚝𝚒𝚕+0.386×𝚋𝚊𝚗𝚔𝚛𝚞𝚙𝚝𝚌𝚢+0.154×𝚝𝚎𝚛𝚖 +0.028×𝚒𝚜𝚜𝚞𝚎𝚍Jan2018−0.040×𝚒𝚜𝚜𝚞𝚎𝚍Mar2018+0.228×𝚌𝚛𝚎𝚍𝚒𝚝_𝚌𝚑𝚎𝚌𝚔𝚜

If we count up the number of predictor coefficients, we get the effective number of predictors in the model: k=9⁠. Notice that the issued categorical predictor counts as two, once for the two levels shown in the model. In general, a categorical predictor with p different levels will be represented by p−1 terms in a multiple regression model.

Answer

R2=1−18.5325.01=0.2591⁠.

Guided Practice 9.15 §9.1 source ↗

There were n=10000 auctions in the loans data set and k=9 predictor variables in the model. Use n⁠, k⁠, and the variances from Guided Practice 9.14 to calculate Radj2 for the interest rate model.

Guided Practice 9.14 in the book ↗

The variance of the residuals for the model given in Guided Practice 9.9 is 18.53, and the variance of the total price in all the auctions is 25.01. Calculate R2 for this model.

Answer. R2=1−18.5325.01=0.2591⁠.

Answer

Radj2= 1− 18.5325.01×10000−11000−9−1= 0.2584⁠. While the difference is very small, it will be important when we fine tune the model in the next section.

Guided Practice 9.16 §9.1 source ↗

Suppose you added another predictor to the model, but the variance of the errors Var(ei) didn’t go down. What would happen to the R2⁠? What would happen to the adjusted R2⁠?

Answer

The unadjusted R2 would stay the same and the adjusted R2 would go down.

9.1 §9.1 source ↗

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.

EstimateStd. Errort valuePr(>|⁠t⁠|⁠)
(Intercept)123.050.65189.600.0000
smoke-8.941.03-8.650.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.)

(a)

Write the equation of the regression model.

(b)

Interpret the slope in this context, and calculate the predicted birth weight of babies born to smoker and non-smoker mothers.

(c)

Is there a statistically significant relationship between the average birth weight and smoking?

Answer (3 parts)

(a)

baby_weightˆ= 123.05− 8.94×smoke

(b)

The estimated body weight of babies born to smoking mothers is 8.94 ounces lower than babies born to non-smoking mothers. Smoker: 123.05−8.94×1=114.11 ounces. Non-smoker: 123.05−8.94×0=123.05 ounces.

(c)

H0⁠: β1=0⁠. HA⁠: β1≠0⁠. T=−8.65⁠, and the p-value is approximately 0. Since the p-value is very small, we reject H0⁠. The data provide strong evidence that the true slope parameter is different than 0 and that there is an association between birth weight and smoking. Furthermore, having rejected H0⁠, we can conclude that smoking is associated with lower birth weights.

9.3 §9.1 source ↗

Exercise 9.1 in the book ↗

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.

EstimateStd. Errort valuePr(>|⁠t⁠|⁠)
(Intercept)123.050.65189.600.0000
smoke-8.941.03-8.650.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.)

(a) Write the equation of the regression model.

(b) Interpret the slope in this context, and calculate the predicted birth weight of babies born to smoker and non-smoker mothers.

(c) Is there a statistically significant relationship between the average birth weight and smoking?

Answer. (a) baby_weightˆ= 123.05− 8.94×smoke (b) The estimated body weight of babies born to smoking mothers is 8.94 ounces lower than babies born to non-smoking mothers. Smoker: 123.05−8.94×1=114.11 ounces. Non-smoker: 123.05−8.94×0=123.05 ounces. (c) H0⁠: β1=0⁠. HA⁠: β1≠0⁠. T=−8.65⁠, and the p-value is approximately 0. Since the p-value is very small, we reject H0⁠. The data provide strong evidence that the true slope parameter is different than 0 and that there is an association between birth weight and smoking. Furthermore, having rejected H0⁠, we can conclude that smoking is associated with lower birth weights.

Exercise 9.2 in the book ↗

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.

EstimateStd. Errort valuePr(>|⁠t⁠|⁠)
(Intercept)120.070.60199.940.0000
parity-1.931.19-1.620.1052

(a) Write the equation of the regression model.

(b) Interpret the slope in this context, and calculate the predicted birth weight of first borns and others.

(c) Is there a statistically significant relationship between the average birth weight and parity?

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.

bwtgestationparityageheightweightsmoke
1120284027621000
2113282033641350
⋮⋮⋮⋮⋮⋮⋮⋮
1236117297038651290

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.

EstimateStd. Errort valuePr(>|⁠t⁠|⁠)
(Intercept)-80.4114.35-5.600.0000
gestation0.440.0315.260.0000
parity-3.331.13-2.950.0033
age-0.010.09-0.100.9170
height1.150.215.630.0000
weight0.050.031.990.0471
smoke-8.400.95-8.810.0000
(a)

Write the equation of the regression model that includes all of the variables.

(b)

Interpret the slopes of gestation and age in this context.

(c)

The coefficient for parity is different than in the linear model shown in Exercise 9.2. Why might there be a difference?

(d)

Calculate the residual for the first observation in the data set.

(e)

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 R2 and the adjusted R2⁠. Note that there are 1,236 observations in the data set.

Answer (5 parts)

(a)

baby_weightˆ= − 80.41+ 0.44×gestation− 3.33×parity− 0.01×age+ 1.15×height+ 0.05×weight− 8.40×smoke⁠.

(b)

βgestation⁠: The model predicts a 0.44 ounce increase in the birth weight of the baby for each additional day of pregnancy, all else held constant. βage⁠: The model predicts a 0.01 ounce decrease in the birth weight of the baby for each additional year in mother’s age, all else held constant.

(c)

Parity might be correlated with one of the other variables in the model, which complicates model estimation.

(d)

baby_weightˆ=120.58⁠. e=120−120.58=−0.58⁠. The model over-predicts this baby’s birth weight.

(e)

R2=0.2504⁠. Radj2=0.2468⁠.

9.5 §9.1 source ↗

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.

EstimateStd. Errort valuePr(>|⁠t⁠|⁠)
(Intercept)3.450.359.850.00
studyweek0.000.000.270.79
sleepnight0.010.050.110.91
outnight0.050.051.010.32
gender-0.080.12-0.680.50
(a)

Calculate a 95% confidence interval for the coefficient of gender in the model, and interpret it in the context of the data.

(b)

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

Answer (2 parts)

(a)

(-0.32, 0.16). We are 95% confident that male students on average have GPAs 0.32 points lower to 0.16 points higher than females when controlling for the other variables in the model.

(b)

Yes, since the p-value is larger than 0.05 in all cases (not including the intercept).

Guided Practice 9.20 §9.2 source ↗

Examine Figure 9.7 on page , which considers the model including all variables except the variable for the month the loan was issued. If we were using the p-value approach with backward elimination and we were considering this model, which of these variables would be up for elimination? Would we drop that variable, or would we keep it in the model?

Figure 9.7 in the book ↗
EstimateStd. Errort valuePr(>|⁠t⁠|⁠)
(Intercept)1.92130.19829.69<⁠0.0001
income_ver: source_only0.97400.09919.83<⁠0.0001
income_ver: verified2.53550.117221.64<⁠0.0001
debt_to_income0.02110.00297.19<⁠0.0001
credit_util4.89580.161930.25<⁠0.0001
bankruptcy0.38690.13242.920.0035
term0.15370.003938.97<⁠0.0001
credit_checks0.22830.018212.51<⁠0.0001
Radj2=0.25854df=9992
The fit for the regression model after dropping the issued variable.

Answer

The bankruptcy predictor is up for elimination since it has the largest p-value. However, since that p-value is smaller than 0.05, we would still keep it in the model.

9.7 §9.2 source ↗

Baby weights, Part IV. Exercise 9.3 considers a model that predicts a newborn’s weight using several predictors (gestation length, parity, age of mother, height of mother, weight of mother, smoking status of mother). The table below shows the adjusted R-squared for the full model as well as adjusted R-squared values for all models we evaluate in the first step of the backwards elimination process.

ModelAdjusted R2
1Full model0.2541
2No gestation0.1031
3No parity0.2492
4No age0.2547
5No height0.2311
6No weight0.2536
7No smoking status0.2072

Which, if any, variable should be removed from the model first?

Exercise 9.3 in the book ↗

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.

bwtgestationparityageheightweightsmoke
1120284027621000
2113282033641350
⋮⋮⋮⋮⋮⋮⋮⋮
1236117297038651290

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.

EstimateStd. Errort valuePr(>|⁠t⁠|⁠)
(Intercept)-80.4114.35-5.600.0000
gestation0.440.0315.260.0000
parity-3.331.13-2.950.0033
age-0.010.09-0.100.9170
height1.150.215.630.0000
weight0.050.031.990.0471
smoke-8.400.95-8.810.0000

(a) Write the equation of the regression model that includes all of the variables.

(b) Interpret the slopes of gestation and age in this context.

(c) The coefficient for parity is different than in the linear model shown in Exercise 9.2. Why might there be a difference?

(d) Calculate the residual for the first observation in the data set.

(e) 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 R2 and the adjusted R2⁠. Note that there are 1,236 observations in the data set.

Answer. (a) baby_weightˆ= − 80.41+ 0.44×gestation− 3.33×parity− 0.01×age+ 1.15×height+ 0.05×weight− 8.40×smoke⁠. (b) βgestation⁠: The model predicts a 0.44 ounce increase in the birth weight of the baby for each additional day of pregnancy, all else held constant. βage⁠: The model predicts a 0.01 ounce decrease in the birth weight of the baby for each additional year in mother’s age, all else held constant. (c) Parity might be correlated with one of the other variables in the model, which complicates model estimation. (d) baby_weightˆ=120.58⁠. e=120−120.58=−0.58⁠. The model over-predicts this baby’s birth weight. (e) R2=0.2504⁠. Radj2=0.2468⁠.

Answer

Remove age.

9.9 §9.2 source ↗

Baby weights, Part V. Exercise 9.3 provides regression output for the full model (including all explanatory variables available in the data set) for predicting birth weight of babies. In this exercise we consider a forward-selection algorithm and add variables to the model one-at-a-time. The table below shows the p-value and adjusted R2 of each model where we include only the corresponding predictor. Based on this table, which variable should be added to the model first?

variablegestationparityageheightweightsmoke
p-value2.2×10−160.10520.23752.97×10−128.2×10−82.2×10−16
Radj20.16570.00130.00030.03860.02290.0569
Exercise 9.3 in the book ↗

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.

bwtgestationparityageheightweightsmoke
1120284027621000
2113282033641350
⋮⋮⋮⋮⋮⋮⋮⋮
1236117297038651290

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.

EstimateStd. Errort valuePr(>|⁠t⁠|⁠)
(Intercept)-80.4114.35-5.600.0000
gestation0.440.0315.260.0000
parity-3.331.13-2.950.0033
age-0.010.09-0.100.9170
height1.150.215.630.0000
weight0.050.031.990.0471
smoke-8.400.95-8.810.0000

(a) Write the equation of the regression model that includes all of the variables.

(b) Interpret the slopes of gestation and age in this context.

(c) The coefficient for parity is different than in the linear model shown in Exercise 9.2. Why might there be a difference?

(d) Calculate the residual for the first observation in the data set.

(e) 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 R2 and the adjusted R2⁠. Note that there are 1,236 observations in the data set.

Answer. (a) baby_weightˆ= − 80.41+ 0.44×gestation− 3.33×parity− 0.01×age+ 1.15×height+ 0.05×weight− 8.40×smoke⁠. (b) βgestation⁠: The model predicts a 0.44 ounce increase in the birth weight of the baby for each additional day of pregnancy, all else held constant. βage⁠: The model predicts a 0.01 ounce decrease in the birth weight of the baby for each additional year in mother’s age, all else held constant. (c) Parity might be correlated with one of the other variables in the model, which complicates model estimation. (d) baby_weightˆ=120.58⁠. e=120−120.58=−0.58⁠. The model over-predicts this baby’s birth weight. (e) R2=0.2504⁠. Radj2=0.2468⁠.

Answer

Based on the p-value alone, either gestation or smoke should be added to the model first. However, since the adjusted R2 for the model with gestation is higher, it would be preferable to add gestation in the first step of the forward- selection algorithm. (Other explanations are possible. For instance, it would be reasonable to only use the adjusted R2⁠.)

9.11 §9.2 source ↗

Movie lovers, Part I. Suppose a social scientist is interested in studying what makes audiences love or hate a movie. She collects a random sample of movies (genre, length, cast, director, budget, etc.) as well as a measure of the success of the movie (score on a film review aggregator website). If as part of her research she is interested in finding out which variables are significant predictors of movie success, what type of model selection method should she use?

Answer

She should use p-value selection since she is interested in finding out about significant predictors, not just optimizing predictions.

9.13 §9.3 source ↗

Baby weights, Part VI. Exercise 9.3 presents a regression model for predicting the average birth weight of babies based on length of gestation, parity, height, weight, and smoking status of the mother. Determine if the model assumptions are met using the plots below. If not, describe how to proceed with the analysis.

A histogram of residuals is shown, which has a bell-shaped distribution, is centered at 0, and has a standard deviation of about 12.

A scatterplot of ”residuals” (vertical axis) against ”fitted values”. The residuals does not show any pattern for different fitted values.

A scatterplot of ”residuals” (vertical axis) against ”order of collection”. The residuals does not show any pattern across the order of collection variable.

A scatterplot of ”residuals” (vertical axis) against ”length of gestation”. The residuals does not show any pattern for different lengths of gestation.

A scatterplot of ”residuals” (vertical axis) against ”parity”, which only takes values 0 and 1. The residuals does not show any apparent patterns across the values 0 and 1 of parity.

A scatterplot of ”residuals” (vertical axis) against ”height of mother”. The residuals does not show any pattern for different values of ”height of mother”.

A scatterplot of ”residuals” (vertical axis) against ”weight of mother”. The residuals does not show any pattern for different values of ”weight of mother”.

A scatterplot of ”residuals” (vertical axis) against ”smoke”, which only takes values 0 and 1. The residuals does not show any pattern for the 0 and 1 values of smoke.

Exercise 9.3 in the book ↗

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.

bwtgestationparityageheightweightsmoke
1120284027621000
2113282033641350
⋮⋮⋮⋮⋮⋮⋮⋮
1236117297038651290

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.

EstimateStd. Errort valuePr(>|⁠t⁠|⁠)
(Intercept)-80.4114.35-5.600.0000
gestation0.440.0315.260.0000
parity-3.331.13-2.950.0033
age-0.010.09-0.100.9170
height1.150.215.630.0000
weight0.050.031.990.0471
smoke-8.400.95-8.810.0000

(a) Write the equation of the regression model that includes all of the variables.

(b) Interpret the slopes of gestation and age in this context.

(c) The coefficient for parity is different than in the linear model shown in Exercise 9.2. Why might there be a difference?

(d) Calculate the residual for the first observation in the data set.

(e) 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 R2 and the adjusted R2⁠. Note that there are 1,236 observations in the data set.

Answer. (a) baby_weightˆ= − 80.41+ 0.44×gestation− 3.33×parity− 0.01×age+ 1.15×height+ 0.05×weight− 8.40×smoke⁠. (b) βgestation⁠: The model predicts a 0.44 ounce increase in the birth weight of the baby for each additional day of pregnancy, all else held constant. βage⁠: The model predicts a 0.01 ounce decrease in the birth weight of the baby for each additional year in mother’s age, all else held constant. (c) Parity might be correlated with one of the other variables in the model, which complicates model estimation. (d) baby_weightˆ=120.58⁠. e=120−120.58=−0.58⁠. The model over-predicts this baby’s birth weight. (e) R2=0.2504⁠. Radj2=0.2468⁠.

Answer

Nearly normal residuals: With so many observations in the data set, we look for particularly extreme outliers in the histogram and do not see any. variability of residuals: The scatterplot of the residuals versus the fitted values does not show any overall structure. However, values that have very low or very high fitted values appear to also have somewhat larger outliers. In addition, the residuals do appear to have constant variability between the two parity and smoking status groups, though these items are relatively minor.
Independent residuals: The scatterplot of residuals versus the order of data collection shows a random scatter, suggesting that there is no apparent structures related to the order the data were collected.
Linear relationships between the response variable and numerical explanatory variables: The residuals vs. height and weight of mother are randomly distributed around 0. The residuals vs. length of gestation plot also does not show any clear or strong remaining structures, with the possible exception of very short or long gestations. The rest of the residuals do appear to be randomly distributed around 0.
All concerns raised here are relatively mild. There are some outliers, but there is so much data that the influence of such observations will be minor.

Guided Practice 9.21 §9.4 source ↗

We fit a linear regression model with the game’s condition as a predictor of auction price. Results of this model are summarized below:

EstimateStd. Errort valuePr(>|⁠t⁠|⁠)
(Intercept)42.87110.814052.67<⁠0.0001
cond_new10.89961.25838.66<⁠0.0001
df=139

Write down the equation for the model, note whether the slope is statistically different from zero, and interpret the coefficient.

Answer

The equation for the line may be written as

priceˆ=42.87+10.90×cond_new

Examining the regression output in Guided Practice 9.21, we can see that the p-value for cond_new is very close to zero, indicating there is strong evidence that the coefficient is different from zero when using this simple one-variable model.

The cond_new is a two-level categorical variable that takes value 1 when the game is new and value 0 when the game is used. This means the 10.90 model coefficient predicts an extra $10.90 for those games that are new versus those that are used.

Guided Practice 9.22 §9.4 source ↗

Write out the model’s equation using the point estimates from Figure 9.15. How many predictors are there in this model?

Figure 9.15 in the book ↗
EstimateStd. Errort valuePr(>|⁠t⁠|⁠)
(Intercept)36.21101.514023.92<⁠0.0001
cond_new5.13061.05114.88<⁠0.0001
stock_photo1.08031.05681.020.3085
duration-0.02680.1904-0.140.8882
wheels7.28520.554713.13<⁠0.0001
df=136
Output for the regression model where price is the outcome and cond_new, stock_photo, duration, and wheels are the predictors.

Answer

priceˆ= 36.21+ 5.13×𝚌𝚘𝚗𝚍_𝚗𝚎𝚠+ 1.08×𝚜𝚝𝚘𝚌𝚔_𝚙𝚑𝚘𝚝𝚘− 0.03×𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗+ 7.29×𝚠𝚑𝚎𝚎𝚕𝚜⁠, with the k=4 predictors.

Guided Practice 9.23 §9.4 source ↗

What does β4⁠, the coefficient of variable x4 (Wii wheels), represent? What is the point estimate of β4⁠?

Answer

It is the average difference in auction price for each additional Wii wheel included when holding the other variables constant. The point estimate is b4=7.29⁠.

Guided Practice 9.24 §9.4 source ↗

Compute the residual of the first observation in Figure 9.13 using the equation identified in Guided Practice 9.22.

Figure 9.13 in the book ↗
pricecond_newstock_photodurationwheels
151.551131
237.040171
⋮⋮⋮⋮⋮⋮
14038.760070
14154.511112
Four observations from the mariokart data set.
Guided Practice 9.22 in the book ↗

Write out the model’s equation using the point estimates from Figure 9.15. How many predictors are there in this model?

Answer. priceˆ= 36.21+ 5.13×𝚌𝚘𝚗𝚍_𝚗𝚎𝚠+ 1.08×𝚜𝚝𝚘𝚌𝚔_𝚙𝚑𝚘𝚝𝚘− 0.03×𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗+ 7.29×𝚠𝚑𝚎𝚎𝚕𝚜⁠, with the k=4 predictors.

Answer

ei= yi− yiˆ= 51.55− 49.62= 1.93⁠, where 49.62 was computed using the variables values from the observation and the equation identified in Guided Practice 9.22.

Guided Practice 9.22 in the book ↗

Write out the model’s equation using the point estimates from Figure 9.15. How many predictors are there in this model?

Answer. priceˆ= 36.21+ 5.13×𝚌𝚘𝚗𝚍_𝚗𝚎𝚠+ 1.08×𝚜𝚝𝚘𝚌𝚔_𝚙𝚑𝚘𝚝𝚘− 0.03×𝚍𝚞𝚛𝚊𝚝𝚒𝚘𝚗+ 7.29×𝚠𝚑𝚎𝚎𝚕𝚜⁠, with the k=4 predictors.

Guided Practice 9.27 §9.4 source ↗

In Example 9.26, we eliminated the duration variable, which resulted in a model with Radj2=0.7128⁠. Let’s look at if we would eliminate another variable from the model using backwards elimination:

Exclude duration and ...cond_newstock_photowheels
Radj2=0.6587Radj2=0.7124Radj2=0.3414

Should we eliminate any additional variable, and if so, which variable should we eliminate?

Example 9.26 in the book ↗

Results corresponding to the full model for the mariokart data were shown in Figure 9.15. For this model, we consider what would happen if dropping each of the variables in the model:

Exclude ...cond_newstock_photodurationwheels
Radj2=0.6626Radj2=0.7107Radj2=0.7128Radj2=0.3487

For the full model, Radj2=0.7108⁠. How should we proceed under the backward elimination strategy?

Answer. The third model without duration has the highest Radj2 of 0.7128, so we compare it to Radj2 for the full model. Because eliminating duration leads to a model with a higher Radj2⁠, we drop duration from the model.

Answer

Removing any of the three remaining variables would lead to a decrease in Radj2⁠, so we should not remove any additional variables from the model after we removed duration.

Guided Practice 9.28 §9.4 source ↗

After eliminating the auction’s duration from the model, we are left with the following reduced model:

priceˆ= 36.05+5.18×𝚌𝚘𝚗𝚍_𝚗𝚎𝚠+1.12×𝚜𝚝𝚘𝚌𝚔_𝚙𝚑𝚘𝚝𝚘+7.30×𝚠𝚑𝚎𝚎𝚕𝚜

How much would you predict for the total price for the Mario Kart game if it was used, used a stock photo, and included two wheels and put up for auction during the time period that the Mario Kart data were collected?

Answer

We would plug in 0 for cond_new 1 for stock_photo, and 2 for wheels into the equation, which would return $51.77, which is the total price we would expect for the auction.

Guided Practice 9.29 §9.4 source ↗

Would you be surprised if the seller from Guided Practice 9.28 didn’t get the exact price predicted?

Guided Practice 9.28 in the book ↗

After eliminating the auction’s duration from the model, we are left with the following reduced model:

priceˆ= 36.05+5.18×𝚌𝚘𝚗𝚍_𝚗𝚎𝚠+1.12×𝚜𝚝𝚘𝚌𝚔_𝚙𝚑𝚘𝚝𝚘+7.30×𝚠𝚑𝚎𝚎𝚕𝚜

How much would you predict for the total price for the Mario Kart game if it was used, used a stock photo, and included two wheels and put up for auction during the time period that the Mario Kart data were collected?

Answer. We would plug in 0 for cond_new 1 for stock_photo, and 2 for wheels into the equation, which would return $51.77, which is the total price we would expect for the auction.

Answer

No. The model provides the average auction price we would expect, and the price for one auction to the next will continue to vary a bit (but less than what our prediction would be without the model).

9.15 §9.5 source ↗

Figure 8.4 View it in the book ↗
The common brushtail possum of Australia.
—————————–

Possum classification, Part I. The common brushtail possum of the Australia region is a bit cuter than its distant cousin, the American opossum (see Figure 8.4). We consider 104 brushtail possums from two regions in Australia, where the possums may be considered a random sample from the population. The first region is Victoria, which is in the eastern half of Australia and traverses the southern coast. The second region consists of New South Wales and Queensland, which make up eastern and northeastern Australia. We use logistic regression to differentiate between possums in these two regions. The outcome variable, called population, takes value 1 when a possum is from Victoria and 0 when it is from New South Wales or Queensland. We consider five predictors: sex_ male (an indicator for a possum being male), head_ length, skull_ width, total_ length, and tail_ length. Each variable is summarized in a histogram. The full logistic regression model and a reduced model after variable selection are summarized in the table.

Six plots are shown for the distributions of each predictor variable. For the ”sex_male” categorical variable, about 42 observations are ”0 (female)” and 65 are ”1 (male)”. For the ”head_length (in mm)” variable, a histogram is shown that is approximately bell-shaped, centered at about 93, and has a standard deviation of about 3. For the ”skull_width (in mm)” variable, a histogram is shown for a slightly right-skewed distribution is shown with its peak at about 56 and a standard deviation of about 3. For the ”total_length (in cm)” variable, a histogram is shown with most values ranging from about 80 to 95, with no major outliers. For the ”tail_length (in cm)” variable, a histogram is shown with most data between about 33 and 42, with no major outliers. For the ”population” categorical variable, about 58 observations are ”0 (Not Victoria)” and 45 are ”1 (Victoria)”.

Full ModelReduced Model
EstimateSEZPr(>|⁠Z⁠|⁠)EstimateSEZPr(>|⁠Z⁠|⁠)
(Intercept)39.234911.53683.400.000733.50959.90533.380.0007
sex_ male-1.23760.6662-1.860.0632-1.42070.6457-2.200.0278
head_ length-0.16010.1386-1.160.2480
skull_ width-0.20120.1327-1.520.1294-0.27870.1226-2.270.0231
total_ length0.64880.15314.240.00000.56870.13224.300.0000
tail_ length-1.87080.3741-5.000.0000-1.80570.3599-5.020.0000
(a)

Examine each of the predictors. Are there any outliers that are likely to have a very large influence on the logistic regression model?

(b)

The summary table for the full model indicates that at least one variable should be eliminated when using the p-value approach for variable selection: head_ length. The second component of the table summarizes the reduced model following variable selection. Explain why the remaining estimates change between the two models.

Answer (2 parts)

(a)

There are a few potential outliers, e.g. on the left in the total_ length variable, but nothing that will be of serious concern in a data set this large.

(b)

When coefficient estimates are sensitive to which variables are included in the model, this typically indicates that some variables are collinear. For example, a possum’s gender may be related to its head length, which would explain why the coefficient (and p-value) for sex_ male changed when we removed the head_ length variable. Likewise, a possum’s skull width is likely to be related to its head length, probably even much more closely related than the head length was to gender.

9.17 §9.5 source ↗

Possum classification, Part II. A logistic regression model was proposed for classifying common brushtail possums into their two regions in Exercise 9.15. The outcome variable took value 1 if the possum was from Victoria and 0 otherwise.

EstimateSEZPr(>|⁠Z⁠|⁠)
(Intercept)33.50959.90533.380.0007
sex_ male-1.42070.6457-2.200.0278
skull_ width-0.27870.1226-2.270.0231
total_ length0.56870.13224.300.0000
tail_ length-1.80570.3599-5.020.0000
(a)

Write out the form of the model. Also identify which of the variables are positively associated when controlling for other variables.

(b)

Suppose we see a brushtail possum at a zoo in the US, and a sign says the possum had been captured in the wild in Australia, but it doesn’t say which part of Australia. However, the sign does indicate that the possum is male, its skull is about 63 mm wide, its tail is 37 cm long, and its total length is 83 cm. What is the reduced model’s computed probability that this possum is from Victoria? How confident are you in the model’s accuracy of this probability calculation?

Exercise 9.15 in the book ↗

Possum classification, Part I. The common brushtail possum of the Australia region is a bit cuter than its distant cousin, the American opossum (see Figure 8.4). We consider 104 brushtail possums from two regions in Australia, where the possums may be considered a random sample from the population. The first region is Victoria, which is in the eastern half of Australia and traverses the southern coast. The second region consists of New South Wales and Queensland, which make up eastern and northeastern Australia. We use logistic regression to differentiate between possums in these two regions. The outcome variable, called population, takes value 1 when a possum is from Victoria and 0 when it is from New South Wales or Queensland. We consider five predictors: sex_ male (an indicator for a possum being male), head_ length, skull_ width, total_ length, and tail_ length. Each variable is summarized in a histogram. The full logistic regression model and a reduced model after variable selection are summarized in the table.

Six plots are shown for the distributions of each predictor variable. For the ”sex_male” categorical variable, about 42 observations are ”0 (female)” and 65 are ”1 (male)”. For the ”head_length (in mm)” variable, a histogram is shown that is approximately bell-shaped, centered at about 93, and has a standard deviation of about 3. For the ”skull_width (in mm)” variable, a histogram is shown for a slightly right-skewed distribution is shown with its peak at about 56 and a standard deviation of about 3. For the ”total_length (in cm)” variable, a histogram is shown with most values ranging from about 80 to 95, with no major outliers. For the ”tail_length (in cm)” variable, a histogram is shown with most data between about 33 and 42, with no major outliers. For the ”population” categorical variable, about 58 observations are ”0 (Not Victoria)” and 45 are ”1 (Victoria)”.

Full ModelReduced Model
EstimateSEZPr(>|⁠Z⁠|⁠)EstimateSEZPr(>|⁠Z⁠|⁠)
(Intercept)39.234911.53683.400.000733.50959.90533.380.0007
sex_ male-1.23760.6662-1.860.0632-1.42070.6457-2.200.0278
head_ length-0.16010.1386-1.160.2480
skull_ width-0.20120.1327-1.520.1294-0.27870.1226-2.270.0231
total_ length0.64880.15314.240.00000.56870.13224.300.0000
tail_ length-1.87080.3741-5.000.0000-1.80570.3599-5.020.0000

(a) Examine each of the predictors. Are there any outliers that are likely to have a very large influence on the logistic regression model?

(b) The summary table for the full model indicates that at least one variable should be eliminated when using the p-value approach for variable selection: head_ length. The second component of the table summarizes the reduced model following variable selection. Explain why the remaining estimates change between the two models.

Answer. (a) There are a few potential outliers, e.g. on the left in the total_ length variable, but nothing that will be of serious concern in a data set this large. (b) When coefficient estimates are sensitive to which variables are included in the model, this typically indicates that some variables are collinear. For example, a possum’s gender may be related to its head length, which would explain why the coefficient (and p-value) for sex_ male changed when we removed the head_ length variable. Likewise, a possum’s skull width is likely to be related to its head length, probably even much more closely related than the head length was to gender.

Answer (2 parts)

(a)

The logistic model relating pˆi to the predictors may be written as log⁡(pˆi1−pˆi)= 33.5095− 1.4207×sex_malei− 0.2787×skull_widthi+ 0.5687×total_lengthi− 1.8057×tail_lengthi⁠. Only total_ length has a positive association with a possum being from Victoria.

(b)

pˆ=0.0062⁠. While the probability is very near zero, we have not run diagnostics on the model. We might also be a little skeptical that the model will remain accurate for a possum found in a US zoo. For example, perhaps the zoo selected a possum with specific characteristics but only looked in one region. On the other hand, it is encouraging that the possum was caught in the wild. (Answers regarding the reliability of the model probability will vary.)

9.19 §9.R source ↗

Multiple regression fact checking. Determine which of the following statements are true and false. For each statement that is false, explain why it is false.

(a)

If predictors are collinear, then removing one variable will have no influence on the point estimate of another variable’s coefficient.

(b)

Suppose a numerical variable x has a coefficient of b1=2.5 in the multiple regression model. Suppose also that the first observation has x1=7.2⁠, the second observation has a value of x1=8.2⁠, and these two observations have the same values for all other predictors. Then the predicted value of the second observation will be 2.5 higher than the prediction of the first observation based on the multiple regression model.

(c)

If a regression model’s first variable has a coefficient of b1=5.7⁠, then if we are able to influence the data so that an observation will have its x1 be 1 larger than it would otherwise, the value y1 for this observation would increase by 5.7.

(d)

Suppose we fit a multiple regression model based on a data set of 472 observations. We also notice that the distribution of the residuals includes some skew but does not include any particularly extreme outliers. Because the residuals are not nearly normal, we should not use this model and require more advanced methods to model these data.

Answer (4 parts)

(a)

False. When predictors are collinear, it means they are correlated, and the inclusion of one variable can have a substantial influence on the point estimate (and standard error) of another.

(b)

True.

(c)

False. This would only be the case if the data was from an experiment and x1 was one of the variables set by the researchers. (Multiple regression can be useful for forming hypotheses about causal relationships, but it offers zero guarantees.)

(d)

False. We should check normality like we would for inference for a single mean: we look for particularly extreme outliers if n≥30 or for clear outliers if n<30⁠.

9.21 §9.R source ↗

Spam filtering, Part I. Spam filters are built on principles similar to those used in logistic regression. We fit a probability that each message is spam or not spam. We have several email variables for this problem: to_multiple, cc, attach, dollar, winner, inherit, password, format, re_subj, exclaim_subj, and sent_email. We won’t describe what each variable means here for the sake of brevity, but each is either a numerical or indicator variable.

(a)

For variable selection, we fit the full model, which includes all variables, and then we also fit each model where we’ve dropped exactly one of the variables. In each of these reduced models, the AIC value for the model is reported below. Based on these results, which variable, if any, should we drop as part of model selection? Explain.

Variable DroppedAIC
None Dropped1863.50
to_multiple2023.50
cc1863.18
attach1871.89
dollar1879.70
winner1885.03
inherit1865.55
password1879.31
format2008.85
re_subj1904.60
exclaim_subj1862.76
sent_email1958.18

See the next page for part (b).

(b)

Consider the following model selection stage. Here again we’ve computed the AIC for each leave-one-variable-out model. Based on the results, which variable, if any, should we drop as part of model selection? Explain.

Variable DroppedAIC
None Dropped1862.41
to_multiple2019.55
attach1871.17
dollar1877.73
winner1884.95
inherit1864.52
password1878.19
format2007.45
re_subj1902.94
sent_email1957.56

Answer (2 parts)

(a)

exclaim_subj should be removed, since it’s removal reduces AIC the most (and the resulting model has lower AIC than the None Dropped model).

(b)

Removing any variable will increase AIC, so we should not remove any variables from this set.

9.23 §9.R source ↗

Spam filtering, Part II. In Exercise 9.21, we encountered a data set where we applied logistic regression to aid in spam classification for individual emails. In this exercise, we’ve taken a small set of these variables and fit a formal model with the following output:

EstimateStd. Errorz valuePr(>|⁠z⁠|⁠)
(Intercept)-0.81240.0870-9.340.0000
to_multiple-2.63510.3036-8.680.0000
winner1.62720.31855.110.0000
format-1.58810.1196-13.280.0000
re_subj-3.04670.3625-8.400.0000
(a)

Write down the model using the coefficients from the model fit.

(b)

Suppose we have an observation where 𝚝𝚘_𝚖𝚞𝚕𝚝𝚒𝚙𝚕𝚎=0⁠, 𝚠𝚒𝚗𝚗𝚎𝚛=1⁠, 𝚏𝚘𝚛𝚖𝚊𝚝=0⁠, and 𝚛𝚎_𝚜𝚞𝚋𝚓=0⁠. What is the predicted probability that this message is spam?

(c)

Put yourself in the shoes of a data scientist working on a spam filter. For a given message, how high must the probability a message is spam be before you think it would be reasonable to put it in a spambox (which the user is unlikely to check)? What tradeoffs might you consider? Any ideas about how you might make your spam-filtering system even better from the perspective of someone using your email service?

Exercise 9.21 in the book ↗

Spam filtering, Part I. Spam filters are built on principles similar to those used in logistic regression. We fit a probability that each message is spam or not spam. We have several email variables for this problem: to_multiple, cc, attach, dollar, winner, inherit, password, format, re_subj, exclaim_subj, and sent_email. We won’t describe what each variable means here for the sake of brevity, but each is either a numerical or indicator variable.

(a) For variable selection, we fit the full model, which includes all variables, and then we also fit each model where we’ve dropped exactly one of the variables. In each of these reduced models, the AIC value for the model is reported below. Based on these results, which variable, if any, should we drop as part of model selection? Explain.

Variable DroppedAIC
None Dropped1863.50
to_multiple2023.50
cc1863.18
attach1871.89
dollar1879.70
winner1885.03
inherit1865.55
password1879.31
format2008.85
re_subj1904.60
exclaim_subj1862.76
sent_email1958.18

See the next page for part (b).

(b) Consider the following model selection stage. Here again we’ve computed the AIC for each leave-one-variable-out model. Based on the results, which variable, if any, should we drop as part of model selection? Explain.

Variable DroppedAIC
None Dropped1862.41
to_multiple2019.55
attach1871.17
dollar1877.73
winner1884.95
inherit1864.52
password1878.19
format2007.45
re_subj1902.94
sent_email1957.56

Answer. (a) exclaim_subj should be removed, since it’s removal reduces AIC the most (and the resulting model has lower AIC than the None Dropped model). (b) Removing any variable will increase AIC, so we should not remove any variables from this set.

Answer (3 parts)

(a)

The equation is:

log⁡(pi1−pi)=−0.8124−2.6351×to_multiple+1.6272×winner−1.5881×format−3.0467×re_subj

(b)

First find log⁡(p1−p)⁠, then solve for p⁠:

log⁡(p1−p)=−0.8124−2.6351×0+1.6272×1−1.5881×0−3.0467×0=0.8148p1−p=e0.8148→p=0.693

(c)

It should probably be pretty high, since it could be very disruptive to the person using the email service if they are missing emails that aren’t spam. Even only a 90% chance that a message is spam is probably enough to warrant keeping it in the inbox. Maybe a probability of 99% would be a reasonable cutoff. As for other ideas to make it even better, it may be worth building a second model that tries to classify the importance of an email message. If we have both the spam model and the importance model, we now have a better way to think about cost-benefit tradeoffs. For instance, perhaps we would be willing to have a lower probability-of-spam threshold for messages we were confident were not important, and perhaps we want an even higher probability threshold (e.g. 99.99%) for emails we are pretty sure are important.

End of the book.

Exercises and answers are adapted from OpenIntro Statistics by David Diez, Mine Çetinkaya-Rundel and Christopher D Barr, which is free to read and download, and are used under the CC BY-SA 3.0 licence. They are taken from the book’s LaTeX source and set for the web, so they may differ slightly from the printed page. This adaptation is released under the same licence and is neither affiliated with nor endorsed by Diez, Çetinkaya-Rundel and Barr or OpenIntro.