Page 16

  1. Take the Galton dataset and find the mean, standard deviation and correlation between the parental and child heights.
## Loading required package: MASS
## Loading required package: HistData
## Loading required package: Hmisc
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, units
##   child parent
## 1  61.7   70.5
## 2  61.7   68.5
## 3  61.7   65.5
## 4  61.7   64.5
## 5  61.7   64.0
## 6  62.2   67.5

The mean of the child and the parent’s height.

##      child           parent     
##  Min.   :61.70   Min.   :64.00  
##  1st Qu.:66.20   1st Qu.:67.50  
##  Median :68.20   Median :68.50  
##  Mean   :68.09   Mean   :68.31  
##  3rd Qu.:70.20   3rd Qu.:69.50  
##  Max.   :73.70   Max.   :73.00

The standard deviation of the height of the child and the parent respectively.

## [1] 2.517941
## [1] 1.787333

correlation between the parental and child heights.

##            child    parent
## child  1.0000000 0.4587624
## parent 0.4587624 1.0000000
  1. Center the parent and child variables and verify that the centered variable means are 0.
##  [1] 70.5 68.5 65.5 64.5 64.0 67.5 67.5 67.5 66.5 66.5
##  [1] 61.7 61.7 61.7 61.7 61.7 62.2 62.2 62.2 62.2 62.2
## [1] 9.775954e-16
  1. Rescale the parent and child variables and verify that the scaled variable standard deviations are 1.
##   [1] 39.44424 38.32525 36.64677 36.08728 35.80753 37.76576 37.76576 37.76576
##   [9] 37.20626 37.20626 37.20626 36.08728 39.44424 38.88474 38.32525 38.32525
##  [17] 38.32525 38.32525 38.32525 38.32525 38.32525 37.76576 37.76576 37.76576
##  [25] 37.76576 37.76576 37.20626 37.20626 37.20626 36.64677 36.64677 36.64677
##  [33] 36.64677 36.64677 36.64677 36.64677 36.64677 36.64677 36.08728 36.08728
##  [41] 36.08728 36.08728 35.80753 35.80753 38.88474 38.88474 38.88474 38.88474
##  [49] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
##  [57] 38.88474 38.88474 38.88474 38.88474 38.32525 38.32525 38.32525 38.32525
##  [65] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 37.76576
##  [73] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
##  [81] 37.76576 37.76576 37.76576 37.76576 37.76576 37.20626 37.20626 37.20626
##  [89] 37.20626 37.20626 36.64677 36.64677 36.64677 36.64677 36.64677 36.08728
##  [97] 36.08728 36.08728 36.08728 35.80753 35.80753 35.80753 35.80753 40.00373
## [105] 39.44424 38.88474 38.88474 38.88474 38.88474 38.32525 38.32525 38.32525
## [113] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [121] 38.32525 38.32525 38.32525 38.32525 38.32525 37.76576 37.76576 37.76576
## [129] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [137] 37.76576 37.76576 37.76576 37.76576 37.20626 37.20626 36.64677 36.64677
## [145] 36.64677 36.64677 36.64677 36.64677 36.64677 36.08728 35.80753 40.00373
## [153] 40.00373 40.00373 39.44424 38.88474 38.88474 38.88474 38.88474 38.88474
## [161] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [169] 38.88474 38.88474 38.88474 38.88474 38.32525 38.32525 38.32525 38.32525
## [177] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [185] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [193] 38.32525 38.32525 38.32525 38.32525 38.32525 37.76576 37.76576 37.76576
## [201] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [209] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [217] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [225] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [233] 37.76576 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626
## [241] 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626
## [249] 37.20626 37.20626 36.64677 36.64677 36.64677 36.64677 36.64677 36.64677
## [257] 36.64677 36.64677 36.64677 36.64677 36.64677 36.08728 36.08728 36.08728
## [265] 36.08728 36.08728 35.80753 35.80753 40.00373 40.00373 40.00373 40.00373
## [273] 39.44424 39.44424 39.44424 38.88474 38.88474 38.88474 38.88474 38.88474
## [281] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [289] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [297] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.32525 38.32525
## [305] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [313] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [321] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [329] 38.32525 38.32525 38.32525 38.32525 38.32525 37.76576 37.76576 37.76576
## [337] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [345] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [353] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [361] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [369] 37.76576 37.76576 37.76576 37.20626 37.20626 37.20626 37.20626 37.20626
## [377] 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626
## [385] 37.20626 37.20626 37.20626 37.20626 36.64677 36.64677 36.64677 36.64677
## [393] 36.64677 36.64677 36.64677 36.64677 36.64677 36.64677 36.64677 36.08728
## [401] 36.08728 36.08728 36.08728 36.08728 35.80753 35.80753 40.56322 40.00373
## [409] 40.00373 40.00373 39.44424 39.44424 39.44424 39.44424 39.44424 39.44424
## [417] 39.44424 39.44424 39.44424 39.44424 39.44424 39.44424 38.88474 38.88474
## [425] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [433] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [441] 38.88474 38.88474 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [449] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [457] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [465] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [473] 38.32525 38.32525 38.32525 38.32525 37.76576 37.76576 37.76576 37.76576
## [481] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [489] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [497] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [505] 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626
## [513] 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626 36.64677 36.64677
## [521] 36.64677 36.64677 36.64677 36.64677 36.64677 35.80753 40.56322 40.56322
## [529] 40.00373 40.00373 40.00373 40.00373 40.00373 39.44424 39.44424 39.44424
## [537] 39.44424 39.44424 39.44424 39.44424 39.44424 39.44424 39.44424 39.44424
## [545] 39.44424 39.44424 39.44424 39.44424 39.44424 39.44424 39.44424 38.88474
## [553] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [561] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [569] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [577] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [585] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [593] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [601] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [609] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [617] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [625] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [633] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [641] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [649] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [657] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [665] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.20626 37.20626
## [673] 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626 37.20626
## [681] 37.20626 37.20626 37.20626 36.64677 36.64677 36.64677 36.64677 36.64677
## [689] 36.64677 36.64677 36.08728 36.08728 35.80753 40.56322 40.00373 40.00373
## [697] 40.00373 40.00373 40.00373 40.00373 40.00373 40.00373 40.00373 40.00373
## [705] 39.44424 39.44424 39.44424 39.44424 39.44424 39.44424 39.44424 39.44424
## [713] 39.44424 39.44424 39.44424 39.44424 39.44424 39.44424 38.88474 38.88474
## [721] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [729] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [737] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.32525
## [745] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [753] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [761] 38.32525 38.32525 38.32525 38.32525 37.76576 37.76576 37.76576 37.76576
## [769] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576
## [777] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 37.20626
## [785] 37.20626 37.20626 37.20626 36.64677 36.64677 36.64677 36.64677 36.64677
## [793] 40.56322 40.56322 40.00373 40.00373 40.00373 40.00373 39.44424 39.44424
## [801] 39.44424 39.44424 39.44424 39.44424 39.44424 38.88474 38.88474 38.88474
## [809] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [817] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [825] 38.88474 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [833] 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525 38.32525
## [841] 38.32525 38.32525 38.32525 37.76576 37.76576 37.76576 37.76576 37.76576
## [849] 37.76576 37.76576 37.76576 37.76576 37.76576 37.76576 36.64677 36.64677
## [857] 40.84297 40.56322 40.56322 40.56322 40.56322 40.56322 40.56322 40.56322
## [865] 40.00373 40.00373 40.00373 40.00373 40.00373 40.00373 40.00373 40.00373
## [873] 40.00373 39.44424 39.44424 39.44424 39.44424 38.88474 38.88474 38.88474
## [881] 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474 38.88474
## [889] 38.32525 38.32525 38.32525 38.32525 37.76576 37.76576 37.76576 37.76576
## [897] 36.64677 40.84297 40.84297 40.84297 40.56322 40.56322 40.00373 40.00373
## [905] 39.44424 39.44424 39.44424 38.88474 38.88474 38.88474 38.88474 38.32525
## [913] 38.32525 38.32525 40.56322 40.56322 40.56322 40.56322 40.00373 40.00373
## [921] 39.44424 39.44424 39.44424 38.88474 38.88474 38.88474 38.88474 38.88474

Emperical Standard Deviation

## [1] 1
  1. Normalize the parental and child heights. Verify that the normalized variables have mean 0 and standard deviation 1 and take the correlation between them.
##  [1] 70.5 68.5 65.5 64.5 64.0 67.5 67.5 67.5 66.5 66.5
##  [1] 61.7 61.7 61.7 61.7 61.7 62.2 62.2 62.2 62.2 62.2

Normalized variables have mean 0.

## [1] 5.501733e-16
## [1] 2.183943e-16

Standard deviation 1.

## [1] 1
## [1] 1

The correlation between the child and parent’s height.

## [1] 0.4587624
## [1] 0.4587624

Page 21 and 22

  1. Install and load the package UsingR and load the father.son data with data(father.son). Get the linear regression fit where the son’s height is the outcome and the father’s height is the predictor. Give the intercept and the slope, plot the data and overlay the fitted regression line.
##      (Intercept)  fheight
## [1,]     33.8866 0.514093
## [2,]     33.8866 0.514093
## `geom_smooth()` using formula = 'y ~ x'

  1. Refer to problem 1. Center the father and son variables and refit the model omitting the intercept. Verify that the slope estimate is the same as the linear regression fit from problem 1.
## 
## Call:
## lm(formula = sheight ~ fheight, data = father.son)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.8772 -1.5144 -0.0079  1.6285  8.9685 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 33.88660    1.83235   18.49   <2e-16 ***
## fheight      0.51409    0.02705   19.01   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.437 on 1076 degrees of freedom
## Multiple R-squared:  0.2513, Adjusted R-squared:  0.2506 
## F-statistic: 361.2 on 1 and 1076 DF,  p-value: < 2.2e-16

father’s height coeffecient is 0.514, let us refit to show that it is the same

## [1] 0.514093
  1. Refer to problem 1. Normalize the father and son data and see that the fitted slope is the correlation.
## 
## Call:
## lm(formula = yN ~ xN)
## 
## Coefficients:
## (Intercept)           xN  
##   1.820e-15    5.013e-01

taking the correlation,

## [1] 0.5013383
  1. Go back to the linear regression line from Problem 1. If a father’s height was 63 inches, what would you predict the son’s height to be?
##        1 
## 66.27447

so the son’s height is around 66.27

  1. Consider a data set where the standard deviation of the outcome variable is double that of the predictor. Also, the variables have a correlation of 0.3. If you fit a linear regression model, what would be the estimate of the slope?

sd(y) = sd(x) => sd(y)/sd(x) = 2

we have cor(y,x) = 3 so, the estimate of the slope would be

cor(y,x)(sd(y)/sd(x)) = (0.3)2 = 0.6

  1. Consider the previous problem. The outcome variable has a mean of 1 and the predictor has a mean of 0.5. What would be the intercept?

recall that the formula of slope is, \[ \beta_0 = \bar Y - \hat \beta_1 \bar X\] 1 - 0.6(0.5) = 0.7

  1. True or false, if the predictor variable has mean 0, the estimated intercept from linear regression will be the mean of the outcome?

recall that our intercept is, \[\hat \beta_0 = \bar Y - \hat \beta_1 \bar X\] if mean is zero then, \[\hat \beta_1 \bar X = 0\] and, \[\hat \beta_0 = \bar Y \].

Hence, True.

  1. Consider problem 5 again. What would be the estimated slope if the predictor and outcome were reversed?

Cor(x, y) (sd(x)/sd(y)) = 0.3(0.5) = 0.15

Page 26

  1. You have two noisy scales and a bunch of people that you’d like to weigh. You weigh each person on both scales. The correlation was 0.75. If you normalized each set of weights, what would you have to multiply the weight on one scale to get a good estimate of the weight on the other scale?

Let us have scale 1 in y-axis and scale 2 in x-axis, we need to normalize it so the center of the axis falls right in the mean of the data and the std of horizontal and vertical line is 1.correlation would be the best fitting regression line.

  1. Consider the previous problem. Someone’s weight was 2 standard deviations above the mean of the group on the first scale. How many standard deviations above the mean would you estimate them to be on the second?

we need to standard deviations, that would be 2(0.75) = 1.5

  1. You ask a collection of husbands and wives to guess how many jellybeans are in a jar. The correlation is 0.2. The standard deviation for the husbands is 10 beans while the standard deviation for wives is 8 beans. Assume that the data were centered so that 0 is the mean for each. The centered guess for a husband was 30 beans (above the mean). What would be your best estimate of the wife’s guess?

correlation = 0.2 so,

(0.2)(8/10) = 1.6

0.16 X 30 = 4.8 above the mean.

Page 32 and 33

  1. Fit a linear regression model to the father.son dataset with the father as the predictor and the son as the outcome. Give a p-value for the slope coefficient and perform the relevant hypothesis test.
##              Estimate Std. Error  t value     Pr(>|t|)
## (Intercept) 33.886604 1.83235382 18.49348 1.604044e-66
## fheight      0.514093 0.02704874 19.00618 1.121268e-69

Sheight = \[\beta_{0} + \beta_1 (fheight) + error$\\]

H_0 : \[\beta_1\] = 0

H_a: \[\beta_1\] not equal to zero

notice that fheight has a t-value of 19 and the p-value is 1.121-69, hence we can say that we fail to reject the alternative hypothesis. Thus, there is a significant difference between the father’s height and the son’s height.

  1. Refer to question 1. Interpret both parameters. Recenter for the intercept if necessary.

In the intercept if the son’s height is 33 when the father is 0 inches, but we can’t have 0 inches, we might want to recenter the father’s height.

##                             Estimate Std. Error   t value     Pr(>|t|)
## (Intercept)                68.684070 0.07421078 925.52689 0.000000e+00
## I(fheight - mean(fheight))  0.514093 0.02704874  19.00618 1.121268e-69

The slope did not change, recentering around the regressor will have no impact on the slope estimate scaling the regressor will of course change the slope . At 69 inches, the estimated son’s height at the average father’s height is 69.

  1. Refer to question 1. Predict the son’s height if the father’s height is 80 inches. Would you recommend this prediction? Why or why not?
##        1 
## 68.68407

If the father’s height is 80, the son’s height would be 75 inches. With this prediction, we are not really sure if the maximum height of the father’s data exceeds or exactly is 80.

##     fheight         sheight     
##  Min.   :59.01   Min.   :58.51  
##  1st Qu.:65.79   1st Qu.:66.93  
##  Median :67.77   Median :68.62  
##  Mean   :67.69   Mean   :68.68  
##  3rd Qu.:69.60   3rd Qu.:70.47  
##  Max.   :75.43   Max.   :78.36

As we can see in the data that the maximum height of the data of the father is 75. so I would not recommend this prediction.

  1. Load the mtcars dataset. Fit a linear regression with miles per gallon as the outcome and horsepower as the predictor. Interpret your coefficients, recenter for the intercept if necessary.
##                      mpg cyl  disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4           21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag       21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710          22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive      21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout   18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2
## Valiant             18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1
## Duster 360          14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4
## Merc 240D           24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
## Merc 230            22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2
## Merc 280            19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4
## Merc 280C           17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4
## Merc 450SE          16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3
## Merc 450SL          17.3   8 275.8 180 3.07 3.730 17.60  0  0    3    3
## Merc 450SLC         15.2   8 275.8 180 3.07 3.780 18.00  0  0    3    3
## Cadillac Fleetwood  10.4   8 472.0 205 2.93 5.250 17.98  0  0    3    4
## Lincoln Continental 10.4   8 460.0 215 3.00 5.424 17.82  0  0    3    4
## Chrysler Imperial   14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4
## Fiat 128            32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1
## Honda Civic         30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2
## Toyota Corolla      33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1
## Toyota Corona       21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1
## Dodge Challenger    15.5   8 318.0 150 2.76 3.520 16.87  0  0    3    2
## AMC Javelin         15.2   8 304.0 150 3.15 3.435 17.30  0  0    3    2
## Camaro Z28          13.3   8 350.0 245 3.73 3.840 15.41  0  0    3    4
## Pontiac Firebird    19.2   8 400.0 175 3.08 3.845 17.05  0  0    3    2
## Fiat X1-9           27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1
## Porsche 914-2       26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2
## Lotus Europa        30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2
## Ford Pantera L      15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4
## Ferrari Dino        19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6
## Maserati Bora       15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8
## Volvo 142E          21.4   4 121.0 109 4.11 2.780 18.60  1  1    4    2
##                Estimate Std. Error   t value     Pr(>|t|)
## (Intercept) 30.09886054  1.6339210 18.421246 6.642736e-18
## hp          -0.06822828  0.0101193 -6.742389 1.787835e-07

When a car has zero horsepower, the model estimates the miles per gallon to be 30.The horsepower of a car increases, the model predicts that the fuel efficiency will decrease by 0.06 miles per gallon, all else being equal.

  1. Refer to question 4. Overlay the fit onto a scatterplot.
## `geom_smooth()` using formula = 'y ~ x'

  1. Refer to question 4. Test the hypothesis of no linear relationship between horsepower and miles per gallon.
##                Estimate Std. Error   t value     Pr(>|t|)
## (Intercept) 30.09886054  1.6339210 18.421246 6.642736e-18
## hp          -0.06822828  0.0101193 -6.742389 1.787835e-07

as we can see that the horsepower’s p-value is 1.787 x 10^-7 , which is less than we say our level of significance is 0.05, thus we reject the null hypothesis.

  1. Refer to question 4. Predict the miles per gallon for a horsepower of 111.
##        1 
## 22.52552

Page 45

  1. Fit a linear regression model to the father.son dataset with the father as the predictor and the son as the outcome. Plot the son’s height (horizontal axis) versus the residuals (vertical axis).

  1. Refer to question 1. Directly estimate the residual variance and compare this estimate to the output of lm.
## [1] 1.148526e-13
## [1] 5.936804
## [1] 5.936804
  1. Refer to question 1. Give the R squared for this model.
## [1] 0.2513401
  1. Load the mtcars dataset. Fit a linear regression with miles per gallon as the outcome and horsepower as the predictor. Plot horsepower versus the residuals.

  1. Refer to question 4. Directly estimate the residual variance and compare this estimate to the output of lm.
## [1] 14.92248
## [1] 14.92248
  1. Refer to question 4. Give the R squared for this model
## [1] 0.6024373