title: “Chapter 8 - Introduction to Linear Regression”
author: “Sufian”
output:
html_document:
df_print: paged
pdf_document:
extra_dependencies:
- geometry
- multicol
- multirow
- xcolor
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.
ans:
The relationship seems to be linear and exibit positive correlation as evidenced by the 45 degree line
ans:
The response variable are the carbs while the explanatory (predictor) variables are the calories
ans:
The see if there are any linear relationship between the 2 variables and if there are, could use a
simple linear regression formula for predictive purposes
ans:
Yes, it seems the 2 variables are linear (45 degree line) and the residuals are showing randomess about
the zero line, which means no heterodasticity and the histogram is “quite” normal.
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.19 The scatterplot below shows the relationship between height and shoulder girth (over deltoid muscles), both measured in centimeters.
\begin{center} \end{center}
ans:
It appears that they are positively related; as shoulder girth increase, so does height
ans:
The slope would flatten out a bit
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.
sx <- 10.37 # std, dev of girth
sy <- 9.41 # std dev of height
corr <- 0.67 #correlation
b1 <- sy/sx*(corr)
b1 # slope
## [1] 0.6079749
ybar <- 171.4
xbar <- 107.2
b0 <- ybar - b1*xbar
b0
## [1] 106.2251
ans:
y = 0.6079x + 106.2251
ans:
slope => for every inch of shoulder girth increase, you get 0.6079 increase in height
ans:
0.45%, This means about 45% of the variability in height can be explained by shoulder girth, see below
rsquare <- corr*corr
rsquare
## [1] 0.4489
ans:
using the linear equation from (b), y = 0.6079x + 106.2251
The predicted height of student is 167 cm
x1 <- 100
y <- b1*x1 + b0
y
## [1] 167.0226
yact <- 160
res <- yact - y
res
## [1] -7.022581
ans:
residual is -7.022 or abs residual is 7.022, it is the difference between actual height and predicted
or in other words, the error between actuals vs. predicted
ans:
It would not be appropriate to use this model to calculate the height of a 1 year old since it maybe
outside of the model’s range.
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.
\begin{center} \end{center}
ans:
y = 4.034x - 0.357
ans:
It normally would’ve indicated the heart weight if body weight was zero. But in this case, it’s a
matter of “anchoring” the regression line
ans:
slope represent that for a unit increase of body weight, 4.034 unit of heart weight would have
increase accordingly
ans:
This means about 64.41% of the variability in height can be explained by body weight
ans: r = 80.4%
rsquare1 <- 0.6466
corr1 <- sqrt(rsquare1 )
corr1
## [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.
\begin{center} \end{center}
avgbeauty <- -0.0883
avgteaching <- 3.9983
intercept <- 4.010
m <- (avgteaching-intercept)/avgbeauty
m
## [1] 0.1325028
ans: slope = 0.1325, see above
ans:
Lets look at the diagnostics from the figures provided below:
heteorsdasticity
the residual plots looks quite normal
The Q-Q plots looks good with no extreme kinks, except for the outer edges, so we can safetly say
it does have a normal distribution
Finally, t-stat:
The t-stat is > 0.05 which means that the slope is significant. This all point to the fact that the
relationship between beauty and teaching is positively correlated