Lecture 4 of 15
Forecasts that survive a chronological comparison
Has the model improved a decision on targets it had not seen?
Prerequisites: Lectures 1–3, conditional variance, and least squares.
Unzip the bundle, open its code folder, and run ch04 in Python, R, or Julia; the entry point loads the course file and data beside it.
Fitting and forecasting answer different questions
A regression’s fitted values use coefficients estimated from its training sample. Their residuals describe how that fitted model represents observations it has already seen. A forecast uses a model constructed before its target is observed. Its errors describe performance on subsequent targets. A small training residual sum of squares can coexist with poor forecasting.
Begin with a historical sequence and a forecast origin . The training window ends at that origin, or at the latest earlier observation available under the release rule. Fit the model using only that window, issue a forecast for , and retain the prediction. Move the origin forward and repeat. This is rolling-origin evaluation. An expanding window starts at a fixed initial date; a rolling window retains a fixed number of recent observations.
An honest comparison holds the target periods, information rule, and loss fixed across methods. If one model is evaluated only on easy months and another on every month, their average losses are not comparable. If a model cannot produce a forecast at an origin, record that failure and apply a declared fallback rule. Do not silently drop the difficult target.
The comparison should reflect the intended deployment. Refitting at every origin evaluates a repeatedly updated procedure. Fitting once and holding coefficients fixed evaluates a different procedure. Both are legitimate designs if their interpretation is explicit.
The algorithm is part of the statistical model
For an estimated AR(1), the procedure at each origin solves
then iterates the estimated recursion steps. contains admissible target-regressor pairs from that origin’s training window. A lagged outcome requires both rows to be available; missing periods must not turn adjacent rows into a false one-period lag.
The executable implementation uses QR-based least squares. Solving the normal equations by explicitly inverting is unnecessary and can amplify numerical problems. Rank checks detect a design with redundant columns or insufficient observations. This is a computational condition; rank sufficiency does not establish exogeneity, stationarity, or stability. Whether the estimated and approach their population values as the training window grows is a statistical question, and the answer rests on stability together with the ergodicity and innovation conditions stated in Lecture 2.
Preprocessing also belongs inside the origin loop. Estimate a mean, standard deviation, imputation rule, seasonal adjustment, or principal component from training data. Apply the retained transformation to the admissible prediction inputs. A full-sample transformation can carry information from the test period into every historical forecast even when the regression itself is refitted correctly.
Tuning requires another boundary. Use an earlier validation segment to choose lag order or window length, then evaluate the chosen procedure on later targets. Repeatedly choosing a model after observing the same test errors turns that test segment into a selection sample. Lecture 14 will freeze a complete procedure before a continuation release.
Match loss to the decision
For errors , common summaries are
Both are in outcome units. RMSE emphasizes large errors. MAE has the conditional median as its population-optimal point forecast; squared loss has the conditional mean. Percentage errors are problematic near zero and can compare series in economically misleading ways. For a scaled error, calculate its scaling denominator from the training sample and state the benchmark defining that scale.
If underprediction costs per unit and overprediction costs , define
For a continuous conditional distribution , differentiating expected loss with respect to gives . The optimum satisfies
With and , the preferred action is the conditional 75th percentile. An unbiased conditional-mean forecast can therefore be an inappropriate reserve decision. The distinction is between estimating an outcome distribution and choosing an action from that distribution.
Identify the uncertainty in an interval
For a known-parameter stable AR(1), the -step process variance is . Gaussian innovations give a conditional Gaussian forecast distribution, so an interval is .
There are several practical qualifications. Estimating parameters adds uncertainty; selecting a model adds another layer; a future covariate may need its own forecast; a geographic measure may be uncertain; and a structural break can invalidate the fitted process entirely. A normal interval computed from a residual variance addresses only the assumptions included in that calculation.
One possible approximation for a one-step regression forecast adds the coefficient-estimation term:
This formula assumes the usual homoskedastic regression conditions and treats the prediction regressors appropriately. It is not a universal ARMA multi-step interval. With dependence, a simulation or bootstrap should preserve the relevant temporal structure and repeat the actual fitting procedure. Resampling individual time rows indiscriminately destroys that structure.
Check intervals empirically. Record coverage, average width, and behavior in periods relevant to the decision. High coverage from enormous intervals can be operationally unhelpful. Narrow intervals with severe undercoverage misstate risk. For overlapping multi-step targets, successive errors are dependent, so a binomial standard error is generally inappropriate without addressing that dependence.
Compare paired errors
Let and be errors on identical targets. Analyze
A negative mean favors A for that loss and those targets. Pairing preserves the fact that both forecasts face the same difficult months. A standard error for must reflect serial dependence, including dependence from overlapping horizons and repeated estimation. A heteroskedasticity-and-autocorrelation-consistent estimate or a carefully designed block bootstrap can be suitable under its assumptions.
The ratio is the test of equal predictive accuracy proposed by Diebold and Mariano (1995), who treated the two forecast sequences as given. For -step forecasts, inherits the MA dependence of overlapping errors described in the diagnostics section below, so the HAC estimate should include at least lags. When a forecast is misspecified, as the no-change forecast is for the stationary AR(1) in this lecture’s laboratory, its errors and can be dependent beyond lag , and lags is then only a lower bound. The Bartlett weights of Newey and West (1987) keep the estimate nonnegative.
Forecasts from estimated models add a complication. West (1996) showed that parameter estimation can contribute a term to the asymptotic variance of . His results require that variance to be positive, and that requirement fails when one model nests the other, which is the case in this lecture: the no-change forecast is the AR(1) with and . Under the null of equal population accuracy, the two nested forecasts coincide in population, the loss differential degenerates, and the DM statistic does not have a standard normal limit. Clark and McCracken (2001) and McCracken (2007) derive nonstandard critical values for such comparisons. Giacomini and White (2006) pose a different null: whether two forecasting methods, each including its estimation window, have equal expected loss given the information available at the origin. With an estimation window of fixed length, their test uses normal or chi-squared critical values for nested and non-nested models alike. An expanding window lies outside that framework.
Do not turn every small numerical difference into a superiority claim. The sample may be short, the decision costs may be poorly specified, or the improvement may disappear when the release lag changes. Report the size of the improvement and what it would change operationally. An inconclusive comparison can justify retaining a transparent benchmark.
Diagnose the innovation sequence
A useful residual audit asks whether mean bias remains, whether lagged residuals predict future residuals, whether squared residuals cluster, and whether errors differ across calendar periods or geographic regimes. A Ljung–Box statistic has the form
Its approximate reference distribution depends on model fitting and degrees-of-freedom adjustments. The statistic aggregates selected residual correlations; failing to reject does not prove independence or complete model correctness. Residual diagnostics complement later-target evaluation. They cannot substitute for it.
Apply the statistic to errors that a correct model would leave unpredictable. One-step errors of a correctly specified AR(1) are its innovations. An -step error,
shares innovations with the errors issued at the preceding origins. It is an MA process, and its first autocorrelations are nonzero even when the model is exactly right. For and they are 0.709, 0.454, and 0.221. Substituting them into with the laboratory’s 237 four-step errors gives about 182, far above 15.5, the 5% critical value of a reference, although nothing is misspecified. For -step errors, either apply the diagnostic to the one-step errors of the same procedure or test only lags and beyond with a variance that allows for the MA structure.
For a correctly specified conditional-mean model, systematic residual correlation with an available predictor reveals a potential repair. The predictor must have been observable at the origin. Regressing historical forecast errors on realized future weather may explain mistakes retrospectively while supplying no feasible real-time forecasting method.
Execute a matched comparison
The lecture’s code simulates an AR(1) with coefficient 0.8 and evaluates four-step forecasts after an initial 120 observations. It refits an intercept and persistence coefficient at every origin. The naive competitor holds the latest observed value for all four steps. Both methods forecast the same targets.
The shared realization gives an AR RMSE of about 1.530 and a naive RMSE of about 1.760. The mean difference in squared loss favors the fitted AR procedure on this realization. This is a conditional teaching result, not a claim that autoregressions always dominate naive forecasts.
The code reports a Ljung–Box statistic of for the four-step errors, as the overlap predicts, and for the one-step errors of the same rolling procedure, which gives no evidence against the specification. It also reports the paired squared-loss statistic with three Bartlett lags, about . Because the comparison is nested and the window expands, comparing that value with is not justified by the results above; read it as a standardized description of the loss difference.
The code also checks a plug-in interval using the generating process variance while the point forecast uses estimated coefficients. Its label explicitly describes the known-parameter variance component. The resulting coverage is diagnostic, not an exact nominal-coverage theorem for the estimated procedure. Change the sample length and persistence to see where ignoring estimation uncertainty becomes more consequential.
Deliberately fit once using the entire series, then use those coefficients at every earlier origin. Compare the apparent performance with the chronological version. The size of the distortion will depend on the sample. Repair the procedure by moving all fitting and transformation steps inside the origin loop. Finally mutate every observation after a chosen origin and confirm that the retained earlier forecast remains unchanged.
Worked problem and assignment preparation
At an origin with 100 training observations, a model produces four forecasts. The first targets and the last targets . If your evaluation table labels them all with origin , how should you join actuals? Join the first to period , the second to , and so forth, keeping both origin and target period. One actual can be the target of forecasts issued at several different origins. Those are distinct forecasting tasks.
Suppose A has squared losses and B has on the same three targets. Their mean losses are and , so the paired mean difference is . The three differences are ; the ranking reverses on the second target. A report should show that heterogeneity, identify the decision’s important regimes, and avoid treating three observations as strong evidence of universal superiority.
For the first concept check, be prepared to derive an AR forecast, identify an inadmissible input, and interpret a loss comparison. For Project 1, retain a forecast table with an explicit origin-target relationship and an unaltered benchmark. The project is now a reproducible decision procedure, not only a fitted model.
Further reading
See Forecasting: Principles and Practice on point accuracy and residual diagnostics. Its forecasting with dynamic regression explains why future regressors also require forecasts. For paired-loss inference, read Diebold and Mariano (1995), West (1996), Clark and McCracken (2001), and Giacomini and White (2006).
Practice and laboratory for Lecture 4
- Assignment 4: Evaluation and action, three tasks with worked answers.
- Run ch04 from the laboratory bundle in Python, R, or Julia.
- Interactive experiment: A decision before its outcome
- Lecture 4 summary, with the central equation, a problem, a failure, and its repair.