Question 1

Consider the following data with x as the predictor and y as as the outcome.

x <- c(0.61, 0.93, 0.83, 0.35, 0.54, 0.16, 0.91, 0.62, 0.62)
y <- c(0.67, 0.84, 0.6, 0.18, 0.85, 0.47, 1.1, 0.65, 0.36)

Give a P-value for the two sided hypothesis test of whether \(\beta_1\) from a linear regression model is 0 or not.

fit <- lm(y ~ x)
summary(fit)$coefficients[2,4]
## [1] 0.05296439

Question 2

Consider the previous problem, give the estimate of the residual standard deviation.

summary(fit)$sigma
## [1] 0.2229981

Question 3

In the mtcars data set, fit a linear regression model of weight (predictor) on mpg (outcome). Get a 95% confidence interval for the expected mpg at the average weight. What is the lower endpoint?

data(mtcars)
fit <- lm(mpg ~ wt, data=mtcars)
(summary(fit)$coeff)
##              Estimate Std. Error   t value     Pr(>|t|)
## (Intercept) 37.285126   1.877627 19.857575 8.241799e-19
## wt          -5.344472   0.559101 -9.559044 1.293959e-10
newdata <- data.frame(wt=mean(mtcars$wt))
predict(fit, newdata, interval=("confidence"))
##        fit      lwr      upr
## 1 20.09062 18.99098 21.19027

Question 5

Consider again the mtcars data set and a linear regression model with mpg as predicted by weight (1,000 lbs). A new car is coming weighing 3000 pounds. Construct a 95% prediction interval for its mpg. What is the upper endpoint?

newdata <- data.frame(wt=3000/1000)
predict(fit, newdata, interval=("prediction"))
##        fit      lwr      upr
## 1 21.25171 14.92987 27.57355

Question 6

Consider again the mtcars data set and a linear regression model with mpg as predicted by weight (in 1,000 lbs). A “short” ton is defined as 2,000 lbs. Construct a 95% confidence interval for the expected change in mpg per 1 short ton increase in weight. Give the lower endpoint.

mtcars$wt_ton <- mtcars$wt / 2
fit <- lm(mpg ~ wt_ton, data=mtcars)
(coef <- summary(fit)$coeff)
##              Estimate Std. Error   t value     Pr(>|t|)
## (Intercept)  37.28513   1.877627 19.857575 8.241799e-19
## wt_ton      -10.68894   1.118202 -9.559044 1.293959e-10
coef[2,1] + c(-1, 1) * qt(.975, df=fit$df) * coef[2,2]
## [1] -12.97262  -8.40527

Question 7

If my X from a linear regression is measured in centimeters and I convert it to meters what would happen to the slope coefficient?

100
## [1] 100

Question 8

I have an outcome, \(Y\), and a predictor, \(X\) and fit a linear regression model with \(Y=\beta_0 + \beta_1 X + \epsilon\) to obtain \(\hat{\beta_0}\) and \(\hat{\beta_1}\). What would be the consequence to the subsequent slope and intercept if I were to refit the model with a new regressor, \(X+c\) for some constant, \(c\)?

The new intercept would be: \(\hat{\beta_0} - c \hat{\beta_1}\)

Question 9

Refer back to the mtcars data set with mpg as an outcome and weight (wt) as the predictor. About what is the ratio of the the sum of the squared errors, \(\sum\limits_{i=1}^n (Y_i - \hat{Y_i})^2\) when comparing a model with just an intercept (denominator) to the model with the intercept and slope (numerator)?

fit_num <- lm(mpg ~ wt, data=mtcars)
fit_denom <- lm(mpg ~ 1 + offset(0 * wt), data=mtcars)
sum(resid(fit_num)^2) / sum(resid(fit_denom)^2)
## [1] 0.2471672