Skip to content

Fix left-censoring bug in score/hessian, merge vignettes, expand tests#1

Merged
queelius merged 1 commit intomainfrom
feat/left-censoring-bugfix-and-vignette-merge
Feb 18, 2026
Merged

Fix left-censoring bug in score/hessian, merge vignettes, expand tests#1
queelius merged 1 commit intomainfrom
feat/left-censoring-bugfix-and-vignette-merge

Conversation

@queelius
Copy link
Owner

Summary

  • Critical bugfix: Analytical score_fn/hess_fn silently produced wrong results with left-censored data (delta=-1). Added guards in score.dfr_dist and hess_loglik.dfr_dist to detect left-censored observations and fall back to numDeriv automatically.
  • Vignette consolidation: Merged getting_started.Rmd into flexhaz-package.Rmd with new left-censoring and custom column name (ob_col/delta_col) sections.
  • Documentation fixes: Corrected log-logistic docs (was claiming "no closed form" despite having analytical cum_haz_rate), updated @param docs for score_fn/hess_fn/delta_col.
  • Test expansion: 57 new tests (322 total, 99.47% coverage) covering left-censoring for all distributions, score/hessian fallback paths, custom column names, and regression tests.

Test plan

  • devtools::test() — 322 pass, 0 fail
  • devtools::document() — NAMESPACE and .Rd files regenerated
  • devtools::build_vignettes() — all 5 vignettes build cleanly
  • Code review (3 rounds) — no outstanding issues
  • devtools::check() — full R CMD check

🤖 Generated with Claude Code

…nd tests

The analytical score_fn and hess_fn in all helper constructors (exponential,
Weibull, Gompertz, log-logistic) only derive from delta in {0,1}. When
left-censored data (delta=-1) was present, these functions silently produced
wrong gradients, causing the BFGS optimizer to receive inconsistent
function/gradient information. Added guards in score.dfr_dist and
hess_loglik.dfr_dist to detect left-censored observations and fall back to
numDeriv automatically.

Also:
- Merge getting_started.Rmd into flexhaz-package.Rmd with new left-censoring
  and custom column name sections
- Fix log-logistic docs (was claiming "no closed form" despite having one)
- Update @param docs for score_fn/hess_fn/delta_col
- Add 57 new tests (322 total, 99.47% coverage)
- Suppress expected NaN optimizer warnings in all vignette fitting chunks
- Remove stale docs artifacts, rename .Rproj, update .gitignore

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 18, 2026 21:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses a critical bugfix for left-censored data handling, consolidates documentation, and significantly expands test coverage. The changes properly implement automatic fallback to numerical derivatives when analytical score/Hessian functions encounter left-censored observations (delta = -1), which they weren't designed to handle.

Changes:

  • Critical bugfix: Score/Hessian functions now detect left-censored data and fall back to numerical derivatives automatically
  • Vignette consolidation: Merged getting_started.Rmd into flexhaz-package.Rmd with expanded coverage of left-censoring and custom column names
  • Test expansion: Added 57 new tests covering left-censoring, score/hessian fallback, custom column names, and regression tests

Reviewed changes

Copilot reviewed 74 out of 81 changed files in this pull request and generated no comments.

Show a summary per file
File Description
R/dfr_dist.R Implements left-censoring guards in score/hess, fixes vectorization in inv_cdf/cum_haz, adds NaN handling
R/distributions.R Updates score_fn/hess_fn signatures to accept ob_col/delta_col parameters
man/dfr_loglogistic.Rd Corrects documentation (was incorrectly claiming no closed form for cumulative hazard)
man/dfr_dist.Rd Updates parameter documentation for score_fn/hess_fn/delta_col
vignettes/flexhaz-package.Rmd Expands with left-censoring and custom column examples from deleted getting_started vignette
vignettes/getting_started.Rmd Deleted (content merged into flexhaz-package.Rmd)
tests/testthat/test-likelihood_model.R Adds comprehensive left-censoring tests for all distributions
tests/testthat/test-bugfixes.R New file with regression tests for vectorization and column name issues
DESCRIPTION Updated to mention left-censored data support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@queelius queelius merged commit 0bfa53a into main Feb 18, 2026
6 of 7 checks passed
@queelius queelius deleted the feat/left-censoring-bugfix-and-vignette-merge branch February 18, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants