normcdf

Normal cumulative distribution function

Description

example

p = normcdf(x) returns the cumulative distribution function (cdf) of the standard normal distribution, evaluated at the values in x.

p = normcdf(x,mu) returns the cdf of the normal distribution with mean mu and unit standard deviation, evaluated at the values in x.

example

p = normcdf(x,mu,sigma) returns the cdf of the normal distribution with mean mu and standard deviation sigma, evaluated at the values in x.

example

[p,pLo,pUp] = normcdf(x,mu,sigma,pCov) also returns the 95% confidence bounds [pLo,pUp] of p when mu and sigma are estimates. pCov is the covariance matrix of the estimated parameters.

[p,pLo,pUp] = normcdf(x,mu,sigma,pCov,alpha) specifies the confidence level for the confidence interval [pLo,pUp] to be 100(1–alpha)%.

example

___ = normcdf(___,'upper') returns the complement of the cdf, evaluated at the values in x, using an algorithm that more accurately computes the extreme upper-tail probabilities. 'upper' can follow any of the input arguments in the previous syntaxes.

Examples

collapse all

Compute the probability that an observation from a standard normal distribution falls on the interval [–1 1].

p = normcdf([-1 1]);
p(2)-p(1)
ans = 0.6827

About 68% of the observations from a normal distribution fall within one standard deviation of the mean 0.

Compute the cdf values evaluated at the values in x for the normal distribution with mean mu and standard deviation sigma.

x = [-2,-1,0,1,2];
mu = 2;
sigma = 1;
p = normcdf(x,mu,sigma)
p = 1×5

    0.0000    0.0013    0.0228    0.1587    0.5000

Compute the cdf values evaluated at zero for various normal distributions with different mean parameters.

mu = [-2,-1,0,1,2];
sigma = 1;
p = normcdf(0,mu,sigma)
p = 1×5

    0.9772    0.8413    0.5000    0.1587    0.0228

Find the maximum likelihood estimates (MLEs) of the normal distribution parameters, and then find the confidence interval of the corresponding 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 theMLEs 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 cdf value at zero and its 95% confidence interval.

[p,pLo,pUp] = normcdf(0,muHat,sigmaHat,pCov)
p = 0.0067
pLo = 0.0047
pUp = 0.0095

p is the cdf value using the normal distribution with the parameters muHat and sigmaHat. The interval [pLo,pUp] is the 95% confidence interval of the cdf evaluated at 0, considering the uncertainty of muHat and sigmaHat using pCov. The 95% confidence interval means the probability that [pLo,pUp] contains the true cdf value is 0.95.

Determine the probability that an observation from a standard normal distribution will fall on the interval [10,Inf].

p1 = 1 - normcdf(10)
p1 = 0

normcdf(10) is nearly 1, so p1 becomes 0. Specify 'upper' so that normcdf computes the extreme upper-tail probabilities more accurately.

p2 = normcdf(10,'upper')
p2 = 7.6199e-24

You can also use 'upper' to compute a right-tailed p-value.

Use the probability distribution function normcdf as a function handle in the chi-square goodness-of-fit test (chi2gof).

Test the null hypothesis that the sample data in the input vector x comes from a normal distribution with parameters µ and σ equal to the mean (mean) and standard deviation (std) of the sample data, respectively.

rng('default') % For reproducibility
x = normrnd(50,5,100,1);
h = chi2gof(x,'cdf',{@normcdf,mean(x),std(x)})
h = 0

The returned result h = 0 indicates that chi2gof does not reject the null hypothesis at the default 5% significance level.

Input Arguments

collapse all

Values at which to evaluate the cdf, specified as a scalar value or an array of scalar values.

If you specify pCov to compute the confidence interval [pLo,pUp], then x must be a scalar value.

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

Example: [-1,0,3,4]

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 [pLo,pUp], then mu must be a scalar value.

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

Example: [0 1 2; 0 1 2]

Data Types: single | double

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

If sigma is zero, then the output p is either 0 or 1. p is 0 if x is smaller than mu, or 1 otherwise.

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

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

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 [pLo,pUp], then x, 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 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

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

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

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

More About

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 cumulative distribution function (cdf) is

p=F(x|μ,σ)=1σ2πxe(tμ)22σ2dt,forx.

p is the probability that a single observation from a normal distribution with parameters μ and σ falls in the interval (-∞,x].

Algorithms

  • The normcdf function uses the complementary error function erfc. The relationship between normcdf and erfc is

    normcdf(x)=12erfc(x2).

    The complementary error function erfc(x) is defined as

    erfc(x)=1erf(x)=2πxet2dt.

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

Alternative Functionality

  • normcdf is a function specific to normal distribution. Statistics and Machine Learning Toolbox™ also offers the generic function cdf, which supports various probability distributions. To use cdf, 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 normcdf is faster than the generic function cdf.

  • Use the Probability Distribution Function app to create an interactive plot of the cumulative distribution function (cdf) or probability density function (pdf) for a probability distribution.

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.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a