Problem
R/calculate_cvs.R (484 lines) has only 41 lines of tests. The existing tests only verify:
- No MOE column is entirely NA
_pct variables have corresponding _M columns
No tests verify the actual statistical formulas produce correct values.
Gaps
Formula verification
se_simple(): trivial but untested
se_sum(): untested, especially the Census zero-estimate special case (keep only the largest MOE among zero-estimate addends)
se_proportion_ratio(): untested edge cases — p > 1 (degenerate proportion, should fall back to ratio formula), zero denominators (should return NA), negative radical (should fall back to ratio formula)
se_product(): completely untested
se_weighted_mean(): completely untested
cv(): defined but never called — may be dead code
Suggested test approach
- Use Census Bureau worked examples from the ACS Accuracy documentation as ground truth
- Test each function independently with known inputs/outputs
- Test edge cases: zero estimates, NA values, p > 1 proportions, zero denominators
- Test
calculate_moes() end-to-end with a small synthetic dataset
Context
Identified during code review. These functions produce the margins of error that users rely on for statistical inference. Incorrect MOEs could lead to wrong conclusions about statistical significance.
Problem
R/calculate_cvs.R(484 lines) has only 41 lines of tests. The existing tests only verify:_pctvariables have corresponding_McolumnsNo tests verify the actual statistical formulas produce correct values.
Gaps
Formula verification
se_simple(): trivial but untestedse_sum(): untested, especially the Census zero-estimate special case (keep only the largest MOE among zero-estimate addends)se_proportion_ratio(): untested edge cases — p > 1 (degenerate proportion, should fall back to ratio formula), zero denominators (should return NA), negative radical (should fall back to ratio formula)se_product(): completely untestedse_weighted_mean(): completely untestedcv(): defined but never called — may be dead codeSuggested test approach
calculate_moes()end-to-end with a small synthetic datasetContext
Identified during code review. These functions produce the margins of error that users rely on for statistical inference. Incorrect MOEs could lead to wrong conclusions about statistical significance.