amazon

29.8.14

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.

0 件のコメント:

コメントを投稿