Context
The MOSAIC package has a dedicated calc_model_ess() function that computes Effective Sample Size using Kish or perplexity methods. During an audit (similar to the 16 inline cor()^2 calls that were replaced with calc_model_R2() in v0.22.4), we found 5 inline ESS calculations that should use the utility function.
Problem
These files compute ESS inline as 1 / sum(weights^2) instead of calling calc_model_ess():
R/grid_search_best_subset.R — lines 157, 221
R/plot_model_parameter_sensitivity.R — line 99
R/plot_model_posteriors_detail.R — lines 346, 356
(R/calc_bfrs_posterior.R:93 also has one, but that file is orphaned — see issue #76)
Required Actions
- Replace each inline
1 / sum(weights^2) with calc_model_ess(weights, method = "kish")
- Verify the utility function handles edge cases (zero weights, single weight) that the inline code may not
- Run
devtools::test() to verify
- Grep for any other inline ESS patterns:
1/sum.*\\^2, sum.*weights.*\\^2
Error Classification
AI-introduced error of omission — same pattern as the calc_model_R2() issue: utility function exists but inline duplicates persist.
🤖 Generated with Claude Code
Context
The MOSAIC package has a dedicated
calc_model_ess()function that computes Effective Sample Size using Kish or perplexity methods. During an audit (similar to the 16 inlinecor()^2calls that were replaced withcalc_model_R2()in v0.22.4), we found 5 inline ESS calculations that should use the utility function.Problem
These files compute ESS inline as
1 / sum(weights^2)instead of callingcalc_model_ess():R/grid_search_best_subset.R— lines 157, 221R/plot_model_parameter_sensitivity.R— line 99R/plot_model_posteriors_detail.R— lines 346, 356(
R/calc_bfrs_posterior.R:93also has one, but that file is orphaned — see issue #76)Required Actions
1 / sum(weights^2)withcalc_model_ess(weights, method = "kish")devtools::test()to verify1/sum.*\\^2,sum.*weights.*\\^2Error Classification
AI-introduced error of omission — same pattern as the
calc_model_R2()issue: utility function exists but inline duplicates persist.🤖 Generated with Claude Code