Tutorials › Exam PA - Predictive Analytics › Worked Gamma GLM For Positive Claim Severity

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

Worked Gamma GLM For Positive Claim Severity

Learn when a Gamma GLM with a log link is appropriate for claim severity, how to fit it in R, and how to check the response, convergence and fitted means.

Intermediate 10 min read

What You'll Learn

  • State the support, mean and variance assumptions of a Gamma response model.
  • Explain why a log link keeps fitted severity means positive.
  • Fit a Gamma GLM with a log link in R.
  • Check whether the severity response satisfies the family requirements.
  • Inspect convergence, fitted means and the residual deviance.

Why Use a Gamma GLM for Claim Severity?

Claim severity is the amount paid for a claim, conditional on a claim having occurred. In a hypothetical insurance portfolio, these amounts are positive and often right-skewed: many claims may be moderate, while a smaller number are much larger. A Gamma generalized linear model (GLM) can model the conditional mean severity while allowing the variability to increase with that mean.

The response must meet the family’s support requirements, and the link must suit the quantity being modeled. For positive severity, the log link is useful because it restricts fitted means to positive values. It does not make nonpositive observed responses valid, however. Check the data before fitting.

Definition: A Gamma GLM for response \(Y_i\), conditional on predictors \(x_i\), assumes independent responses with \(Y_i>0\), conditional mean \(\mu_i=E[Y_i\mid x_i]\), and variance \(\operatorname{Var}(Y_i\mid x_i)=\phi\mu_i^2\), where the common dispersion parameter \(\phi>0\). With a log link, \(\log(\mu_i)=\eta_i=x_i^\mathsf{T}\beta\), so \(\mu_i=\exp(\eta_i)>0\).

One parameterization writes \(Y_i\mid x_i\) as Gamma with shape \(1/\phi\) and scale \(\phi\mu_i\). Under this parameterization, its mean is \((1/\phi)(\phi\mu_i)=\mu_i\), and its variance is \((1/\phi)(\phi\mu_i)^2=\phi\mu_i^2\). The model therefore allows the variance to grow as the squared mean grows. It is not appropriate merely because a response is positive: its conditional distribution and mean-variance relationship should also be plausible for the application.

Model Specification and the R Family

For observations \(i=1,\ldots,n\), the linear predictor combines the chosen predictors with regression coefficients. The log link relates that predictor to the conditional mean. In R, specify the Gamma family and link explicitly:

$$ \eta_i=x_i^\mathsf{T}\beta,\qquad \log(\mu_i)=\eta_i,\qquad \mu_i=\exp(x_i^\mathsf{T}\beta) $$

A basic R call has the form glm(severity ~ predictor1 + predictor2, family = Gamma(link = "log"), data = claim_data). The response should be the positive claim amount, not a zero-filled amount for every policy. If a record represents no claim rather than an observed claim of zero severity, it belongs to a different modeling question. The family does not permit zero or negative response values.

As with other GLMs, fitting estimates coefficients by likelihood-based methods. R uses iterative calculations; a successful fit should report convergence. Convergence is necessary for treating the result as a fitted model, but it does not show that the response meets the Gamma assumptions or that the specification is suitable.

Why Group Fitted Means Equal Group Averages in a Saturated Model

A short likelihood argument explains one useful check on a Gamma log-link fit. Suppose a model has a separate fitted mean \(\mu_g\) for each group \(g\), with observations independent and a common dispersion \(\phi\). The Gamma density under the parameterization above is proportional, as a function of \(\mu_g\), to \(\mu_g^{-1/\phi}\exp[-y_i/(\phi\mu_g)]\). Writing \(\eta_g=\log(\mu_g)\), the derivative of the log-likelihood contribution for observation \(i\) with respect to \(\eta_g\) is \((y_i/\mu_g-1)/\phi\). Setting the group score to zero gives:

$$ \sum_{i\in g}\frac{1}{\phi}\left(\frac{y_i}{\mu_g}-1\right)=0 \quad\Longrightarrow\quad \frac{\sum_{i\in g}y_i}{\mu_g}=n_g \quad\Longrightarrow\quad \widehat{\mu}_g=\frac{1}{n_g}\sum_{i\in g}y_i $$

Thus a model with a separate mean for each group fits each group’s arithmetic average. This is a special case, not a rule that fitted means in every Gamma GLM equal averages within arbitrary subsets. With continuous predictors or a less saturated model, the fitted values are determined jointly by the model and its likelihood.

Worked Example: Fitting Two Group Means by Hand

A hypothetical insurer has six observed positive repair severities, in dollars. Three claims are from channel A: \(100,150,200\). Three are from channel B: \(180,240,300\). Fit a Gamma GLM with a log link and a separate mean for each channel. Use the method of solving the group score equations, and identify a common mistake this calculation avoids.

Step 1: Check the response. All six amounts are strictly positive, so they meet the Gamma support requirement. The model treats the observed severities as independent conditional on channel and uses a common dispersion parameter.

Step 2: Calculate the fitted means. For channel A, the sum is \(100+150+200=450\), so its mean is \(450/3=150\). For channel B, the sum is \(180+240+300=720\), so its mean is \(720/3=240\). By the group score result, these are the fitted means.

Step 3: Express the result as a log-link model. With A as the reference channel, the intercept is \(\log(150)\approx5.0106\). The coefficient for B is \(\log(240/150)=\log(1.6)\approx0.4700\). Thus A has linear predictor \(\log(150)\) and fitted mean \(\exp(\log(150))=150\); B has linear predictor \(\log(150)+\log(1.6)=\log(240)\) and fitted mean \(240\).

Step 4: Check the fit using Gamma deviance. For positive observations, the unit deviance contribution is \(2[(y_i-\widehat{\mu}_i)/\widehat{\mu}_i-\log(y_i/\widehat{\mu}_i)]\). For A, the contributions are \(0.144264\), \(0\), and \(0.091302\), totaling \(0.235566\). For B, they are \(0.075364\), \(0\), and \(0.053713\), totaling \(0.129077\). The total deviance is \(0.364643\). There are \(6-2=4\) residual degrees of freedom, so the usual residual-deviance estimate of dispersion is \(0.364643/4=0.091161\), or \(0.0912\) to four decimal places.

Check. Substituting the coefficients back into the log-link equation gives positive fitted means of \(150\) and \(240\), equal to the calculated group averages. The common mistake avoided is using a Gaussian model by default or taking logarithms of the observed severities simply because the GLM uses a log link. The link transforms the mean; it does not instruct us to transform the response.

Fitting and Inspecting the Model in R

The next example follows a complete fitting workflow. It checks the response first, specifies a factor predictor, fits the model, and inspects convergence and fitted means. The data are hypothetical.

Worked Example: Fitting and Checking a Gamma GLM in R

Six hypothetical positive severities, in dollars, are recorded for two service networks. Cedar has severities \(90,120,150\); Pine has \(120,180,240\). Fit a model with a separate mean by network. Name the method and a common mistake it avoids.

Step 1: Enter and validate the response. The values are all positive. In R:

d <- data.frame(severity = c(90, 120, 150, 120, 180, 240), network = factor(c("Cedar", "Cedar", "Cedar", "Pine", "Pine", "Pine")))
stopifnot(all(is.finite(d$severity)), all(d$severity > 0))

The first check rules out non-finite values, and the second checks the strict positivity required by the Gamma family.

Step 2: Fit the model and check convergence.

fit <- glm(severity ~ network, family = Gamma(link = "log"), data = d)
fit$converged
fit$boundary
coef(fit)

The separate group means are Cedar: \((90+120+150)/3=360/3=120\), and Pine: \((120+180+240)/3=540/3=180\). Therefore the fitted intercept is \(\log(120)\approx4.7875\), and the Pine coefficient is \(\log(180/120)=\log(1.5)\approx0.4055\). The converged indicator should be TRUE for this fit, and the boundary indicator should be FALSE. Always inspect warnings as well as these indicators.

Step 3: Inspect the fitted values. Use fitted(fit) or predict(fit, type = "response") to obtain means on the dollar scale. The six values, in data order, are \(120,120,120,180,180,180\). With predict(fit, type = "link"), the corresponding linear predictors are \(\log(120)\) for Cedar and \(\log(180)\) for Pine.

Step 4: Review residual deviance and degrees of freedom. For Cedar, the observations divided by \(120\) are \(0.75,1,1.25\). Their deviance contributions are \(0.075364,0,0.053713\). For Pine, dividing by \(180\) gives \(2/3,1,4/3\), with contributions \(0.144264,0,0.091302\). Total deviance is \(0.364643\), and residual degrees of freedom are \(6-2=4\). The residual-deviance dispersion estimate is therefore \(0.091161\).

Check. The response values satisfy the family’s support requirement, the fitted means are positive, and each group fitted mean matches its arithmetic average. The method is a group-indicator Gamma GLM with a log link. The mistake avoided is treating converged = TRUE as proof that the response is valid or the model is appropriate; those checks are separate.

Response Checks and Convergence Are Different Questions

A reliable workflow distinguishes data eligibility from optimization diagnostics. Before fitting, confirm that the response contains observed positive severities and that the records represent the intended population. A zero may mean no claim, an unpaid claim, or a data-coding issue; those possibilities should not be silently treated as equivalent. Negative severity is generally a data error or a sign that the response definition needs review. Do not add a small constant to zero values automatically to force a fit.

After fitting, examine warnings, coefficient estimates, fitted values, residual deviance and residual degrees of freedom. The fitted response-scale means should be positive under a log link. Also consider whether the fitted values and residual patterns are plausible for the problem. A model can converge and still be poorly specified, and a plausible-looking fit cannot repair invalid response values.

Key takeaway: A Gamma GLM with a log link models strictly positive responses with conditional variance \(\phi\mu_i^2\) and fitted mean \(\mu_i=\exp(x_i^\mathsf{T}\beta)\). Check positivity before fitting; then inspect convergence, fitted means and fit diagnostics separately.

Check Your Understanding

Work through each problem and compare your result with the answer.

  1. A hypothetical repair portfolio has three positive severities in one group: \(70,100,130\). Under a Gamma log-link model with a separate mean for this group, calculate the fitted mean. (Answer: \(100\))
  2. A two-group saturated Gamma GLM with a log link has a reference-group fitted mean of \(200\) and a second-group fitted mean of \(300\). What is the second-group coefficient relative to the reference? (Answer: \(\log(1.5)\approx0.4055\))
  3. A severity column contains \(40,0,55\). Does it satisfy the Gamma response support requirement as entered, and what should be checked about the zero before fitting? (Answer: No; determine whether zero means no claim, a coding issue, or another outcome, and do not silently treat it as positive severity.)
  4. For one positive observation \(y=120\) with fitted mean \(\widehat{\mu}=100\), calculate its Gamma deviance contribution \(2[(y-\widehat{\mu})/\widehat{\mu}-\log(y/\widehat{\mu})]\). (Answer: \(2[0.2-\log(1.2)]\approx0.0354\))
  5. A fitted model has \(\log(\widehat{\mu})=\log(100)+x\log(1.1)\). Calculate the fitted mean when \(x=4\), and state whether it meets the positive-mean constraint. (Answer: \(100(1.1)^4=146.41\); yes, it is positive.)
Clinical Biostats