St · Statistics & Probability

How to Find the Median of Discrete and Continuous Variables

Published By the 9to5Science editorial team

At a glance

  1. 1. Write the CDF

    Use F(x) = P(X ≤ x), which includes both probability accumulated below x and any probability at x.

  2. 2. Find the halfway point

    Locate where the cumulative probability reaches or passes one half.

  3. 3. Check both sides

    A median must leave at least half the probability at or below it and at least half at or above it.

  4. 4. Handle jumps or flats

    For discrete or mixed laws, account for jumps; for continuous laws, a flat CDF can allow multiple medians.

The same definition of a median works for discrete, continuous, and mixed random variables. The calculation differs because a discrete distribution has jumps in its cumulative probability, while a continuous distribution usually accumulates probability smoothly.

The most reliable method is to use the cumulative distribution function (CDF). It also handles cases where a distribution has more than one median.

The median definition

The CDF of a random variable XX is F(x)=P(X≤x)F(x)=P(X\le x). A number mm is a median if

P(X≤m)≥12andP(X≥m)≥12.P(X\le m)\ge \frac12 \quad\text{and}\quad P(X\ge m)\ge \frac12.

Equivalently, using the left-hand limit F(m−)=P(X<m)F(m-)=P(X<m),

F(m−)≤12≤F(m).F(m-)\le \frac12\le F(m).

This form matters when XX can equal mm with positive probability. A common convention is to report the lower 0.5-quantile, inf⁡{x:F(x)≥1/2}\inf\{x:F(x)\ge 1/2\}. When the median is not unique, this convention picks one particular median.

Finding a median for a discrete variable

For a discrete variable, list the possible values in increasing order and add their probabilities cumulatively. The first value where the cumulative probability reaches or exceeds 0.50.5 is the lower 0.5-quantile. Check the median conditions if you need to describe all medians rather than report one.

For example, suppose XX has this distribution:

xxP(X=x)P(X=x)Cumulative probability F(x)F(x)
−1-10.200.200.200.20
000.350.350.550.55
220.450.451.001.00

The cumulative probability first reaches 0.50.5 at x=0x=0, so the lower 0.5-quantile is 00. It is a median because P(X≤0)=0.55P(X\le0)=0.55 and P(X≥0)=0.80P(X\ge0)=0.80, both at least one half.

A discrete distribution can have an interval of medians. For example, if P(X=0)=P(X=1)=0.5P(X=0)=P(X=1)=0.5, every mm between 0 and 1 satisfies both median conditions. The lower-quantile convention reports 0, but it is not the only median under the two-sided definition.

Finding a median for a continuous variable

For a continuous variable with density ff, calculate the CDF by integrating the density. A median usually solves F(m)=0.5F(m)=0.5, or equivalently, the area under the density to the left of mm is one half.

For an exponential random variable with rate 22, the CDF for x≥0x\ge0 is

F(x)=1−e−2x.F(x)=1-e^{-2x}.

Set this equal to one half and solve:

1−e−2m=12,e−2m=12,m=ln⁡22≈0.3466.\begin{aligned} 1-e^{-2m}&=\frac12,\\ e^{-2m}&=\frac12,\\ m&=\frac{\ln 2}{2}\approx0.3466. \end{aligned}

Thus the median is about 0.34660.3466 in the same units as XX. If the CDF is flat across a range at probability 0.50.5, every point in that range is a median; strict increase is not required for a continuous variable.

What if the variable is mixed?

A mixed variable has both point probabilities and a continuous part. Use the same CDF rule: include the point masses as jumps, and add the continuous probability accumulated between them.

Suppose P(X=0)=0.4P(X=0)=0.4, and with probability 0.60.6, XX is uniform on [0,2][0,2]. For 0≤x≤20\le x\le2,

F(x)=0.4+0.6x2=0.4+0.3x.F(x)=0.4+0.6\frac{x}{2}=0.4+0.3x.

The median is where this reaches 0.50.5:

0.4+0.3m=0.5⟹m=13.0.4+0.3m=0.5 \quad\Longrightarrow\quad m=\frac13.

At this value, half the total probability is at or below mm and half is at or above it. The atom at zero creates a jump in the CDF, but it does not change the method.

Common mistakes

  • Using the density value as the median. A median is about cumulative probability, not the value of the density f(m)f(m). Integrate the density to obtain F(m)F(m).
  • Treating a discrete jump like a smooth crossing. For discrete variables, FF can jump from below 0.50.5 to above it. The median may be the value at that jump; you do not need an outcome with cumulative probability exactly 0.50.5.
  • Assuming there is always one median. Flat regions or probability split evenly across separated points can produce multiple medians. State which convention you use if you need one number.
  • Confusing a population median with a sample convention. For an even-sized data set, the sample median is commonly defined as the average of the two middle observations. A random variable’s median is instead defined by its probability on either side, so that average need not be a possible value of the variable.

References

  1. George Casella and Roger L. Berger, Statistical Inference, 2nd ed.

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.