Workshop 10.5a: Logistic regression

Murray Logan

05 Sep 2016

Logistic regression

Logistic regression

Binary data

Link: \(log\left(\frac{\pi}{1-\pi}\right)\)

Transform scale of linear predictor (\(-\infty,\infty\)) into that of the response (0,1)

Logistic regression


Logistic regression


\[E(Y) = \left(\begin{array}{c} n\\x \end{array}\right)p^{x}(1-p)^{n-x}\]

Spread assumed to be equal to mean. (\(\phi = 1\))

Dispersion

Over-dispersion

Sample more varied than expected from its mean

Logistic regression

Example data

  y        x
1 0 1.024733
2 0 2.696719
3 0 3.626263
4 0 4.948643
5 0 6.024718
6 0 6.254113

Logistic regression

> dat.glmL <- glm(y ~ x, data = dat, family = "binomial")

Logistic regression

> par(mfrow=c(2,2)) 
> plot(dat.glmL)

Logistic regression

> dat.resid <- sum(resid(dat.glmL, type = "pearson")^2)
> 1 - pchisq(dat.resid, dat.glmL$df.resid)
[1] 0.8571451
> 1-pchisq(dat.glmL$deviance, dat.glmL$df.resid)
[1] 0.8647024

Logistic regression

Slope parameter is on log odds-ratio scale

> summary(dat.glmL)

Call:
glm(formula = y ~ x, family = "binomial", data = dat)

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-1.97157  -0.33665  -0.08191   0.30035   1.59628  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)  
(Intercept)  -6.9899     3.1599  -2.212   0.0270 *
x             0.6559     0.2936   2.234   0.0255 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 27.526  on 19  degrees of freedom
Residual deviance: 11.651  on 18  degrees of freedom
AIC: 15.651

Number of Fisher Scoring iterations: 6

Logistic regression

> 1-(dat.glmL$deviance/dat.glmL$null)
[1] 0.5767057

Logistic regression

> -dat.glmL$coef[1]/dat.glmL$coef[2]
(Intercept) 
   10.65781 

Logistic regression

Worked Examples

Worked Examples