Repository navigation
cdf: hazard and cumulative hazard at a target match the returned curve - #181
Closed
gitRasheed wants to merge 1 commit into
Closed
gitRasheed wants to merge 1 commit into
gitRasheed wants to merge 1 commit into
Conversation
…e (R cumhaz-target) Mirrors R NNS.CDF (OVVO-Financial/NNS cumhaz-target). The univariate target.value for "hazard" divided the fitted hazard at the target by the survival at the nearest data point, and "cumulative hazard" refit the curve with NNS.reg and read it at the target. Both now apply the curve's own transformation to the survival at the target: hazard: min(max(Point.est / max(1 - F(t), 1e-10), 0), 1e6) cumulative hazard: max(-log(max(1 - F(t), 1e-10)), 0) so target.value equals the curve at every data point, lies between its neighbours elsewhere, and the hazard is clamped like the curve. The multivariate path already worked this way. Before -> after (= R): nns_cdf(1:4, 1, target=2.5, type="cumulative hazard") 6.17 -> 0.693 nns_cdf(1:4, 1, target=2.5, type="hazard") 0.387 -> 0.580 2 NNS.CDF.custom cache entries (those two target values) predate the R change and were refilled from the cache's R build plus that change alone; the other 37 came back identical.
Contributor
|
Incorporated through NNS R 14.0 integration #192, merged as |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
R's univariate
NNS.CDFcomputedtarget.valuefor"hazard"from the survival at the data point nearest the target, and for"cumulative hazard"by refitting the curve withNNS.regand reading it at the target. Neither matched the curve it returned. OVVO-Financial/NNS#123 (merged) applies the curve's own transformation to the survival at the target. This slice mirrors it.Stacked on #180; merge with a merge commit.
Changes
_univariate_cdf(cdf.py): hazard ismin(max(Point.est / max(1 - F(t), 1e-10), 0), 1e6)and cumulative hazardmax(-log(max(1 - F(t), 1e-10)), 0), with F the LPM ratio at the target.target.valuenow equals the curve at every data point and lies between its neighbours elsewhere, and the hazard is clamped like the curve. The multivariate path already worked this way and is unchanged.nns_cdf(1:4, 1, target=2.5, type="cumulative hazard")6.17 -> 0.693, andtype="hazard"0.387 -> 0.580.Tests
rlnormunderset.seed(11), so I used a NumPy lognormal sample of the same size rounded the same way. 7 of these fail on the old code.NNS_DISABLE_NATIVE=1: 2913 passed, 29 skipped, 2 xpassed. The 3 xfails are mode: break tied discrete modes by gravity, not their mean (mirrors R #111) #178's strict ones and the 2 xpasses the existing non-strict live-R VAR xfails. tests/parity/test_practical_examples.py against the usual R library: 9 passed, 2 xfailed, as on mode: break tied discrete modes by gravity, not their mean (mirrors R #111) #178. ruff check is clean on every changed file.Review
GPT-6.1 Sol reviewed the #143, #125 and #123 mirrors together: SHIP.
Mirrors OVVO-Financial/NNS#123