Chapter 7 - Linear Regression
Practice: 7.23, 7.25, 7.29, 7.39
Graded: 7.24, 7.26, 7.30, 7.40
The scatterplot below shows the relationship between the number of calories and amount of carbohydrates (in grams) Starbucks food menu items contain. Since Starbucks only lists the number of calories on the display items, we are interested in predicting the amount of carbs a menu item has based on its calorie content.
There is a moderately strong association between number of calories and carbs with substantial residuals.
Number of calories is the explanatory variable, and number of carbs is the response.
We might want to project how many carbs a new drink would have based on number of carbs. Though, given that carbs are one of three components of calories, it seems a little weird that we’d start with calories to get carbs.
Conditions: 1. Linearity: It shows a largely positive association - pretty linear.
2. Nearly normal residuals: Looks nearly normal in the graph and residual histogram.
3. Constant variability: Residuals are much larger at large values of x, so variability is not constant.Therefore, the conditions are not met.
4. Independent observations: Observations likely independent.
Because of non-constant variability, conditions for fitting a least squares line not met.
Exercise 7.15 introduces data on shoulder girth and height of a group of individuals. The mean shoulder girth is 107.20 cm with a standard deviation of 10.37 cm. The mean height is 171.14 cm with a standard deviation of 9.41 cm. The correlation between height and shoulder girth is 0.67.
\[ y = B_0 + B_1x\\ height = B_0 + B_1 * girth_shoulder\\ \\ B_0 = y-intercept\\ B_1 = slope\\ B_1 = s_y/s_x * R\\ B_1 = s_height/s_girth_shoulder * correlation\\ B_1 = 9.41 cm/10.37 cm * .67 = \]
b1_7.26 <- (9.41/10.37) * .67
b1_7.26
## [1] 0.6079749
Back to 8th grade, using the mean values: \[ y - y_0 = b_1 * (x-x_0)\\ y - 171.14 = .6080 * (x - 107.20) \]
b0_7.26 = b1_7.26 * (-107.20) + 171.14
b0_7.26
## [1] 105.9651
\[ height = 105.965 + .608 * girth_shoulder \]
The y-intercept here is tricky, as it implies that someone with no shoulder girth would be more than 100 cm tall. The slope is more helpful - for every additional cm of shoulder girth, the regression line predicts a person is .608 cm taller.
R-squared describes “the amount of variation in the response that is explained by the least squares line.”
R2_7.26 <- .67^2
R2_7.26
## [1] 0.4489
*44.9% of the variation in height is reduced by using information about shoulder girth.**
x_7.26 = 100
height_7.26 = 105.965 + .608 * x_7.26
height_7.26
## [1] 166.765
166.77 cm tall
actual_height_7.26 <- 160
actual_height_7.26 - height_7.26
## [1] -6.765
Residual is -6.77 cm, which means the least squares line overestimated the residual by more than 6 cm.
Nope. Looking at the data in 7.15, we see that the smallest shoulder girths in the study are above 80 cm. 56 cm is way outside our study - should not use linear regression on values outsides the study value minimum and maximums.
The following regression output is for predicting the heart weight (in g) of cats from their body weight (in kg). The coecients are estimated using a dataset of 144 domestic cats.
\[ hweight = -.357 + 4.034 * bweight \]
Heart weight can’t be negative at 0 or close to 0 bodyweights, so not a meaningful value. Function is to adjust the height of the line for regression.
For each increase of 1 kg in body weight, the heart weight increases more than 4 g.
More than 64 percent of the variation in heart weight can be explained by changes in body weight.
sqrt(.6466)
## [1] 0.8041144
Many college courses conclude by giving students the opportunity to evaluate the course and the instructor anonymously. However, the use of these student evaluations as an indicator of course quality and teaching e???ectiveness is often criticized because these measures may re???ect the in???uence of non-teaching related characteristics, such as the physical appearance of the instructor. Researchers at University of Texas, Austin collected data on teaching evaluation score (higher score means better) and standardized beauty score (a score of 0 means average, negative score means below average, and a positive score means above average) for a sample of 463 professors. The scatterplot below shows the relationship between these variables, and also provided is a regression output for predicting teaching evaluation score from beauty score.
\[ y = B_0 + B_1 * x\\ y_1 = 4.010 + B_1 * x_1 3.9983 = 4.010 + B_1 * -.0883 \]
(3.9983-4.010)/-.0883
## [1] 0.1325028
Slope is .133.
The slope is slightly positive. P values are very small. The null hypothesis would be that the slope is 0. With our p values and slope, we can reject the null hypothesis and conclude the relationship is slightly positive.
Conditions: 1. Linearity: This is the weakest performing. Slope is only slightly positive with huge residuals abounding. Marginal pass. 2. Nearly normal residuals: Looks nearly normal in the residual histogram.
3. Constant variability: Residuals are mostly constant, though there seem to be more negative ones at lower beauty ratings.
4. Independent observations: Looks soundly independent.
Despite the relatively weak linearity, the seems to satisfy the conditions.