iqr

Class: prob.TruncatableDistribution
Package: prob

Interquartile range of probability distribution object

Syntax

r = iqr(pd)

Description

r = iqr(pd) returns the interquartile range r of the probability distribution pd.

Input Arguments

expand all

pd — Probability distributionprobability distribution object

Probability distribution, specified as a probability distribution object. Create a probability distribution object with specified parameter values using makedist. Alternatively, for fittable distributions, create a probability distribution object by fitting it to data using fitdist or the Distribution Fitting app.

Output Arguments

expand all

r — Interquartile rangescalar value

Interquartile range of the probability distribution, returned as a scalar value. The value of r is the difference between the values of the 75th and 25th percentile of the probability distribution.

Examples

expand all

Interquartile Range of a Fitted Distribution

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

load examgrades;
x = grades(:,1);

Crete 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 =
   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.

Was this topic helpful?