计算连续回归的CDF

时间:2016-06-10 03:16:35

标签: python-3.x regression cdf

我需要为回归计算CDF。我有N个观察值,我需要在联合分布中重新估计系数(beta)。 Yobs是我的观察结果,Y由X(捕食者矩阵)*系数数组(beta)计算

def CDF(beta):
    Y = X.dot(beta)
    sigma = 0
    for n in range(0,N):
       sigma = sigma + (np.square(Yobs[n] - Y[n])) # summation of squarred of residuals
    SSR = sigma / N    # mu (mean or expectation)
    dof = N - P - 1    # degree of freedom
    var = sigma / dof  # the mean square of residuals
    PDF = np.zeros(N)
    CDF = np.zeros(N)  # I want to calculate the F(X < Yobs)
    for n in range (0,N):
       PDF[n] = (1/np.sqrt(2*np.pi*var))*np.exp(-SSR/(2*var))  # probability density function
       CDF[n] = integrate.quad(PDF, -np.inf , (Yobs+a))    # CDF
    return CDF

我哪里错了?我认为CDF是错误的,因为我还没有确定arg,但我该如何定义?我可以简单地使用吗?

from scipy.stats import norm
def CDF(beta):
    Y = X.dot(beta)
    sigma = 0
    for n in range(0,N):
       sigma = sigma + (np.square(Yobs[n] - Y[n])) # summation of squarred of residuals
    SSR = sigma / N    # mu (mean or expectation)
    dof = N - P - 1    # degree of freedom
    var = sigma / dof  # the mean square of residuals
    CDF = np.zeros(N)
    for n in range(0,N):           # I want to calculate the F(X < Yobs)
        CDF[n] = norm.cdf(Yobs[n],SSR,var)
    return CDF

0 个答案:

没有答案