Skip to content

feat: calibrate(bounds=) holds g within bounds during the solve, as R's grake - #421

Merged
MamadouSDiallo merged 1 commit into
mainfrom
feat/bounded-calibration
Oct 29, 2026
Merged

MamadouSDiallo merged 1 commit into
mainfrom
feat/bounded-calibration

Conversation

@MamadouSDiallo

Copy link
Copy Markdown
Contributor

calibrate(bounds=(lo, hi)) and calibrate_matrix(bounds=) no longer raise NOT_SUPPORTED: the factor g = new/old weight is held within the bounds during the solve, as R survey's calibrate(bounds=) with the linear distance.

  • svy-rs: calibrate_bounded and calibrate_bounded_by_domain, a port of grake with cal.linear (Newton steps on the MASS::ginv pseudo-inverse, R's stopping rule |misfit| / (1 + |t|) < epsilon, and its pre-scaling of weights far below the controls).
  • svy: new tol= (1e-7, R epsilon) and max_iter= (50, R maxit), used with bounds. A solve that stops short raises WEIGHTING_NOT_CONVERGED naming the domains or replicate weights; on_nonconvergence="warn" keeps the last iterate (R force=TRUE). Failed replicates follow on_nonconvergence, as the closed-form replicate check does; R keeps them with a warning. bounds= with trimming= raises NOT_SUPPORTED. No side set keeps the closed form, unchanged.
  • Variance: no change; the existing GREG record already matches R.

Tests: R 4.5 fixtures on apiclus1, apistrat and apisrs (two-sided, one-sided, tol=0.01, scale=, stratum interaction, by=, unit weights, non-convergence, JK1 replicates). Weights match at 1e-12, Taylor SEs at 1e-8, and the failing replicates (9, 11, 12) and their miss match R. Rust unit tests pin hand-computed cases. The five tests that asserted the refusal are replaced.

Needs an svy-rs release before svy.

@MamadouSDiallo
MamadouSDiallo merged commit 81a953c into main Oct 29, 2026
25 checks passed
@MamadouSDiallo
MamadouSDiallo deleted the feat/bounded-calibration branch October 29, 2026 19:49
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.

1 participant