Today in class we learned how to produce confidence and prediction intervals for a set of data. These are two important concepts because they help to identify how accurate a future estimate may be, or how sure we can be that a point lies close to the mean.
I begin my review by bringing in the BeerWings data I worked with previously.
library(resampledata)
##
## Attaching package: 'resampledata'
## The following object is masked from 'package:datasets':
##
## Titanic
data("Beerwings")
attach(Beerwings)
beer.mod<- lm(Beer ~ Hotwings)
beer.mod
##
## Call:
## lm(formula = Beer ~ Hotwings)
##
## Coefficients:
## (Intercept) Hotwings
## 3.040 1.941
summary(beer.mod)
##
## Call:
## lm(formula = Beer ~ Hotwings)
##
## Residuals:
## Min 1Q Median 3Q Max
## -18.566 -4.537 -0.122 3.671 17.789
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.0404 3.7235 0.817 0.421
## Hotwings 1.9408 0.2903 6.686 2.95e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.479 on 28 degrees of freedom
## Multiple R-squared: 0.6148, Adjusted R-squared: 0.6011
## F-statistic: 44.7 on 1 and 28 DF, p-value: 2.953e-07
Above we see the summary of our data.
confint(beer.mod)
## 2.5 % 97.5 %
## (Intercept) -4.586851 10.667590
## Hotwings 1.346131 2.535371
cor(Beerwings$Beer, Beerwings$Hotwings)
## [1] 0.7841224
We see the confidence interval above for our prediction of intercept and slope. We can also look at the information from our summary. A few key points to look at is our R-squared value of .6148, which is a significant measure that we can say our model explains 61% of the variation from our mean. With a smaller p-value, we can also expect less occurances of extremes measures from our mean. The last measure we had was a correlation component- which we can say that the two variables have a strong correlation with one another.
Now we will predict how many Hotwings were eaten if someone had dranken 30 FL OZ of beer.
myinfo<-data.frame(Hotwings=10)
predict(beer.mod, myinfo, interval= "predict")
## fit lwr upr
## 1 22.44788 6.831517 38.06425
predict(beer.mod, myinfo, interval="confidence")
## fit lwr upr
## 1 22.44788 19.42369 25.47207
Following the info received, if someone had eaten 10 wings, we are 95% sure the true mean lies within the interval 6.8-38.1 ounces of beer.
Extending this, we are 95% confident that the interval of 19.4-25.5 contains the true mean value of ounces drank by everyone who ate 10 wings.
Tankya for reading.