Chapter 7 - Introduction to Linear Regression Practice: 7.23, 7.25, 7.29, 7.39 Graded: 7.24, 7.26, 7.30, 7.40
7.24 Nutrition at Starbucks, Part I. The scatterplot below shows the relationship between the number of calories and amount of carbohydrates (in grams) Starbucks food menu items con- tain.21 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.
In this scenario, what are the explanatory and response variables? x(Carbs) is the explanatory, y(Calories) is the response
Do these data meet the conditions required for fitting a least squares line? Yes, because the residual plot reveals increased frequency at higher calories and tighter bound errors at lower calories. Least squares should help us fit this accordingly.
7.26 Body measurements, Part III. 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. (a) Write the equation of the regression line for predicting height. \[ \hat{height} = beta_0 - beta_1*\hat{shoulder girth} \] (b) Interpret the slope and the intercept in this context. \[ beta_1 = R * s_y/s_x \]
R <- 0.67
x_mean <- 107.20
y_mean <- 171.14
beta_1 <- 0.67 * (9.41/10.37)
beta_0 <- y_mean - (beta_1*x_mean)
R_squared <- R * R
x_rand <- 100
y_rand <- beta_0 + beta_1*x_rand
cat("the predicted height of the student is:", y_rand, "cm" )
## the predicted height of the student is: 166.7626 cm
e_i <- 160 - y_rand
cat("the residual is:", e_i, "cm")
## the residual is: -6.762581 cm
A positive residual means that the model underestimates the height.
No, this calculation would require extrapolation.
7.30 Cats, Part I. The following regression output is for predicting the heart weight (in g) of cats from their body weight (in kg). The coefficients are estimated using a dataset of 144 domestic cats.
Interpret R2. 64.66 % of the time, the linear model describes the variation in heart weight(g) by body weight(kg.)
Calculate the correlation coefficient.
R <- sqrt(.6466)
cat("the correlation coefficient (R) =", R)
## the correlation coefficient (R) = 0.8041144
7.40 Rate my professor. Many college courses conclude by giving students the opportunity to evaluate the course and the instructor anonymously. However, the use of these student evalu- ations as an indicator of course quality and teaching effectiveness is often criticized because these measures may reflect the influence 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.24 The scatterplot below shows the relationship between these variables, and also provided is a regression output for predicting teaching evaluation score from beauty score.
x_mean <- -.0883
y_mean <- 3.9983
beta_0 <- 4.010
beta_1 <- (y_mean - beta_0)/x_mean
cat("The slope is:", beta_1)
## The slope is: 0.1325028