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):
CategoryInd2Ind3Ind4Reading
North (baseline)000intercept only
East100intercept
South010intercept
West001intercept

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*b expands to a + b + a:b).

βš–οΈ Core Decision Matrix

TransformationTrigger conditionNew columns addedWhat the coefficient meansCost
Indicatorspredictor is categorical with levelsshift vs the baseline category parameters for one variable
Logspread of grows with ; all (replaces the column)effect per unit of βž” multiplicative in undefined at
Polynomial degree residual-vs- plot bendscurvature, read off the sign of the top termoverfits fast as grows
Interaction effect of believed to depend on per pairhow 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