Sundar Dorai-Raj wrote:



orkun wrote:

Hello

I try to find probability values of some predictor combinations using logistic reg. in response level.
Firstly I found coefficients by glm function.
Then I followed two ways to get probability values:
1- probility <- exp(X0+bX1+cX2+...)/((1+exp(X0+bX1+cX2+...))
2- probility <- predict(glm.obj,type="resp")


Should have these two given same result ?
if so, I did not have. Why ?

Does anyone have any idea ?


This works for me. Are you sure you're getting the correct linear predictor in (1). Here's an example:


R> x = glm(y ~ trt + I(week > 2), data = bacteria, family = binomial)
R> str(predict(x, type = "resp"))
 Named num [1:220] 0.944 0.944 0.823 0.823 0.900 ...
 - attr(*, "names")= chr [1:220] "1" "2" "3" "4" ...
R> coef(x)
    (Intercept)         trtdrug        trtdrug+ I(week > 2)TRUE
      2.8332455      -1.1186847      -0.6372255      -1.2948522
R> lp = model.matrix(x) %*% coef(x)
R> str(exp(lp)/(1 + exp(lp)))
 num [1:220, 1] 0.944 0.944 0.823 0.823 0.900 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:220] "1" "2" "3" "4" ...
  ..$ : NULL
R>



thank you for your help

Now one thing is  clear to me:
predict(x, type = "resp") gives probability values.
For the sake of simplicity, I can choose it, instead of using first way.

cordially




______________________________________




______________________________________
The views and opinions expressed in this e-mail message are the ... {{dropped}}

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to