Jul-23-2019, 04:35 PM
Hello,
I have been given some python code that I am trying to understand, and I am not a python user (I know some R, but zero python). I would really appreciate a 'plain English' reading of what the code is doing exactly, so I can make modifications or be able to explain it to others.
Here is the code:
I have been given some python code that I am trying to understand, and I am not a python user (I know some R, but zero python). I would really appreciate a 'plain English' reading of what the code is doing exactly, so I can make modifications or be able to explain it to others.
Here is the code:
def calcPrior(n, N): l = [N/i for i in range(1, N+1)] tot = sum(l) l = [i/tot for i in l] return l[int(n*N)] def calcL(s, initialF, finalF): N = 180 eps = 0.0005 mu = initialF sd = (mu*(1-mu))**0.5#/N for i in range(50): old_mu = mu mu = (1+s)*mu/(1+s*mu) sd = (1.0/N)*(mu*(1-mu)) + (((1+s)/(1+s*old_mu))**2)*sd prob = quad(norm(loc=mu, scale=sd).pdf, finalF-eps, finalF+eps) return prob[0]*calcPrior(initialF, N) p value of s=0.5 p = 1-chi2.cdf(2*(np.log10(calcL(0.5, start, 1))-np.log10(findS(0, start, 1))), 1)The last line is especially important, thanks for your time.