Main Content

median

Median of probability distribution

Description

m = median(pd) returns the median m for the probability distribution pd

example

Examples

collapse all

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

load examgrades
x = grades(:,1);

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 median of the fitted distribution.

m = median(pd)
m = 
75.0083

For a symmetrical distribution such as the normal distribution, the median is equal to the mean, mu.

Create a Weibull probability distribution object.

pd = makedist('Weibull','A',5,'B',2)
pd = 
  WeibullDistribution

  Weibull distribution
    A = 5
    B = 2

Compute the median of the distribution.

m = median(pd)
m = 
4.1628

For a skewed distribution such as the Weibull distribution, the median and the mean may not be equal.

Calculate the mean of the Weibull distribution and compare it to the median.

mean = mean(pd)
mean = 
4.4311

The mean of the distribution is greater than the median.

Plot the pdf to visualize the distribution.

x = [0:.1:15];
pdf = pdf(pd,x);
plot(x,pdf)

Figure contains an axes object. The axes object contains an object of type line.

Input Arguments

collapse all

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

Distribution ObjectFunction or App Used 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

Output Arguments

collapse all

Median of the probability distribution, returned as a scalar value. The value of m is the 50th percentile of the probability distribution.

Extended Capabilities

Version History

Introduced in R2013a