Tutorials › High-Dimensional Genomic Data Analysis › The Weighted Median Estimator

Mendelian Randomization · Tutorial 676 of 795

The Weighted Median Estimator

Learn how to calculate and interpret the weighted median MR estimate, and why its consistency can tolerate invalid instruments when valid variants contribute more than half the weight.

Advanced 12 min read

What You'll Learn

  • Define a weighted median of variant-specific causal ratio estimates.
  • Derive the weighted median as a minimizer of weighted absolute deviations.
  • Calculate ratio estimates, approximate their standard errors, and form inverse-variance weights.
  • Explain the more-than-half-valid-weight condition for consistency.
  • Compare weighted median estimates with IVW and MR-Egger, including important limitations.
  • Identify diagnostics and assumptions that can undermine a weighted median analysis.

Why Use a Weighted Median?

Mendelian randomization (MR) uses genetic variants as instruments to estimate the effect of an exposure on an outcome. A variant-specific ratio estimate divides its estimated association with the outcome by its estimated association with the exposure. If a variant is a valid instrument, its ratio estimates the same causal effect as other valid instruments. But invalid instruments can have ratio estimates that do not target that effect, for example because the variant affects the outcome through a pathway other than the exposure.

The inverse-variance weighted (IVW) estimator combines ratio estimates using their precision. This can be efficient when its assumptions hold, but a small number of precise invalid instruments can pull a weighted mean away from the causal effect. The weighted median offers a different combination rule: it selects the middle of the ratio estimates after accounting for their weights. Its key robustness property is that it can remain consistent when valid instruments contribute more than half of the total weight, even if some other instruments are invalid.

Definition: For variant \(j\), let \(\hat{\gamma}_j\) be its estimated association with the exposure and \(\hat{\Gamma}_j\) its estimated association with the outcome. Its ratio estimate is \(\hat{\beta}_j=\hat{\Gamma}_j/\hat{\gamma}_j\). Given positive weights \(w_j\), a weighted median is a value \(m\) such that at least half of the total weight lies at or below \(m\), and at least half lies at or above \(m\). The total weight is \(W=\sum_{j=1}^{K}w_j\).

One computational convention is to sort the ratio estimates from smallest to largest and take the first estimate whose cumulative weight is at least \(W/2\). This gives a weighted median. If cumulative weight equals exactly half at a gap between two estimates, any value in that gap satisfies the definition; software may report an endpoint or interpolate. The convention should be made clear when reproducing a calculation.

Model, Weights, and Assumptions

A useful population-level representation is \(\Gamma_j=\beta\gamma_j+\alpha_j\), where \(\gamma_j\) and \(\Gamma_j\) are the true variant-exposure and variant-outcome associations, \(\beta\) is the causal effect of interest, and \(\alpha_j\) is a direct effect of variant \(j\) on the outcome not mediated by the exposure. A valid instrument has \(\alpha_j=0\), so its population ratio is \(\Gamma_j/\gamma_j=\beta\), provided \(\gamma_j\ne0\). An invalid instrument can have \(\alpha_j\ne0\), and its ratio need not equal \(\beta\).

The usual ratio-estimation framework also requires that the variant associations be aligned to the same effect allele, as in allele harmonization, and that the exposure and outcome associations refer to compatible populations and scales. The simple formulas below presume variants are independent, or that dependence has otherwise been handled appropriately. With correlated variants, treating each ratio as independent and assigning separate inverse-variance weights can misstate both the weighting and uncertainty.

A common choice is inverse-variance weighting, \(w_j=1/\widehat{\mathrm{Var}}(\hat{\beta}_j)\). When exposure-association uncertainty is negligible and the exposure and outcome estimates are independent, a first-order approximation gives \(\widehat{\mathrm{Var}}(\hat{\beta}_j)\approx SE(\hat{\Gamma}_j)^2/\hat{\gamma}_j^2\). If exposure-association uncertainty is not negligible, a delta-method approximation for independent estimates includes it:

$$ \widehat{\mathrm{Var}}(\hat{\beta}_j) \approx \frac{SE(\hat{\Gamma}_j)^2}{\hat{\gamma}_j^2} + \frac{\hat{\Gamma}_j^2 SE(\hat{\gamma}_j)^2}{\hat{\gamma}_j^4}. $$

This approximation follows by applying the first-order variance rule to the ratio function \(g(\Gamma,\gamma)=\Gamma/\gamma\), whose derivatives are \(1/\gamma\) and \(-\Gamma/\gamma^2\). If the two association estimates are correlated, a covariance term is also needed. The approximation can be poor when \(\hat{\gamma}_j\) is close to zero; weak-instrument problems can make ratio estimates highly unstable, and the weighted median does not by itself eliminate that problem.

Worked Example: Calculating Ratio Weights

Suppose one hypothetical variant has \(\hat{\gamma}=0.080\) exposure units per allele, \(SE(\hat{\gamma})=0.010\), \(\hat{\Gamma}=0.024\) outcome units per allele, and \(SE(\hat{\Gamma})=0.006\). Assume the two estimates are independent. The ratio estimate is

$$ \hat{\beta}=\frac{0.024}{0.080}=0.300 \quad\text{outcome units per exposure unit.} $$

Including uncertainty in both associations, the delta-method variance is

$$ \widehat{\mathrm{Var}}(\hat{\beta}) \approx \frac{0.006^2}{0.080^2} + \frac{0.024^2(0.010^2)}{0.080^4} =0.005625+0.001406 =0.007031. $$

Thus \(SE(\hat{\beta})\approx\sqrt{0.007031}=0.08385\), and the corresponding inverse-variance weight is approximately \(1/0.007031=142.2\). This is a first-order approximation, not a guarantee that the ratio has a normal sampling distribution. In particular, a weak exposure association can produce a skewed or otherwise poorly approximated ratio distribution.

Deriving the Weighted Median

The weighted median is not obtained by averaging the ratios. It is the value that minimizes the total weighted absolute distance from the observed ratios. This gives both a derivation and a practical characterization.

$$ L(m)=\sum_{j=1}^{K} w_j|\hat{\beta}_j-m|. $$

To see why a weighted median minimizes \(L(m)\), consider a value \(m\) that is not equal to any observed ratio. As \(m\) moves slightly to the right, each ratio below \(m\) contributes slope \(+w_j\) to \(L\), while each ratio above \(m\) contributes slope \(-w_j\). Therefore the slope is the total weight below \(m\) minus the total weight above \(m\). If more than half the weight is below \(m\), the slope is positive, so moving left reduces the loss. If more than half is above \(m\), the slope is negative, so moving right reduces the loss. A minimum is reached where neither side has more than half the total weight. At an observed ratio, the same conclusion follows using the left and right slopes: the point minimizes the loss when the weight on each side is no greater than \(W/2\). That is exactly the weighted-median condition.

This differs from the weighted mean, which minimizes a weighted sum of squared deviations. Squared deviations can give a distant ratio substantial influence; absolute deviations increase linearly with distance. The median’s resistance to distant values is the basis of its robustness, but it does not mean that every invalid instrument is harmless.

Worked Example: Finding a Weighted Median

Consider four hypothetical ratio estimates with standard errors and inverse-variance weights as shown. The units of each ratio are outcome units per exposure unit.

VariantRatio estimateStandard errorWeight \(1/SE^2\)Cumulative weight
A0.100.2002525
B0.200.115575100
C0.250.100100200
D0.400.141450250

For example, variant C has weight \(1/(0.100)^2=100\). The total weight is \(W=25+75+100+50=250\), so half is \(125\). After sorting the ratios, cumulative weight is 100 at 0.20 and 200 at 0.25. The first ratio whose cumulative weight reaches at least 125 is 0.25, so the weighted median is 0.25 outcome units per exposure unit.

Why More Than Half the Weight Can Protect Consistency

The weighted median’s central consistency condition is stronger than simply having a majority of the variants be valid. The relevant majority is a majority of the total weight. A few highly precise variants can contribute more weight than many imprecise variants.

Theorem: Suppose there is a common causal effect \(\beta\), and the valid variants’ ratio estimates converge to \(\beta\) as the association estimates become precise. Suppose also that the proportion of total weight assigned to valid variants is bounded above \(1/2\), and that the weights are positive and appropriately estimated. Then the weighted median converges to \(\beta\), even if the remaining variants are invalid and their ratios do not converge to \(\beta\).

Here is the key justification. Let the valid variants’ total weight be \(W_V\), and assume \(W_V>W/2\). For any fixed \(\epsilon>0\), consistency of the valid ratio estimates means that, with increasing precision, their weighted mass lies within \((\beta-\epsilon,\beta+\epsilon)\). The total invalid weight is \(W-W_V<W/2\). Consequently, the weight strictly below \(\beta-\epsilon\) cannot exceed the invalid weight, which is less than \(W/2\); likewise, the weight strictly above \(\beta+\epsilon\) is less than \(W/2\). A weighted median therefore cannot remain outside this interval. Since this holds for every \(\epsilon>0\), the weighted median converges to \(\beta\).

The statement is asymptotic: in a finite sample, valid ratio estimates fluctuate around \(\beta\), so the median need not equal the true effect. It also relies on valid ratios targeting the same effect and on the valid-weight majority persisting as the data become more precise. It is not enough that a majority of variants are valid by count if those variants carry less than half the weight.

Worked Example: A Majority of Valid Weight

Suppose five hypothetical ratio estimates have the following weights. Three variants are valid under the assumed MR model, while two are invalid. The valid estimates fluctuate around a causal effect of 0.20 outcome units per exposure unit.

VariantRatio estimateWeightStatus in this hypothetical example
A0.183Valid
B0.203Valid
C0.222Valid
D0.404Invalid
E0.502Invalid

The total weight is \(W=3+3+2+4+2=14\); the three valid variants carry weight \(3+3+2=8\), which exceeds half of 14, or 7. In increasing order, cumulative weights are 3 at 0.18, 6 at 0.20, and 8 at 0.22. Since the halfway point is 7, the weighted median is 0.22 outcome units per exposure unit. The two invalid variants have high ratios, but their combined weight is 6, less than half the total. In repeated samples with more precise associations, if the valid ratios concentrate around 0.20 and the valid-weight majority remains, the weighted median can converge to 0.20 even though this particular finite-sample estimate is 0.22.

Comparisons, Diagnostics, and Limitations

The IVW estimate is a weighted mean of the ratio estimates under the usual independent-variant formulation. It can be more statistically efficient when its identifying assumptions hold, but it is sensitive to sufficiently influential invalid ratios. The weighted median trades some efficiency for robustness to invalid instruments, provided the valid instruments have more than half the total weight. MR-Egger uses a regression model with an intercept and relies on different identifying assumptions; it can address some forms of directional pleiotropy, but its validity depends on assumptions such as InSIDE. Neither estimator is a universal correction for invalid instruments, and agreement between methods does not prove that their assumptions hold.

Several checks help reveal when a weighted median analysis may be unreliable:

  • Inspect weights and ratios together. A few variants may dominate total weight, so report or examine the share carried by each variant. A valid majority by variant count is not sufficient.
  • Check instrument strength and ratio stability. Very small estimated exposure associations can produce extreme ratios and unreliable delta-method standard errors. Earlier material on weak-instrument bias and F statistics is relevant to this assessment.
  • Examine heterogeneity and influential variants. Large dispersion among ratio estimates can signal pleiotropy, measurement problems, or model violations. Heterogeneity tests can flag incompatibility, but a low or high test statistic does not establish which instruments are valid.
  • Verify allele alignment and the data structure. A sign error from incorrect harmonization can reverse a ratio. Correlated variants require an approach that accounts for their dependence rather than naive independent weights.
  • Assess the robustness of the valid-weight condition. Validity is not directly observed. Sensitivity to removing or down-weighting influential variants can be informative, but no such check proves that more than half the weight is valid.

The method has further limitations. The weighted median is not protected if invalid instruments carry at least half the total weight. It can also be imprecise, especially when the ratio estimates are heterogeneous or when no single central value is well supported. Weak instruments, selection effects, winner’s curse, sample overlap, and violations of the MR assumptions can affect the component associations or their uncertainty. Inference for the weighted median needs an appropriate variance or resampling procedure; the standard error of one ratio, or an ordinary weighted-mean standard error, cannot simply be assigned to the median.

Common pitfall: “Most variants are valid, so the weighted median is consistent.” This is not the relevant condition: validity must account for more than half of the total weight, not merely more than half of the variant count. Conversely, a weighted median of 0.22 in a finite sample does not show that the true effect is exactly 0.22 or that invalid instruments are absent. The majority-weight condition is an assumption about which instruments are valid and how their weight behaves, not a conclusion obtained from the estimate alone.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. Three ratio estimates, in increasing order, are 0.1, 0.3, and 0.6, with weights 2, 5, and 3. What is their weighted median?
  2. There are 8 valid variants with total weight 40 and 5 invalid variants with total weight 45. Does the more-than-half-valid-weight condition hold?
  3. Why can a variant with a very small exposure association have an unstable ratio estimate?
  4. In the model \(\Gamma_j=\beta\gamma_j+\alpha_j\), what condition makes a variant valid, and what is its population ratio when \(\gamma_j\ne0\)?

Solutions. (1) The total weight is 10, so half is 5. Cumulative weight reaches 2 at 0.1 and 7 at 0.3; the weighted median is 0.3. (2) Total weight is \(40+45=85\), and half is 42.5. Valid weight 40 is less than 42.5, so the condition does not hold, despite having more valid variants by count. (3) The ratio divides the outcome association by the exposure association; a denominator near zero magnifies sampling variation and can produce highly variable, skewed ratios. (4) Validity requires \(\alpha_j=0\). Then \(\Gamma_j/\gamma_j=\beta\gamma_j/\gamma_j=\beta\), provided \(\gamma_j\ne0\).

Clinical Biostats