# norminv

Normal inverse cumulative distribution function

## Syntax

``x = norminv(p)``
``x = norminv(p,mu)``
``x = norminv(p,mu,sigma)``
``[x,xLo,xUp] = norminv(p,mu,sigma,pCov)``
``[x,xLo,xUp] = norminv(p,mu,sigma,pCov,alpha)``

## Description

example

````x = norminv(p)` returns the inverse of the standard normal cumulative distribution function (cdf), evaluated at the probability values in `p`.```
````x = norminv(p,mu)` returns the inverse of the normal cdf with mean `mu` and the unit standard deviation, evaluated at the probability values in `p`.```

example

````x = norminv(p,mu,sigma)` returns the inverse of the normal cdf with mean `mu` and standard deviation `sigma`, evaluated at the probability values in `p`.```
````[x,xLo,xUp] = norminv(p,mu,sigma,pCov)` also returns the 95% confidence bounds [`xLo`,`xUp`] of `x` when `mu` and `sigma` are estimates. `pCov` is the covariance matrix of the estimated parameters.```

example

````[x,xLo,xUp] = norminv(p,mu,sigma,pCov,alpha)` specifies the confidence level for the confidence interval [`xLo`,`xUp`] to be `100(1–alpha)`%.```

## Examples

collapse all

Find an interval that contains 95% of the values from a standard normal distribution.

`x = norminv([0.025 0.975])`
```x = 1×2 -1.9600 1.9600 ```

Note that the interval `x` is not the only such interval, but it is the shortest. Find another interval.

`xl = norminv([0.01 0.96])`
```xl = 1×2 -2.3263 1.7507 ```

The interval `x1` also contains 95% of the probability, but it is longer than `x`.

Compute the inverse of cdf values evaluated at the probability values in `p` for the normal distribution with mean `mu` and standard deviation `sigma`.

```p = 0:0.25:1; mu = 2; sigma = 1; x = norminv(p,mu,sigma)```
```x = 1×5 -Inf 1.3255 2.0000 2.6745 Inf ```

Compute the inverse of cdf values evaluated at 0.5 for various normal distributions with different mean parameters.

```mu = [-2,-1,0,1,2]; sigma = 1; x = norminv(0.5,mu,sigma)```
```x = 1×5 -2 -1 0 1 2 ```

Find the maximum likelihood estimates (MLEs) of the normal distribution parameters, and then find the confidence interval of the corresponding inverse cdf value.

Generate 1000 normal random numbers from the normal distribution with mean 5 and standard deviation 2.

```rng('default') % For reproducibility n = 1000; % Number of samples x = normrnd(5,2,[n,1]);```

Find the MLEs for the distribution parameters (mean and standard deviation) by using `mle`.

`phat = mle(x)`
```phat = 1×2 4.9347 1.9969 ```
```muHat = phat(1); sigmaHat = phat(2);```

Estimate the covariance of the distribution parameters by using `normlike`. The function `normlike` returns an approximation to the asymptotic covariance matrix if you pass the MLEs and the samples used to estimate the MLEs.

`[~,pCov] = normlike([muHat,sigmaHat],x)`
```pCov = 2×2 0.0040 -0.0000 -0.0000 0.0020 ```

Find the inverse cdf value at 0.5 and its 99% confidence interval.

`[x,xLo,xUp] = norminv(0.5,muHat,sigmaHat,pCov,0.01)`
```x = 4.9347 ```
```xLo = 4.7721 ```
```xUp = 5.0974 ```

`x` is the inverse cdf value using the normal distribution with the parameters `muHat` and `sigmaHat`. The interval `[xLo,xUp]` is the 99% confidence interval of the inverse cdf value evaluated at 0.5, considering the uncertainty of `muHat` and `sigmaHat` using `pCov`. The 99% confidence interval means the probability that `[xLo,xUp]` contains the true inverse cdf value is 0.99.

## Input Arguments

collapse all

Probability values at which to evaluate the inverse of the cdf (icdf), specified as a scalar value or an array of scalar values, where each element is in the range `[0,1]`.

If you specify `pCov` to compute the confidence interval `[xLo,xUp]`, then `p` must be a scalar value.

To evaluate the icdf at multiple values, specify `p` using an array. To evaluate the icdfs of multiple distributions, specify `mu` and `sigma` using arrays. If one or more of the input arguments `p`, `mu`, and `sigma` are arrays, then the array sizes must be the same. In this case, `norminv` expands each scalar input into a constant array of the same size as the array inputs. Each element in `x` is the icdf value of the distribution specified by the corresponding elements in `mu` and `sigma`, evaluated at the corresponding element in `p`.

Example: `[0.1,0.5,0.9]`

Data Types: `single` | `double`

Mean of the normal distribution, specified as a scalar value or an array of scalar values.

If you specify `pCov` to compute the confidence interval `[xLo,xUp]`, then `mu` must be a scalar value.

To evaluate the icdf at multiple values, specify `p` using an array. To evaluate the icdfs of multiple distributions, specify `mu` and `sigma` using arrays. If one or more of the input arguments `p`, `mu`, and `sigma` are arrays, then the array sizes must be the same. In this case, `norminv` expands each scalar input into a constant array of the same size as the array inputs. Each element in `x` is the icdf value of the distribution specified by the corresponding elements in `mu` and `sigma`, evaluated at the corresponding element in `p`.

Example: `[0 1 2; 0 1 2]`

Data Types: `single` | `double`

Standard deviation of the normal distribution, specified as a positive scalar value or an array of positive scalar values.

If you specify `pCov` to compute the confidence interval `[xLo,xUp]`, then `sigma` must be a scalar value.

To evaluate the icdf at multiple values, specify `p` using an array. To evaluate the icdfs of multiple distributions, specify `mu` and `sigma` using arrays. If one or more of the input arguments `p`, `mu`, and `sigma` are arrays, then the array sizes must be the same. In this case, `norminv` expands each scalar input into a constant array of the same size as the array inputs. Each element in `x` is the icdf value of the distribution specified by the corresponding elements in `mu` and `sigma`, evaluated at the corresponding element in `p`.

Example: `[1 1 1; 2 2 2]`

Data Types: `single` | `double`

Covariance of the estimates `mu` and `sigma`, specified as a 2-by-2 matrix.

If you specify `pCov` to compute the confidence interval `[xLo,xUp]`, then `p`, `mu`, and `sigma` must be scalar values.

You can estimate `mu` and `sigma` by using `mle`, and estimate the covariance of `mu` and `sigma` by using `normlike`. For an example, see Confidence Interval of Inverse Normal cdf Value.

Data Types: `single` | `double`

Significance level for the confidence interval, specified as a scalar in the range (0,1). The confidence level is `100(1–alpha)`%, where `alpha` is the probability that the confidence interval does not contain the true value.

Example: `0.01`

Data Types: `single` | `double`

## Output Arguments

collapse all

icdf values, evaluated at the probability values in `p`, returned as a scalar value or an array of scalar values. `x` is the same size as `p`, `mu`, and `sigma` after any necessary scalar expansion. Each element in `x` is the icdf value of the distribution specified by the corresponding elements in `mu` and `sigma`, evaluated at the corresponding element in `p`.

Lower confidence bound for `x`, returned as a scalar value or an array of scalar values. `xLo` has the same size as `x`.

Upper confidence bound for `x`, returned as a scalar value or an array of scalar values. `xUp` has the same size as `x`.

collapse all

### Normal Distribution

The normal distribution is a two-parameter family of curves. The first parameter, µ, is the mean. The second parameter, σ, is the standard deviation.

The standard normal distribution has zero mean and unit standard deviation.

The normal inverse function is defined in terms of the normal cdf as

`$x={F}^{-1}\left(p|\mu ,\sigma \right)=\left\{x:F\left(x|\mu ,\sigma \right)=p\right\},$`

where

`$p=F\left(x|\mu ,\sigma \right)=\frac{1}{\sigma \sqrt{2\pi }}{\int }_{-\infty }^{x}{e}^{\frac{-{\left(t-\mu \right)}^{2}}{2{\sigma }^{2}}}dt.$`

The result x is the solution of the integral equation where you supply the desired probability p.

## Algorithms

• The `norminv` function uses the inverse complementary error function `erfcinv`. The relationship between `norminv` and `erfcinv` is

`$\text{norminv}\left(p\right)=-\sqrt{2}\text{ }\text{erfcinv}\left(2p\right)$`

The inverse complementary error function `erfcinv(x)` is defined as `erfcinv(erfc(x))=x`, and the complementary error function `erfc(x)` is defined as

`$\text{erfc}\left(x\right)=1-\text{erf}\left(x\right)=\frac{2}{\sqrt{\pi }}{\int }_{x}^{\infty }{e}^{-{t}^{2}}dt.$`

• The `norminv` function computes confidence bounds for `x` by using the delta method. `norminv(p,mu,sigma)` is equivalent to `mu + sigma*norminv(p,0,1)`. Therefore, the `norminv` function estimates the variance of `mu + sigma*norminv(p,0,1)` using the covariance matrix of `mu` and `sigma` by the delta method, and finds the confidence bounds using the estimates of this variance. The computed bounds give approximately the desired confidence level when you estimate `mu`, `sigma`, and `pCov` from large samples.

## Alternative Functionality

• `norminv` is a function specific to normal distribution. Statistics and Machine Learning Toolbox™ also offers the generic function `icdf`, which supports various probability distributions. To use `icdf`, create a `NormalDistribution` probability distribution object and pass the object as an input argument or specify the probability distribution name and its parameters. Note that the distribution-specific function `norminv` is faster than the generic function `icdf`.

## References

[1] Abramowitz, M., and I. A. Stegun. Handbook of Mathematical Functions. New York: Dover, 1964.

[2] Evans, M., N. Hastings, and B. Peacock. Statistical Distributions. 2nd ed. Hoboken, NJ: John Wiley & Sons, Inc., 1993.

## Version History

Introduced before R2006a