basic statistics in python
Travis Oliphant
oliphant at ee.byu.edu
Tue Mar 19 17:10:46 EST 2002
On Sat, 16 Mar 2002, Tim Churches wrote:
> >
> > this is really embarassing :-)
> >
> > >>> import win32com.client
> > >>> xl = win32com.client.Dispatch('Excel.Application')
> > >>> xl.WorksheetFunction.StDev(1,1,1,3,3,45,3,2,1,1,2,3,2,1)
> > 11.565627361442019
> > >>> xl.WorksheetFunction.Pearson((1,4,3,2,5),(5,3,2,5,4))
> > -0.48507125007266594
>
> Hmm, how about these legacy-free solutions...
>
> Using Walter Moreira's RPy module ( http://rpy.sourceforge.net ) and R (
> http://www.r-project.org ):
>
> >>> from rpy import *
> >>> r.var((1,1,1,3,3,45,3,2,1,1,2,3,2,1)) ** 0.5
> 11.565627361442019
> >>> r.cor((1,4,3,2,5),(5,3,2,5,4))
> -0.48507125007266594
>
> Or using Gary Strangman's stats.py module (
> http://www.nmr.mgh.harvard.edu/Neural_Systems_Group/gary/python.html ):
>
> >>> from stats import *
> >>> stdev((1,1,1,3,3,45,3,2,1,1,2,3,2,1))
> 11.565627361442017
> >>> pearsonr((1,4,3,2,5),(5,3,2,5,4))
> (-0.48507125007266594, 0.40754435760237651)
>
> Note that stats.py also returns the 2-tailed p-value as well (which can
> also easily be obtained from R via RPy).
Note, also that this works in SciPy
from scipy import *
>>> std((1,1,1,3,3,45,3,2,1,1,2,3,2,1))
11.565627361442017
>>> stats.pearsonr((1,4,3,2,5),(5,3,2,5,4))
(-0.48507125007266594, 0.40754435760237651)
The stats module in SciPy (in CVS) is getting quite useful.
It calculates current the pdf, cdf, and ppf (inverse cdf) for over 80
continuous distribution functions.
Together with Gary's stats.py, the stats sub-package of SciPy is coming
along.
If you'd like to be part of improving this package go to www.scipy.org and
check it out.
The 0.1 release is now quite old, so it takes a little willingness to get
the package installed (you need a fortran compiler and the atlas
libraries).
There seem to be lots of people re-inventing the wheel, here. SciPy is
trying to be an easy-to-install package that has all the basic,
commonly-implemented algorithms as well as tools to help you write your
algorithms in a faster, compiled language.
Jump on board. Lot's has been done, but lot's remains to be done. The
earlier you join us, the more impact you will have.
-Travis Oliphant
More information about the Python-list
mailing list