22 Quiz 2:
1. Give a p-value for the two sided hypothesis test for whether \(\beta_1\) is 0 or not
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)
##
## 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
0.05296
2. Consider the previous problem, give the estimate of the residual standard deviation.
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)$sigma
## [1] 0.2229981
0.223
3. 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?
fit1 <- lm(mpg ~ wt, data = mtcars)
meanvalue <- data.frame(wt=mean(mtcars$wt))
predict(fit1, newdata = meanvalue, interval="confidence")
## fit lwr upr
## 1 20.09062 18.99098 21.19027
18.99098
4. Refer to the previous question. Read the help file for mtcars. What is the weight coefficient interpreted as?
Estimated expected change in mpg per 1,000 lbs weight increase.
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?
## fit lwr upr
## 1 21.25171 14.92987 27.57355
27.75355
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.
newpredictor <-lm(mpg~I(wt/2), data=mtcars)
newsummary <-summary(newpredictor)$coefficients
newsummary
## 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
## 2.5 % 97.5 %
## (Intercept) 33.45050 41.11975
## I(wt/2) -12.97262 -8.40527
-12.97262
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
8.
InterSlope<-lm(mpg~wt, data=mtcars)
JustInter<-lm(mpg~1, data=mtcars)
num<-sum((predict(InterSlope)-mtcars$mpg)^2)
den<-sum((predict(JustInter)-mtcars$mpg)^2)
num/den
## [1] 0.2471672
It would be 0.25