Why Use a Logistic GLM for a Claim Indicator?
A claim indicator records whether a specified event occurred, not how large a claim was. For policy \(i\), write \(Y_i=1\) if the policy had at least one claim during the observation period, and \(Y_i=0\) otherwise. A model for this response should produce a probability for each policy. Ordinary linear regression does not guarantee that its fitted values lie between zero and one. A logistic generalized linear model (GLM) handles this by modeling a transformation of the probability.
The response definition must match the question. “At least one claim during the year” is a binary outcome; it is not the number of claims, nor the dollar amount paid. In the hypothetical examples below, the observation period is stated explicitly so that each indicator has a clear meaning.
For this model, observations are ordinarily treated as independent conditional on their predictors. The logit link is appropriate for a binary probability response. It does not make every possible predictor specification suitable: the response and predictors still need to be coded as intended, and the linear predictor must represent the chosen model structure.
From Linear Predictor to Fitted Probability
The logit link puts the probability on an unrestricted scale. Solving the link equation for \(p_i\) gives the inverse-logit transformation, also called the logistic function:
This is the fitted probability of \(Y_i=1\), conditional on the predictors and the fitted coefficients. The derivation also proves the required range: for any finite real \(\widehat{\eta}_i\), \(\exp(-\widehat{\eta}_i)>0\), so the denominator \(1+\exp(-\widehat{\eta}_i)>1\). Therefore \(0<\widehat{p}_i<1\). The values can approach zero or one as the linear predictor becomes very negative or very positive, but a finite linear predictor does not produce either endpoint.
In R, specify both the binomial family and the logit link explicitly. For a numeric response coded zero and one, the basic pattern is: glm(claim ~ predictor1 + predictor2, family = binomial(link = "logit"), data = training_data). The response should have one zero-or-one value per observation. Use predict(fit, newdata = ..., type = "response") for fitted probabilities. By contrast, type = "link" returns the linear predictor, which can be any real number.
Worked Example: Fitting a Logistic GLM With a Categorical Predictor
Suppose a hypothetical insurer observes nine policies over one year. Four policies are in area A, with one claim indicator equal to 1; five are in area B, with three indicators equal to 1. Fit a logistic model using area as a categorical predictor, calculate both fitted probabilities, and check the fitted claim totals.
Method and coding. The response is one if the policy had at least one claim during the year and zero otherwise. Set the factor levels so area A is the reference category. The data can be entered in R as: claim = c(1, 0, 0, 0, 1, 1, 1, 0, 0); area = factor(c(rep("A", 4), rep("B", 5)), levels = c("A", "B")). Then fit: fit = glm(claim ~ area, family = binomial(link = "logit"), data = data.frame(claim, area)).
Model and estimates. With A as the reference category, the model is \(\eta_i=\beta_0+\beta_1I(\text{area}_i=\text{B})\). In the two groups, the observed claim proportions are \(1/4=0.25\) for A and \(3/5=0.60\) for B. This model gives each group its own fitted probability, so the maximum-likelihood fitted probabilities equal those proportions. The corresponding logits are:
Subtracting the first linear predictor from the second gives \(\widehat{\beta}_1=0.4055-(-1.0986)=1.5041\). Equivalently, \(\widehat{\beta}_1=\log(1.5)-\log(1/3)=\log(4.5)\). These are the estimates the logistic fit produces, up to rounding.
Predictions and check. For area A, \(\widehat{\eta}_A=-1.0986\), giving \(\widehat{p}_A=1/(1+\exp(1.0986))=1/(1+3)=0.25\). For area B, \(\widehat{\eta}_B=-1.0986+1.5041=0.4055\), giving \(\widehat{p}_B=1/(1+\exp(-0.4055))=1/(1+2/3)=0.60\). The expected fitted claim totals are \(4(0.25)=1\) in A and \(5(0.60)=3\) in B, matching the observed totals. Both probabilities are strictly between zero and one.
R verification. Use predict(fit, type = "response") to obtain the fitted probabilities on the response scale; the four A values are 0.25 and the five B values are 0.60. This example avoids the common mistake of treating the estimated coefficient as a probability: the coefficient estimates are on the logit scale, and the inverse-logit calculation is needed to obtain probabilities.
Checking Response and Predictor Coding
A correctly specified family and link cannot repair a mis-coded response. For a numeric binomial response, verify that zero means the event did not occur and one means it did. Also check that there is one response value for each intended observational unit. For example, if a policy appears several times because it has several records, decide whether the modeling unit is a policy or a record before fitting; otherwise, the data may not represent the intended claim indicator.
For a categorical predictor, check its levels and reference category. R represents a factor through indicator columns, so changing the reference category changes the coefficient representation. It should not change the fitted probabilities when the model includes the same factor information. For a numeric predictor, check that the values are numeric quantities on the intended scale rather than character strings or category labels accidentally stored as numbers.
A two-level factor response requires particular care. In a binomial GLM, R treats the first factor level as failure and the second as success. That convention can reverse the event being modeled if the level order is not checked. A numeric zero-one response avoids this specific ambiguity. If a factor response is used, explicitly set and inspect its levels before fitting.
Worked Example: Catching a Reversed Factor Response
Use the nine hypothetical policies from the previous example: area A has one claim and three nonclaims, while area B has three claims and two nonclaims. A data analyst stores the outcome as the labels “claim” and “no claim,” then sets factor levels to c("claim", "no claim"). Determine what event a binomial GLM will model as success, and correct the coding.
Identify the event used by R. With those ordered levels, “claim” is first and “no claim” is second. R therefore treats “no claim” as success. If the analyst fits glm(outcome ~ area, family = binomial(link = "logit"), data = data), the modeled probabilities are probabilities of no claim, not probabilities of claim.
Calculate the reversed fitted values. In area A, three of four policies have no claim, so the fitted probability for the event R calls success is \(3/4=0.75\). In area B, two of five have no claim, so that probability is \(2/5=0.40\). The fitted claim probabilities from the intended model are their complements: \(1-0.75=0.25\) and \(1-0.40=0.60\). The corresponding link-scale values for the reversed response are \(\log(0.75/0.25)=\log(3)\approx1.0986\) for A and \(\log(0.40/0.60)=\log(2/3)\approx-0.4055\) for B.
Correct the fit. Create a numeric response with claim = 1 and no claim = 0, or set the factor levels explicitly as c("no claim", "claim") before fitting. Then refit and request predict(fit, type = "response"). The returned values now target the probability of a claim. Merely relabeling a fitted probability without checking which event was modeled is the trap this coding check prevents.
Using Fitted Models for New Policies
After fitting, provide new predictor values in a data frame with the same variable names and compatible types as those used in the model. A factor in the new data must have levels represented in the fitted data. Then use type = "response" when the requested output is a probability. If the model contains a numeric predictor, keep its units consistent: a value of 40 means something different if the training variable was recorded in years rather than months.
Worked Example: Predicting Claim Probabilities for New Ages
Suppose a hypothetical one-year claim-indicator model uses age in years and has fitted linear predictor \(\widehat{\eta}=-3+0.04\,\text{age}\). Calculate the fitted probabilities for ages 40, 60, and 80. State how to obtain the same results in R and verify their range.
Method. For each age, first calculate the linear predictor, then apply the inverse-logit. The R prediction data frame should contain the numeric variable age with values 40, 60, and 80. Use predict(fit, newdata = data.frame(age = c(40, 60, 80)), type = "response").
At age 40, \(\widehat{\eta}=-3+0.04(40)=-3+1.6=-1.4\). Thus \(\widehat{p}=1/(1+\exp(1.4))\approx1/(1+4.0552)=0.1978\).
At age 60, \(\widehat{\eta}=-3+0.04(60)=-3+2.4=-0.6\). Thus \(\widehat{p}=1/(1+\exp(0.6))\approx1/(1+1.8221)=0.3543\).
At age 80, \(\widehat{\eta}=-3+0.04(80)=-3+3.2=0.2\). Thus \(\widehat{p}=1/(1+\exp(-0.2))\approx1/(1+0.8187)=0.5498\). Rounded to four decimal places, the probabilities are 0.1978, 0.3543, and 0.5498. Each is between zero and one, as required. Requesting type = "link" instead would return \(-1.4\), \(-0.6\), and \(0.2\), which are linear predictors, not probabilities.
Common mistake avoided. Do not pass a linear predictor off as a fitted probability just because it came from a probability model. Transform it through the inverse-logit, or ask R for type = "response."
A Practical Verification Sequence
A short sequence of checks catches many avoidable errors before fitted values are used in a report or calculation.
Write what one means in context, including the observation period and unit of observation.
Confirm that numeric responses use zero for no event and one for event, or confirm the ordered levels of a factor response. Check factor predictors and numeric units as well.
Use family = binomial(link = "logit") and a formula containing the intended predictors. Retain the intercept unless the model specification calls for its removal.
Use type = "response" for fitted probabilities and verify that each is at least zero and at most one. If a requested prediction is outside this range, check that it was not produced on the link scale or by a different model.
The logistic transformation guarantees valid probability bounds for finite linear predictors; it does not by itself guarantee that the data, response definition, or predictor specification is appropriate. In particular, a bounded prediction can still answer the wrong question if the event was reversed or the predictor units were misread. Checking the coding and the scale of the output is therefore part of constructing the model, not merely a final software check. This modeling workflow is aligned with the SOA Exam PA (Predictive Analytics) syllabus.
Check Your Understanding
Work through each coding or calculation step, then compare your final result.
- A hypothetical model for a one-year claim indicator has \(\widehat{\eta}=-2+0.5x\). For \(x=3\), calculate the fitted probability using the inverse-logit and give the result to four decimal places. (Answer: \(\widehat{\eta}=-0.5\), \(\widehat{p}=0.3775\).)
- In a hypothetical training set, group A has 2 claims among 8 policies and group B has 4 claims among 10 policies. For a logistic model with group as the only predictor, give the fitted claim probability in each group and the expected fitted claim total in each group. (Answer: A: probability 0.2500 and fitted total 2; B: probability 0.4000 and fitted total 4.)
- A factor response has levels c("event", "no event"). Which event is treated as success by R's binomial GLM, and what is a safe numeric coding if the target is the probability of an event? (Answer: R treats “no event” as success; use event = 1 and no event = 0, or order the factor levels as c("no event", "event").)
- A fitted logistic model has \(\widehat{\eta}=0.2-0.03x+0.8z\). For \(x=20\) and \(z=1\), calculate the linear predictor and fitted probability to four decimal places. (Answer: \(\widehat{\eta}=0.4\), \(\widehat{p}=0.5987\).)
- An R prediction call returns 1.35 for a policy, and the analyst reports this as a claim probability. Identify the likely scale error and state the appropriate prediction setting. (Answer: 1.35 is not a probability and is likely a link-scale linear predictor; use type = "response" to obtain the fitted probability.)