188. Multiple Linear Regression

Causal vs. extrapolative. Time-series methods (SMA, ETS, ARIMA) build a forecast from the demand series alone — extracting level, trend, and seasonality from 𝑥1,,𝑥𝑡. Causal models flip the framing: demand is driven by exogenous regressors (price, weather, promotions, demographics, day-of-week, …) and we fit a relationship between them.
𝑌𝑖=𝛽0+𝛽1𝑥1,𝑖++𝛽𝑘𝑥𝑘,𝑖+𝜀𝑖,𝜀𝑖iid𝒩︀(0,𝜎2)

188.0.1. Why “least squares”?

Three candidate loss functions for the residuals 𝑒𝑖=𝑦𝑖𝑦̂𝑖:

LossWhat it capturesVerdict
𝑖𝑒𝑖Bias onlyPositive and negative errors cancel — useless for accuracy
𝑖|𝑒𝑖|Bias + accuracyNo closed-form minimiser — intractable analytically (OK numerically)
𝑖𝑒𝑖2Bias + accuracy + smoothClosed form via calculus

OLS picks 𝑏̂ to minimise the Residual Sum of Squares:

RSS(𝑏0,,𝑏𝑘)=𝑖=1𝑛(𝑦𝑖𝑏0𝑏1𝑥1,𝑖𝑏𝑘𝑥𝑘,𝑖)2

For the univariate case (𝑘=1), setting first-order conditions to zero gives a clean closed form:

𝑏̂1=𝑖=1𝑛(𝑥𝑖𝑥̄)(𝑦𝑖𝑦̄)𝑖=1𝑛(𝑥𝑖𝑥̄)2,𝑏̂0=𝑦̄𝑏̂1𝑥̄

For the multivariate case, the same exercise in matrix form yields the normal equations:

𝑏̂=(𝑋𝑇𝑋)1𝑋𝑇𝑦

where 𝑋 is the 𝑛×(𝑘+1) design matrix (a column of ones for the intercept, plus one column per regressor).

188.0.2. Goodness of fit (𝑅2)

Total variation in 𝑦 around its mean splits cleanly into the part the model explains and the part it leaves behind:

𝑖=1𝑛(𝑦𝑖𝑦̄)2TSS (total)=𝑖=1𝑛(𝑦̂𝑖𝑦̄)2RSS (regression)+𝑖=1𝑛(𝑦𝑖𝑦̂𝑖)2ESS (residual)

The coefficient of determination is the fraction of variation the model explains:

𝑅2=RSSTSS=1ESSTSS[0,1]

Cautions on 𝑅2:

  • 𝑅2 never decreases when you add a regressor → use adjusted 𝑅2=1(1𝑅2)𝑛1𝑛𝑘1 when comparing models of different sizes.
  • High 𝑅2 does not imply causality — only that variation co-moves.
  • Each coefficient still needs its own t-test / confidence interval; the F-test on 𝑅2 only says “some coefficient is non-zero”.
Example

Trend + summer dummy on monthly demand (20 months, Jan year 1 — Aug year 2).

Model — level, linear trend, and a summer indicator:

𝐹𝑖=𝛽0+𝛽1Period𝑖+𝛽2Summer𝑖,𝑖=1,,20

where Period𝑖{1,,20} is a linear time index and Summer𝑖{0,1} flags May–Aug.

Data

Mo.𝑦𝑡𝑆Mo.𝑦𝑡𝑆
Jan3 02510Nov3 499110
Feb3 04720Dec3 598120
Mar3 07930Jan3 596130
Apr3 13640Feb3 721140
May3 45451Mar3 745150
Jun3 66161Apr3 650160
Jul3 55471May4 157171
Aug3 69281Jun4 221181
Sep3 40790Jul4 238191
Oct3 410100Aug4 008201

Fit (e.g. numpy.linalg.lstsq, statsmodels.OLS, or Excel’s regression tool):

𝐹̂𝑖=2969.14+48.03Period𝑖+303.51Summer𝑖

Diagnostics

  • 𝑅2=0.958, adj. 𝑅2=0.953, residual standard error 79.21
  • All three coefficients have 𝑝<0.001 (t-stats: intercept 79.8, period 15.0, summer 8.05)

Interpretation

  • Intercept (2969): baseline demand at Period=0 in a non-summer month
  • Period (48): underlying trend adds 48 units per month
  • Summer (304): summer months run 304 units above the trend, holding period fixed

Forecast next month (Sep, 𝑖=21, 𝑆=0):

𝐹̂21=2969.14+48.03(21)+303.51(0)=3977.77

188.0.3. When to reach for OLS

Strengths:

Limitations: