Skip to content

nns_copula: independence anchors from the empirical marginals (book ch12) - #171

Closed
gitRasheed wants to merge 1 commit into
rasheed/book-seas-all-phasesfrom
rasheed/book-copula-anchor
Closed

gitRasheed wants to merge 1 commit into
rasheed/book-seas-all-phasesfrom
rasheed/book-copula-anchor

Conversation

@gitRasheed

@gitRasheed gitRasheed commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

nns_copula compares its co-moments with fixed anchors, 0.25 * (n^2 - n) for the pairwise sum and 1 - 2 * 0.5^n for the nD divergent share. They hold only when every target is the median, and the default target is the column means, so independent skewed data read about 0.2. Book ch12 defines the copula through the marginals, CoLPM_00 = C(F_X(t_X), F_Y(t_Y)) (ch12:130-133). We mirror OVVO-Financial/NNS#86, which makes R follow the book, including its round-2 fixes. That PR changes the method, so the R author may close it; if so, this slice should be dropped too.

Stacked on #170; merge with a merge commit.

Changes

  • Each term uses its own independence value from each margin's lower share p_j at its target: pairs sum p_i p_j + (1 - p_i)(1 - p_j), and the divergent share is 1 - prod(p) - prod(1 - p). Degree-0 terms use LPM(0, t_j, x_j) and degree-1 terms LPM.ratio(1, t_j, x_j), or degree 0 for both with continuous=False. Independent Exp(1) data with 3 columns at n = 2e4 go from 0.1910 to 0.0604; independent normals stay at 0.0663.
  • The nD terms are clamped to 1 like the pairwise ones.
  • Constant margins are dropped first, and fewer than two varying margins give 0, so [x, 1] for x = -2..2 goes from 0.7746 to 0. A moment equal to a zero anchor scores 0.
  • copula._copula and the native copula_nd both change, and nns_reg's default order and dependence inherit it.

Tests

New parity cases for the anchors, constant margins and boundary targets. The test_Copula.R fixture takes R's updated values: B, C, D and E go from 0.2554, 0.2, 0.2470, 0.2 to 0.2543, 0.1970, 0.2506, 0.2088. 26 entries that predate the R change are refilled (14 NNS.copula, 5 NNS.reg, 5 dy.dx.numeric, 2 NNS.boost.numeric), one of them the boost balance case whose structure-only test had let a stale value pass. The parity cache encodes R 13.3 plus the fixes in OVVO-Financial/NNS#73-#92. The nine NNS.VAR strict xfails from #170 stay until #174.

Mirrors OVVO-Financial/NNS#86
Part of OVVO-Financial/NNS#70

Review

GPT-6.1 Sol reviewed this slice and found nothing. It compared 400 cases against R on both paths.

…chor)

Mirrors R's copula-marginal-anchor branch (NNS.copula), including its
round-2 fixes. The copula compared its co-moments with fixed anchors,
0.25 * (n^2 - n) for the pairwise sum and 1 - 2 * 0.5^n for the nD
divergent share, which hold only when every target is the median. The
default target is the column means, so independent skewed data read
about 0.2.

Each term now uses its own independence value from each margin's lower
share p_j at its target: pairs sum p_i p_j + (1 - p_i)(1 - p_j), and the
divergent share is 1 - prod(p) - prod(1 - p). Degree-0 terms use
p_j = LPM(0, t_j, x_j), degree-1 terms LPM.ratio(1, t_j, x_j) (degree 0
for both with continuous=False). The nD terms are clamped to 1 like the
pairwise ones. Constant margins are dropped first (fewer than two
varying margins give 0), and a moment equal to a zero anchor scores 0.
Both copula._copula and the native copula_nd change; nns_reg's default
order and dependence inherit it.

Before -> after (= R):
  independent Exp(1), 3 columns, n = 2e4     0.1910 -> 0.0604
    continuous=False                         0.2591 -> 0.0382
  independent normals, 3 columns             0.0663 (unchanged)
  [x, 1], x = -2..2                          0.7746 -> 0
  three -10/0.1 rows, target 0               0.7053 -> 0.8507
  interior-pair-sum integer matrix           0.5837 -> 0.5780
  test_Copula.R B C D E      0.2554 0.2 0.2470 0.2
                          -> 0.2543 0.1970 0.2506 0.2088

The adopted test_Copula.R fixture takes R's updated values. 26 entries
(14 NNS.copula, 5 NNS.reg, 5 dy.dx.numeric, 2 NNS.boost.numeric) predate
the R change and were refilled; 10 are added for the new test.
@gitRasheed
gitRasheed force-pushed the rasheed/book-copula-anchor branch from dc59d8c to f01e08b 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 f01e08bcc0d708cdcb8def0fa6dc0eda9373ee05 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-copula-anchor 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