library(faraway)
data(orings)
#View(orings)
library(SMPracticals)
data(shuttle)
#View(shuttle)
There is a discrepancy between ELM and SM about the data. Going back to the original source (Dalal et al., 1989), and also the Rogers Commission Report (1986), it seems that SM has the correct numbers. I think they are counting slightly different things. There is also a weird error in the shuttle
data frame, that is solved by
shuttle2 <- data.frame(shuttle)
I’ll fit and then plot both sets of data; note I’ve also used two different summaries; sumary
provided by Faraway and the usual one.
# Faraway's fitting
logitmod <- glm(cbind(damage,6-damage) ~ temp, family = binomial,
data = orings)
sumary(logitmod)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 11.662990 3.296263 3.5382 0.0004028
## temp -0.216234 0.053177 -4.0663 4.777e-05
##
## n = 23 p = 2
## Deviance = 16.91228 Null Deviance = 38.89766 (Difference = 21.98538)
# Davison's fitting
logitmodcorrect <- glm(cbind(r,m-r) ~ temperature, family = binomial,
data = shuttle2)
summary(logitmodcorrect)
##
## Call:
## glm(formula = cbind(r, m - r) ~ temperature, family = binomial,
## data = shuttle2)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.95227 -0.78299 -0.54117 -0.04379 2.65152
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 5.08498 3.05247 1.666 0.0957 .
## temperature -0.11560 0.04702 -2.458 0.0140 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 24.230 on 22 degrees of freedom
## Residual deviance: 18.086 on 21 degrees of freedom
## AIC: 35.647
##
## Number of Fisher Scoring iterations: 5
Now I’ll compute and then plot the fitted curves. The function ilogit
is provided by Faraway, it’s the inverse.
tempvals <- seq(30,80,length=100)
# predicting prob of O-ring damage at temperature = 31 degrees F
ilogit(5.085 -.11560*31); ilogit(11.663-.2162*31)
## [1] 0.8177832
## [1] 0.9930414
## adding the fitted curves to the plots
tempvals <- seq(30,80,length=100)
par(mfrow=c(2,2)) # 4 plots on one page
with(orings, plot(temp,damage,main="Faraway",xlim=c(31,80)))
with(shuttle2,plot(temperature,r,main="Davison",xlim=c(31,80),ylim=c(0,5)))
with(orings, plot(temp,damage/6,main="Faraway",xlim=c(31,80), ylim=c(0,1)))
lines(tempvals,ilogit(11.6630-.2162*tempvals))
abline(v=32, lty=2)
with(shuttle2,plot(temperature,r/6,main="Davison",xlim=c(31,80),ylim=c(0,1)))
lines(tempvals,ilogit(5.08498-.1156*tempvals))
abline(v=32, lty=2)