Nutrition at Starbucks, Part I. (8.22, p. 326) 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.
Based on the graph, there’s an upward positive trend, as the amount of calories increase so do the carbs.
Explanatory Variable: in this scenario, the calories is the explanatory variable Response Variable: the carbs would be the response variable in this scenario
We would want to fit a regression line in order to make better predictions about the data. By doing so in this data set we’d be able to predict the amount of carbs based on the calories.
Based on the plot, the data fits a linear plot, the residuals appear to be normal and we cannot achieve constant variability. We cannot be sure if the variables are independent since this is from the Starbucks menu. Therefore, it does not satisfy the conditions required for a fitting a least squares line.
Body measurements, Part I. (8.13, p. 316) Researchers studying anthropometry collected body girth measurements and skeletal diameter measurements, as well as age, weight, height and gender for 507 physically active individuals. The scatterplot below shows the relationship between height and shoulder girth (over deltoid muscles), both measured in centimeters.
Based on the plot, it seems to have a positive upward trend where as the shoulder girth increases so does the height.
The relationship wouldn’t change if the units changed to inches for shoulder girth. It will still show a positive upward trend.
Body measurements, Part III. (8.24, p. 326) Exercise above 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.
The equation of regression line for predicting height is: y = b0 + b1x or height = 105.97 + 0.608 girth.
The slope is .608, which is the rate of increase for the height in centimeters and the intercept is 105.97 is the height in centimeters of the shoulder girth.
# Shoulder girth mean and standard deviation
sg_mean <- 107.20
sg_sd <- 10.37
# Height mean and standard deviation
h_mean <- 171.14
h_sd <- 9.41
# Correlation between height and shoulder girth
corr <- 0.67
# Calculate slope
b1 <- (h_sd / sg_sd) * corr
b1
## [1] 0.6079749
# Calculate Intercept
b0 <- h_mean - (b1 * sg_mean)
b0
## [1] 105.9651
The \(R^2\) is 45% meaning that 45% of the variation is found within this data.
# $R^2$
r_sqr <- corr^2
r_sqr
## [1] 0.4489
The predicted height of the student is 166.76 cm.
# shoulder girth
g <- 100
# Predict height
predict_height <- b0 + b1 * g
predict_height
## [1] 166.7626
The residual is -6.76 meaning that the model overestimated the height of the student.
# Calculate the residual
act_height <- 160
residual <- act_height - predict_height
residual
## [1] -6.762581
Being that a one year old’s shoulder girth is 56 cm, it is otuside of the range in the sample data.
Cats, Part I. (8.26, p. 327) 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.
y = b0 + b1x or heart weight(g) = -0.357 + 4.034 body weight(kg)
With 0kg being the body weight, the intercept is -0.357 of the heart weight. Since there is no such thing as a 0 kg body weight, this result is not meaningful.
For the slope, for every additional body weight(kg) there is an expected additional 4.034g increase in heart weight.
The body weight explains the 65% variability in the heart weight of the cats.
The correlation coefficient is 0.804 and being that it is greater than 0.5 there is a positive correlation.
R2 <- 0.6466
# Correlation Coefficient
cc <- sqrt(R2)
cc
## [1] 0.8041144
Rate my professor. (8.44, p. 340) 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 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. The scatterplot below shows the relationship between these variables, and also provided is a regression output for predicting teaching evaluation score from beauty score.
The slope is -0.13
# y = b0 + b1*x
b0 <- 4.010
y <- 3.9983
x <- 0.0883
# Slope
b1 <- (y - b0) / x
b1
## [1] -0.1325028
The slope found is positive because the p-value is almost 0.
Based on the plots below, the conditions for linear regression are met. The data is almost linear, it’s a random observation and assumes that the points are independent from each other and the distribution appears to be normal.