Function Repository Resource:

SigmaConfidenceLevel

Source Notebook

Calculate the confidence level corresponding to width around the mean of a normal distribution

Contributed by: Julien Kluge

ResourceFunction["SigmaConfidenceLevel"][σ]

calculates the fraction of the normal distribution that falls within σ standard deviations of the mean.

Details and Options

ResourceFunction["SigmaConfidenceLevel"] automatically threads over lists.
ResourceFunction["SigmaConfidenceLevel"] evaluates to exact outputs for exact inputs and certain values.
The associated one-sided p-value can be calculated by using p=(1-ResourceFunction["SigmaConfidenceLevel"][σ])/2.

Examples

Basic Examples (2) 

Calculate the confidence level at one standard deviation:

In[1]:=
PercentForm@ResourceFunction["SigmaConfidenceLevel"][1.0]
Out[1]=

Calculate the p-value associated with 3σ:

In[2]:=
(1 - ResourceFunction["SigmaConfidenceLevel"][3.0])/2
Out[2]=

Scope (5) 

SigmaConfidenceLevel returns exact outputs for exact inputs:

In[3]:=
ResourceFunction["SigmaConfidenceLevel"][2]
Out[3]=

SigmaConfidenceLevel automatically threads over lists:

In[4]:=
ResourceFunction["SigmaConfidenceLevel"][{1, 2.0, Sqrt[2], 1000.0}]
Out[4]=

In physics, a discovery typically has to pass a five-σ of certainty test. Calculate the probability that a five-σ result is not a statistical fluctuation:

In[5]:=
PercentForm[ResourceFunction["SigmaConfidenceLevel"][5.0], 8]
Out[5]=

A p<0.05 test corresponds to a maximum displacement from mean of about 1.64 standard deviations:

In[6]:=
Quiet@NSolve[(1 - ResourceFunction["SigmaConfidenceLevel"][sigma])/
    2 == 1/20, sigma]
Out[6]=

SigmaConfidenceLevel can be defined as the integral between -σ and σ of the NormalDistribution with mean 0 and standard deviation 1:

In[7]:=
Subtract @@ CDF[NormalDistribution[0, 1], {\[Sigma], -\[Sigma]}] == ResourceFunction["SigmaConfidenceLevel"][\[Sigma]] /. \[Sigma] -> 5 // FullSimplify
Out[7]=

Applications (1) 

Fit the mean prediction bands of a linear model fit with a confidence level of 1σ, 2σ and 3σ:

In[8]:=
data = {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 4}};
fit = LinearModelFit[data, x, x];
Show[{
  Plot[Evaluate[
    fit["MeanPredictionBands", ConfidenceLevel -> ResourceFunction["SigmaConfidenceLevel"][N[#]]] & /@ Range[3]],
   {x, -1, 5},
   PlotStyle -> (GrayLevel /@ {0.0, 0.0, 0.4, 0.4, 0.8, 0.8}),
   Filling -> {1 -> {2}, 3 -> {4}, 5 -> {6}}
   ],
  ListPlot[data]
  }]
Out[10]=

Properties and Relations (1) 

SigmaConfidenceLevel handles infinities:

In[11]:=
ResourceFunction["SigmaConfidenceLevel"][{-Infinity, Infinity}]
Out[11]=

Neat Examples (1) 

The 5σ classification limit in physics for discoveries has a false-positive probability of approximately:

In[12]:=
((1 - ResourceFunction["SigmaConfidenceLevel"][5.0])/2) // N[#, 5] &
Out[12]=

Publisher

Julien Kluge

Version History

  • 1.0.0 – 23 April 2020

Related Resources

Author Notes

Julien Kluge Quantum Optical Metrology; Joint Lab Integrated Quantum Sensors Department of Physics Humboldt-Universität zu Berlin (julien@physik.hu-berlin.de)

License Information