Skip to content

Replace 5 inline ESS calculations with calc_model_ess() #81

@gilesjohnr

Description

@gilesjohnr

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():

  1. R/grid_search_best_subset.R — lines 157, 221
  2. R/plot_model_parameter_sensitivity.R — line 99
  3. 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

  1. Replace each inline 1 / sum(weights^2) with calc_model_ess(weights, method = "kish")
  2. Verify the utility function handles edge cases (zero weights, single weight) that the inline code may not
  3. Run devtools::test() to verify
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions