0

I need to calculate a CDF for a regression.I have N observations, I need to reestimate coefficients(beta) in a joint distribution. Yobs is my observations and Y is calculated by X(matrix of predctors)* array of coefficients(betas)

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

Where am I wrong? I think CDF is wrong since I haven't determined the arg, but how can I define? can I simply use?

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
Jongware
  • 22,200
  • 8
  • 54
  • 100
elnaz irannezhad
  • 319
  • 2
  • 3
  • 12
  • What isn't working, are you getting an error or is the code working but the result is incorrect? I'm assuming this is part of a larger script where X is defined outside the function, is that so? – juanpa.arrivillaga Jun 10 '16 at 06:32
  • Yes, it works, but I am not sure about the result. Do you think am I right? P.S. correct, X matrix has been defined outside the function. – elnaz irannezhad Jun 10 '16 at 07:30
  • (FYI, the tag [tag:pdf] is for Adobe's Portable Document Format, and not related to your question.) – Jongware Jun 10 '16 at 10:20

0 Answers0