4

Consider the Challenger-Disaster:

Temp <- c(66,67,68,70,72,75,76,79,53,58,70,75,67,67,69,70,73,76,78,81,57,63,70)
Fail <- factor(c(0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1))
shuttle <- data.frame(Temp, Fail)
colnames(shuttle) <- c("Temp", "Fail")

Now I can fit a logistic model which will explain the "Fail" of O-ring seals by Temperature:

fit <- glm(Fail~Temp,data=shuttle, family=binomial); fit

The R output looks like this:

 Call:  glm(formula = Ausfall ~ Temp, family = binomial, data =
 shuttle)

 Coefficients: (Intercept)         Temp  
     15.0429      -0.2322  

 Degrees of Freedom: 22 Total (i.e. Null);  21 Residual Null Deviance:  
 28.27  Residual Deviance: 20.32    AIC: 24.32

Questions

  • In general, how do you predict probabilities for specific data in logistic regressions using R?
  • Or specifically, what is the command to calculate the probability of a "Fail" if temperature is at 37°? (which it was in the night before the Challenger disaster).

I thought it would be something like this:

predict(fit, Temp=37)

but it won't give me "0.9984243" (which I calculated myself with:

exp(15.0429 + (37*(-0.2322))) / 1+ exp(15.0429 + (37*(-0.2322)))

The method predict returns a matrix of numbers that makes no sense to me.

Jeromy Anglim
  • 42,044
  • 23
  • 146
  • 250
Produnis
  • 421
  • 1
  • 3
  • 12

1 Answers1

5

how about

?predict.glm

or, more specifically

predict(fit, data.frame(Temp=37), type="response")
hplieninger
  • 802
  • 9
  • 25
  • ähh? this works! So, my fault was to just type "temp=37" and not "data.frame(Temp=37)" ?! Stupid me... Thx, dude! Do you know how to modify the command if the outcome is not binary (YES/NO) but ordinal (A/B/C/D/E/F) ? – Produnis Jul 23 '13 at 13:29
  • I don't think `glm` can handle ordered regression, but you may have a look at http://www.ats.ucla.edu/stat/r/dae/ologit.htm or the web in general – hplieninger Jul 24 '13 at 08:06
  • 1
    thanks for your time and the url... However, I started a new request on ordinal regression here http://stats.stackexchange.com/questions/65375/how-to-predict-rank-in-ordinal-regression-using-r providing my data... – Produnis Jul 24 '13 at 08:22