def gof_test(fo, fe=None, alpha=0.05):
    '拟合优度检验\n    输入：\n    fo:观察频数\n    fe:期望频数，缺省为平均数\n    返回：\n    1: 样本与总体有差异\n    0：样本与总体无差异\n    例子：\n    gof_test(np.array([0.3,0.4,0.3])*222)\n    '
    import scipy.stats as stats
    fo = np.array(fo).flatten()
    C = len(fo)
    if (not fe):
        N = fo.sum()
        fe = np.array(([(N / C)] * C))
    else:
        fe = np.array(fe).flatten()
    chi_value = (((fo - fe) ** 2) / fe)
    chi_value = chi_value.sum()
    chi_value_fit = stats.chi2.ppf(q=(1 - alpha), df=(C - 1))
    if (chi_value > chi_value_fit):
        result = 1
    else:
        result = 0
    return result
拟合优度检验
输入：
fo:观察频数
fe:期望频数，缺省为平均数
返回：
1: 样本与总体有差异
0：样本与总体无差异
例子：
gof_test(np.array([0.3,0.4,0.3])*222)
def gof_test(fo, fe=None, alpha=0.05):
    '拟合优度检验\n    输入：\n    fo:观察频数\n    fe:期望频数，缺省为平均数\n    返回：\n    1: 样本与总体有差异\n    0：样本与总体无差异\n    例子：\n    gof_test(np.array([0.3,0.4,0.3])*222)\n    '
    import scipy.stats as stats
    fo = np.array(fo).flatten()
    C = len(fo)
    if (not fe):
        N = fo.sum()
        fe = np.array(([(N / C)] * C))
    else:
        fe = np.array(fe).flatten()
    chi_value = (((fo - fe) ** 2) / fe)
    chi_value = chi_value.sum()
    chi_value_fit = stats.chi2.ppf(q=(1 - alpha), df=(C - 1))
    if (chi_value > chi_value_fit):
        result = 1
    else:
        result = 0
    return result