Fix model-level edfct derivatives for absolute ED type#188
Conversation
…evel edfct functions When type='absolute', the edfct functions in model files set derivatives for c (lower limit) and d (upper limit) to 0. This is incorrect because the absolute-to-relative conversion makes p depend on c and d, requiring chain-rule corrections. Use central differences to compute correct c and d derivatives for absolute type in all affected model files. Fixes: braincousens.R, fplogistic.R, llogistic.R, llogistic2.R, lnormal.R, weibull1.R, weibull2.R, logistic.R Agent-Logs-Url: https://github.com/hreinwald/drc/sessions/7ea3ad01-6a69-4d8a-8c99-5b419f07b01f Co-authored-by: hreinwald <115988583+hreinwald@users.noreply.github.com>
…legation path Agent-Logs-Url: https://github.com/hreinwald/drc/sessions/7ea3ad01-6a69-4d8a-8c99-5b419f07b01f Co-authored-by: hreinwald <115988583+hreinwald@users.noreply.github.com>
|
There seems to me an issue with the unit tests. @copilot please review the errors from the R-CMD-check which all failed for the unit test (testthat) section. Identify the issue and fix it. |
…d incorrect p-swap The logistic model has opposite b-sign convention from log-logistic: b < 0 means increasing (not decreasing). EDhelper swaps p for b < 0, which is correct for log-logistic but wrong for logistic. Replace with inline absolute-to-relative conversion that skips the p-swap. Agent-Logs-Url: https://github.com/hreinwald/drc/sessions/801bd853-cb45-4ae2-8e75-c28dae361ad5 Co-authored-by: hreinwald <115988583+hreinwald@users.noreply.github.com>
The R-CMD-check failures were all in Root cause: I incorrectly added Fix (aef7e9f): Replaced |
When
type = "absolute", each model'sedfctfunction sets ∂ED/∂c and ∂ED/∂d to 0. This is wrong — the absolute-to-relative conversion (p = 100·(d−respl)/(d−c)) makespa function ofcandd, so the chain rule requires non-zero partials. TheED.drccaller already patches this with a numerical override, but the model-level functions themselves remain incorrect for direct callers.Changes
braincousens.R, fplogistic.R, llogistic.R, llogistic2.R, lnormal.R, weibull1.R, weibull2.R: When
type == "absolute", compute ∂ED/∂c and ∂ED/∂d via central differences on a closure that re-evaluates the full ED computation with perturbedc/d, capturing the chain-rule contribution throughEDhelper/absToRel.weibull2.R: Special handling because it delegates to
weibull1$edfctwithtype="relative". The.edvalwrapper replicates both weibull2's reversal (b > 0) and weibull1's EDhelper swap (b < 0) to match the actual computation path.logistic.R: Previously did not accept
reference/typeat all — absolute ED estimates were silently wrong. Addedreference/typeparameters with an inline absolute-to-relative conversion instead ofEDhelper, because the logistic model has the opposite b-sign convention from log-logistic (b < 0= increasing, not decreasing).EDhelper's p-swap forb < 0would incorrectly swap ED values for the logistic model, so only the raw conversionp = 100·(d−respl)/(d−c)is applied for absolute type, withp = resplused directly for relative type.Pattern applied in each file
No changes to
type = "relative"behavior. Verified model-level SE matchesED()output for LL.4, W1.4, W2.4, LN.4. All 152 ED tests, 83 ED_robust tests pass.