# iqr

Interquartile range of probability distribution

## Description

example

r = iqr(pd) returns the interquartile range of the probability distribution pd. The scalar value of r is the difference between the values of the 75th and 25th percentiles of the probability distribution.

## Examples

collapse all

Create a standard normal distribution object with the mean, $\mu$, equal to 0 and the standard deviation, $\sigma$, equal to 1.

pd = makedist('Normal','mu',0,'sigma',1);

Compute the interquartile range of the standard normal distribution.

r = iqr(pd)
r = 1.3490

The returned value is the difference between the 75th and the 25th percentile values for the distribution. This is equivalent to computing the difference between the inverse cumulative distribution function (icdf) values at the probabilities y equal to 0.75 and 0.25.

r2 = icdf(pd,0.75) - icdf(pd,0.25)
r2 = 1.3490

Load the sample data. Create a vector containing the first column of students’ exam grade data.

Create a normal distribution object by fitting it to the data.

pd = fitdist(x,'Normal')
pd =
NormalDistribution

Normal distribution
mu = 75.0083   [73.4321, 76.5846]
sigma =  8.7202   [7.7391, 9.98843]

Compute the interquartile range of the fitted distribution.

r = iqr(pd)
r = 11.7634

The returned result indicates that the difference between the 75th and 25th percentile of the students’ grades is 11.7634.

Use icdf to determine the 75th and 25th percentiles of the students’ grades.

y = icdf(pd,[0.25,0.75])
y = 1×2

69.1266   80.8900

Calculate the difference between the 75th and 25th percentiles. This yields the same result as iqr.

y(2)-y(1)
ans = 11.7634

Use boxplot to visualize the interquartile range.

boxplot(x)

The top line of the box shows the 75th percentile, and the bottom line shows the 25th percentile. The center line shows the median, which is the 50th percentile.

## Input Arguments

collapse all

Probability distribution, specified as one of the probability distribution objects in this table.

Distribution ObjectFunction or App to Create Probability Distribution Object
BetaDistributionmakedist, fitdist, Distribution Fitter
BinomialDistributionmakedist, fitdist, Distribution Fitter
BirnbaumSaundersDistributionmakedist, fitdist, Distribution Fitter
BurrDistributionmakedist, fitdist, Distribution Fitter
ExponentialDistributionmakedist, fitdist, Distribution Fitter
ExtremeValueDistributionmakedist, fitdist, Distribution Fitter
GammaDistributionmakedist, fitdist, Distribution Fitter
GeneralizedExtremeValueDistributionmakedist, fitdist, Distribution Fitter
GeneralizedParetoDistributionmakedist, fitdist, Distribution Fitter
HalfNormalDistributionmakedist, fitdist, Distribution Fitter
InverseGaussianDistributionmakedist, fitdist, Distribution Fitter
KernelDistributionfitdist, Distribution Fitter
LogisticDistributionmakedist, fitdist, Distribution Fitter
LoglogisticDistributionmakedist, fitdist, Distribution Fitter
LognormalDistributionmakedist, fitdist, Distribution Fitter
LoguniformDistributionmakedist
MultinomialDistributionmakedist
NakagamiDistributionmakedist, fitdist, Distribution Fitter
NegativeBinomialDistributionmakedist, fitdist, Distribution Fitter
NormalDistributionmakedist, fitdist, Distribution Fitter
PiecewiseLinearDistributionmakedist
PoissonDistributionmakedist, fitdist, Distribution Fitter
RayleighDistributionmakedist, fitdist, Distribution Fitter
RicianDistributionmakedist, fitdist, Distribution Fitter
StableDistributionmakedist, fitdist, Distribution Fitter
tLocationScaleDistributionmakedist, fitdist, Distribution Fitter
TriangularDistributionmakedist
UniformDistributionmakedist
WeibullDistributionmakedist, fitdist, Distribution Fitter

## Version History

Introduced in R2013a