u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
Logistic regression
Susanne Rosthøj
Section of Biostatistics Institute of Public Health University of Copenhagen sr@biostat.ku.dk
Logistic regression Susanne Rosthj Section of Biostatistics - - PowerPoint PPT Presentation
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s Logistic regression Susanne Rosthj Section of Biostatistics Institute of Public Health University of Copenhagen sr@biostat.ku.dk u n i v e r s i
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
Section of Biostatistics Institute of Public Health University of Copenhagen sr@biostat.ku.dk
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
2 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
3 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
4 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
0.0 0.2 0.4 0.6 0.8 1.0 2 4 6 8 p Odds p/(1−p) 0.0 0.2 0.4 0.6 0.8 1.0 −6 −4 −2 2 4 p log−odds
6 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
7 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
8 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
> d <- read.dbf(’framingham.dbf’) > glm1 <- glm( chd01 ~ factor(sex), data=d, family=binomial ) > summary( glm1 ) Call: glm(formula = chd01 ~ factor(sex), family = binomial, data = d) Deviance Residuals: Min 1Q Median 3Q Max
1.9672 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept)
0.1060 -16.780 < 2e-16 *** factor(sex)1 0.7070 0.1394 5.073 3.92e-07 ***
0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 1351.2
degrees of freedom Residual deviance: 1324.9
degrees of freedom (43 observations deleted due to missingness) AIC: 1328.9 Number of Fisher Scoring iterations: 4 >
9 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
> > # Estimates in terms of log-odds > coef( glm1 ) (Intercept) factor(sex)1
0.7070219 > > > # OR’s : > exp( coef( glm1 ) ) (Intercept) factor(sex)1 0.1688312 2.0279428 > > > # Confidence intervals : > exp( confint.default( glm1 ) ) 2.5 % 97.5 % (Intercept) 0.1371558 0.2078218 factor(sex)1 1.5432055 2.6649413 >
10 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
1−pi
11 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
12 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
exp(a+b·agei) 1+exp(a+b·agei).
50 100 150 0.0 0.2 0.4 0.6 0.8 1.0 Alder p
13 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
14 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
15 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
d SE =
16 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
17 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
> glm1 <- glm( chd01 ~ factor(sex)*factor(hyper), data=d, family=binomial ) > summary( glm1 ) Call: glm(formula = chd01 ~ factor(sex) * factor(hyper), family = binomial, data = d) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept)
0.1867
< 2e-16 *** factor(sex)1 1.2147 0.2196 5.532 3.16e-08 *** factor(hyper)1 1.3812 0.2300 6.005 1.92e-09 *** factor(sex)1:factor(hyper)1
0.2977
0.0221 *
0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 1351.2
degrees of freedom Residual deviance: 1271.7
degrees of freedom (43 observations deleted due to missingness) AIC: 1279.7 Number of Fisher Scoring iterations: 5 > > exp( coef( glm1 ) ) (Intercept) factor(sex)1 0.08010336 3.36922654 factor(hyper)1 factor(sex)1:factor(hyper)1 3.97957459 0.50585702 >
18 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
> glm2 <- glm( chd01 ~ factor(sex) + factor(sex):factor(hyper), data=d, family=binomial) > summary( glm2 ) Call: glm(formula = chd01 ~ factor(sex) + factor(sex):factor(hyper), family = binomial, data = d) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept)
0.1867 -13.524 < 2e-16 *** factor(sex)1 1.2147 0.2196 5.532 3.16e-08 *** factor(sex)0:factor(hyper)1 1.3812 0.2300 6.005 1.92e-09 *** factor(sex)1:factor(hyper)1 0.6997 0.1890 3.701 0.000214 ***
0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 1351.2
degrees of freedom Residual deviance: 1271.7
degrees of freedom (43 observations deleted due to missingness) AIC: 1279.7 Number of Fisher Scoring iterations: 5 > > exp( coef( glm2 ) ) (Intercept) factor(sex)1 0.08010336 3.36922654 factor(sex)0:factor(hyper)1 factor(sex)1:factor(hyper)1 3.97957459 2.01309573 >
19 / 20
u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s
> glm3 <- glm( chd01 ~ factor(hyper) + factor(sex):factor(hyper), data=d, family=binomial ) > summary( glm3 ) Call: glm(formula = chd01 ~ factor(hyper) + factor(sex):factor(hyper), family = binomial, data = d) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept)
0.1867 -13.524 < 2e-16 *** factor(hyper)1 1.3812 0.2300 6.005 1.92e-09 *** factor(hyper)0:factor(sex)1 1.2147 0.2196 5.532 3.16e-08 *** factor(hyper)1:factor(sex)1 0.5332 0.2011 2.652 0.00801 **
0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 1351.2
degrees of freedom Residual deviance: 1271.7
degrees of freedom (43 observations deleted due to missingness) AIC: 1279.7 Number of Fisher Scoring iterations: 5 > > exp( coef( glm3 ) ) (Intercept) factor(hyper)1 0.08010336 3.97957459 factor(hyper)0:factor(sex)1 factor(hyper)1:factor(sex)1 3.36922654 1.70434689 >
20 / 20