Skip to content

Improve estimator variance and allocation formulas#32

Open
XavierCLL wants to merge 1 commit into
mainfrom
fix-estimator-calculations
Open

Improve estimator variance and allocation formulas#32
XavierCLL wants to merge 1 commit into
mainfrom
fix-estimator-calculations

Conversation

@XavierCLL

@XavierCLL XavierCLL commented Jun 9, 2026

Copy link
Copy Markdown
Member

Summary

This PR fixes two estimator-calculation issues found while reviewing the AcATaMa equation table against the implementation and cited estimator formulas.

1. Post-stratified area variance

The simple/systematic post-stratified estimator previously built the variance component with only the contribution from samples belonging to a reference class:

n_hj * (1 - n_hj / n_h+)^2 / (n_h+ - 1)

For a binary class indicator inside a post-stratum, the sample variance must include both successes and failures. Algebraically:

s_hj^2 = [n_hj(1 - p_hj)^2 + (n_h+ - n_hj)(0 - p_hj)^2] / (n_h+ - 1)
       = n_hj(1 - p_hj) / (n_h+ - 1)

where p_hj = n_hj / n_h+.

This PR usea a shared post_stratified_variance_table helper with:

n_hj * (1 - n_hj / n_h+) / (n_h+ - 1)

This avoids underestimating post-stratified standard errors and confidence intervals, especially when p_hj is high.

2. Stratified sample allocation

The stratified sample-size helper already computed total sample size using the weighted stratum standard deviations:

n = (sum_i W_i S_i / S(OA))^2
S_i = sqrt(U_i(1 - U_i))

However, per-stratum allocation used only mapped area proportions:

n_i = round(W_i * n)

This meant the conjectured user accuracy U_i affected total sample size but not the relative allocation among strata. This PR updates allocation to:

n_i = round((W_i S_i / sum_k W_k S_k) * n)

so per-stratum sample counts now use both mapped area proportion and expected stratum variability.

Files changed

  • AcATaMa/gui/accuracy_assessment_results.py
    • Adds a shared helper for post-stratified class-indicator variance components.
  • AcATaMa/utils/sampling_utils.py
    • Keeps the existing total sample-size equation.
    • Updates per-stratum allocation to weight by W_i S_i rather than W_i alone.

Verification

No test suite was run, per request.

Performed only non-test verification:

  • Static LSP diagnostics on changed files: clean.
  • Syntax-only compile checks with python -m py_compile on both changed modules.
  • Manual standalone formula checks confirming:
    • the post-stratified binary sample-variance identity matches the implemented expression;
    • stratified allocation now changes when S_i differs across strata, as expected.

Notes

Stratified sampling fixtures may also change when area-based allocation is regenerated, because per-stratum counts now include S_i in the allocation weights.

@XavierCLL

XavierCLL commented Jun 10, 2026

Copy link
Copy Markdown
Member Author
Affected table item Before After
STR — Sample size and allocation Sᵢ = √[Uᵢ(1−Uᵢ)]; n ≈ (Σᵢ WᵢSᵢ/S(Ô))²; nᵢ ≈ round(Wᵢn), with minimum-per-stratum override Sᵢ = √[Uᵢ(1−Uᵢ)]; n ≈ (Σᵢ WᵢSᵢ/S(Ô))²; nᵢ ≈ round((WᵢSᵢ / ΣₖWₖSₖ)n), with minimum-per-stratum override
Post-Stratified designs — Area estimation and CI p̂₊ⱼᴾˢ = Σₕ Wₕᴾˢ(nₕⱼ/nₕ₊); AcATaMa applies its implemented post-stratified variance p̂₊ⱼᴾˢ = Σₕ Wₕᴾˢ(nₕⱼ/nₕ₊); variance uses the corrected post-stratum class-indicator component: sₕⱼ² = nₕⱼ(1−nₕⱼ/nₕ₊)/(nₕ₊−1)

Note: the STR change affects sample allocation only. The Post-Stratified-design change affects standard error, confidence intervals, coefficient of variation, and uncertainty for post-stratified simple/systematic estimators.

@XavierCLL XavierCLL changed the title Fix estimator variance and allocation formulas Improve estimator variance and allocation formulas Jul 11, 2026
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