Search code examples
pythonscipynormal-distribution

cdf for 'trimmed' normal distribution


I have a left-censored normal distribution: it is 'flat' (equal to zero) up to mu, and then normal.

I know how to calculate cdf for a standard normal distribution:

from scipy.stats import norm
norm(mu, sigma).cdf(1)

for instance. But of course that is not correct for this 'truncated' version. Neither is correct:

norm(mu, sigma).cdf(1) - norm(mu, sigma).cdf(0)

because I should adjust values proportionally to the fact that the left tail is non-existent. What is the right way to do it?


Solution

  • As suggested in the comment,

    from scipy.stats import truncnorm
    truncnorm(loc=1, scale=2, a=0, b=np.inf).cdf(x)
    

    Where

    • loc - mean
    • scale - standard deviation
    • a - left truncation point
    • b - right truncation point
    • x - evaluation point