Dimitri Liakhovitski
2010-Feb-18 18:58 UTC
[R] logistic regression - what is being predicted when using predict - probabilities or odds?
Dear gurus, I've analyzed a (fake) data set ("data") using logistic regression (glm): logreg1 <- glm(z ~ x1 + x2 + y, data=data, family=binomial("logit"), na.action=na.pass) Then, I created a data frame with 2 fixed levels (0 and 1) for each predictor: attach(data) x1<-c(0,1) x2<-c(0,1) y<-c(0,1) newdata1<-data.frame(expand.grid(x1,x2,y)) names(newdata1)<-c("x1","x2","y") Finally, I calculated model-predicted probabilities for each combination of those fixed levels: newdata1$predicted <-predict(logreg1,newdata=newdata1, type="response") I am pretty sure the results I get (see the table below) are actual probabilities. But just in case - could someone please confirm that these are probabilities rather than log odds or odds? Thanks a lot! x1 x2 y predicted 1 0 0 0 0.08700468 2 1 0 0 0.19262901 3 0 1 0 0.27108334 4 1 1 0 0.48216220 5 0 0 1 0.53686154 6 1 0 1 0.74373367 7 0 1 1 0.81896484 8 1 1 1 0.91887072 -- Dimitri Liakhovitski Dimitri.Liakhovitski at ninah.com
(Ted Harding)
2010-Feb-18 19:38 UTC
[R] logistic regression - what is being predicted when using
On 18-Feb-10 18:58:57, Dimitri Liakhovitski wrote:> Dear gurus, > I've analyzed a (fake) data set ("data") using logistic regression > (glm): > > logreg1 <- glm(z ~ x1 + x2 + y, data=data, family=binomial("logit"), > na.action=na.pass) > > Then, I created a data frame with 2 fixed levels (0 and 1) for each > predictor: > > attach(data) > x1<-c(0,1) > x2<-c(0,1) > y<-c(0,1) > newdata1<-data.frame(expand.grid(x1,x2,y)) > names(newdata1)<-c("x1","x2","y") > > Finally, I calculated model-predicted probabilities for each > combination of those fixed levels: > > newdata1$predicted <-predict(logreg1,newdata=newdata1, type="response") > > I am pretty sure the results I get (see the table below) are actual > probabilities. But just in case - could someone please confirm that > these are probabilities rather than log odds or odds? > Thanks a lot! > > x1 x2 y predicted > 1 0 0 0 0.08700468 > 2 1 0 0 0.19262901 > 3 0 1 0 0.27108334 > 4 1 1 0 0.48216220 > 5 0 0 1 0.53686154 > 6 1 0 1 0.74373367 > 7 0 1 1 0.81896484 > 8 1 1 1 0.91887072 > -- > Dimitri LiakhovitskiYes, they are predicted probabilities of response Z=1. You specified this by setting 'type="response"'. See ?predict.glm (the method for 'predict' which is used for GLMs). Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 18-Feb-10 Time: 19:38:54 ------------------------------ XFMail ------------------------------