amazon

29.8.14

Python ScipyでExcelのftest


ScipyにはExcelのftestやRのvar.testのように単純に等分散かどうかのp値を返す関数がない。
python用ftestを作ってみた。因みに両側検定。

import numpy as np
import scipy.stats as stats
def ftest(x1, x2):
    dfn = len(x1)-1
    dfd = len(x2)-1
    F = np.var(x1) / np.var(x2)
    f_pf = stats.f.cdf(F, dfn, dfd)
    return min(f_pf, 1 - f_pf)*2

Simple Excel-like f-test in python using scipy


Python Scipy does not have Excel-like f-test of equality of variances, which simply returns p-value of it.
Here provides a simple f-test function.

import numpy as np
import scipy.stats as stats
def ftest(x1, x2):
    dfn = len(x1)-1
    dfd = len(x2)-1
    F = np.var(x1) / np.var(x2)
    f_pf = stats.f.cdf(F, dfn, dfd)
    return min(f_pf, 1 - f_pf)*2

Note this is two-sided model as implemented in Excel.

5.8.14

Macでanacondaのipythonを直接呼び出す

AnacondaのLaunhcher.appから起動したIPython notebookでは、matplotlibのpylab.plotがブラウザ内に表示されない。
plt.show()を呼べば表示されるが、別ウインドウに描画されるので美しくない。

そこで、Anaconda内のipythonバイナリを直接叩く。
/anaconda/bin/ipython notebook --pylab=inline
オプション--pylab=inlineを付けると、グラフがブラウザ内に表示される。

Plot a graph inline in IPython notebook of Anaconda on Mac

I could not show a graph of matplotlib pylab.plot inline with ipython notebook, unless using plt.show(), which however showed an separated "aqua" window.

Therefore, I typed on the terminal,
/anaconda/bin/ipython notebook --pylab=inline
, instead of launching notebook with anaconda Launcher.app.