def test_normal_power_explicit(): # a few initial test cases for NormalIndPower sigma = 1 d = 0.3 nobs = 80 alpha = 0.05 res1 = smp.normal_power(d, nobs/2., 0.05) res2 = smp.NormalIndPower().power(d, nobs, 0.05) res3 = smp.NormalIndPower().solve_power(effect_size=0.3, nobs1=80, alpha=0.05, power=None) res_R = 0.475100870572638 assert_almost_equal(res1, res_R, decimal=13) assert_almost_equal(res2, res_R, decimal=13) assert_almost_equal(res3, res_R, decimal=13) norm_pow = smp.normal_power(-0.01, nobs/2., 0.05) norm_pow_R = 0.05045832927039234 #value from R: >pwr.2p.test(h=0.01,n=80,sig.level=0.05,alternative="two.sided") assert_almost_equal(norm_pow, norm_pow_R, decimal=11) norm_pow = smp.NormalIndPower().power(0.01, nobs, 0.05, alternative="larger") norm_pow_R = 0.056869534873146124 #value from R: >pwr.2p.test(h=0.01,n=80,sig.level=0.05,alternative="greater") assert_almost_equal(norm_pow, norm_pow_R, decimal=11) # Note: negative effect size is same as switching one-sided alternative # TODO: should I switch to larger/smaller instead of "one-sided" options norm_pow = smp.NormalIndPower().power(-0.01, nobs, 0.05, alternative="larger") norm_pow_R = 0.0438089705093578 #value from R: >pwr.2p.test(h=0.01,n=80,sig.level=0.05,alternative="less") assert_almost_equal(norm_pow, norm_pow_R, decimal=11)
def test_normal_power_explicit(): # a few initial test cases for NormalIndPower sigma = 1 d = 0.3 nobs = 80 alpha = 0.05 res1 = smp.normal_power(d, nobs/2., 0.05) res2 = smp.NormalIndPower().power(d, nobs, 0.05) res3 = smp.NormalIndPower().solve_power(effect_size=0.3, nobs1=80, alpha=0.05, power=None) res_R = 0.475100870572638 assert_almost_equal(res1, res_R, decimal=13) assert_almost_equal(res2, res_R, decimal=13) assert_almost_equal(res3, res_R, decimal=13) norm_pow = smp.normal_power(-0.01, nobs/2., 0.05) norm_pow_R = 0.05045832927039234 #value from R: >pwr.2p.test(h=0.01,n=80,sig.level=0.05,alternative="two.sided") assert_almost_equal(norm_pow, norm_pow_R, decimal=13) norm_pow = smp.NormalIndPower().power(0.01, nobs, 0.05, alternative="larger") norm_pow_R = 0.056869534873146124 #value from R: >pwr.2p.test(h=0.01,n=80,sig.level=0.05,alternative="greater") assert_almost_equal(norm_pow, norm_pow_R, decimal=13) # Note: negative effect size is same as switching one-sided alternative # TODO: should I switch to larger/smaller instead of "one-sided" options norm_pow = smp.NormalIndPower().power(-0.01, nobs, 0.05, alternative="larger") norm_pow_R = 0.0438089705093578 #value from R: >pwr.2p.test(h=0.01,n=80,sig.level=0.05,alternative="less") assert_almost_equal(norm_pow, norm_pow_R, decimal=13)
Created on Sat Mar 02 14:38:17 2013 Author: Josef Perktold """ from __future__ import print_function import numpy as np import statsmodels.stats.power as smp import statsmodels.stats.proportion as smpr sigma = 1 d = 0.3 nobs = 80 alpha = 0.05 print(smp.normal_power(d, nobs / 2, 0.05)) print(smp.NormalIndPower().power(d, nobs, 0.05)) print(smp.NormalIndPower().solve_power(effect_size=0.3, nobs1=80, alpha=0.05, power=None)) print(0.475100870572638, 'R') norm_pow = smp.normal_power(-0.01, nobs / 2, 0.05) norm_pow_R = 0.05045832927039234 #value from R: >pwr.2p.test(h=0.01,n=80,sig.level=0.05,alternative="two.sided") print('norm_pow', norm_pow, norm_pow - norm_pow_R) norm_pow = smp.NormalIndPower().power(0.01, nobs, 0.05, alternative="larger") norm_pow_R = 0.056869534873146124 #value from R: >pwr.2p.test(h=0.01,n=80,sig.level=0.05,alternative="greater")
""" Created on Sat Mar 02 14:38:17 2013 Author: Josef Perktold """ from __future__ import print_function import statsmodels.stats.power as smp sigma=1 d=0.3 nobs=80 alpha=0.05 print(smp.normal_power(d, nobs/2, 0.05)) print(smp.NormalIndPower().power(d, nobs, 0.05)) print(smp.NormalIndPower().solve_power(effect_size=0.3, nobs1=80, alpha=0.05, power=None)) print(0.475100870572638, 'R') norm_pow = smp.normal_power(-0.01, nobs/2, 0.05) norm_pow_R = 0.05045832927039234 #value from R: >pwr.2p.test(h=0.01,n=80,sig.level=0.05,alternative="two.sided") print('norm_pow', norm_pow, norm_pow - norm_pow_R) norm_pow = smp.NormalIndPower().power(0.01, nobs, 0.05, alternative="larger") norm_pow_R = 0.056869534873146124 #value from R: >pwr.2p.test(h=0.01,n=80,sig.level=0.05,alternative="greater") print('norm_pow', norm_pow, norm_pow - norm_pow_R) # Note: negative effect size is same as switching one-sided alternative