4
votes
$\begingroup$

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.

$\endgroup$
5
votes
$\begingroup$

how about

?predict.glm

or, more specifically

predict(fit, data.frame(Temp=37), type="response")
$\endgroup$
3
  • $\begingroup$ ä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) ? $\endgroup$
    – Produnis
    Jul 23 '13 at 13:29
  • $\begingroup$ I don't think glm can handle ordered regression, but you may have a look at ats.ucla.edu/stat/r/dae/ologit.htm or the web in general $\endgroup$ Jul 24 '13 at 8:06
  • 1
    $\begingroup$ thanks for your time and the url... However, I started a new request on ordinal regression here stats.stackexchange.com/questions/65375/… providing my data... $\endgroup$
    – Produnis
    Jul 24 '13 at 8:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.