library(ggplot2)
midterm <-read.csv("midterm1data.csv")Mid-Term Question 2
Testing variables:
lm1 <- lm(head_l ~ skull_w, data=midterm)
summary(lm1)
Call:
lm(formula = head_l ~ skull_w, data = midterm)
Residuals:
Min 1Q Median 3Q Max
-8.9615 -1.3320 0.0588 1.6153 6.4444
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 46.19537 4.55355 10.14 <2e-16 ***
skull_w 0.81583 0.07993 10.21 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.526 on 102 degrees of freedom
Multiple R-squared: 0.5053, Adjusted R-squared: 0.5004
F-statistic: 104.2 on 1 and 102 DF, p-value: < 2.2e-16
The adjusted R-squared value is 0.5004. This means that 50.04% of the head length can be explained by changes in the skull width.
The regression equation is head length=46.19537+.81583(skull width). That means that for every 1 mm increase in skull width, we expect to see a about a .81 increase in head length.
For a skull width of 55mm, the predicted value of head length would be 46.19537+.81583(55)=93.401867mm
The B_hat_0 value of my equation is 46.19537mm. This is not a meaningful value, as it would be very weird to encounter a possum with a head length of roughly 46 mm and a skull width of 0 mm.
predictdata<-data.frame(skull_w=55)
pred <- predict(lm1, predictdata, interval = "prediction")Using R to create a 97% confidence interval for a 55mm skull width:
predictdata<-data.frame(skull_w=55)
predict(lm1, newdata= predictdata) 1
91.06614