help-calc

08 Numbers and Units

Weighted Median Calculator: Formula & Examples

Card 08-0879 · Updated · Standard formula, shown below

The calculator on this page is switched off while it is checked. The formula is below, and the worked example shows how to do the sum by hand.

Yes, you can calculate a weighted median by finding the value where the cumulative sum of weights reaches exactly half of the total weight. This calculator determines that specific data point from your provided values and their corresponding importance scores.

Background

The standard median is a fundamental statistical measure used to find the middle value in a dataset. It is robust against outliers, meaning extreme high or low numbers do not skew the result as much as they do with the mean (average). However, the standard median assumes every data point contributes equally to the distribution. In many real-world scenarios, this assumption is false.

Consider a survey of customer satisfaction across three stores. Store A has 10 customers giving a rating of 5/10. Store B has 10 customers giving a rating of 8/10. Store C has 100 customers giving a rating of 2/10. If you simply take the median of the ratings {2, 5, 8}, you get 5. But this ignores the fact that 100 people experienced the lower rating. The weighted median accounts for these “sizes” or frequencies, providing a more accurate representation of the central tendency when data points have different levels of influence or frequency.

How It Works

Calculating the weighted median involves sorting your data and accumulating weights until you cross the halfway threshold. Unlike the arithmetic mean, which sums all values and divides by the count, the weighted median looks for the balance point of mass.

  1. Sort the Data: Arrange your data values in ascending order (from smallest to largest).
  2. Assign Weights: Ensure each value has an associated weight. These weights represent frequency, importance, or probability density.
  3. Calculate Total Weight: Sum all the individual weights to get $W_{total}$.
  4. Determine the Threshold: Divide the total weight by two ($W_{total} / 2$). This is the target cumulative weight.
  5. Accumulate Weights: Starting from the lowest value, add the weights sequentially. Keep a running total.
  6. Identify the Median: The first value at which the cumulative weight equals or exceeds the threshold is the weighted median.

If the cumulative weight hits the threshold exactly at a data point, that value is the median. If the threshold falls between two data points (i.e., the cumulative weight jumps from below 50% to above 50% after adding a specific weight), there are two common conventions:

  • Lower Convention: Take the value just before the jump.
  • Upper Convention: Take the value that caused the jump (this is the most common definition in statistics and what this calculator uses).

Formula

While there isn’t a single closed-form algebraic equation like $(a+b)/2$, the algorithmic formula is defined as follows:

Let $x_1, x_2, …, x_n$ be the sorted values.
Let $w_1, w_2, …, w_n$ be the corresponding non-negative weights.
Let $W = \sum_{i=1}^{n} w_i$ be the total weight.

The weighted median $M_w$ is the value $x_k$ such that:

$\sum_{i=1}^{k-1} w_i < \frac{W}{2}$ AND $\sum_{i=1}^{k} w_i \ge \frac{W}{2}$

Variable Definitions:

  • $x_i$ (Value): The numeric data point being measured. Unit depends on context (e.g., dollars, degrees, seconds).
  • $w_i$ (Weight): The relative importance or frequency of the value. Must be non-negative ($\ge 0$). Units cancel out in the ratio, so weights are dimensionless ratios.
  • $W$ (Total Weight): The sum of all weights.

Worked Example

Let’s use the default values provided in the calculator block above to demonstrate the calculation step-by-step.

Data Set:

  • Value 1: 10, Weight: 1
  • Value 2: 20, Weight: 1
  • Value 3: 30, Weight: 1

Step 1: Sort Values

The values are already sorted: 10, 20, 30.

Step 2: Calculate Total Weight

$W = 1 + 1 + 1 = 3$

Step 3: Determine Threshold

Threshold $= W / 2 = 3 / 2 = 1.5$

Step 4: Accumulate Weights

  • At Value 10: Cumulative Weight = 1. Is $1 \ge 1.5$? No.
  • At Value 20: Cumulative Weight = $1 + 1 = 2$. Is $2 \ge 1.5$? Yes.

Result:

The cumulative weight first meets or exceeds 1.5 at the value 20. Therefore, the weighted median is 20.

Note: In this specific equal-weight case, the weighted median matches the standard median. To see the difference, change the weights to 1, 1, and 10. The total weight becomes 12. The threshold is 6. The cumulative weight at 10 is 1, at 20 is 2, and at 30 is 12. Since 12 is the first time we exceed 6, the weighted median becomes 30, heavily pulling toward the most frequent value.

Common Problems and Misconceptions

Users often confuse the weighted median with the weighted mean. The weighted mean calculates the average by multiplying each value by its weight, summing them, and dividing by the sum of weights. The weighted mean is sensitive to outliers; if you have one extremely high value with a small but non-zero weight, it will pull the mean up. The weighted median is resistant to outliers because it only cares about the position in the sorted list, not the magnitude of the values beyond the median point.

Another common error is using negative weights. Weights must be non-negative. Negative weights imply “anti-influence,” which breaks the logical foundation of a cumulative distribution function used to find the median. If you have data that requires subtraction, you likely need a different statistical model entirely.

Rounding errors can also occur if weights are very small decimals. It is best practice to work with integer weights or ensure your calculator handles floating-point precision accurately. The calculator provided here uses standard double-precision arithmetic to minimize rounding issues.

Comparisons

Feature Arithmetic Mean Standard Median Weighted Median
Sensitivity to Outliers High Low Low
Handles Unequal Frequency Yes (via weights) No Yes
Complexity Simple Simple Moderate
Best Use Case Normal distributions Skewed distributions (equal freq) Skewed distributions (unequal freq)

When to Use It

You should use the weighted median when:

  • Analyzing Survey Data: Respondents may belong to different demographic groups with different population sizes. You want the median opinion of the general population, not just the median respondent.
  • Financial Analysis: Calculating the median house price in a neighborhood where some houses sell frequently and others rarely. The volume of sales (weight) matters more than the mere existence of the listing.
  • Supply Chain: Determining the typical delivery time when some routes are taken daily (high weight) and others monthly (low weight).
  • Survival Analysis: Finding the median survival time where patients drop out of a study at different rates (censored data often requires weighted approaches).

Frequently Asked Questions

Can the weighted median be higher than the highest value?

No. By definition, the weighted median must be one of the values present in your dataset. It cannot exceed the maximum value or fall below the minimum value, regardless of how large the weights are.

What if two weights are zero?

Weights of zero indicate that a data point should be ignored entirely. If you assign a weight of 0 to a value, it effectively removes that value from the calculation. Ensure your remaining weights sum to greater than zero, or the calculation will fail.

Is the weighted median always one of the input values?

In the discrete case (which this calculator handles), yes. The weighted median is selected from the existing data points. In continuous probability distributions, the weighted median is the value $x$ where the integral of the probability density function from $-\infty$ to $x$ equals 0.5. For discrete datasets, this translates to picking the specific entry where the cumulative weight crosses 50%.

How do I handle tied values?

If multiple entries have the same value, you should sum their weights together before performing the cumulative check. For example, if Value 10 appears twice with weights 2 and 3, treat it as a single entry of Value 10 with Weight 5. The calculator accepts lists of values and weights; ensure they correspond correctly index-by-index.

Does the order of input matter?

No. The calculator automatically sorts the values in ascending order before calculating the cumulative weights. You can enter your data in any random order, and the result will be identical.

Related

Formula used
in v | Value 1 | - | 10 | -1000000 | 1000000
in w | Weight 1 | - | 1 | 0 | 1000000
in v2 | Value 2 | - | 20 | -1000000 | 1000000
in w2 | Weight 2 | - | 1 | 0 | 1000000
in v3 | Value 3 | - | 30 | -1000000 | 1000000
in w3 | Weight 3 | - | 1 | 0 | 1000000
list vals | All Values | 10, 20, 30
list wtss | All Weights | 1, 1, 1
out med | Weighted Median | - | round(median(vals), 4) | 4

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More on this shelf

The whole Numbers and Units shelf →