Predictor Transformations (Indicators, Polynomials, Interactions)
Context: FIT2086_MOC Β· how a model that is linear in the coefficients still fits categories, curves and conditional effects β by rewriting the columns, never the fitting machinery of Linear Regression (FIT2086) Β· more columns βΉ more complexity to police β Model Selection and Information Criteria (AIC, BIC)
Quick Revision
- π― Objective: detect the shortfall (a category, a curved residual plot, a conditional effect) β add the right new columns to the design matrix β re-fit by ordinary least squares.
- π¦ Core Components: categories β indicators | curvature β or | conditional effect β the product .
- β‘ Key Constraint: βlinearβ means linear in , not in β so every transformation below leaves the model a linear regression, and every one of them buys flexibility at the price of overfitting risk.
π How It Works
1. Categorical Predictors β Indicator Variables
- Why not use the codes β a category coded is a label, not a quantity; adding or multiplying it is meaningless and would force an arbitrary equal-spacing.
- Construction β categories become indicator (dummy) columns, each when the individual is in that category and otherwise.
- The dropped category is the baseline β no indicator is built for the first category; every other coefficient is the increase in the target relative to that baseline.
- Coding table β for a 4-level variable (North/East/South/West):
| Category | Ind2 | Ind3 | Ind4 | Reading |
|---|---|---|---|---|
| North (baseline) | 0 | 0 | 0 | intercept only |
| East | 1 | 0 | 0 | intercept |
| South | 0 | 1 | 0 | intercept |
| West | 0 | 0 | 1 | intercept |
2. Nonlinear Effects β Transform the Predictor
- Diagnostic β plot residuals against a predictor; a curve or trend means a transformation is needed (a linear fit cannot leave linear-in- structure behind, so a visible bend is genuinely nonlinear).
- Log transform β ; use when the predictor is more variable at larger values. Requires all .
- Polynomial expansion β β a general-purpose nonlinear fit; higher = more flexibility and more overfitting risk.
- Payoff on the lecture data β gives but curved residuals; gives .
- Reading a quadratic β the sign of the coefficient carries the shape: positive βΉ initially decreasing then increasing returns (a ), negative βΉ diminishing returns (a ).
3. Interactions β Multiply Two Predictors
- The claim being modelled β the effect of predictor on the target depends on the value of predictor .
- Construction β append one new design-matrix column equal to ; fit as usual.
- Reading the sign β with both main effects negative, a positive interaction means their combined negative effect is weakened when both rise together.
- Practical note β most packages build interaction columns for you (in R,
y ~ a*bexpands toa + b + a:b).
βοΈ Core Decision Matrix
| Transformation | Trigger condition | New columns added | What the coefficient means | Cost |
|---|---|---|---|---|
| Indicators | predictor is categorical with levels | shift vs the baseline category | parameters for one variable | |
| Log | spread of grows with ; all | (replaces the column) | effect per unit of β multiplicative in | undefined at |
| Polynomial degree | residual-vs- plot bends | curvature, read off the sign of the top term | overfits fast as grows | |
| Interaction | effect of believed to depend on | per pair | how the effect of changes per unit of | pairs explode combinatorially |
When It Flips: a transformation keeps the column count flat and is the cheap first move; a polynomial expansion buys arbitrary curvature but is the point at which an information criterion must decide β will keep rising to and beyond.
π Exam Execution Trace & Applied Exercises
Applied Exercise
Problem: Cooling load is fitted with orientation coded by indicators Orient2 (East), Orient3 (South), Orient4 (West), baseline North:
.
Predict for compactness , surface , wall , height , orientation East, window proportion .
Final Extracted Output: . Only the East indicator fires; South and West contribute exactly zero, and North would have zeroed all three.
Applied Exercise 2
Problem: Internet sales on website hits (β000): intercept ; hits (); hits (). Characterise the nonlinearity and judge the model. Final Extracted Output: β a shape: returns to hits are initially decreasing, then increasing. The quadratic term is highly significant, so the evidence for nonlinearity is strong; the linear term is only marginally insignificant at the level, so the model is moderately reasonable and the curvature is the real finding.
β οΈ Common Mistakes
- π‘ Building indicators instead of β the full set is perfectly collinear with the intercept βΉ the LS solution stops being unique; the omitted level is the baseline.
- π‘ Reading an indicator coefficient as an absolute level β is East relative to North, not Eastβs predicted value.
- π‘ Treating a coded category as a number β regressing on the raw codes silently asserts that βSouth East East Northβ.
- π‘ Chasing with polynomial degree β rises monotonically in ; a degree- fit will look best and generalise worst.
π§ Active Recall
A polynomial regression fits a curve. In what sense is it still a linear model?
- Hint: Linear in what?
Answer
- Short answer: Linear in the coefficients β are just extra columns, and the model is still with a fixed function of the data.
- Why: Least squares is untouched β the same stationary equations and the same solve it; only the design matrix changed.
Why is a categorical predictor with levels given only indicators, and what does the intercept then mean?
Answer
- Short answer: The -th indicator is redundant β the baseline is identified by all others being β and including it makes the design collinear with the intercept. The intercept then holds the baseline categoryβs predicted value (with the other predictors at zero).
- Why: Relative coding β each is the shift from the omitted level, so changing the baseline changes every indicator coefficient but not a single prediction.