This tutorial draws heavily from:
Introduction to SAS. UCLA: Statistical Consulting Group. from http://www.ats.ucla.edu/stat/sas/notes2/ (accessed November 24, 2007).

Why Logistic Regression?

  1. When the outcome of interest is binary, we are trying to predict the probability of the given outcome being 1.
  2. Probabilities run from 0 to 1. This “restricted range” is problematic for models which rely on distributions that run from negative infinity to positive infinity.
    2.1 Thus, transforming the outcome from a probability ranging from 0 to 1 into the “logodds” (also called logit) allows us to model a distribution that ranges from negative to positive infinity.

While the logit is just one possible transformation, it has the desirable property of being relatively understood (the log of the odds).

For the purposes of this tutorial, the following terms need to be understood:

p = represents probabilities and is read “the probability of

\(\begin{align}\frac{p}{1-p}\end{align}\) = is the formula to convert probabilities into odds, and is read “the odds of

p(Y) = the probability of Y occuring


The general logistic regression equation is:

\(\begin{aligned}logit(p) = log(\frac{p}{1-p}) = \beta_0+\beta_1X_1+\beta_2X_2\dots+\beta_kX_k\end{aligned}+\epsilon\)

And thus the probability of outcome “Y” is found by solving for ‘p’ resulting in:

\(\begin{aligned}p(Y) = \frac{e^{(\beta_0+\beta_1X_1+\beta_2X_2\dots+\beta_kX_k}}{e^{(1 + \beta_0+\beta_1X_1+\beta_2X_2\dots+\beta_kX_k)}}\end{aligned}\)


Example 1 - Intercept Only

Let’s consider a simple example, a logistic regression with no predictors (just an intercept)
In this case, we are predicting the likelihood of being in an honors class:


The general equation is: \(\begin{aligned}logit(p) =\beta_0 \end{aligned}\)

Dependent variable:
Being in Honors
Constant -1.13*** (-1.45, -0.80)
Observations 200
Log Likelihood -111.00
Akaike Inf. Crit. 225.00
Note: p<0.1; p<0.05; p<0.01


So, the intercept, -1.125, is the log of the odds (logit) of being in honors. To get the odds of being in honors, we exponentiate the logit:

\(\begin{aligned}\frac{p}{1-p} = e^{-1.125} = 0.325\end{aligned}\)

An odds of 0.325 translates to odds of “1 to 3.082”, which means that for every 1 person in honors, there are ~3 persons who are not in honors. To do this translation, you divide 1 by the odds.

What is the estimated population probability of being in honors?

\(\begin{aligned}p(honors) = \frac{e^{-1.125}}{1+e^{-1.125}} = 24.5\%\end{aligned}\)

Note, examining the equation above, you can determine that converting odds to probabilities involves solving the equation, \(\frac{odds}{1+odds}\), you do not need to redo the exponentiation if you have computed the odds to derive the probability. In our case we know that the probability = \(\frac{0.325}{1.325}\).

Example 2 - A Single Categorical (dichotomous) Predictor


What happens if we predict the likelihood of being in honors and use gender as a predictor? In our data, male is coded as zero, and female as 1.
\(\begin{aligned}logit(p) =\beta_0 + \beta_1*female \end{aligned}\)


    Being in Honors
    OR CI p
(Intercept)   -1.47 -2.03 – -0.97 <.001
gender (Female)   0.59 -0.07 – 1.28 .083
Observations   200


So, the intercept, -1.471, is the log of the odds (logit) of being in honors for males, and \(e^{-1.471}\) = 0.23 is the odds of being in honors for males.

Then what is the estimated population probability of being in honors for males?

\(\begin{aligned}p(honors~|~male) = \frac{e^{-1.471}}{1+e^{-1.471}} = \frac{0.23}{1.23} = 18.68\%\end{aligned}\)


Now, the coefficient for gender, 0.593, is the log of the odds ratio of being in honors for females, compared to males (see discussion below for details on interpreting the odds ratios).

To calculate the population odds for females we must fill in the entire equation:

\(\begin{aligned}\frac{p}{1-p} = e^{-1.471~+~0.593} = e^{-0.878} = 0.416\end{aligned}\)

What is the estimated population probability of being in honors for females?

\(\begin{aligned}p(honors~|~female) = \frac{e^{-1.471~+~0.593}}{1+e^{-1.471~+~0.593}} = \frac{0.42}{1.416} = 29.36\%\end{aligned}\)

Interpreting the individualcoefficients in units of “log” is not intuitive.

Common practice in logistic regression is to convert our coefficients into odds ratios

Doing this is simple, it just involves exponentiating the coefficients. From our example:

Remember:


\(\begin{aligned}logit(p) = log(\frac{p}{1-p}) = \beta_0+\beta_1X_1\end{aligned}\)


So: we have two situations of interest, the baseline odds for males, and the odds ratio for females compared to males.

To get these values, we exponentiate the coefficients.

The odds of being in honors for males is:

\(\begin{aligned}e^{\beta_0} = e^{-1.47} = 0.23\end{aligned}\)

Whereas the odds for females is:

\(\begin{aligned}e^{\beta_0 + \beta_1} = e^{-1.47~+~0.59} = 0.42\end{aligned}\)

Whereas the odds ratio for females to males is:


\(\begin{aligned}\frac{e^{\beta_0+\beta_1}}{e^{\beta_0}} = \frac{0.42}{0.23} = 1.81\end{aligned}\)


Which can be calculated directly by exponentiating the coefficient for females


\(\begin{aligned}e^{\beta_1} = e^{0.59} = 1.81\end{aligned}\)


The exponentiated coefficients of predictors in logistic regression represent the odds of going from one state to another, they are odds ratios (OR)

Note, the OR is often interpreted as 1.81 = 81% greater odds for females than for males.

Example 3 - A Single Continuous Predictor

We’ll predict being in honors based on math scores

\(\begin{aligned}logit(p) =\beta_0 + \beta_1*math \end{aligned}\)


    Being in Honors
    OR CI p
(Intercept)   -9.79 -12.94 – -7.09 <.001
math   0.16 0.11 – 0.21 <.001
Observations   200


So, the intercept, -9.794, is the log of the odds (logit) of being in honors when math scores = zero. The odds of being in honors when math = 0 is the exponentiated coeffcient:

\(\begin{aligned}e^{-9.794} =0.0001\end{aligned}\)

The probability of being in honors when math = 0 is:

\(\begin{aligned}p(honors~|~math=0) = \frac{e^{-9.794}}{1+e^{-9.794}} = \frac{0}{1} = 0.01\%\end{aligned}\)

The coefficient on math represents the change in log odds for each 1-point increase in math scores.

So, as math scores go up 1 point, the log odds of beign in honors goes up by 0.156 points.

The probability of being in honors when math = mean(math) is:

\(\begin{aligned}p(honors~|~math=52.65) = \frac{e^{-9.794~+~0.156*52.65}}{1+e^{-9.794~+~0.156*52.65}} = 17.32\%\end{aligned}\)


The odds ratio for a 1 point increase in math scores is:

\(\begin{aligned}e^{\beta_1} = e^{0.156} = 1.17 \end{aligned}\)

Which = a 17% increase in odds for every 1 point increase in math scores

Example 4 - Multiple Predictors

Let’s look at predicting beign in honors based on math scores, reading scores, and gender

\(\begin{aligned}logit(p) =\beta_0 + \beta_1math + \beta_2gender+\beta_3read\end{aligned}\)


    Being in Honors
    OR CI p
(Intercept)   -11.77 -15.40 – -8.66 <.001
math   0.12 0.06 – 0.19 <.001
female   0.98 0.17 – 1.84 .020
read   0.06 0.01 – 0.11 .026
Observations   200


This fitted model says that, holding math and reading at a fixed value, the odds of getting into an honors class for females (female = 1) over the odds of getting into an honors class for males (female = 0) is:

\(\begin{aligned}e^{0.98} = 2.66\end{aligned}\)

In terms of percent change, we can say that the odds for females are 166% higher than the odds for males.

Similarly, the coefficient for math (0.12) says that, holding gender and reading scores at a fixed value, a one point change in math scores results in a change of odds:

\(\begin{aligned}e^{0.12} = 1.13\end{aligned}\)

In terms of percent change, we can say that the change in odds for every 1 point increase in math scores is: 13%.

Example 5 - An Interaction between a categorical and a continuous predictor

Let’s see if gender modifies the influence of math scores on the likelihood of being in honors.
Note, when we model interactions, we center our continuous predictor variables. Thus, the mean of math will now be zero.

We’ll start with the 2 predictors, gender and math, with no interaction.


\(\begin{aligned}logit(p) =\beta_0 + \beta_1gender + \beta_2math\end{aligned}\)