Whether a task is completed is a yes or no outcome, but the probability of completing it can change smoothly with the difficulty of the task and the experience of the person attempting it. A straight line for that probability can give fitted values below or above . Logistic regression fits a linear model to the log odds instead. This lesson shows how to move between log odds, odds and probability, what an exponentiated coefficient does and does not say, when the ordinary fit fails to exist, and how to check predicted probabilities against observed outcomes.
Key terms
Logit
Definition For a probability with , the odds are and the logit, or log odds, is
where is the natural logarithm. The logit is strictly increasing, takes every real value exactly once as runs over , equals at and satisfies . It is not defined at or .
In plain words Odds compare the chance that the event happens with the chance that it does not. Odds of mean the two are equally likely, and odds of mean the event is a third as likely as its absence. The logarithm then stretches the probability scale over the whole number line, sending probabilities near far to the left and probabilities near far to the right.
Example Three probabilities and their odds and logits are below.
| odds | |||
| logit |
Logistic function
Definition The logistic function, also called the inverse logit, is
for every real . Its values lie strictly between and . It is strictly increasing, equals at and satisfies . It undoes the logit, since for every real and for . The formula comes from solving for .
In plain words The logistic function turns any real number into a probability along an S-shaped curve. It is steepest at , where the probability is , and it flattens toward on the left and toward on the right without reaching either. Equal steps in therefore move the probability more near the middle than near the ends.
Example The values , and lie on the curve. By the symmetry, .
Logistic regression
Definition Logistic regression models a binary response , coded for the event and otherwise, given predictors . With , the model states
so , where is the linear predictor on the right. The responses are assumed independent given their predictors. Because is binary, , and no normal errors or constant variance are assumed. The coefficients are usually estimated by maximum likelihood, maximizing
over , where . The predicted probability for a profile is , with the estimates in place of the . It estimates under the model, and it is not a prediction that the event will happen.
In plain words The model puts a linear function of the predictors on the log-odds scale, and the logistic function bends it into an S-shaped curve for the probability that stays between and . Each observed contributes its modeled probability to the likelihood and each observed contributes one minus that probability, so maximum likelihood looks for the coefficients under which the observed pattern of outcomes is most probable.
Example For teaching, declare the model , with coefficients chosen rather than estimated. At the log odds are , the odds and the probability . At the probability is , and at it is . Four records with and outcomes have likelihood contributions of about , , and under this model, with product about . Giving every record probability yields likelihood , so the declared coefficients fit these outcomes better. Comparing two candidates does not find the best one, and for these four records no finite best one exists, as the section on complete separation shows.
Odds ratio for a predictor
Definition Suppose a predictor enters a logistic regression only through the term . Raising by one unit while every other predictor stays fixed adds to the log odds and multiplies the odds by
whatever the starting values. This number is the odds ratio for a one-unit increase in , adjusted for the other predictors in the model, and an increase of units multiplies the odds by . If also appears in an interaction or a squared term, the odds ratio for a one-unit increase depends on the value of the interacting predictor or on the starting value of .
In plain words A coefficient is a fixed change on the log-odds scale, and its exponential is a fixed multiplier on the odds scale. It is not a fixed change in probability and not a fixed risk ratio. In percentage points the same odds ratio moves a probability very close to or only slightly, and its largest move is the one centered on . When both probabilities are small the odds ratio and the risk ratio are close, and otherwise they can differ a lot. An adjusted odds ratio describes an association within the model, and reading it as a causal effect needs a design that supports it, such as random assignment.
Example In the declared model , so each unit of multiplies the odds by about . From to the probability rises from about to , by about percentage points, a risk ratio of about . From to it rises from to about , by about percentage points, a risk ratio of about . The odds ratio is the same for both steps, while the probability changes and the risk ratios differ.
Complete separation
Definition The outcomes of a data set are completely separated when some linear predictor is positive for every record with and negative for every record with . Multiplying those coefficients by a constant and letting grow sends every likelihood contribution toward . Every finite choice of coefficients gives each record a probability strictly between and , so the likelihood approaches without reaching it, and the ordinary maximum likelihood estimate does not exist as a finite vector. A weaker pattern, quasi-complete separation, also rules out a finite estimate. In that pattern some linear predictor is positive or for every record with , negative or for every record with , and for some but not all records.
In plain words If a threshold on some weighted sum of the predictors sorts every success from every failure, steeper and steeper S-curves fit better and better without end. Software may stop at a very large coefficient with an enormous standard error, issue a warning, or report fitted probabilities that are numerically and . Those numbers show where the algorithm stopped, not a precise estimate. Separation is common with small samples or rare outcomes, and it does not show that the true probabilities are and . Penalized or Bayesian methods can give finite estimates, but they change the estimation procedure and should be reported as such.
Example The four records with outcomes are separated at . Take with . The likelihood is about at , at , at and at . It keeps rising toward , so no finite pair of coefficients maximizes it.
Calibration
Definition A model’s predicted probabilities are calibrated in a population when, among the cases that receive predicted probability , the proportion of events equals , for every value that the model produces. In symbols, . Calibration is checked on observations not used to choose or fit the model, usually by grouping cases with similar predicted probabilities and comparing each group’s observed event rate with its average predicted probability.
In plain words Calibration asks whether the probabilities can be taken at face value, so that events given probability happen about percent of the time. It is different from discrimination, the ability to rank cases with events above cases without them. A model can order cases exactly by their true risk and still overstate every probability, and a model that gives every case the overall event rate is calibrated but cannot rank cases at all. Small groups give noisy event rates, so a gap in one group is a reason to look further rather than proof of miscalibration.
Example Twenty held-out cases each receive predicted probability , and events occur. The predicted count is and the observed rate is . If the predictions were correct and the outcomes independent, the count of events would be binomial with and , and or fewer events would occur with probability about . The shortfall deserves a check with more data, but this one group does not establish miscalibration. In a different case, two groups with true event rates and that receive predictions and are ranked correctly, yet both are overstated by .
Check yourself
- A declared model for the probability that a task is completed is , where is the difficulty level of the task and is the years of experience of the person attempting it. Find the log odds, the odds and the probability of completion for a task of difficulty attempted by someone with years of experience.
Show the answer
The log odds are . The odds are , and the probability is
Under the model, attempts with this profile succeed with probability about , which is about completions for every failures in the long run.
- In the same model and for the same task, a colleague says that each extra year of experience multiplies the probability of completion by , so with years it is . Find the correct probability and explain the mistake.
Show the answer
The factor multiplies the odds, with difficulty held fixed, not the probability. With years the log odds are and the odds are , so the probability is
The probability rises by about , a risk ratio of about , not . The colleague treated the odds ratio as a risk ratio. The coefficient also describes an association within the model. It shows what gaining a year of experience would do only if the design supports that causal reading.
- Six tasks have difficulties to . The three easiest were completed and the three hardest were not. Fitting , the software reports a very large negative slope with an enormous standard error and a convergence warning. What happened, and how should the result be reported?
Show the answer
The outcomes are completely separated. The linear predictor is positive for the three completed tasks and negative for the three others, so for the likelihood approaches as grows without ever reaching it. No finite maximum likelihood estimate exists, and the reported slope and standard error only show where the algorithm stopped. They are neither a precise estimate nor evidence of an extremely strong association, and a p-value computed from them means little. The report should state the separation and either gather more data or use a penalized or Bayesian method with its penalty or prior stated. Six tasks also cannot show that tasks harder than are never completed.