Tutorials › Exam PA - Predictive Analytics › Selecting GLM Family And Link Arguments In R

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

Selecting GLM Family And Link Arguments In R

Choose and code a GLM family and link in R by checking the outcome’s distribution, response format, and allowable mean range.

Intermediate 10 min read

What You'll Learn

  • Distinguish a GLM family’s response distribution from its link function.
  • Select valid R family and link arguments for six common GLM families.
  • Check response values and formats before fitting binomial and count models.
  • Recognize when positive-only outcomes suit Gamma or inverse Gaussian models.
  • Specify a Tweedie family and link with a package rather than base R.
  • Identify link choices that can produce inadmissible fitted means.

Why Family and Link Must Be Chosen Together

In R, a GLM call asks for two related specifications: a family and a link. The family describes the response distribution and its mean–variance relationship; the link determines how the conditional mean is connected to the linear predictor. The family does not merely label the outcome, and the link is not a cosmetic option. A suitable choice must match both the observed response and the range of means that the model can produce.

For example, a binary outcome is not entered in the same way as a count, and a Gamma response must be positive. Even when R accepts a particular link for a family, the resulting fitted means may not be suitable for every data set. The practical task is to check the response format, choose a defensible distribution, and then choose a link whose inverse maps the predictor to plausible means.

Definition: A generalized linear model specifies a conditional response distribution from an exponential-dispersion family, a linear predictor \(\eta_i = \mathbf{x}_i^\mathsf{T}\boldsymbol{\beta}\), and a link \(g\) satisfying \(g(\mu_i)=\eta_i\), where \(\mu_i=E[Y_i\mid \mathbf{x}_i]\). In R, the family object supplies the distributional family and a link function, including the inverse link used to obtain fitted means.

The usual R form is glm(response ~ predictors, family = family_function(link = "link_name"), data = ...). For instance, family = binomial(link = "logit") requests a binomial response with the logit link. The family controls more than the name of the outcome: it also determines how variance depends on the mean and, where relevant, how dispersion is handled.

R Family Objects and Available Links

The following are the standard link names accepted by the corresponding base R family functions. Each function has a default, but specifying the link explicitly makes the modeling choice visible and easier to check.

R family functionCommon response requirementAvailable link arguments in base RDefault link
binomial()Binary outcomes, grouped successes and failures, or proportions with trial weightslogit, probit, cloglog, cauchit, loglogit
poisson()Nonnegative integer event countslog, identity, sqrtlog
gaussian()Real-valued observationsidentity, log, inverseidentity
Gamma()Strictly positive observationsinverse, identity, loginverse
inverse.gaussian()Strictly positive observations1/mu^2, inverse, identity, log1/mu^2
TweedieDepends on the variance power; for compound claim costs, often nonnegative values including zeroPackage-specific; for example, a power link is set through link.powerPackage-specific

Tweedie is not a base R family function. One common R implementation is the tweedie package, whose tweedie(var.power = ..., link.power = ...) function returns a family object for use in glm(). Under this convention, link.power = 0 gives the log link and link.power = 1 gives the identity link. The variance power and link power are distinct choices: the former specifies the variance structure, while the latter specifies the link. Confirm the package’s documented parameter range for the model being fitted.

Key distinction: The family describes the response distribution and its variance pattern; the link specifies how the conditional mean is transformed. A plausible link cannot repair a response that does not meet the family’s requirements, and a suitable family does not guarantee that every available link will produce admissible fitted means.

Check the Response Before Writing the R Call

A reliable selection starts with the response column, not with the syntax. Identify what one row represents and what the recorded response means. In particular, distinguish a binary indicator from a count, a positive severity from a total that includes zeros, and a grouped proportion from an individual-level outcome.

  • Binomial: Individual outcomes can be coded as 0/1, or as a two-level factor. For grouped data, use a two-column response containing successes and failures. A proportion can be used with trial-count prior weights; the weights must correspond to the number of trials behind each proportion.
  • Poisson: The response represents event counts, so it should be a nonnegative integer. R can warn when a Poisson response is non-integer; such a warning is a reason to check the data and model specification, not to ignore the count interpretation.
  • Gaussian: The response can be real-valued, including negative values. The identity link is the standard choice when an additive predictor for the mean is appropriate.
  • Gamma and inverse Gaussian: These are for strictly positive responses. They are not appropriate for a response column containing zero values unless the response is transformed or a different model is chosen for a well-justified reason.
  • Tweedie: The response requirement depends on its variance power. For a compound Poisson–Gamma model with variance power between 1 and 2, the response is nonnegative and may include zero, making it useful for outcomes with a point mass at zero and positive continuous values.

Links, Inverse Links, and Mean Ranges

The link must be defined for the mean values under consideration. Its inverse, \(g^{-1}\), maps the linear predictor back to the response scale: \(\mu_i=g^{-1}(\eta_i)\). This gives a direct way to check a candidate link: ask whether every predictor value the model can produce maps to a permissible conditional mean.

$$ \eta_i = g(\mu_i) \qquad\Longleftrightarrow\qquad \mu_i = g^{-1}(\eta_i) $$

For a binomial response, the mean is a probability, so it must lie between 0 and 1. The logit link maps any real predictor to a probability strictly between 0 and 1. By contrast, the binomial log link maps \(\eta\) to \(\exp(\eta)\), which exceeds 1 whenever \(\eta>0\). Although R lists log as an available binomial link, it does not automatically keep all fitted means in the probability range. Similarly, identity links for binomial or Poisson models can yield means outside the appropriate range if the predictor is unconstrained.

For a positive response family, a log link has a useful range property: \(\exp(\eta)>0\) for every real \(\eta\). That does not make it universally preferable; the distributional assumptions and the intended mean relationship still matter. Available link names are software options, not a guarantee that a model will be statistically appropriate or numerically successful.

Justification: A valid conditional mean must be a possible expectation under the chosen response distribution. Since the linear predictor can, in principle, take any real value, the inverse link determines whether the model maps that predictor to a permissible mean. For binomial-logit, \(g(\mu)=\log\{\mu/(1-\mu)\}\). Solving for \(\mu\) gives \(\mu=\exp(\eta)/\{1+\exp(\eta)\}\). The numerator is positive and the denominator exceeds the numerator, so \(0<\mu<1\) for every real \(\eta\). This is why the logit link respects the binomial mean range without separately constraining the linear predictor.

Worked Family and Link Selections

Worked Example: Grouped Binary Outcomes

A hypothetical insurer groups policies by a risk category. In one group, 18 of 120 policies had a specified event during the observation period; in another, 9 of 75 did. The intended response is the event probability for a policy. Specify an R response format and a standard link, and check the response calculations.

Method. These are grouped Bernoulli trials, so use a binomial family. The first group has 18 successes and \(120-18=102\) failures. Its observed event proportion is \(18/120=0.15\). The second has 9 successes and \(75-9=66\) failures, giving \(9/75=0.12\).

The two-column response should therefore contain rows (18, 102) and (9, 66), where the first column is successes and the second is failures. A suitable model call is glm(cbind(event, non_event) ~ risk_category, family = binomial(link = "logit"), data = groups). The trial totals are 120 and 75, respectively, and are represented by the two column sums.

The logit link is appropriate for a probability mean because its inverse always lies between 0 and 1. As a check on the encoding, the row sums must equal the trial totals: \(18+102=120\) and \(9+66=75\). The proportions also reproduce the stated values. This avoids a common error: entering 18 and 9 as if they were individual binary responses, when they are success counts from groups of different sizes.

Worked Example: Selecting a Family for Event Counts

A hypothetical maintenance study records the number of equipment failures for each of four sites over the same fixed observation period: 0, 2, 1, and 5. The target is the expected number of failures per site, and no exposure adjustment is needed because all periods are equal. Select a base R family and link, then verify the response summary.

Method. These values are counts, all are nonnegative integers, and a zero is a valid count. A Poisson family with a log link is a standard starting specification: glm(failures ~ site_type, family = poisson(link = "log"), data = sites).

The total count is \(0+2+1+5=8\), so the sample mean is \(8/4=2\) failures per site. The observed minimum is 0 and maximum is 5; each value meets the nonnegative-integer requirement. With a log link, \(\mu=\exp(\eta)\), which is positive for every real \(\eta\), as required for a Poisson mean.

This call selects a family and link; it does not by itself establish that the Poisson assumptions fit the application. The response check confirms only that the observed values have the right count form. A common mistake is to choose Gaussian merely because the counts can be averaged. The fact that the sample mean is 2 does not make the row-level response continuous.

Worked Example: Positive Costs Versus Costs With Zeros

A hypothetical portfolio file contains payment amounts in dollars for five claims: 80, 120, 200, 160, and 40. A second file contains total costs for five exposure units, including units with no claim: 0, 80, 0, 120, and 200. Choose a family and link for each response, and check whether the same family can be used for both without changing the response definition.

Positive claim payments. All five claim amounts are strictly positive, so a Gamma model is a possible choice. A log link gives positive fitted means: glm(payment ~ risk_group, family = Gamma(link = "log"), data = claims). The total is \(80+120+200+160+40=600\), and the mean is \(600/5=120\) dollars. The minimum is 40 dollars, so there are no zero or negative responses.

Total costs including zero. The second response contains two zeros. A Gamma response requirement is therefore violated; changing only the link does not solve that issue. If the intended model is a compound Poisson–Gamma mean model, one possible specification is a Tweedie family with variance power 1.5 and log link, using the tweedie package: glm(total_cost ~ risk_group, family = tweedie::tweedie(var.power = 1.5, link.power = 0), data = units).

For the total-cost response, the sum is \(0+80+0+120+200=400\), giving a mean of \(400/5=80\) dollars. The minimum is zero and the maximum is 200. Those values are nonnegative, which is compatible with the stated compound Poisson–Gamma use of Tweedie. This check does not prove the Tweedie variance power is correct; it confirms why a positive-only Gamma family cannot be applied unchanged to this response. The common mistake is to discard zero-cost units merely to make Gamma fitting possible, thereby changing the population being modeled.

Common R Selection Traps

A family-and-link call can be syntactically valid yet encode the wrong problem. Before fitting, check both the response column and the mean-scale implications of the link.

  • Using the wrong binomial response format. A proportion alone does not record how many trials produced it. Use success/failure counts, or provide the trial totals as appropriate prior weights.
  • Treating all numeric responses as continuous. Counts remain count responses even when an average is meaningful. Conversely, a factor label is not a numeric response just because it has been assigned integer codes.
  • Assuming an available link guarantees legal means. For instance, identity can predict negative Poisson means, and the binomial log link can predict values above 1. Check \(g^{-1}(\eta)\) against the family’s mean range.
  • Using Gamma for zero values. Gamma responses must be strictly positive. A link change does not alter this response requirement.
  • Calling Tweedie as if it were a base R family. Specify the package function and its variance power and link power. Do not confuse link.power with var.power.
  • Leaving defaults implicit when the choice matters. Defaults are convenient, but explicit link arguments make the model specification auditable and reduce ambiguity when comparing candidate models.
Key takeaway: Choose the family from the response’s distributional form and support, then choose a link whose inverse maps the linear predictor to permissible means. Confirm the R response encoding and state any package-specific Tweedie parameters explicitly. These selection checks are aligned with the SOA Exam PA (Predictive Analytics) syllabus.

Check Your Understanding

For each case, select a family and link, identify the response-format check that matters, and compare your conclusion with the answer.

  1. A study records one binary result per person as 0 or 1 and models the probability of a positive result. Which base R family and link are a standard choice? (Answer: binomial(link = "logit"); confirm each response is 0 or 1.)
  2. A hypothetical call center records calls requiring escalation for four equal-length shifts: 1, 0, 3, and 2. Find the response mean and give a standard family and link. (Answer: The mean is \((1+0+3+2)/4=1.5\); use poisson(link = "log") as a standard count-model specification.)
  3. A model uses a binomial response with the log link and a fitted linear predictor \(\eta=0.2\). Calculate the implied mean and determine whether it is a valid probability. (Answer: \(\exp(0.2)\approx1.2214\), which is greater than 1 and is not a valid probability.)
  4. A hypothetical severity file contains 35, 70, and 95 dollars, with no zero amounts. State a suitable family and link, and verify the response mean. (Answer: A possible choice is Gamma(link = "log"); the mean is \((35+70+95)/3=200/3\approx66.67\) dollars.)
  5. A cost outcome takes values 0, 25, 0, and 75 dollars. The analyst proposes Gamma with a log link. Identify the problem and give a possible alternative specification for a compound Poisson–Gamma response. (Answer: Gamma requires strictly positive responses, so the zeros violate its response requirement; a possible alternative is tweedie::tweedie(var.power = 1.5, link.power = 0), subject to checking whether that variance power is suitable.)
Clinical Biostats