Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

Possible warning: basic question ahead.

Let's say that I model whether I wear red shoes depending on the weather. Red shoes, which is my dependent variable, is a dichotomous variable as I either wear them or don't. Weather is a variable with five 'levels' and I'm trying to find the probability that I will wear read shoes.

Let's say I model out this relationship with a logistic regression model in R:

mod = glm(shoes ~ weather, data=mydat, family=binomial(link="logit"))

Now, what I am interested in is finding what are the probabilities for wearing red shoes for each of the five 'levels' in weather. So perhaps I might have a 20% probability of wearing red shoes when cold, 30% when mild, 40% when warm, and so forth.

I'm wondering if modeling is a requirement for finding this information? If so, how does one go from somewhat meaningful regression coefficients to meaningful probabilities in R?

share|improve this question
What do you mean by "modeling" in your last paragraph? Are you asking whether you need to exploit the result of your GLM to find the corresponding probabilities or that maybe simple algebra would suffice? – chl Jan 5 '12 at 22:34
Bingo! Do I need to use a statistical model (logit, probit, etc) or can I simply run a few functions in R and get the desired results? – ATMathew Jan 5 '12 at 22:44
If you only have qualitative predictors, the model predictions are going to be equivalent to just taking the proportion of times in your data set that you wore red shoes under each of the conditions, if that's what you want to know. – gung Jan 6 '12 at 2:59

1 Answer

up vote 4 down vote accepted

Here is some R code to calculate the desired probabilities.

mydat <- read.csv(url("http://www.ats.ucla.edu/stat/r/dae/binary.csv"))
mod = glm(admit ~ rank, data=mydat, family=binomial(link="logit")) 
predict(mod,newdata=data.frame(rank<-c(1,2,3,4)),type="response")
    1         2         3         4 

0.5125867 0.3691354 0.2456011 0.1533587

All you need to do is supply a new data frame to R with the values that you want to use for the independent variables as above. The function predict(), with the option newdata="dfname", applies the fitted model from the original data set to the new data. The type "response" gives you probabilities rather than logits.

If your predictor is quantitative, then supply an entire range for X and plot the response probabilities. Like this...

mod2 = glm(admit ~ gre, data=mydat, family=binomial(link="logit"))
plot(gre<-400:800,predict(mod2,newdata=data.frame(gre<-c(400:800)),type="response"))

enter image description here

share|improve this answer
Thanks! Unofortunately, this becomes a problem when you have a factor with 50+ levels because it will specifity each from 1,2,3,...50. – ATMathew Jan 5 '12 at 23:12
Isn't that what you wanted? "Now, what I am interested in is finding what are the probabilities for wearing red shoes for each of the five 'levels' in weather." Yes, if your weather factor has 50 levels and you want an estimate for each you will get one. Otherwise, you can select any subset of levels that you want. If your "factor" is actually continuous, plot as many probabilities as you want. See mod2 in the edit to the post above. – Brett Magill Jan 5 '12 at 23:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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