How To Convert Odds To Probability
Logistic regression may give a headache initially. While the structure and idea is the same as “normal” regression, the interpretation of the b’s (ie., the regression coefficients) can be more challenging.
This post provides a convenience function for converting the output of the glm
function to a probability. Or more generally, to convert logits (that’s what spit out by glm
) to a probabilty.
Note1: The objective of this post is to explain the mechanics of logits. There are more convenient tools out there. (Thanks to Jack’s comment who made me adding this note.)
Finite Math Mini Presentation 3 Tre Swilling Q.2 Convert the probability 3/7 to odds. Do the same for the probability 0.2. Difference between probability & odds Probability: refers to the likelihood of occurrence of an event. Expressed in percent or decimal - Ranges from 0 to 1 Odds: refers to the chances in favor of the event to the chances against it. Negative odds - The probability divided by (1 minus (the probability divided by 100)) then multiply by -1 to convert into a negative e.g. A probability of 60% = (60 / (1 - (60/100))).1 = -150. How do you convert american odds to decimal? Positive odds - 1 plus (the american odds divided by 100) e.g. American odds of 300 = 1 + (300/100) = 4.
Note2: I have corrected an error pointed out by Jana’s comment, below (you can always check older versions on the Github repo).
Convert Fractional odds to probability. The most common form of odds are going to be decimal odds in the UK and here is how to convert decimal odds to probability.These are clear odds to read and for example the 6/5 odds on Liverpool from the example above means that for every 5 units you put on, you will receive 6 back as a profit. In other words, odds of 1.65 means that for every 1.00 you place on a particular outcome, you will receive a profit of 0.65 should that outcome prevail. To convert these odds to their respective implied probabilities we make a simple calculation. 1 divided by the. Convert Decimal Odds into Probability. If we use the decimal odds of 1.80 for this and use the following equation:. 1 / decimal odds x 100 = implied probability. So, 1 / 1.80 is 0.555 (rounded up to 0.56), giving the mathematical equation of 0.56 x 100 = 56%. This means that odds of 1.80 reflect a 56% chance of that particular outcome.
How To Convert Odds Ratio Into Probability
So, let’s look at an example. First load some data (package need be installed!):
Compute a simple glm:
The coeffients are the interesting thing:
These coefficients are in a form called ‘logits’.
If coefficient (logit) is positive, the effect of this predictor (on survival rate) is positive and vice versa.
Here Pclass
coefficient is negative indicating that the higherPclass
the lower is the probability of survival.
To convert a logit (glm
output) to probability, follow these 3 steps:
- Take
glm
output coefficient (logit) - compute e-function on the logit using
exp()
“de-logarithimize” (you’ll get odds then) - convert odds to probability using this formula
prob = odds / (1 + odds)
. For example, sayodds = 2/1
, then probability is2 / (1+2)= 2 / 3
(~.67)
This function converts logits to probability.
For convenience, you can source the function like this:
For our glm:
How to interpret:
- The survival probability is 0.8095038 if
Pclass
were zero (intercept). - However, you cannot just add the probability of, say
Pclass 1
to survival probability ofPClass 0
to get the survival chance of 1st class passengers.
Instead, consider that the logistic regression can be interpreted as a normal regression as long as you use logits. So the general regression formula applies as always:
That is, in our example
where b_survival
is given in logits (it’s just the b-coefficient of Pclass).
So, it’ simple to calculate by hand, eg., the survival logits for a 2nd class passenger:
Thus, the logits of survival are -0.25Now we can convert to probability:
Remember that (e^1 approx 2.71). That is, if your logit is 1, your odds will be approx. 2.7 to 1, so the the probability is 2.7 / 3.7, or about 3/4, 75%.
Similarly important, (e^0 = 1). Hence, your odds will be 1:1, ie., 50%.
Hence, whenever your logit is negative, the associated probability is below 50% and v.v. (positive logit <–> probability above 50%).
However, more convenient would be to use the predict
function instance of glm
; this post is aimed at explaining the idea. In practice, rather use:
In the 1st class, survival chance is ~65%, and for 2nd class about 44%.
Here’s a look up table for the conversion:
Logit | Probability | |
---|---|---|
1 | -10 | 0 |
2 | -8 | 0 |
3 | -6 | 0.002 |
4 | -4 | 0.018 |
5 | -2 | 0.119 |
6 | 0 | 0.5 |
7 | 2 | 0.881 |
8 | 4 | 0.982 |
9 | 6 | 0.998 |
10 | 8 | 1 |
11 | 10 | 1 |
A handy function is datatable
, does not work in this environment however it appears.
The package mfx provides a convenient functions to get odds out of a logistic regression (Thanks for Henry Cann’s comment for pointing that out!).
More convenient for an overview is a plot like this.
The relationship between logit and probability is not linear, but of s-curve type.
The coefficients in logit form can be be treated as in normal regression in terms of computing the y-value.
How To Convert Betting Odds Into Probability
Transform the logit of your y-value to probability to get a sense of the probability of the modeled event.
Convert Odds To Probability Formula
Happy glming!