Outline Logistic Regression Fitting the Model Assessment and Testing
STAT 213 Logistic Regression II
Colin Reimer Dawson
Oberlin College
STAT 213 Logistic Regression II Colin Reimer Dawson Oberlin - - PowerPoint PPT Presentation
Outline Logistic Regression Fitting the Model Assessment and Testing STAT 213 Logistic Regression II Colin Reimer Dawson Oberlin College 28 April 2016 Outline Logistic Regression Fitting the Model Assessment and Testing Outline
Outline Logistic Regression Fitting the Model Assessment and Testing
Oberlin College
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
1 is the odds ratio resulting from a one
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
library("mosaic") Putts <- data.frame(Distance = 3:7, Made = c(84,88,61,61,44), Total = c(101,119,108,125,134)) Putts <- mutate(Putts, PropMade = Made / Total) (model <- glm(PropMade ~ Distance, weights = Total, data = Putts, family = "binomial")) Call: glm(formula = PropMade ~ Distance, family = "binomial", data = Putts, weights = Total) Coefficients: (Intercept) Distance 3.2568
Degrees of Freedom: 4 Total (i.e. Null); 3 Residual Null Deviance: 81.39 Residual Deviance: 1.069 AIC: 30.18
Outline Logistic Regression Fitting the Model Assessment and Testing
xyplot(PropMade ~ Distance, data = Putts) f.hat <- makeFun(model) plotFun(f.hat(Distance) ~ Distance, add = TRUE) Distance PropMade
0.4 0.5 0.6 0.7 0.8 3 4 5 6 7
Outline Logistic Regression Fitting the Model Assessment and Testing
f.hat <- makeFun(model, transform = function(p){p/(1-p)}) xyplot(PropMade/(1 - PropMade) ~ Distance, data = Putts) plotFun(f.hat(Distance) ~ Distance, add = TRUE) Distance PropMade/(1 − PropMade)
1 2 3 4 5 3 4 5 6 7
[1] 0.5677353
Outline Logistic Regression Fitting the Model Assessment and Testing
f.hat <- makeFun(model, transform = logit) xyplot(logit(PropMade) ~ Distance, data = Putts) plotFun(f.hat(Distance) ~ Distance, add = TRUE) Distance logit(PropMade)
−0.5 0.0 0.5 1.0 1.5 3 4 5 6 7
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
n
i (1 − ˆ
n
ˆ β0+ˆ β1Xi
β0+ˆ β1Xi
β0+ˆ β1Xi
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
xyplot(logit(PropMade) ~ Distance, data = Putts, type = c("p","r")) Distance logit(PropMade)
−0.5 0.0 0.5 1.0 1.5 3 4 5 6 7
Outline Logistic Regression Fitting the Model Assessment and Testing
Putts <- mutate(Putts, Missed = Total - Made) (m2 <- glm(cbind(Made,Missed) ~ Distance, data = Putts, family = "binomial")) Call: glm(formula = cbind(Made, Missed) ~ Distance, family = "binomial", data = Putts) Coefficients: (Intercept) Distance 3.2568
Degrees of Freedom: 4 Total (i.e. Null); 3 Residual Null Deviance: 81.39 Residual Deviance: 1.069 AIC: 30.18
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
data("Election08") model <- glm(ObamaWin ~ BA, data = Election08, family = "binomial") summary(model) Call: glm(formula = ObamaWin ~ BA, family = "binomial", data = Election08) Deviance Residuals: Min 1Q Median 3Q Max
0.2436 0.7314 1.7952 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept)
2.9656
0.00141 ** BA 0.3706 0.1143 3.243 0.00118 **
0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 69.737
degrees of freedom Residual deviance: 49.689
degrees of freedom
Outline Logistic Regression Fitting the Model Assessment and Testing
Estimate Std. Error z value Pr(>|z|) (Intercept) -9.4667396 2.9655946 -3.192189 0.001411987 BA 0.3705518 0.1142507 3.243321 0.001181449
1
1
Outline Logistic Regression Fitting the Model Assessment and Testing
confint(model) 2.5 % 97.5 % (Intercept) -16.3335145 -4.4506636 BA 0.1789443 0.6366837 confint(model) %>% exp() 2.5 % 97.5 % (Intercept) 8.062037e-08 0.01167082 BA 1.195954e+00 1.89020201
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
Call: glm(formula = ObamaWin ~ BA, family = "binomial", data = Election08) Deviance Residuals: Min 1Q Median 3Q Max
0.2436 0.7314 1.7952 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept)
2.9656
0.00141 ** BA 0.3706 0.1143 3.243 0.00118 **
0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 69.737
degrees of freedom Residual deviance: 49.689
degrees of freedom AIC: 53.689 Number of Fisher Scoring iterations: 5
Outline Logistic Regression Fitting the Model Assessment and Testing
Outline Logistic Regression Fitting the Model Assessment and Testing
anova(model, test = "LRT") Analysis of Deviance Table Model: binomial, link: logit Response: ObamaWin Terms added sequentially (first to last) Df Deviance Resid. Df Resid. Dev Pr(>Chi) NULL 50 69.737 BA 1 20.048 49 49.689 7.553e-06 ***
0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1