pythonscipystatisticsnormal-distributionscipy.stats

How to find the argument of scipy.stats.exponnorm given certain parameters and output


My problem is as follows: Consider two PDFs - one normal distribution (let's call it norm) , and one exponentially modified normal distribution (exponorm). Given a point X, F is the fractional ratio of the area of norm and the area of exponorm between point X and infinity. I.e. F = (1 - exponorm.CDF(X))/(1 - norm.CDF(X)) .

I am specifically looking at the scipy function https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.exponnorm.html, and trying to work out how I can input a value for F, as well as all other parameters norm and exponorm require, and then output a value for K as defined in the link.

Tl;dr how do I extract an argument for a PDF given a value for the CDF and all other parameters.

Thanks in advance :)


Solution

  • how I can input a value for F, as well as all other parameters norm and exponorm require, and then output a value for K as defined in the link.

    IIUC, in the first question, you want to output the K shape parameter of exponnorm given the values of all other variables.

    That is, you want to solve the equation "F = (1 - exponorm.CDF(X))/(1 - norm.CDF(X))" for "K", which is a parameter of "exponnorm" (not shown explicitly).

    Recognizing that the complement of the CDF is the SF (survival function), you want to find the value of K such that the function f below:

    from scipy import stats
    def f(K, x, F):
        exponnorm = stats.exponnorm(K=K)
        norm = stats.norm()  # assuming standard normal
        return exponnorm.sf(x)/norm.sf(x) - K
    

    returns zero when called like f(K, x, F).

    You have a scalar-valued function of a scalar unknown, so you can use scipy.optimize.root to solve it. We know that K must be greater than zero, and we assume a large upper bound on K.

    from scipy import optimize
    # define "all other parameters"
    x = 1.5
    F = 2
    bracket=(1e-8, 1e8)  # assume K is within this bracket
    res = optimize.root_scalar(f, args=(x, F), bracket=bracket)
    res.root  # 13.385243944296551
    f(res.root, x, F)  # 0    
    

    I'm not sure about the second question because "a PDF" and "the CDF" are ambiguous, but it still sounds like you're trying to solve a scalar-valued function of one variable, so you can adapt the approach above as needed.