How to Find the Median of Discrete and Continuous Variables
At a glance
- 1. Write the CDF
Use F(x) = P(X ≤ x), which includes both probability accumulated below x and any probability at x.
- 2. Find the halfway point
Locate where the cumulative probability reaches or passes one half.
- 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. 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 is . A number is a median if
Equivalently, using the left-hand limit ,
This form matters when can equal with positive probability. A common convention is to report the lower 0.5-quantile, . 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 is the lower 0.5-quantile. Check the median conditions if you need to describe all medians rather than report one.
For example, suppose has this distribution:
| Cumulative probability | ||
|---|---|---|
The cumulative probability first reaches at , so the lower 0.5-quantile is . It is a median because and , both at least one half.
A discrete distribution can have an interval of medians. For example, if , every 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 , calculate the CDF by integrating the density. A median usually solves , or equivalently, the area under the density to the left of is one half.
For an exponential random variable with rate , the CDF for is
Set this equal to one half and solve:
Thus the median is about in the same units as . If the CDF is flat across a range at probability , 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 , and with probability , is uniform on . For ,
The median is where this reaches :
At this value, half the total probability is at or below 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 . Integrate the density to obtain .
- Treating a discrete jump like a smooth crossing. For discrete variables, can jump from below to above it. The median may be the value at that jump; you do not need an outcome with cumulative probability exactly .
- 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
- 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.