Tutorials › Exam PA - Predictive Analytics › Bernoulli GLMs With The Logit Link

Exam PA · GLM Families and Model Construction · Tutorial 301 of 966

Bernoulli GLMs With The Logit Link

Learn to express binary event probabilities with a logistic GLM, interpret its coefficients, and fit the model in R with `glm()` and `family = binomial()`.

Intermediate 12 min read

What You'll Learn

  • Define a Bernoulli response and state the assumptions for a logistic GLM.
  • Convert a linear predictor into an event probability using the inverse-logit formula.
  • Interpret logistic regression coefficients as changes in log odds and odds ratios.
  • Calculate fitted probabilities for hypothetical actuarial risk profiles.
  • Fit an individual-level binary response model with `glm()` in R.
  • Avoid common errors in event coding and probability interpretation.

Why Use a Logit Model for a Binary Outcome?

Many actuarial outcomes are recorded as either an event or no event: a policyholder has a claim during the year, a policy lapses, or a payment is made. A linear model for a zero-or-one response can produce fitted values below zero or above one, which cannot be probabilities. A Bernoulli generalized linear model (GLM) instead models the event probability on a transformed scale and converts the result back to a value between zero and one.

The logit link is especially useful because it makes the log odds a linear function of predictors. This gives a clear interpretation of coefficients while ensuring that predicted probabilities remain valid. The tutorial focuses on individual binary observations, not counts of successes in grouped trials.

Definition: For observation \(i\), let \(Y_i=1\) indicate that the event occurs and \(Y_i=0\) indicate that it does not. If \(P(Y_i=1\mid \boldsymbol{x}_i)=p_i\), then \(Y_i\mid\boldsymbol{x}_i\) has a Bernoulli distribution with parameter \(p_i\). A Bernoulli GLM with the logit link specifies $$ \log\left(\frac{p_i}{1-p_i}\right)=\eta_i=\beta_0+\beta_1x_{i1}+\cdots+\beta_kx_{ik}, $$ where \(\eta_i\) is the linear predictor and the \(\beta_j\) are model coefficients.

From Linear Predictor to Probability

The logit of a probability \(p\) is \(\log(p/(1-p))\), the logarithm of the event odds. Solving the logit equation for \(p_i\) gives the inverse-logit formula:

$$ p_i=\frac{\exp(\eta_i)}{1+\exp(\eta_i)} =\frac{1}{1+\exp(-\eta_i)}. $$

For every finite value of \(\eta_i\), this expression is strictly between zero and one. A positive linear predictor means event odds greater than one and therefore an event probability above one-half; a negative linear predictor means event probability below one-half. The probability is not equal to the linear predictor.

Why the Inverse-Logit Formula Holds

The inverse-logit is obtained by algebraically undoing the logit transformation. Starting with the model equation, exponentiate both sides. The result is the odds, not yet the probability:

$$ \log\left(\frac{p_i}{1-p_i}\right)=\eta_i \quad\Longrightarrow\quad \frac{p_i}{1-p_i}=\exp(\eta_i). $$

Multiply by \(1-p_i\), collect the terms involving \(p_i\), and divide:

$$ p_i=\exp(\eta_i)(1-p_i) \quad\Longrightarrow\quad p_i\{1+\exp(\eta_i)\}=\exp(\eta_i) \quad\Longrightarrow\quad p_i=\frac{\exp(\eta_i)}{1+\exp(\eta_i)}. $$

This derivation also shows why the model is expressed in terms of log odds: any real-valued linear predictor maps to a valid probability through the inverse-logit.

Interpreting Coefficients

A coefficient describes a change in log odds, holding the other predictors fixed. If \(x_j\) increases by one unit, then \(\eta_i\) changes by \(\beta_j\), so the event odds are multiplied by \(\exp(\beta_j)\). This multiplicative effect is an odds ratio. It is not a fixed change in probability: the probability change depends on the starting predictor values.

For a categorical predictor represented by an indicator, its coefficient compares the indicated category with the reference category, conditional on the other predictors. For example, if \(z=1\) denotes a particular distribution channel and \(z=0\) is the reference channel, then \(\exp(\beta_z)\) is the ratio of the event odds for \(z=1\) to those for \(z=0\), at the same values of the other predictors.

Worked Example: Claim Probability by Prior Incidents

Method and mistake avoided. Use the inverse-logit to convert the linear predictor into a probability. The common mistake is to report the linear predictor itself as the probability.

Consider a hypothetical portfolio model for whether an individual policy has at least one claim during the next policy year. Let \(Y=1\) indicate a claim and let \(x\) be the number of prior incidents. Suppose a fitted model is \(\operatorname{logit}(p)=-2+0.5x\). Calculate the predicted probability for a policyholder with two prior incidents, and interpret the slope.

Step 1: Calculate the linear predictor. For \(x=2\), \(\eta=-2+0.5(2)=-2+1=-1\).

Step 2: Convert the predictor to a probability. \(p=1/(1+\exp(-\eta))=1/(1+\exp(1))\). Using \(\exp(1)\approx2.7183\), \(p=1/3.7183\approx0.2689\). The predicted claim probability is 0.2689, or 26.89%.

Step 3: Interpret the slope. One additional prior incident multiplies the claim odds by \(\exp(0.5)\approx1.6487\). Thus the odds are about 1.6487 times as large for each additional incident, holding the model structure fixed. This is not an increase of 0.5 in probability.

Check. The linear predictor \(-1\) is negative, so the probability should be below 0.5. The computed value, 0.2689, is consistent with that check.

Worked Example: Comparing Two Risk Profiles

Method and mistake avoided. Calculate each profile's linear predictor and then apply the inverse-logit. This avoids treating a coefficient as a constant percentage-point change in probability.

A hypothetical insurer models the probability that a policy lapses within a year. Let \(a\) be an affordability index and let \(c=1\) indicate an online channel, with \(c=0\) denoting the reference channel. Suppose the fitted model is \(\operatorname{logit}(p)=-1+0.5a+0.7c\). Compare the predicted probabilities for (A) \(a=1,c=0\) and (B) \(a=1,c=1\).

Profile A. The linear predictor is \(\eta_A=-1+0.5(1)+0.7(0)=-0.5\). Hence \(p_A=1/(1+\exp(0.5))\). Since \(\exp(0.5)\approx1.6487\), \(p_A=1/2.6487\approx0.3775\), or 37.75%.

Profile B. The linear predictor is \(\eta_B=-1+0.5(1)+0.7(1)=0.2\). Hence \(p_B=1/(1+\exp(-0.2))\). Since \(\exp(-0.2)\approx0.8187\), \(p_B=1/1.8187\approx0.5498\), or 54.98%.

Compare and check. The online-channel coefficient gives an odds ratio of \(\exp(0.7)\approx2.0138\) at the same affordability index. Profile B has the higher predicted probability, as expected from its larger linear predictor. The probability difference is about \(0.5498-0.3775=0.1723\), or 17.23 percentage points; it is not the coefficient 0.7.

Fitting a Bernoulli GLM in R

In R, fit an individual-level binary response with `glm()` and `family = binomial()`. The default link for the binomial family is the logit link. Writing `family = binomial(link = "logit")` makes that choice explicit. Each row in this setup represents one observation, and the response should clearly identify which value means the event occurred.

$$ \texttt{glm(event \textasciitilde{} predictor\_1 + predictor\_2,}\\ \texttt{\ \ \ \ family = binomial(), data = portfolio)} $$

For a zero-or-one response, a typical workflow is to check the response coding, fit the specified model, inspect the coefficient estimates, and obtain predicted probabilities on the response scale. The following code illustrates that structure; the data are hypothetical.

1
Confirm the event definition.
Here, `claim` is 1 for a claim during the observation period and 0 otherwise. Confirm that each row represents one policy observation and that the event is coded consistently.
2
Specify and fit the model.
Use `glm(claim ~ prior_incidents + channel, family = binomial(), data = portfolio)`. R estimates coefficients by maximum likelihood. A factor predictor is represented relative to a reference level.
3
Obtain probabilities.
Use `predict(fit, newdata = new_policies, type = "response")` to obtain predicted probabilities. Without `type = "response"`, predictions are on the link scale by default, so they are linear predictors rather than probabilities.

The equivalent explicit family specification is `family = binomial(link = "logit")`. For example:

$$ \texttt{fit <- glm(claim \textasciitilde{} prior\_incidents + channel,}\\ \texttt{\ \ \ \ \ \ \ \ \ family = binomial(link = "logit"), data = portfolio)} $$

The fitted coefficients are on the log-odds scale. Applying `exp(coef(fit))` gives the corresponding multiplicative odds effects, but predicted probabilities still require the full linear predictor for each profile followed by the inverse-logit.

Worked Example: Turning a Fitted R Model into a Prediction

Method and mistake avoided. First calculate the linear predictor from the supplied fitted coefficients, then transform it to the response scale. The main trap is interpreting a link-scale prediction as a probability.

Suppose R fitting a hypothetical claim model gives the illustrative coefficients \(\hat{\beta}_0=-1.6\), \(\hat{\beta}_1=0.4\) for prior incidents \(x\), and \(\hat{\beta}_2=0.6\) for an indicator \(z\) that equals 1 for a specified channel. For a new policy with \(x=2,z=1\), calculate its predicted probability. These coefficients are supplied for this calculation; no particular dataset is asserted to produce them.

Step 1: Form the linear predictor. \(\hat{\eta}=-1.6+0.4(2)+0.6(1)=-1.6+0.8+0.6=-0.2\).

Step 2: Apply the inverse-logit. \(\hat{p}=1/(1+\exp(-\hat{\eta}))=1/(1+\exp(0.2))\). Since \(\exp(0.2)\approx1.2214\), \(\hat{p}=1/2.2214\approx0.4502\). The predicted probability is 0.4502, or 45.02%.

Step 3: Check the scale. The link-scale prediction is \(-0.2\), while the response-scale prediction is 0.4502. Because the linear predictor is negative, the probability is below one-half, which agrees with the calculation. In R, the corresponding prediction uses `type = "response"` to return the probability directly.

Assumptions and Common Traps

A logistic GLM is appropriate when the response for each observation is binary and the conditional event probability is modeled through the logit of its mean. The usual model assumes that, conditional on the predictors, observations are independent and that the specified linear predictor is an adequate representation of the log odds. The predictors need not themselves be normally distributed. These assumptions concern the response and model structure; a fitted probability is not automatically a causal effect.

The model also relies on having enough information in the observed data to estimate its coefficients. In particular, if a predictor or combination of predictors perfectly separates event and non-event observations, finite maximum-likelihood coefficient estimates may not exist. A successful software call should therefore not be treated as proof that estimates are stable or that the model is suitable.

  • Confusing odds with probability. If odds are \(r\), the probability is \(r/(1+r)\), not \(r\). Convert log odds through the inverse-logit.
  • Reading a coefficient as a probability change. A coefficient changes log odds; its exponential is an odds ratio. The probability change depends on the starting profile.
  • Using the wrong R prediction scale. The default prediction scale is the link scale. Specify `type = "response"` when probabilities are required.
  • Reversing the event coding. If 1 represents no claim rather than a claim, the model predicts the probability of no claim. State the event before fitting and interpret accordingly.
Key takeaway: A Bernoulli GLM with the logit link makes the log odds linear in the predictors and maps that linear predictor to a valid event probability. Interpret coefficients on the odds scale, and use response-scale predictions when reporting probabilities.

Check Your Understanding

For each question, calculate on the log-odds scale first and then interpret or transform as requested.

  1. A fitted model has \(\eta=-1.2+0.4x\). Find the event probability when \(x=3\). (Answer: \(\eta=0\), so \(p=0.5000\).)
  2. A fitted model has \(\eta=-2+0.6x\). Find the event probability when \(x=2\), to four decimals. (Answer: \(\eta=-0.8\), so \(p=1/(1+\exp(0.8))=0.3100\).)
  3. A binary predictor has fitted coefficient \(0.9\). By what factor are event odds multiplied when the predictor changes from 0 to 1, holding other predictors fixed? (Answer: \(\exp(0.9)=2.4596\), approximately.)
  4. A fitted model is \(\eta=-2.5+0.3x+0.8z\). Find the probability for \(x=4,z=1\), to four decimals. (Answer: \(\eta=-0.5\), so \(p=1/(1+\exp(0.5))=0.3775\).)
  5. An R model uses `glm(event ~ age, family = binomial(), data = d)`. A prediction for a new record is required as a probability. Which prediction setting should be used, and what does it return? (Answer: Use `type = "response"`; it returns the inverse-logit-transformed fitted probability of the event coded as 1.)
Clinical Biostats