Binary categories
Switch a group adjustment on or off. A dummy variable is 0 for the reference group and 1 for the other group:
is the prediction; is the reference prediction; is the other group’s adjustment. Hats mark estimates fitted from data.
Substitute first:
Invented example: . Predictions are and ; the gap is 15.
With other predictors included, compare groups at the same input values. This constant gap assumes no interaction involving the group.
Multiple categories
One baseline; switches. is the number of categories. For nonreference category , set when the observation belongs to it and 0 otherwise:
is the prediction; is the fitted baseline; is category ‘s fitted adjustment. All switches are 0 for the reference.
For two nonreference categories , the prediction difference is .
Invented example: baseline 20, adjustments 5 and . Predictions: , , . The last two differ by .
All switches would sum to the intercept column of ones, making the weights inseparable. Changing the reference changes coefficient meanings, but preserves predictions.
Quantitative interactions
Product = a new feature
For numerical inputs , calculate and give that column its own coefficient:
is the prediction. The fitted coefficients are intercept , main-input multipliers , and product multiplier .
Collect every term multiplying the input you change
Hold the other input fixed. One extra input unit changes the prediction by its slope:
is the slope at ; is the slope at . The interaction makes those slopes change.
Slide coefficients, invented input: TV coefficient 0.0191, product coefficient 0.0011, assumed radio input 20. TV’s slope is .
Hierarchy principle: keep and when including , even if their individual tests are not significant.
Coefficient / standard error / t
| Readout | Meaning |
|---|---|
| Coefficient | The fitted multiplier. |
| Standard error (SE) | Estimated sample-to-sample variation in that multiplier. |
| t-statistic | Gap from the tested value, measured in standard errors. |
To test the true interaction coefficient :
Under the module’s approximate two-sided rule, reject zero when ; otherwise fail to reject, including at .
The interaction slide reports coefficient 0.0011 and . Since , reject zero under the model’s assumptions. Its displayed SE of 0.000 is rounded, not exactly zero; printed values need not reproduce the reported t. Statistical evidence alone proves neither causation nor better test predictions.
Exact t-tests
For an exact test under independent mean-zero normal errors of constant variance and linearly independent design columns, compare with a t-distribution having degrees of freedom. Here counts observations and counts input columns excluding the intercept; this interaction model has .
Category interactions
The switch can add an intercept and a slope. Let be a numerical input, and for the reference group or for the other group:
is the prediction. are the fitted reference intercept and slope. adds to the other group’s intercept; adds to its slope.
Substitute and before reading the lines:
At the same , other-group prediction minus reference prediction is
The lines are parallel when .
Invented example: . The lines are and . At , predictions are 28 and 50; the gap rule gives .
Polynomial features
Calculate powers first; fit their weights second. For numerical input , use columns :
is the prediction; is the fitted intercept; multiplies power . Degree is the largest power. The coefficients still multiply known columns and add: this is linear regression.
Invented example: for at , the row becomes . Prediction: .
Count the columns actually present. counts input columns excluding the intercept. A full cubic uses : . The specified model uses : and two fitted coefficients, and .
Training and test RSS
Circle TRAIN or TEST first. Training chooses the weights; test data checks those weights without refitting.
RSS is the total squared prediction error:
counts observations, is actual output , and is its prediction. Subtract, square, then add. Compare models on the same observations.
The cubic can copy the line
For ordinary least-squares fits with intercepts on the same training data, zeroing the cubic’s squared and cubed coefficients makes it a line. Therefore
This holds whatever generated the data; equality is possible.
| True relationship | Test comparison |
|---|---|
| Linear | Expect the line to do better; individual datasets can differ. |
| Nonlinear, amount unknown | Not enough information to choose. |
Training improvement gives no test guarantee: extra terms may learn real curvature or training noise.
Transformed least squares
Rename the column, reuse the line formula
To fit , calculate . Here are supplied input and output for observation ; is its prediction; is the weight and the intercept to fit.
The model becomes . For observations, calculate means:
Then calculate how the columns move together, , and the input spread, :
For , the least-squares coefficients are
If , every new input is identical and the slope cannot be uniquely identified.
Q6 shortcut: two distinct inputs
The supplied pairs become in coordinates.
At , the output mean is 0, so . At , the output mean is , so and . The fitted line hits both group averages, minimizing squared error.
Q6 through the general formula
With , the means are and .
Subtracting gives centered inputs and centered outputs .
Thus and .
Check: predicts at original inputs . Subtract those predictions from supplied outputs :
The general formula works for any specified new column , where is the rule for calculating it.