This week we learned more about logistic regression, which is used when you have a binomial response variable, like yes or no. Pretty much the same as last week, I’ll put in a few examples below that we did.
Here is a problem we did for class on beer.
beer <- read.csv("http://www.cknudson.com/data/MNbeer.csv")
head(beer)
## Brewery Beer Description Style ABV IBU Rating Good
## 1 Bauhaus Wonderstuff New Bohemian Pilsner Lager 5.4 48 88 0
## 2 Bauhaus Stargazer German Style Schwarzbier Lager 5.0 28 87 0
## 3 Bauhaus Wagon Party West Cost Style Lager Lager 5.4 55 86 0
## 4 Bauhaus Sky-Five! Midwest Coast IPA IPA 6.7 70 86 0
## 5 Bent Paddle Kanu Session Pale Ale Ale 4.8 48 85 0
## 6 Bent Paddle Venture Pils Pilsner Lager Lager 5.0 38 87 0
library(faraway)
Holding IBU constant, beers with higher ABVs are more likely to be good with a multiplicative change of 1.008282 in the logodds of being a good beer. After accounting for IBU, there is a relationships between the ABV and a beer’s log odds of being “Good” at the significance level .1. The pvalue for ABV is .0697.
modBeer <- glm(Good ~ ABV + IBU, family = binomial, data = beer)
exp(coef(modBeer))
## (Intercept) ABV IBU
## 9.072303e-05 3.702429e+00 1.008282e+00
summary(modBeer)
##
## Call:
## glm(formula = Good ~ ABV + IBU, family = binomial, data = beer)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.2930 -0.7759 -0.4435 0.7678 2.1315
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -9.307699 3.678245 -2.530 0.0114 *
## ABV 1.308989 0.721717 1.814 0.0697 .
## IBU 0.008248 0.025139 0.328 0.7428
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 51.564 on 43 degrees of freedom
## Residual deviance: 42.000 on 41 degrees of freedom
## AIC: 48
##
## Number of Fisher Scoring iterations: 5
ilogit(-9.307699+1.308989*4.2 + .008248*27)
## [1] 0.02692911
For more explanation on this project, we made a powerpoint which can be accessed here: https://docs.google.com/presentation/d/1cAaw2Xo1nnEJheXWdmkaHpF99wlxy0Knvc9C4KNfzlw/edit?usp=sharing
That’s pretty much all for this week, we mostly worked on homework