Home > Statistics > Main text

Common test to measure significance


Tag: statistics

Different types of hypothesis test

From Python for R users, p151

img

Test in Python Scipy stat

fisher exact test

import scipy.stats as stats
oddsratio, pvalue = stats.fisher_exact([[8, 2], [1, 5]])
print oddsratio,pvalue

# 20.0 0.03496503496503495

test distribution

# test based on poisson distribution
def sig_test_poisson(x=0.3,mu=0.001):
    p=stats.distributions.poisson.pmf(x,mu)
    #print "poisson test:",p # work correctly
    return p

# test based on negative binomial distribution
def sig_test_nbinom(x=100,n=50,p=0.3):
    p=stats.distributions.nbinom.pmf(x,n,p)
    #print "nbinom test:",p # work correctly
    return p

KS test

# two sample distribution test
def ks_2samp(x,y):
    p=stats.ks_2samp(x,y)[1]
    return p

calculate correlation

# two sample rank test
def sig_spearman_corr(x,y):
    p=stats.spearmanr(x,y)[0]
    return p

def sig_pearson_corr(x,y):
    p=stats.pearsonr(x,y)[0]
    return p

t-test

rvs1 = stats.norm.rvs(loc=5,scale=10,size=500)
rvs2 = stats.norm.rvs(loc=5,scale=10,size=500)
stats.ttest_ind(rvs1,rvs2)
# (0.26833823296239279, 0.78849443369564776)

stats.ttest_ind(rvs1,rvs2, equal_var = False)
# (0.26833823296239279, 0.78849452749500748)

If you link this blog, please refer to this page, thanks!
Post link:https://tsinghua-gongjing.github.io/posts/common_statistical_test.html

Previous: Common file format in bioinformatics