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 β1 from a linear regression model is 0 or not. 2.325 0.05296 0.391 0.025

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)
fit <- lm(y ~ x); 
summary(fit)$coefficients
##              Estimate Std. Error   t value   Pr(>|t|)
## (Intercept) 0.1884572  0.2061290 0.9142681 0.39098029
## x           0.7224211  0.3106531 2.3254912 0.05296439
n <- length(x)
b1 <- cor(y,x) * sd(y)/sd(x)
b0 <- mean(y) - b1 * mean(x)
y_hat <- b0 + b1 * x
e <- y - y_hat
ssx <- sum((x-mean(x))^2)
sigma <- sqrt(sum(e^2) / (n-2))
seB1 <- sigma / sqrt(ssx)
tB1 <- b1 / seB1
pB1 <- 2 * pt(tB1, n-2, lower.tail=FALSE)
print(pB1)
## [1] 0.05296439

Question 2

Consider the previous problem, give the estimate of the residual standard deviation. 0.3552 0.05296 0.4358 0.223

print(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? -6.486 21.190 -4.00 18.991

data(mtcars)
str(mtcars)
## 'data.frame':    32 obs. of  11 variables:
##  $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
##  $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...
##  $ disp: num  160 160 108 258 360 ...
##  $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...
##  $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
##  $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...
##  $ qsec: num  16.5 17 18.6 19.4 17 ...
##  $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...
##  $ am  : num  1 1 1 0 0 0 0 0 0 0 ...
##  $ gear: num  4 4 4 3 3 3 3 4 4 4 ...
##  $ carb: num  4 4 1 1 2 1 4 2 2 4 ...
x <- mtcars$wt
y <- mtcars$mpg
fit <- lm(y ~ x)
coef <- summary(fit)$coefficients
newdata <- data.frame(x=c(mean(x)))
p1 <- predict(fit, newdata, interval = ("confidence"))
print(p1)
##        fit      lwr      upr
## 1 20.09062 18.99098 21.19027

Question 4

Refer to the previous question. Read the help file for mtcars. What is the weight coefficient interpreted as? ([, 6] wt Weight (lb/1000)) The estimated expected change in mpg per 1 lb increase in weight. The estimated 1,000 lb change in weight per 1 mpg increase.

The estimated expected change in mpg per 1,000 lb increase in weight. It can’t be interpreted without further information

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? -5.77 27.57 14.93 21.25

newdata <- data.frame(x=3000/1000)
p2 <- predict(fit, newdata, interval = ("prediction"))
print(p2)
##        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. 4.2026 -12.973 -6.486 -9.000

print(coef)
##              Estimate Std. Error   t value     Pr(>|t|)
## (Intercept) 37.285126   1.877627 19.857575 8.241799e-19
## x           -5.344472   0.559101 -9.559044 1.293959e-10
n <- length(x)
(coef[2,1] + coef[2,2] * qt(0.025, n-2)) * 2
## [1] -12.97262

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?

It would get multiplied by 100. It would get divided by 10 It would get multiplied by 10 It would get divided by 100

Question 8 I have an outcome, Y, and a predictor, X and fit a linear regression model with Y=β0+β1X+ϵ to obtain β^0 and β^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 β0+cβ1 The new slope would be cβ^1 The new intercept would be β0−cβ1 The new slope would be β^1+c #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, ∑ni=1(Yi−Y^i)2 when comparing a model with just an intercept (denominator) to the model with the intercept and slope (numerator)? 0.25 0.75 0.50 4.00

sum(residuals(fit)^2) / sum((y-mean(y))^2)
## [1] 0.2471672

residuals(lmobject) Question 10 Do the residuals always have to sum to 0 in linear regression? The residuals never sum to zero. If an intercept is included, then they will sum to 0. The residuals must always sum to zero. If an intercept is included, the residuals most likely won’t sum to zero.