Issue
In the Image below, for example, if I supply x as a percentage (like 68.2%), how do I get the values at 1Sigma and -1Sigma in Python?
Similarity, x = 100% should give me the extreme endpoints in the data distribution
The upper and lower bounds must be calculated about the mean of the data.
Any help would be appreciated. Thanks!
Solution
In your particular example, the answer is simple for a normal distribution with mean parameter (mu
/loc
) and standard deviation (std
/scale
).
upper, lower = loc-scale, loc+scale
so there is no need for elaborate Python code.
However, for a more general case where you wonder what quantiles (centered around the mean) enclose a certain probability p
taking values in [0,1]
, you can use SciPy's stats
library for the normal distribution. The code is:
from scipy.stats import norm
p = 0.68268949 # prob. in between [mu-std, mu+std]
loc = 0 # mu
scale = 1 # sigma/std
lower = norm.ppf((1-p)/2., loc, scale)
upper = norm.ppf((1+p)/2., loc, scale)
lower, upper
>(-0.9999999955839989, 0.9999999955839989)
After accounting for floating point arithmetic, this equates to [-1,1] = [loc-scale, loc+scale]
as expected.
Since the normal distribution density has support on the entire real line, only that exact interval, namely (-inf, +inf), encloses the probability of 1
. The code above produces that result consistently, since
p = 1.0
lower = norm.ppf((1-p)/2., loc, scale)
upper = norm.ppf((1+p)/2., loc, scale)
lower, upper
>(-inf, inf)
Answered By - 7shoe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.