Question 1

## 
## Call:
## lm(formula = Y ~ X1 + X2)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -15.00  -6.57  -1.95   4.42  24.56 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  39.6556    13.5076   2.936 0.005225 ** 
## X1            0.1662     0.1626   1.022 0.312128    
## X2           -1.7021     0.4421  -3.850 0.000371 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.098 on 45 degrees of freedom
## Multiple R-squared:  0.5613, Adjusted R-squared:  0.5418 
## F-statistic: 28.79 on 2 and 45 DF,  p-value: 8.869e-09

##        fit      lwr      upr
## 1 37.79178 27.08759 48.49596
## Installing package into 'C:/Users/sthal/OneDrive/Documents/R/win-library/3.6'
## (as 'lib' is unspecified)
## package 'car' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\sthal\AppData\Local\Temp\Rtmpqw6dxM\downloaded_packages
## Loading required package: carData
##       X1       X2 
## 2.611671 2.611671

Question 2: Simple LR, Y = 10 + 5X - X^2 with only X

## 
## Call:
## lm(formula = Y ~ X, data = YDF)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.2342 -0.2929  0.1358  0.5694  1.9273 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  27.5188     0.4870   56.51   <2e-16 ***
## X            -6.9848     0.1588  -43.99   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8617 on 98 degrees of freedom
## Multiple R-squared:  0.9518, Adjusted R-squared:  0.9513 
## F-statistic:  1935 on 1 and 98 DF,  p-value: < 2.2e-16

Question 2: Quadratic LR, Y = 10 + 5X - 2X^2 with X^2

## 
## Call:
## lm(formula = Y ~ X + XX, data = YDF)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.19046 -0.30582  0.03546  0.31477  1.38463 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  10.7438     1.0707  10.034  < 2e-16 ***
## X             4.4770     0.7154   6.258 1.06e-08 ***
## XX           -1.8949     0.1175 -16.131  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4513 on 97 degrees of freedom
## Multiple R-squared:  0.9869, Adjusted R-squared:  0.9866 
## F-statistic:  3656 on 2 and 97 DF,  p-value: < 2.2e-16

##        X       XX 
## 73.97863 73.97863

Part e: Centering the data

## 
## Call:
## lm(formula = Y ~ I(X - mean(X)) + I((X - mean(X))^2), data = YDF)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.19046 -0.30582  0.03546  0.31477  1.38463 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         6.99386    0.05686  122.99   <2e-16 ***
## I(X - mean(X))     -6.96179    0.08319  -83.69   <2e-16 ***
## I((X - mean(X))^2) -1.89486    0.11747  -16.13   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4513 on 97 degrees of freedom
## Multiple R-squared:  0.9869, Adjusted R-squared:  0.9866 
## F-statistic:  3656 on 2 and 97 DF,  p-value: < 2.2e-16

##     I(X - mean(X)) I((X - mean(X))^2) 
##           1.000295           1.000295