Package mvpa :: Package misc :: Module stats
[hide private]
[frames] | no frames]

Source Code for Module mvpa.misc.stats

 1  #emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*- 
 2  #ex: set sts=4 ts=4 sw=4 et: 
 3  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## 
 4  # 
 5  #   See COPYING file distributed along with the PyMVPA package for the 
 6  #   copyright and license terms. 
 7  # 
 8  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## 
 9  """Little statistics helper""" 
10   
11  __docformat__ = 'restructuredtext' 
12   
13  import scipy.stats as stats 
14  import numpy as N 
15   
16 -def chisquare(obs, exp=None):
17 """Compute the chisquare value of a contingency table with arbitrary 18 dimensions. 19 20 If no expected frequencies are supplied, the total N is assumed to be 21 equally distributed across all cells. 22 23 Returns: chisquare-stats, associated p-value (upper tail) 24 """ 25 obs = N.array(obs) 26 27 # get total number of observations 28 nobs = N.sum(obs) 29 30 # if no expected value are supplied assume equal distribution 31 if exp == None: 32 exp = N.ones(obs.shape) * nobs / N.prod(obs.shape) 33 34 # make sure to have floating point data 35 exp = exp.astype(float) 36 37 # compute chisquare value 38 chisq = N.sum((obs - exp )**2 / exp) 39 40 # return chisq and probability (upper tail) 41 return chisq, stats.chisqprob(chisq, N.prod(obs.shape) - 1)
42