Quiz 2

  1. Consider the following data with x as the predictor and y as as the outcome. Give a P-value for the two sided hypothesis test of whether from a linear regression model is 0 or not.

ANSWER: p-value: 0.05296

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)

xy <- lm( y ~ x)
summary(xy)
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.27636 -0.18807  0.01364  0.16595  0.27143 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)   0.1885     0.2061   0.914    0.391  
## x             0.7224     0.3107   2.325    0.053 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.223 on 7 degrees of freedom
## Multiple R-squared:  0.4358, Adjusted R-squared:  0.3552 
## F-statistic: 5.408 on 1 and 7 DF,  p-value: 0.05296
  1. Consider the previous problem, give the estimate of the residual standard deviation.

ANSWER: 0.223

  1. In the 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?

ANSWER: 18.99

regcarmodel  <- lm(mpg ~ wt, data = mtcars)
# mpg = outcome
# wt = predictor
meanvalue = data.frame(wt = mean(mtcars$wt))
predict(regcarmodel, meanvalue, interval = "confidence")
##        fit      lwr      upr
## 1 20.09062 18.99098 21.19027
  1. Refer to the previous question. Read the help file for . What is the weight coefficient interpreted as?

ANSWER: The estimated expected change in mpg per 1000 lb increase in weight.

  1. Consider again the 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?

ANSWER: 27.57

newvalue = data.frame(wt=3)
predict(regcarmodel, newvalue, interval = "predict")
##        fit      lwr      upr
## 1 21.25171 14.92987 27.57355
  1. Consider again the 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.

ANSWER: -12.97

newmodel <- lm(mpg ~ I(wt/2), data = mtcars)
newsumm <- summary(newmodel)$coefficients
# print the summary for the new model
newsumm
##              Estimate Std. Error   t value     Pr(>|t|)
## (Intercept)  37.28513   1.877627 19.857575 8.241799e-19
## I(wt/2)     -10.68894   1.118202 -9.559044 1.293959e-10
# calculate the confidence interval for the slope
newsumm[2,1] + c(-1,1)*qt(.975, df = newmodel$df)*newsumm[2,2]
## [1] -12.97262  -8.40527
  1. If my X from a linear regression is measured in centimeters and I convert it to meters what would happen to the slope coefficient?

y = beta0 + beta1x x(cm)1/100(cm) = 1/100(m) beta1 = (y - beta0)/x

ANSWER: It would get multiplied by 100.

  1. I have an outcome, Y, and a predictor, X and fit a linear regression model with “Y = Beta0 + Beta1.X + error” to obtain Beta0-hat and Beta1-hat. 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?

Shifting x with a constant variable does not change the slope but it affects the intercept.

y = beta0 - c.beta1 + beta1(x + c) + error

ANSWER: beta0-hat - c.beta1-hat

  1. 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, when comparing a model with just an intercept (denominator) to the model with the intercept and slope (numerator)?

ANSWER: 0.25

carmodel1 <- lm(mpg ~ wt, data = mtcars)
carmodel2 <- lm(mpg ~ 1, data = mtcars)
num <- sum(resid(carmodel1)^2)
den <- sum(resid(carmodel2)^2)
ratio <- num/den
ratio
## [1] 0.2471672
  1. Do the residuals always have to sum to 0 in linear regression?

ANSWER: If an intercept is included, then they will sum to 0.