k2 - Attachments - CT Lecture 18a. Multiple Logistic Regression Model 3
k2 - Attachments - CT Lecture 18a. Multiple Logistic Regression Model 3
Interaction
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Contents
Topics
– Binary anova
– Variable selection
– Under/over dispersion
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Binary Anova
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Example
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Data
length time r n
1 long autumn 156 240
2 long spring 84 240
3 short autumn 107 240
4 short spring 31 240
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Fitting
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Points to note
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Fitted logits
> predict(plum.glm)
[1] 0.6190392 -0.6190392 -0.2175203 -1.9083470
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Interaction plot
attach(plum.df)
interaction.plot(length,time,log((r+0.5)/(n-r+0.5)))
0.5
time
on the log-odds scale
autumn
spring
0.0
-0.5
logit of s/n
-1.0
-1.5
-2.0
long short
length
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Anova
> anova(plum.glm,test="Chisq")
Analysis of Deviance Table
Model: binomial, link: logit
Response: cbind(r, n - r)
Terms added sequentially (first to last)
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Final model: interpretation and fitted
probabilities
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Final model: interpretation and fitted
probabilities
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Fitted Probabilities
Length= Length=
long short
Time =
0.6712 0.4246
autumn
Time =
0.3288 0.1504
spring
> predict(plum2.glm,type="response")
[1] 0.6712339 0.3287661 0.4245994 0.1504006
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Variable selection
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Example: lizard data
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Data
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Eyeball analysis
> plot.design(lizard.df, y=log((lizard.df$r+0.5)
/(lizard.df$n-lizard.df$r+0.5)), ylab="mean of logits")
1.6
early
high
mid
1.4
short
1.2
Proportion of
mean of logits
grahami lizards
1.0
low
perches are short
0.6
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Model selection
• Full model is
cbind(r,n-r)~time*length*height
so fit this first.
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
anova
> lizard.glm<-glm(cbind(r,n-r)~time*length*height,
+ family=binomial,data=lizard.df)
> anova(lizard.glm, test="Chisq")
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
stepwise
>null.model<-glm(cbind(r,n-r)~1, family=binomial,
data=lizard.df)
> step(null.model, formula(lizard.glm), direction="both")
Coefficients:
(Intercept) heightlow timelate timemid lengthshort
1.49466 -0.83011 -1.05278 0.04003 0.67630
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Summary
> summary(model2)
Call:
glm(formula = cbind(r, n - r) ~ time + length + height,
family = binomial, data = lizard.df)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.49466 0.28809 5.188 2.12e-07 ***
timelate -1.05278 0.28026 -3.756 0.000172 ***
timemid 0.04003 0.23971 0.167 0.867384
lengthshort 0.67630 0.20588 3.285 0.001020 **
heightlow -0.83011 0.23204 -3.578 0.000347 ***
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 `
' 1
(Dispersion parameter for binomial family taken to be 1)
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Diagnostics
1.5
10
11
5
Residuals
0.5
> par(mfrow=c(2,2))
0
-0.5
> plot(model2,
-5
-10
which=1:4)
-1.5
10 3
10
0.0 0.5 1.0 1.5 2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5
0.6
No major 3
10
6
10
3.0
0.5
Std. deviance resid.
problems
Cook's distance
0.4
11
2.0
0.3
0.2
1.0
0.1
0.0
0.0
0.0 0.5 1.0 1.5 2.0 2 4 6 8 10 12
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Conclusions
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Over/under dispersion
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Over/under-dispersion
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Over-dispersed model
> model3<-glm(cbind(r,n-r)~time+length+height,
family=quasibinomial,data=lizard.df)
> summary(model3)
Call:
glm(formula = cbind(r, n - r) ~ time + length + height,
family = quasibinomial, data = lizard.df)
> Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.49466 0.33128 4.512 0.00276 **
timelate -1.05278 0.32228 -3.267 0.01374 *
timemid 0.04003 0.27565 0.145 0.88864
lengthshort 0.67630 0.23675 2.857 0.02446 *
heightlow -0.83011 0.26683 -3.111 0.01706 *
---
(Dispersion parameter for quasibinomial family taken to be
1.322352)
Null deviance: 54.0430 on 11 degrees of freedom
Residual deviance: 9.8815 on 7 degrees of freedom
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012
Comparison
Binomial
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.49466 0.28809 5.188 2.12e-07 ***
timelate -1.05278 0.28026 -3.756 0.000172 ***
timemid 0.04003 0.23971 0.167 0.867384
lengthshort 0.67630 0.20588 3.285 0.001020 **
heightlow -0.83011 0.23204 -3.578 0.000347 ***
Quasibinomial
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.49466 0.33128 4.512 0.00276 **
timelate -1.05278 0.32228 -3.267 0.01374 *
timemid 0.04003 0.27565 0.145 0.88864
lengthshort 0.67630 0.23675 2.857 0.02446 *
heightlow -0.83011 0.26683 -3.111 0.01706 *
Workshop on Analysis of Clinical Studies – Can Tho University of Medicine and Pharmacy – April 2012