From a Linear Predictor to a Fitted Mean
A fitted generalized linear model does not usually predict the response by applying its coefficients directly on the response scale. Instead, the model first forms a linear predictor from the coefficients and predictor values, then applies the inverse link to obtain the conditional mean. In R, predict.glm() can return either of these quantities. Knowing which scale is being returned is essential: the linear predictor is generally not itself a probability, an event count, or a claim severity.
For a fitted model and a specified set of predictor values, use predict(fit, newdata = ..., type = "link") to request the linear predictor. Use predict(fit, newdata = ..., type = "response") to request the fitted mean on the response scale. For a binomial model, this response-scale value is a fitted probability or proportion. For a Poisson or Gamma model, it is a fitted conditional mean on the scale of the response.
The linear predictor is assembled from the fitted coefficients and the predictor values. For example, with an intercept and one numeric predictor, \(\widehat{\eta}=\widehat{\beta}_0+\widehat{\beta}_1x\). A model with more predictors includes the corresponding fitted terms. The calculation must use the same coding and predictor structure as the fitted model; the examples below use deliberately simple numeric predictors to make the scale conversion visible.
Why the Inverse Link Gives the Fitted Mean
A GLM specifies the conditional mean through the link equation \(g(\mu)=\eta\). Since the link is invertible over the relevant range, applying its inverse to both sides gives \(\mu=g^{-1}(\eta)\). Replacing the unknown model quantities with their fitted values gives the fitted-mean calculation:
This is not an extra correction applied after prediction; it is how the model defines the mean. The inverse link depends on the chosen family and link. In particular, a logistic model uses the inverse-logit function, while a log-link model uses the exponential function. A different link requires its own inverse, so do not assume that every GLM prediction should be exponentiated.
Supply predictor values in
newdata using the variable names and compatible forms used to fit the model.Use
type = "link" to inspect \(\widehat{\eta}\), or type = "response" to obtain the fitted conditional mean.Apply the inverse of the model’s link to the link-scale prediction and compare with the response-scale result.
State whether the value is a probability, an expected count, or a mean on another response scale. For grouped binomial data, distinguish the fitted probability from the expected number of successes.
Logistic GLMs: Fitted Probabilities
For a binomial GLM with the logit link, the linear predictor is the log odds of success. The inverse link converts it to a probability between zero and one:
Here \(p\) is the conditional probability of success at the specified predictor values. If each observation represents multiple trials, the fitted mean on the response scale is still the success probability (or proportion), not the expected number of successes. For \(m\) trials with the same fitted probability, the expected number of successes is \(mp\).
Worked Example: A Grouped Binomial Prediction
A hypothetical insurer models whether a small commercial property has a specified type of equipment failure during the coming year. Conditional on the predictors, let the outcome be binomial with \(m=20\) trials and success probability \(p\). The fitted logistic GLM has \(\widehat{\eta}=0.20-0.50x\). At \(x=1\), calculate the link-scale prediction, fitted probability, and expected number of successes. Use the binomial distribution with \(m=20\) and fitted probability as stated; no additional exposure or mortality assumption is involved.
Method. First calculate the linear predictor, then apply the inverse-logit. Finally multiply the unrounded fitted probability by the number of trials.
Link scale. Substituting \(x=1\) gives \(\widehat{\eta}=0.20-0.50(1)=-0.3000\).
Response scale. The fitted probability is \(\widehat{p}=1/(1+\exp(-(-0.3)))=1/(1+\exp(0.3))\). Since \(\exp(0.3)\approx1.349858808\), this gives \(\widehat{p}\approx1/2.349858808\approx0.425557484\), or \(0.4256\) to four decimals.
Expected successes. Using the unrounded probability, \(E[Y\mid x=1]=20\widehat{p}=20(0.425557484)\approx8.51114968\), or \(8.5111\) to four decimals. The result is between zero and 20, as required for an expected success count.
In R, requesting type = "link" returns \(-0.3\), while requesting type = "response" returns approximately \(0.4255575\). For grouped binomial data, multiply the response-scale probability by 20 to obtain the expected count; do not mistake the returned probability for that count.
Poisson GLMs: Fitted Event-Count Means
For a Poisson GLM with the log link, the conditional response distribution is \(Y\mid\mathbf{x}\sim\operatorname{Poisson}(\mu)\), and its mean and variance are both \(\mu\). The link equation is \(\log(\mu)=\eta\), so the inverse-link calculation is \(\mu=\exp(\eta)\). Thus the response-scale prediction is a nonnegative fitted mean count, which need not be an integer.
Worked Example: Predicting a Poisson Event Mean
Suppose a hypothetical model describes the number of equipment breakdowns reported by a workshop during a fixed one-year observation period. Conditional on the predictor, the count is Poisson with mean \(\mu\). A fitted log-link model is \(\widehat{\eta}=0.10+0.25x\). At \(x=2\), find the link-scale and response-scale predictions. No offset is included, so the prediction refers to the stated one-year period.
Method. Evaluate the linear predictor and exponentiate it because the inverse of the log link is the exponential function.
The link-scale value is \(\widehat{\eta}=0.10+0.25(2)=0.10+0.50=0.6000\). Therefore, \(\widehat{\mu}=\exp(0.6)\approx1.822118800\), or \(1.8221\) to four decimals.
The model predicts a conditional mean of about 1.8221 breakdowns in the specified year for cases with \(x=2\). It does not predict that an individual workshop will experience a fractional breakdown; a realized Poisson count is an integer. The fractional value is the mean over the model’s conditional distribution.
In R, type = "link" returns \(0.6\), and type = "response" returns approximately \(1.822119\). Checking that \(\log(1.822118800)\approx0.6\) verifies the conversion.
Gamma GLMs: Fitted Positive-Outcome Means
A Gamma GLM is often used for a positive, right-skewed response. With the log link, \(g(\mu)=\log(\mu)\), so the fitted mean is again the exponential of the linear predictor. The response-scale value is a mean on the original response scale, not a fitted dispersion or an individual observed outcome. For a Gamma model parameterized with dispersion \(\phi\), the conditional variance is \(\operatorname{Var}(Y\mid\mathbf{x})=\phi\mu^2\); the dispersion affects the variance, but the inverse-link calculation for the mean remains \(\exp(\eta)\).
Worked Example: Predicting Mean Claim Severity With a Gamma GLM
Consider a hypothetical model for positive claim severity, measured in thousands of dollars. Conditional on the predictors, severity has a Gamma distribution with mean \(\mu\) and dispersion \(\phi=0.25\), so its variance is \(0.25\mu^2\). A fitted Gamma GLM uses the log link and has \(\widehat{\eta}=-0.10+0.20x\). Calculate the fitted mean at \(x=3\), first in thousands of dollars and then in dollars.
Method. Use the fitted coefficients to calculate \(\widehat{\eta}\), then apply the inverse log link. The Gamma dispersion is stated to describe the distribution, but it is not needed to convert the predictor to the fitted mean.
The link-scale prediction is \(\widehat{\eta}=-0.10+0.20(3)=-0.10+0.60=0.5000\). Therefore, the fitted mean is \(\widehat{\mu}=\exp(0.5)\approx1.648721271\) thousand dollars, or \(1.6487\) thousand dollars to four decimals.
Converting the unrounded mean to dollars gives \(1.648721271(1000)=\$1,648.721271\), which is \(\$1,648.72\) to the nearest cent. As a check, \(\log(1.648721271)\approx0.5\), and the fitted mean is positive, consistent with the Gamma response. The dispersion would imply conditional variance \(0.25(1.648721271)^2\) in squared thousands of dollars; it does not change this mean prediction.
In R, type = "link" returns \(0.5\), and type = "response" returns approximately \(1.648721\) in the response units, thousands of dollars. The model’s response units must be retained when reporting its prediction.
Common Mistakes and Checks
A common exam error is to report a link-scale prediction as if it were a mean. For example, a Poisson log-link prediction of \(0.6\) is not a mean count of \(0.6\); its fitted mean is \(\exp(0.6)\approx1.8221\). Similarly, a logistic link-scale prediction of \(-0.3\) is not a negative probability; its fitted probability is about \(0.4256\). The correct conversion depends on the link, not merely on the response family’s name.
Another error is to round an intermediate probability and then use that rounded value in a further calculation. In the grouped-binomial example, multiplying the displayed four-decimal probability by 20 gives \(20(0.4256)=8.5120\). That is the product of a rounded display value, not the correctly rounded fitted expected count. Using the unrounded probability gives \(20/(1+\exp(0.3))\approx8.51114968\), which rounds to \(8.5111\) to four decimals. Keep full precision through the calculation and round only the final reported result.
A useful verification is to apply the link to a response-scale prediction and check that it reproduces the link-scale prediction, subject to numerical rounding. For example, check \(\log(\widehat{\mu})\approx\widehat{\eta}\) for a log-link model, or \(\log(\widehat{p}/(1-\widehat{p}))\approx\widehat{\eta}\) for a logistic model. This check can expose a sign error or an incorrect inverse link.
predict.glm() returns a quantity on the requested scale. Identify the link, calculate \(\widehat{\eta}\), and use its inverse to obtain \(\widehat{\mu}\). Interpret the response-scale result in the model’s units, and use unrounded values for any subsequent calculation.
Check Your Understanding
For each problem, identify the link-scale quantity and convert it to the requested response-scale prediction. Round probabilities and means to four decimals unless another unit is specified.
- A hypothetical logistic model for a binary equipment inspection result has \(\widehat{\eta}=-0.20+0.40x\). At \(x=2\), calculate the fitted probability of a positive result. (Answer: \(\widehat{\eta}=0.6000\), \(\widehat{p}=0.6457\).)
- A Poisson log-link model for the number of service calls in a fixed month has \(\widehat{\eta}=-0.30+0.20x\). At \(x=4\), calculate the fitted mean number of calls. (Answer: \(\widehat{\eta}=0.5000\), \(\widehat{\mu}=\exp(0.5)=1.6487\) calls.)
- A Gamma GLM for positive repair cost, measured in thousands of dollars, uses the inverse link \(g(\mu)=1/\mu\). Its fitted predictor is \(\widehat{\eta}=0.25+0.10x\). At \(x=5\), calculate the response-scale mean. (Answer: \(\widehat{\eta}=0.7500\), \(\widehat{\mu}=1/0.75=1.3333\) thousand dollars.)
- A grouped-binomial model has \(\widehat{\eta}=0.20-0.50x\). At \(x=1\), the group has 20 trials. Calculate the fitted probability and expected success count, using the unrounded probability for the count. (Answer: \(\widehat{\eta}=-0.3000\), \(\widehat{p}=0.4256\), expected successes \(=20/(1+\exp(0.3))\approx8.5111\).)
- A Poisson model with a log link gives \(\widehat{\eta}=0.40\) for a specified case. A colleague reports \(0.40\) as the fitted mean count. State the correct response-scale mean and the error. (Answer: \(\widehat{\mu}=\exp(0.40)\approx1.4918\); \(0.40\) is the link-scale prediction, not the fitted mean count.)