Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A quick check for size and power of mannwhitneyu if data is poisson
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:52:22 2013
Author: Josef Perktold
"""
import numpy as np
from scipy import stats
quantiles = np.array([0.01, 0.05, 0.10, 0.25])
n_mc = 1000
nobs1, nobs2 = 10, 10 #20, 20
print 'lam1, lam2, nobs1, nobs2, [0.01, 0.05, 0.10, 0.25]'
for lam1 in range(1, 10, 2):
for lam2 in range(1, 10, 2):
mc = np.zeros((n_mc,2))
for i in xrange(n_mc):
rvs1 = np.random.poisson(lam1, nobs1)
rvs2 = np.random.poisson(lam2, nobs2)
mc[i] = stats.mannwhitneyu(rvs1, rvs2)
null = 'null' if lam1 == lam2 else ''
print lam1, lam2, nobs1, nobs2, (mc[:,1:2]*2 < quantiles).mean(0), null
'''
lam1, lam2, nobs1, nobs2, [0.01, 0.05, 0.10, 0.25]
1 1 20 20 [ 0.013 0.045 0.085 0.22 ] null
1 3 20 20 [ 0.949 0.991 0.995 0.999]
1 5 20 20 [ 1. 1. 1. 1.]
1 7 20 20 [ 1. 1. 1. 1.]
1 9 20 20 [ 1. 1. 1. 1.]
3 1 20 20 [ 0.947 0.989 0.998 0.999]
3 3 20 20 [ 0.007 0.062 0.107 0.243] null
3 5 20 20 [ 0.604 0.843 0.911 0.973]
3 7 20 20 [ 0.992 1. 1. 1. ]
3 9 20 20 [ 1. 1. 1. 1.]
5 1 20 20 [ 1. 1. 1. 1.]
5 3 20 20 [ 0.629 0.832 0.899 0.964]
5 5 20 20 [ 0.009 0.047 0.098 0.247] null
5 7 20 20 [ 0.407 0.685 0.792 0.921]
5 9 20 20 [ 0.96 0.996 0.998 1. ]
7 1 20 20 [ 1. 1. 1. 1.]
7 3 20 20 [ 0.996 1. 1. 1. ]
7 5 20 20 [ 0.433 0.703 0.804 0.911]
7 7 20 20 [ 0.012 0.047 0.102 0.239] null
7 9 20 20 [ 0.288 0.564 0.699 0.861]
9 1 20 20 [ 1. 1. 1. 1.]
9 3 20 20 [ 1. 1. 1. 1.]
9 5 20 20 [ 0.964 0.992 0.995 0.998]
9 7 20 20 [ 0.308 0.575 0.706 0.865]
9 9 20 20 [ 0.01 0.045 0.103 0.259] null
'''
''' n=10 slightly underrejects if lambda > 1
lam1, lam2, nobs1, nobs2, [0.01, 0.05, 0.10, 0.25]
1 1 10 10 [ 0.012 0.062 0.105 0.245] null
1 3 10 10 [ 0.59 0.84 0.909 0.966]
1 5 10 10 [ 0.982 0.999 1. 1. ]
1 7 10 10 [ 0.998 1. 1. 1. ]
1 9 10 10 [ 1. 1. 1. 1.]
3 1 10 10 [ 0.549 0.814 0.895 0.964]
3 3 10 10 [ 0.01 0.041 0.081 0.221] null
3 5 10 10 [ 0.234 0.516 0.671 0.84 ]
3 7 10 10 [ 0.819 0.953 0.986 0.996]
3 9 10 10 [ 0.981 0.998 1. 1. ]
5 1 10 10 [ 0.978 0.999 1. 1. ]
5 3 10 10 [ 0.231 0.554 0.695 0.859]
5 5 10 10 [ 0.016 0.06 0.095 0.238] null
5 7 10 10 [ 0.131 0.346 0.507 0.705]
5 9 10 10 [ 0.598 0.854 0.929 0.976]
7 1 10 10 [ 1. 1. 1. 1.]
7 3 10 10 [ 0.798 0.962 0.985 0.998]
7 5 10 10 [ 0.132 0.36 0.492 0.709]
7 7 10 10 [ 0.006 0.042 0.091 0.245] null
7 9 10 10 [ 0.098 0.298 0.429 0.648]
9 1 10 10 [ 1. 1. 1. 1.]
9 3 10 10 [ 0.981 1. 1. 1. ]
9 5 10 10 [ 0.616 0.86 0.936 0.986]
9 7 10 10 [ 0.095 0.3 0.426 0.643]
9 9 10 10 [ 0.008 0.037 0.082 0.232] null
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.