Skip to content

nns_meboot: keep the residual scale when the drift changes (book ch20) - #172

Closed
gitRasheed wants to merge 2 commits into
rasheed/book-copula-anchorfrom
rasheed/book-meboot-drift
Closed

gitRasheed wants to merge 2 commits into
rasheed/book-copula-anchorfrom
rasheed/book-meboot-drift

Conversation

@gitRasheed

@gitRasheed gitRasheed commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Book ch20 builds replicates as a baseline plus resampled residuals (ch20:193-206), but three steps of nns_meboot measured the residual density against the levels. With drift=False every replicate was rescaled toward sd(x), trend included, so AirPassengers replicates kept the full sd of the trending series. We mirror OVVO-Financial/NNS#92, which makes R follow the book, including its round-2 corrections. That PR changes the method, so the R author may close it; if so, this slice should be dropped too.

Stacked on #171; merge with a merge commit.

Changes

  • expand_sd runs only when the original slope is kept.
  • With a changed drift, force_clt centres and spreads the replicate means on the new baseline plus the original residuals instead of on x.
  • scl_adjustment takes kappa from the residuals' mean and sd and scales the residuals before the baseline is added.
  • A changed slope (drift=False, target_drift, target_drift_scale) pivots about mean(x): mean(x) + slope * (t - (n + 1) / 2).

AirPassengers, reps = 100, rho = 1, seed 1, mean over replicates: drift=False sd goes from 122.89 to 47.31, target_drift=1 from 122.89 to 62.82, and scl_adjustment=True from 51.55 to 122.00. The default drift=True path is unchanged (sd 122.05), and the replicate mean stays 280.30 in every case.

Tests

New parity tests and NNS.meboot cache entries for the changed-drift and scl_adjustment cases; the stat-summary R helper takes drift and target_drift. The parity cache encodes R 13.3 plus the fixes in OVVO-Financial/NNS#73-#92. The nine NNS.VAR strict xfails stay until #174.

Mirrors OVVO-Financial/NNS#92

Review

GPT-6.1 Sol reviewed this slice and raised one finding, which we took: the new tests still passed with the old force.clt reference and without the scale adjustment. New tests pin the spread of the replicate means (0.0706 expected; the old reference gives 0.270) and check that kappa scales the residuals, not the levels. Each fails on its mutant. The fix commit has not been re-reviewed.

Mirrors R's meboot-drift branch (NNS.meboot), including the round-2
corrections. Replicates are a baseline plus resampled residuals (book
ch. 20), but three steps measured the residual density against the
levels:
- expand_sd rescaled every replicate toward sd(x), which includes the
  original trend. It now runs only when the original slope is kept.
- force_clt centred and spread the replicate means on x. With a changed
  drift it now uses the new baseline plus the original residuals.
- scl_adjustment compared the residual density with mean(x) and sd(x)
  and scaled the levels. kappa now uses the residuals' mean and sd and
  scales the residuals before the baseline is added.
A changed slope (drift=False, target_drift, target_drift_scale) now
pivots about mean(x): mean(x) + slope * (t - (n + 1) / 2).
The default drift=True path is unchanged.

AirPassengers, reps = 100, rho = 1, seed 1, mean over replicates
(before -> after; R moves the same way):
  drift=False               sd 122.89 -> 47.31, slope -0.024 -> -0.009
  target_drift=1            sd 122.89 -> 62.82, slope  1.938 ->  0.991
  target_drift_scale=0.5    sd 122.89 -> 72.57, slope  2.234 ->  1.320
  scl_adjustment=True       sd  51.55 -> 122.00, slope 1.136 -> 2.688
  defaults                  unchanged (sd 122.05, slope 2.690)
The replicate mean stays 280.30 in every case.

The stat-summary R helper takes drift and target_drift, only entering
the payload when given. New NNS.meboot entries for the new tests.
…aling

The drift tests passed with the old force_clt reference (drift=False mean
spread 0.270, not 0.0706) and the scale test without the adjustment; all now fail on those mutants.
@gitRasheed
gitRasheed force-pushed the rasheed/book-copula-anchor branch from dc59d8c to f01e08b Compare November 2, 2026 23:09
@gitRasheed
gitRasheed force-pushed the rasheed/book-meboot-drift branch from 41b0ec5 to 0f32a89 Compare November 2, 2026 23:09
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Incorporated through NNS R 14.0 integration #192, merged as bd19c3303222af46da79d8c97f258248eb5674d2. Verified exact head 0f32a890d960dc99bb19f390e2c14bb05989c4d9 is an ancestor of main; original commits and authorship are preserved. The integration includes the subsequent R14 compatibility corrections and passed the complete GitHub Python 3.11-3.14 matrix. This supersedes the separate landing, not the work or review history.

@github-actions github-actions Bot closed this Nov 7, 2026
@github-actions
github-actions Bot deleted the rasheed/book-meboot-drift branch November 7, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant