# Calculating sigma from a probability distribution

I think this is a rather basic question, but I am not sure if there is already a function in Mathematica to do what I need or if I have to write the code myself.

I have this simple code that gives me the probability corresponding to any number of sigma in a normal distribution:

Manipulate[
Probability[μ - n*σ < x < μ + n*σ, x \[Distributed] NormalDistribution[μ, σ]],
{n, 1, 5}]


I would like to know how to do the inverse, that is getting the number of sigma corresponding to a given probability.

Thanks

• How about Sqrt InverseErf[p] – Simon Woods Sep 2 '16 at 10:12
• Then you should specify, how this probability is given? It is unclear. I can imagine that you might gave a distribution of points P(x) obtained from experiment. Is it the case? Then it is one scenario. You might have a plot of a probability drawn by somebody else with unknown parameters. It is another one. May be something else? – Alexei Boulbitch Sep 2 '16 at 10:15

You can come up with the answer given by @SimonWoods using Reduce or Solve. For example:

Reduce[
Probability[ μ - n σ < x < μ + n σ, x \[Distributed] NormalDistribution[ μ,σ]] == prob &&
0 <= prob <= 1 && n > 0, n, Reals
]


0 < prob < 1 && n == Sqrt InverseErf[prob]

## Update

You may also have used InverseCDF, since the Normal-PDF is a symmetric function we know:

\begin{align*} Pr(X\le \mu-n \sigma) &= \Phi(\mu-n \sigma)= \frac{1-p}{2}\\ \Rightarrow \mu-n \sigma &=\Phi^{-1}\left(\frac{1-p}{2}\right) \end{align*}

So we do:

InverseCDF[ NormalDistribution[μ,σ], (1-prob)/2 ]//Simplify


ConditionalExpression[ μ - Sqrt σ InverseErfc[ 1-prob ], -1<=prob<=1 ]

From this we immediately see that n = Sqrt InverseErfc[ 1 - prob ] where InverseErfc[1-prob] is equivalent to InverseErf[ prob ].

Just use Variance, even for a symbolic distribution, for instance:

Variance[MeixnerDistribution[a, b, m, d]]


(* 1/2 a^2 d Sec[b/2]^2 *)

and then take the square root.

If you want to get the probability from a threshold try this:

Module[{a,x,σ},
Manipulate[a=N[θ/((4*σ))];
Plot[PDF[NormalDistribution[0,σ],x],{x,-6,6},
ColorFunction->Function[x,If[Abs[x]>θ,Red,Green]],
ColorFunctionScaling->False,
Filling->Axis,
PlotRange->{{-6,6},{-0.01,0.45}},
PlotPoints->100,
Ticks->{
Union[{{-4*σ,"μ-4σ"},{-3*σ,"μ-3σ"},{-2*σ,"μ-2σ"},{-σ,"μ-σ"},{0,"μ"},{1*σ,"μ+σ"},{2*σ,"μ+2σ"},{3*σ,"μ+3σ"},{4*σ,"μ+4σ"}},{{θ,
Text[Style[("" """")┬θ,16,Red]],{0.6,0.01},
Directive[Red,Dashed]},{-θ,
Text[Style[("" """")┬("-""θ"),16,Red]],{0.6,0.01},
Directive[Red,Dashed]}}],None}],{{θ,1},0,4},{{a,1,"θ/σ"}},{{σ,1,"σ"},5,1,-0.1}]]