mod = glm(Good ~ Style, data = beer, family = binomial)
summary(mod)
##
## Call:
## glm(formula = Good ~ Style, family = binomial, data = beer)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.0302 -0.8067 -0.8067 1.3321 1.6006
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.9555 0.5262 -1.816 0.0694 .
## StyleIPA 0.5988 0.7210 0.831 0.4062
## StyleLager -17.6106 2174.2129 -0.008 0.9935
## ---
## 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: 44.305 on 41 degrees of freedom
## AIC: 50.305
##
## Number of Fisher Scoring iterations: 17
#log odds of the beer being good = -0.9555 + 0.5988I(IPA) - 17.6106I(lager)
#IPA has better chance of being good than lager (coefficient for IPA is positive, coefficient for lager is negative)
#Ale is built into the intercept
#log odds of being good for ale: -0.9555
#for IPA: -0.9555 + 0.5988
#for lager: -0.9555 - 17.6106
coef(mod)
## (Intercept) StyleIPA StyleLager
## -0.9555114 0.5988365 -17.6105571
ilogit(coef(mod)[1]) #ale's probability of being good
## (Intercept)
## 0.2777778
ilogit(sum(coef(mod)[c(1,2)])) #IPA's probability of being good
## [1] 0.4117647
ilogit(sum(coef(mod)[c(1,3)])) #lager's probability of being good
## [1] 8.646869e-09
#the odds of an IPA being good are ??? times the odds of an ale being good
exp(coef(mod)[2])
## StyleIPA
## 1.82
#the odds of an IPA being good are 1.82 times the odds of an ale being good
exp(coef(mod)[3])
## StyleLager
## 2.248186e-08
#the odds of a lager being good are 1.2*10^-8 times the odds of an ale being good
exp(-coef(mod)[3]) #flip it to make it easier to understand
## StyleLager
## 44480305
#the odds of an ale being good are 44480305 times the odds of a lager being good
mod2 = glm(Good ~ 0+ Style, data = beer, family = binomial) #model without ale in intercept
summary(mod2)
##
## Call:
## glm(formula = Good ~ 0 + Style, family = binomial, data = beer)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.0302 -0.8067 -0.8067 1.3321 1.6006
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## StyleAle -0.9555 0.5262 -1.816 0.0694 .
## StyleIPA -0.3567 0.4928 -0.724 0.4692
## StyleLager -18.5661 2174.2129 -0.009 0.9932
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 60.997 on 44 degrees of freedom
## Residual deviance: 44.305 on 41 degrees of freedom
## AIC: 50.305
##
## Number of Fisher Scoring iterations: 17
coef(mod2)[1] #log odds of ale being good
## StyleAle
## -0.9555114
coef(mod2)[2] #log odds of IPA being good
## StyleIPA
## -0.3566749
coef(mod2)[3] #log odds of lager being good
## StyleLager
## -18.56607
exp(coef(mod2)[2]) #odds of IPA being good
## StyleIPA
## 0.7
exp(coef(mod2)[3]) #odds of lager being good
## StyleLager
## 8.646869e-09
exp(coef(mod2)[2]) / exp(coef(mod2)[3])
## StyleIPA
## 80954155
#the odds of an IPA being good are 8 million times the odds of a lager being good
mod3 = glm(Good ~ Style + ABV, data = beer, family = binomial)
summary(mod3)
##
## Call:
## glm(formula = Good ~ Style + ABV, family = binomial, data = beer)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.7351 -0.8053 -0.3668 0.7564 1.8907
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -9.8628 4.3839 -2.250 0.0245 *
## StyleIPA -0.9435 1.0476 -0.901 0.3678
## StyleLager -16.7872 2105.6351 -0.008 0.9936
## ABV 1.5882 0.7657 2.074 0.0381 *
## ---
## 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: 39.097 on 40 degrees of freedom
## AIC: 47.097
##
## Number of Fisher Scoring iterations: 17
exp(coef(mod3)[2])
## StyleIPA
## 0.3892449
#after accounting for the ABV of the beer, the odds of an IPA being good are 0.3892 times the odds of an ale being good
exp(-coef(mod3)[2])
## StyleIPA
## 2.569077
#after accounting for the ABV of the beer, the odds an ale being good are 2.5 times the odds of an IPA being good
#Interpretations
#Binary: The mean number of complaints a doctor in residency receives is about -- times the mean number of complaints a non-residency doctor receives.
#Male doctors receive on average 1.4 times as many complaints as female doctors.
#lack of fit: model does/does not exhibit lack of fit
#no such thing as evidence supporting the H0