卡方检验是否为高斯函数?

时间:2019-06-14 21:22:03

标签: python-3.x chi-squared

我一直在尝试对高斯函数的情况实施卡方检验,但我不明白为什么python会将“ nan”作为输出。我该如何纠正我的代码,这样才不会发生?

def gaussian(sigma,mu, x):
    #===================================================#
    #Define and Compute Gaussian Function with the FWDM #
    #===================================================#   
    k = 1 / (sigma * math.sqrt(2*math.pi))
    s = -1.0 / (2 * sigma * sigma)
    def f(x):
        return k * math.exp(s * (x - mu)*(x - mu))



def Gaussian_Chi2_Generate(gaussian_observed_values = [], gaussian_expected_values = []):
    g = gaussian(sigma = np.mean(random.randint(-10,10)), mu = np.var(random.randint(-10,10)), x = random.randint(-10,10))
    gaussian_expected_values.append(g)
    gaussian_observed_values.append(g)

    t_g_s = 0
    g_o_v = np.array(gaussian_observed_values)
    g_e_v = np.array(gaussian_expected_values)
    g_o_v_f = g_o_v.astype(float)
    g_e_v_f = g_e_v.astype(float)
    z_g_o_v_f = zip(g_o_v.astype(float), g_e_v.astype(float))

    for o,e in z_g_o_v_f:
            t_g_s = (g_o_v_f - g_e_v_f)**2 /(g_e_v_f)
    dfg = len(g_o_v_f)-1
    print("Our Goodness of fit for our gaussian functions", stats.chi2.cdf(t_g_s,dfg))
    return t_g_s

0 个答案:

没有答案