Skip to content

Commit

Permalink
Merge pull request #8096 from bashtage/backport/maintenance/0.13.x/pr…
Browse files Browse the repository at this point in the history
…-8093

[maintenance/0.13.x] Merge pull request #8093 from josef-pkt/bug_proportion_pwer_2indep
  • Loading branch information
bashtage committed Feb 2, 2022
2 parents 0e4272f + d226f7c commit ff14cd8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions statsmodels/stats/proportion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ def _std_2prop_power(diff, p2, ratio=1, alpha=0.05, value=0):
p2_alt = p2
p1_alt = p2_alt + diff

std_null = _std_diff_prop(p1_vnull, p2_vnull)
std_null = _std_diff_prop(p1_vnull, p2_vnull, ratio=nobs_ratio)
std_alt = _std_diff_prop(p1_alt, p2_alt, ratio=nobs_ratio)
return p_pooled, std_null, std_alt

Expand Down Expand Up @@ -1892,16 +1892,16 @@ def power_proportions_2indep(diff, prop2, nobs1, ratio=1, alpha=0.05,
pooled proportion, used for std_null
std_null
standard error of difference under the null hypothesis (without
sqrt(nobs))
sqrt(nobs1))
std_alt
standard error of difference under the alternative hypothesis
(without sqrt(nobs))
(without sqrt(nobs1))
"""
# TODO: avoid possible circular import, check if needed
from statsmodels.stats.power import normal_power_het

p_pooled, std_null, std_alt = _std_2prop_power(diff, prop2, ratio=1,
alpha=0.05, value=0)
p_pooled, std_null, std_alt = _std_2prop_power(diff, prop2, ratio=ratio,
alpha=alpha, value=value)

pow_ = normal_power_het(diff, nobs1, alpha, std_null=std_null,
std_alternative=std_alt,
Expand Down
10 changes: 10 additions & 0 deletions statsmodels/stats/tests/test_proportion.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,13 @@ def test_power_2indep():
ratio=1, alpha=0.05, value=0,
alternative='two-sided')
assert_allclose(n2, n, rtol=1e-13)

# with nobs ratio != 1
# note Stata has reversed ratio compared to ours, see #8049
pwr_st = 0.7995659211532175
n = 154
res = power_proportions_2indep(-0.1, 0.2, n, ratio=2.)
assert_allclose(res.power, pwr_st, atol=1e-7)

n2 = samplesize_proportions_2indep_onetail(-0.1, 0.2, pwr_st, ratio=2)
assert_allclose(n2, n, rtol=1e-4)

0 comments on commit ff14cd8

Please sign in to comment.