Skip to content

BUG: power_equivalence_poisson_2indep and power_equivalence_neginb_2indep wrong for nobs_ratio != 1 #10519

Closed

Description

@Jason10191019999

Describe the bug

power_equivalence_poisson_2indep and power_equivalence_neginb_2indep in statsmodels/stats/rates.py return wrong power values whenever nobs_ratio != 1 (and, for the negative binomial version, rate1 != rate2). All three bugs are invisible at nobs_ratio = 1, which is why the current test suite does not catch them — the existing tests only use equal sample sizes.

Bug 1 — power_equivalence_poisson_2indep passes nobs2 where the formula requires nobs1.

The standard errors are defined per-nobs1 (the same v1 definition as power_poisson_ratio_2indep, which correctly calls normal_power_het(es, nobs1, ...)), but the function calls

pow_ = _power_equivalence_het(es_low, es_upp, nobs2, ...)

The sibling power_equivalence_neginb_2indep correctly passes nobs1.

Reproducer (nobs_ratio=2, nobs1=100, rate1=rate2=1.0, low=0.8, upp=1.25, method_var='alt'):

  • current (buggy) analytic power: 0.6486
  • Monte Carlo reference (50,000 replications of Poisson counts, TOST at alpha=0.05): 0.143 (MC se 0.002)
  • corrected analytic power: 0.1406 (matches MC within its standard error)
import numpy as np
from statsmodels.stats.rates import power_equivalence_poisson_2indep

power_equivalence_poisson_2indep(
    rate1=1.0, rate2=1.0, nobs1=100, low=0.8, upp=1.25,
    nobs_ratio=2, method_var="alt",
)  # -> 0.6486, expected ~0.14

Bug 2 — same function, method_var='score': wrong constrained-null variance.

The variance under the constrained null uses

v0 = dispersion / exposure * (1 + low * nobs_ratio) ** 2 / (
    low * nobs_ratio * (rate1 + nobs_ratio * rate2))

Brute-force constrained CMLE (maximizing the Poisson likelihood under rate1/rate2 = low) gives the variance of the log rate ratio per nobs1 as

(low + nobs_ratio)**2 / (low * nobs_ratio * (rate1 + nobs_ratio * rate2))

which also matches the sibling power_poisson_ratio_2indep. Same fix for the upp occurrence.

Bug 3 — power_equivalence_neginb_2indep: rate1/rate2 swapped in the alternative variance.

v1 = (1 / rate2 + 1 / (nobs_ratio * rate1)) / exposure + (1 + nobs_ratio) / nobs_ratio * dispersion

Since nobs1 is passed to _power_equivalence_het, the per-nobs1 delta-method variance of the log rate ratio is

1 / (exposure * rate1) + 1 / (exposure * nobs_ratio * rate2) + dispersion * (1 + 1 / nobs_ratio)

matching the sibling power_negbin_ratio_2indep.

Expected behavior

Power values consistent with Monte Carlo simulation and with the per-nobs1 variance definitions used everywhere else in the module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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