Variable Transformation
Study guides: Exam SRM, Exam PCPA, Exam ACIA-CAPSTONE
A Variable Transformation replaces a predictor x with a function of it, h(x), so that its relationship with the response is captured by a model that is linear on the scale of the link. The transformed predictor enters the linear predictor as
g(\mu) = \beta_0 + \beta_1\,h(x) + \cdots
\mu = E[Y]is the mean response andgis the link.
The need for a transformation shows up in exploratory data analysis and in a residual plot against the predictor, as a curve where there should be none.
Log transformation
A log suits positive, right-skewed predictors whose effect is proportional, such as amount of insurance or building value. With a log link it is usually the natural first choice. Under a log link with h(x) = \ln x, the mean is
\mu \propto x^{\beta_1}
Doubling x multiplies the mean by 2^{\beta_1}, whatever the starting value of x.
A log-link severity GLM includes
\ln(\text)with\hat = 0.6. How does expected severity change when the amount of insurance doubles?
- Expected severity is proportional to
\text{AOI}^{0.6}.- Doubling the amount of insurance multiplies it by
2^{0.6} = 1.516, an increase of about52\%.- A
50\%increase would multiply it by1.5^{0.6} = 1.275.- Severity grows less than proportionally because
\hat{\beta} < 1. Larger properties rarely burn to the ground, so their average claim is a smaller share of the amount insured.
Binning, polynomial and hinge terms
A single linear term forces the effect to move in one direction. Binning (banding) cuts a continuous variable into groups and fits a level for each, treating it as a categorical predictor. It captures any shape, but spends a parameter per band and ignores the ordering within one. Polynomial terms (x, x^2, …) and piecewise linear (hinge) terms such as \max(0, x - c) fit a curve with a few parameters. Polynomials can behave badly at the edges of the data.
What is wrong with a single linear term for this driver-age effect, and what are the options? A frequency model's residuals show that the effect of driver age is high for young drivers, falls through middle age, and rises again after 75.
Answer
- A linear term forces the effect to move in one direction, so it cannot capture a U-shape; it will understate the risk at both ends.
- Binning age (for example
16–20,21–25, …,76+) fits a level per band. This is flexible and easy to explain, but the bands need enough exposure to be credible.- Polynomial or hinge terms, such as
\max(0, \text{age} - 75), bend the line with fewer parameters.- Choose between them on hold-out performance rather than training fit, which always favours more parameters.
Standardizing
Before a penalized fit such as ridge regression, standardizing, (x - \bar{x})/s_x, puts predictors on a common scale.
\bar{x}ands_xare the predictor's sample mean and standard deviation.
The standardized predictor has mean 0 and standard deviation 1.
Transforming the response
The response can be transformed too. When the residual spread grows with the fitted value, ISLR transforms the response with a concave function such as \ln Y or \sqrt{Y}.