Skip to main content

rdrobust_core/
bwselect.rs

1//! Bandwidth selector -- port of `rdbwselect` (R rdbwselect.R), the orchestration
2//! that runs ~14 `rdrobust_bw` pilot fits and combines their `V`/`B`/`R` into the
3//! MSE/CER-optimal `h`/`b` bandwidths.
4//!
5//! Implemented: sharp/fuzzy, covariates, clusters, user weights, nn/hc0-hc3, all 10
6//! selectors + CER, and the prep options (`stdvars` rescaling, mass-point
7//! `M`-counts, `bwrestrict` range clamps, `bwcheck` floor). Implements the
8//! `vcache`: each side's 3 distinct `(o,nu)` V-fits are computed once and reused
9//! across the 7 pilots (`compute_vfit` + `assemble_from_vfit`), bit-identical to
10//! the per-call form.
11//!
12//! Parity gate: continuous `h`/`b` to ~1e-8 vs R, exact on the discrete selector
13//! branch.
14
15use crate::bw::{assemble_from_vfit, compute_vfit, VFit};
16use crate::{Kernel, Vce};
17
18/// Selected bandwidths: `h`/`b` for the left and right sides (common selectors
19/// duplicate the scalar into both sides).
20#[derive(Debug, Clone, Copy, PartialEq)]
21pub struct Bws {
22    /// Main bandwidth `h` (point-estimate window), left side.
23    pub h_l: f64,
24    /// Main bandwidth `h` (point-estimate window), right side.
25    pub h_r: f64,
26    /// Bias (pilot) bandwidth `b` (bias-correction window), left side.
27    pub b_l: f64,
28    /// Bias (pilot) bandwidth `b` (bias-correction window), right side.
29    pub b_r: f64,
30}
31
32/// Pilot kernel constant `C_c` (rdbwselect.R:265-274).
33fn c_c(kernel: Kernel) -> f64 {
34    match kernel {
35        Kernel::Epanechnikov => 2.34,
36        Kernel::Uniform => 1.843,
37        Kernel::Triangular => 2.576,
38    }
39}
40
41/// Sample standard deviation (ddof = 1), R `sd`.
42fn sd(x: &[f64]) -> f64 {
43    let n = x.len() as f64;
44    let mean = x.iter().sum::<f64>() / n;
45    (x.iter().map(|&v| (v - mean) * (v - mean)).sum::<f64>() / (n - 1.0)).sqrt()
46}
47
48/// R quantile type 2 on a SORTED slice (rdbwselect.R:117 `quantile(.,type=2)`):
49/// j = floor(n p) (1-based); if the fractional part g>0, return x_(j+1); if g==0,
50/// average x_(j) and x_(j+1).
51fn quantile_type2(sorted: &[f64], p: f64) -> f64 {
52    let n = sorted.len();
53    let np = n as f64 * p;
54    let j = np.floor() as usize; // 1-based floor index
55    let g = np - j as f64;
56    if g > 0.0 {
57        sorted[j.min(n - 1)] // x_(j+1), 0-based = sorted[j]
58    } else {
59        let lo = j.max(1) - 1; // x_(j)
60        let hi = j.min(n - 1); // x_(j+1)
61        0.5 * (sorted[lo] + sorted[hi])
62    }
63}
64
65/// Median of three finite values (R `median` of an odd count = the middle).
66fn median3(a: f64, b: f64, c: f64) -> f64 {
67    let mut v = [a, b, c];
68    v.sort_by(|x, y| x.total_cmp(y));
69    v[1]
70}
71
72/// Select the RD bandwidths `h` (point estimate) and `b` (bias correction) by
73/// running the ~14 `rdrobust_bw` pilot fits and combining their `V`/`B`/`R` per the
74/// chosen criterion (R rdbwselect.R). `x` must be sorted ascending when `vce = nn`.
75///
76/// # Arguments
77///
78/// - `y`, `x`: outcome and running variable (length n; `x` sorted for nn).
79/// - `t`: treatment take-up for a fuzzy design; `None` for sharp.
80/// - `z`, `dz`: covariates as a flat row-major `n x dz` slice, and the column count
81///   (`None` / `0` for no covariates).
82/// - `c`: the cutoff.
83/// - `p`: local-polynomial order of the point estimate (R default 1).
84/// - `q`: order of the bias-correction fit (R default 2, `q > p`).
85/// - `deriv`: derivative order of the estimand (R default 0).
86/// - `kernel`: weighting kernel (drives the pilot constants).
87/// - `vce`: variance estimator used in the pilot `V` (a `cluster` vector remaps it).
88/// - `nnmatch`: neighbors per side for nearest-neighbor variance.
89/// - `covs_drop_coll`: drop collinear covariate columns (ginv path) vs Cholesky.
90/// - `scaleregul`: regularization scale on the bias-bandwidth denominator (R default 1).
91/// - `bwselect`: selector name -- `mserd`, `msetwo`, `msesum`, `msecomb1`,
92///   `msecomb2`, `cerrd`, `certwo`, `cersum`, `cercomb1`, or `cercomb2`.
93/// - `cluster`: cluster ids; their presence remaps `vce` to CR1/CRV2/CRV3 and uses
94///   the cluster count in the CER rate.
95/// - `weights`: user weights `W` (multiplied into the kernel weights).
96/// - `masspoints`: `"adjust"` uses the unique-point count `M` for pilot rates and
97///   may auto-set `bwcheck`; `"off"` disables both.
98/// - `stdvars`: standardize `x`/`y`/`c` before selection, then rescale the chosen
99///   bandwidths by the `x` standard deviation.
100/// - `bwrestrict`: clamp each pilot stage to the side's support range.
101/// - `bwcheck`: floor the pilot and final bandwidths at the k-th nearest unique
102///   distance (`None` to disable).
103#[allow(clippy::too_many_arguments)]
104pub fn rdbwselect(
105    y: &[f64],
106    x: &[f64],
107    t: Option<&[f64]>,
108    z: Option<&[f64]>,
109    dz: usize,
110    c: f64,
111    p: usize,
112    q: usize,
113    deriv: usize,
114    kernel: Kernel,
115    vce: Vce,
116    nnmatch: usize,
117    covs_drop_coll: bool,
118    scaleregul: f64,
119    bwselect: &str,
120    cluster: Option<&[f64]>,
121    weights: Option<&[f64]>,
122    masspoints: &str,
123    stdvars: bool,
124    bwrestrict: bool,
125    bwcheck: Option<usize>,
126) -> Bws {
127    let n = y.len();
128
129    // stdvars (rdrobust.R:146-153): run selection on standardized x/y/c, then
130    // multiply the chosen bandwidths by x_sd at the end. No-op when stdvars=false.
131    let (x_sd, y_sd) = if stdvars { (sd(x), sd(y)) } else { (1.0, 1.0) };
132    let xv: Vec<f64> = x.iter().map(|v| v / x_sd).collect();
133    let yv: Vec<f64> = y.iter().map(|v| v / y_sd).collect();
134    let x = xv.as_slice();
135    let y = yv.as_slice();
136    let c = c / x_sd;
137
138    // BWp = min(sd(x), IQR_type2(x)/1.349); c_bw = C_c * BWp * N^(-1/5) (or M^-1/5).
139    let mut xs = x.to_vec();
140    xs.sort_by(|a, b| a.total_cmp(b));
141    let x_iq = quantile_type2(&xs, 0.75) - quantile_type2(&xs, 0.25);
142    let bwp = sd(x).min(x_iq / 1.349);
143
144    // split L (x<c) / R (x>=c), preserving (sorted) order; z flat row-major (n x dz)
145    let (mut yl, mut xl, mut tl, mut zl, mut cll, mut fwl) = (
146        Vec::new(),
147        Vec::new(),
148        Vec::new(),
149        Vec::new(),
150        Vec::new(),
151        Vec::new(),
152    );
153    let (mut yr, mut xr, mut tr, mut zr, mut clr, mut fwr) = (
154        Vec::new(),
155        Vec::new(),
156        Vec::new(),
157        Vec::new(),
158        Vec::new(),
159        Vec::new(),
160    );
161    for i in 0..n {
162        if x[i] < c {
163            yl.push(y[i]);
164            xl.push(x[i]);
165            if let Some(tt) = t {
166                tl.push(tt[i]);
167            }
168            if let Some(zz) = z {
169                zl.extend_from_slice(&zz[i * dz..i * dz + dz]);
170            }
171            if let Some(cc) = cluster {
172                cll.push(cc[i]);
173            }
174            if let Some(ww) = weights {
175                fwl.push(ww[i]);
176            }
177        } else {
178            yr.push(y[i]);
179            xr.push(x[i]);
180            if let Some(tt) = t {
181                tr.push(tt[i]);
182            }
183            if let Some(zz) = z {
184                zr.extend_from_slice(&zz[i * dz..i * dz + dz]);
185            }
186            if let Some(cc) = cluster {
187                clr.push(cc[i]);
188            }
189            if let Some(ww) = weights {
190                fwr.push(ww[i]);
191            }
192        }
193    }
194    let tl_opt = t.map(|_| tl.as_slice());
195    let tr_opt = t.map(|_| tr.as_slice());
196    let zl_opt = z.map(|_| zl.as_slice());
197    let zr_opt = z.map(|_| zr.as_slice());
198    let cll_opt = cluster.map(|_| cll.as_slice());
199    let clr_opt = cluster.map(|_| clr.as_slice());
200    let fwl_opt = weights.map(|_| fwl.as_slice());
201    let fwr_opt = weights.map(|_| fwr.as_slice());
202
203    // distinct-cluster counts per side -> the CER bandwidth factor (rdrobust.R:477)
204    let n_unique = |v: &[f64]| -> usize {
205        let mut s = v.to_vec();
206        s.sort_by(|a, b| a.total_cmp(b));
207        s.dedup();
208        s.len()
209    };
210    let g_l = cluster.map(|_| n_unique(&cll));
211    let g_r = cluster.map(|_| n_unique(&clr));
212    let range_l = (c - xs[0]).abs();
213    let range_r = (c - xs[n - 1]).abs();
214
215    // ----- masspoints / bwrestrict / bwcheck prep (spec 10; rdrobust.R:361-406) -----
216    let nl = xl.len();
217    let nr = xr.len();
218    let mp_on = masspoints == "check" || masspoints == "adjust";
219    let (m_l, m_r) = if mp_on || bwcheck.is_some() {
220        (n_unique(&xl), n_unique(&xr))
221    } else {
222        (nl, nr)
223    };
224    let m = m_l + m_r;
225    // auto-set bwcheck=10 when adjust detects mass points (>=20% duplicates)
226    let mut bwcheck_eff = bwcheck;
227    if mp_on {
228        let mass_l = 1.0 - m_l as f64 / nl as f64;
229        let mass_r = 1.0 - m_r as f64 / nr as f64;
230        if (mass_l >= 0.2 || mass_r >= 0.2) && masspoints == "adjust" && bwcheck.is_none() {
231            bwcheck_eff = Some(10);
232        }
233    }
234    // pilot bandwidth: M^(-1/5) under masspoints=adjust, else N^(-1/5)
235    let pilot_pow = if masspoints == "adjust" {
236        m as f64
237    } else {
238        n as f64
239    };
240    let mut c_bw = c_c(kernel) * bwp * pilot_pow.powf(-1.0 / 5.0);
241    // bwrestrict clamp bounds (reused for all per-stage clamps)
242    let bw_max_l = range_l;
243    let bw_max_r = range_r;
244    let bw_max = bw_max_l.max(bw_max_r);
245    if bwrestrict {
246        c_bw = c_bw.min(bw_max);
247    }
248    // bwcheck floor: distance to the k-th nearest unique point per side
249    let (bw_min_l, bw_min_r) = match bwcheck_eff {
250        Some(bc) => {
251            let mut ul = xl.clone();
252            ul.sort_by(|a, b| a.total_cmp(b));
253            ul.dedup();
254            let mut ur = xr.clone();
255            ur.sort_by(|a, b| a.total_cmp(b));
256            ur.dedup();
257            // X_uniq_l descending (closest to c last); X_uniq_r ascending
258            let bcl = bc.min(m_l);
259            let bcr = bc.min(m_r);
260            let lhs = (ul[ul.len() - bcl] - c).abs(); // descending[bcl-1] = ascending[len-bcl]
261            let rhs = (ur[bcr - 1] - c).abs();
262            (lhs, rhs)
263        }
264        None => (0.0, 0.0),
265    };
266    if bwcheck_eff.is_some() {
267        c_bw = c_bw.max(bw_min_l).max(bw_min_r);
268    }
269    // per-stage clamp helpers (no-ops when the option is off)
270    let restrict = |v: f64, bmax: f64| if bwrestrict { v.min(bmax) } else { v };
271    let floor_side = |v: f64, bmin: f64| {
272        if bwcheck_eff.is_some() {
273            v.max(bmin)
274        } else {
275            v
276        }
277    };
278    let floor_comb = |v: f64| {
279        if bwcheck_eff.is_some() {
280            v.max(bw_min_l).max(bw_min_r)
281        } else {
282            v
283        }
284    };
285
286    // vcache (functions.R:213-231): the V-fit depends only on (o,nu) since h_V=c_bw
287    // is fixed across pilots. The 7 pilot calls per side use only 3 distinct (o,nu)
288    // V-fits -- precompute each once, then run the B-fit per pilot via h_B.
289    let mk_vfit = |yy: &[f64], xx: &[f64], tt, zz, cc, ww, o, nu| {
290        compute_vfit(
291            yy,
292            xx,
293            tt,
294            zz,
295            dz,
296            c,
297            o,
298            nu,
299            c_bw,
300            vce,
301            nnmatch,
302            covs_drop_coll,
303            kernel,
304            cc,
305            ww,
306        )
307    };
308    let vd_l = mk_vfit(&yl, &xl, tl_opt, zl_opt, cll_opt, fwl_opt, q + 1, q + 1);
309    let vb_l = mk_vfit(&yl, &xl, tl_opt, zl_opt, cll_opt, fwl_opt, q, p + 1);
310    let vh_l = mk_vfit(&yl, &xl, tl_opt, zl_opt, cll_opt, fwl_opt, p, deriv);
311    let vd_r = mk_vfit(&yr, &xr, tr_opt, zr_opt, clr_opt, fwr_opt, q + 1, q + 1);
312    let vb_r = mk_vfit(&yr, &xr, tr_opt, zr_opt, clr_opt, fwr_opt, q, p + 1);
313    let vh_r = mk_vfit(&yr, &xr, tr_opt, zr_opt, clr_opt, fwr_opt, p, deriv);
314
315    // one pilot B-fit + assembly against a cached V-fit (h_V = c_bw fixed)
316    let asm = |vf: &VFit, yy: &[f64], xx: &[f64], tt, zz, cc, ww, o, nu, o_b, h_b, scale| {
317        assemble_from_vfit(
318            vf, yy, xx, tt, zz, dz, c, o, nu, o_b, c_bw, h_b, scale, vce, nnmatch, kernel, cc, ww,
319        )
320    };
321
322    // ----- d-stage (o=q+1, scale=0, no regularization) -----
323    let cdl = asm(
324        &vd_l,
325        &yl,
326        &xl,
327        tl_opt,
328        zl_opt,
329        cll_opt,
330        fwl_opt,
331        q + 1,
332        q + 1,
333        q + 2,
334        range_l,
335        0.0,
336    );
337    let cdr = asm(
338        &vd_r,
339        &yr,
340        &xr,
341        tr_opt,
342        zr_opt,
343        clr_opt,
344        fwr_opt,
345        q + 1,
346        q + 1,
347        q + 2,
348        range_r,
349        0.0,
350    );
351    let rate_d = cdl.rate;
352    let d_bw_l = (cdl.v / cdl.b.powi(2)).powf(rate_d);
353    let d_bw_r = (cdr.v / cdr.b.powi(2)).powf(rate_d);
354    let d_bw_s = ((cdl.v + cdr.v) / (cdr.b + cdl.b).powi(2)).powf(rate_d);
355    let d_bw_d = ((cdl.v + cdr.v) / (cdr.b - cdl.b).powi(2)).powf(rate_d);
356    // d-stage clamps: bwrestrict cap then bwcheck floor (TWO per-side, SUM/RD combined)
357    let d_bw_l = floor_side(restrict(d_bw_l, bw_max_l), bw_min_l);
358    let d_bw_r = floor_side(restrict(d_bw_r, bw_max_r), bw_min_r);
359    let d_bw_s = floor_comb(restrict(d_bw_s, bw_max));
360    let d_bw_d = floor_comb(restrict(d_bw_d, bw_max));
361
362    // helper for the regularized b/h combine (RD uses Br-Bl, SUM uses Br+Bl)
363    let reg_two =
364        |cv: f64, cb: f64, cr: f64, rate: f64| (cv / (cb.powi(2) + scaleregul * cr)).powf(rate);
365    let reg_comb = |vl: f64, vr: f64, b_combined: f64, rl: f64, rr: f64, rate: f64| {
366        ((vl + vr) / (b_combined.powi(2) + scaleregul * (rl + rr))).powf(rate)
367    };
368
369    // ----- TWO (per-side h_B = d_bw_l/_r) -----
370    let cbl = asm(
371        &vb_l,
372        &yl,
373        &xl,
374        tl_opt,
375        zl_opt,
376        cll_opt,
377        fwl_opt,
378        q,
379        p + 1,
380        q + 1,
381        d_bw_l,
382        scaleregul,
383    );
384    let cbr = asm(
385        &vb_r,
386        &yr,
387        &xr,
388        tr_opt,
389        zr_opt,
390        clr_opt,
391        fwr_opt,
392        q,
393        p + 1,
394        q + 1,
395        d_bw_r,
396        scaleregul,
397    );
398    let rate_b = cbl.rate;
399    let b_bw_l = restrict(reg_two(cbl.v, cbl.b, cbl.r, rate_b), bw_max_l);
400    let b_bw_r = restrict(reg_two(cbr.v, cbr.b, cbr.r, rate_b), bw_max_r);
401    let chl = asm(
402        &vh_l, &yl, &xl, tl_opt, zl_opt, cll_opt, fwl_opt, p, deriv, q, b_bw_l, scaleregul,
403    );
404    let chr = asm(
405        &vh_r, &yr, &xr, tr_opt, zr_opt, clr_opt, fwr_opt, p, deriv, q, b_bw_r, scaleregul,
406    );
407    let rate_h = chl.rate;
408    let h_bw_l = restrict(reg_two(chl.v, chl.b, chl.r, rate_h), bw_max_l);
409    let h_bw_r = restrict(reg_two(chr.v, chr.b, chr.r, rate_h), bw_max_r);
410
411    // ----- SUM (shared h_B = d_bw_s, Br+Bl) -----
412    let cbl_s = asm(
413        &vb_l,
414        &yl,
415        &xl,
416        tl_opt,
417        zl_opt,
418        cll_opt,
419        fwl_opt,
420        q,
421        p + 1,
422        q + 1,
423        d_bw_s,
424        scaleregul,
425    );
426    let cbr_s = asm(
427        &vb_r,
428        &yr,
429        &xr,
430        tr_opt,
431        zr_opt,
432        clr_opt,
433        fwr_opt,
434        q,
435        p + 1,
436        q + 1,
437        d_bw_s,
438        scaleregul,
439    );
440    let b_bw_s = restrict(
441        reg_comb(
442            cbl_s.v,
443            cbr_s.v,
444            cbr_s.b + cbl_s.b,
445            cbl_s.r,
446            cbr_s.r,
447            rate_b,
448        ),
449        bw_max,
450    );
451    let chl_s = asm(
452        &vh_l, &yl, &xl, tl_opt, zl_opt, cll_opt, fwl_opt, p, deriv, q, b_bw_s, scaleregul,
453    );
454    let chr_s = asm(
455        &vh_r, &yr, &xr, tr_opt, zr_opt, clr_opt, fwr_opt, p, deriv, q, b_bw_s, scaleregul,
456    );
457    let h_bw_s = restrict(
458        reg_comb(
459            chl_s.v,
460            chr_s.v,
461            chr_s.b + chl_s.b,
462            chl_s.r,
463            chr_s.r,
464            rate_h,
465        ),
466        bw_max,
467    );
468
469    // ----- RD (shared h_B = d_bw_d, Br-Bl) -----
470    let cbl_d = asm(
471        &vb_l,
472        &yl,
473        &xl,
474        tl_opt,
475        zl_opt,
476        cll_opt,
477        fwl_opt,
478        q,
479        p + 1,
480        q + 1,
481        d_bw_d,
482        scaleregul,
483    );
484    let cbr_d = asm(
485        &vb_r,
486        &yr,
487        &xr,
488        tr_opt,
489        zr_opt,
490        clr_opt,
491        fwr_opt,
492        q,
493        p + 1,
494        q + 1,
495        d_bw_d,
496        scaleregul,
497    );
498    let b_bw_d = restrict(
499        reg_comb(
500            cbl_d.v,
501            cbr_d.v,
502            cbr_d.b - cbl_d.b,
503            cbl_d.r,
504            cbr_d.r,
505            rate_b,
506        ),
507        bw_max,
508    );
509    let chl_d = asm(
510        &vh_l, &yl, &xl, tl_opt, zl_opt, cll_opt, fwl_opt, p, deriv, q, b_bw_d, scaleregul,
511    );
512    let chr_d = asm(
513        &vh_r, &yr, &xr, tr_opt, zr_opt, clr_opt, fwr_opt, p, deriv, q, b_bw_d, scaleregul,
514    );
515    let h_bw_d = restrict(
516        reg_comb(
517            chl_d.v,
518            chr_d.v,
519            chr_d.b - chl_d.b,
520            chl_d.r,
521            chr_d.r,
522            rate_h,
523        ),
524        bw_max,
525    );
526
527    // ----- combine + CER -----
528    let (h_rd, b_rd) = (h_bw_d, b_bw_d);
529    let (h_sum, b_sum) = (h_bw_s, b_bw_s);
530    let h_c1 = h_rd.min(h_sum);
531    let b_c1 = b_rd.min(b_sum);
532    let h_c2_l = median3(h_rd, h_sum, h_bw_l);
533    let h_c2_r = median3(h_rd, h_sum, h_bw_r);
534    let b_c2_l = median3(b_rd, b_sum, b_bw_l);
535    let b_c2_r = median3(b_rd, b_sum, b_bw_r);
536    let pf = p as f64;
537    // CER rate factor: cluster count (g_l+g_r) replaces N when clustered (R:476-477)
538    let cer_base = match (g_l, g_r) {
539        (Some(gl), Some(gr)) => (gl + gr) as f64,
540        _ => n as f64,
541    };
542    let cer_h = cer_base.powf(-(pf / ((3.0 + pf) * (3.0 + 2.0 * pf))));
543    let cer_b = 1.0;
544
545    let common = |h: f64, b: f64| Bws {
546        h_l: h,
547        h_r: h,
548        b_l: b,
549        b_r: b,
550    };
551    let bws = match bwselect {
552        "mserd" | "" => common(h_rd, b_rd),
553        "msesum" => common(h_sum, b_sum),
554        "msetwo" => Bws {
555            h_l: h_bw_l,
556            h_r: h_bw_r,
557            b_l: b_bw_l,
558            b_r: b_bw_r,
559        },
560        "msecomb1" => common(h_c1, b_c1),
561        "msecomb2" => Bws {
562            h_l: h_c2_l,
563            h_r: h_c2_r,
564            b_l: b_c2_l,
565            b_r: b_c2_r,
566        },
567        "cerrd" => common(h_rd * cer_h, b_rd * cer_b),
568        "cersum" => common(h_sum * cer_h, b_sum * cer_b),
569        "certwo" => Bws {
570            h_l: h_bw_l * cer_h,
571            h_r: h_bw_r * cer_h,
572            b_l: b_bw_l * cer_b,
573            b_r: b_bw_r * cer_b,
574        },
575        "cercomb1" => common(h_c1 * cer_h, b_c1 * cer_b),
576        "cercomb2" => Bws {
577            h_l: h_c2_l * cer_h,
578            h_r: h_c2_r * cer_h,
579            b_l: b_c2_l * cer_b,
580            b_r: b_c2_r * cer_b,
581        },
582        other => panic!("unknown bwselect {other}"),
583    };
584    // de-standardize: bandwidths return on the original x scale (rdrobust.R:467-469)
585    Bws {
586        h_l: bws.h_l * x_sd,
587        h_r: bws.h_r * x_sd,
588        b_l: bws.b_l * x_sd,
589        b_r: bws.b_r * x_sd,
590    }
591}
592
593#[cfg(test)]
594mod tests {
595    use super::*;
596
597    #[test]
598    fn quantile_type2_even_n_averages() {
599        // n=4, p=0.5: np=2, g=0 -> avg of x_(2),x_(3)
600        let s = [1.0, 2.0, 3.0, 4.0];
601        assert_eq!(quantile_type2(&s, 0.5), 2.5);
602    }
603
604    #[test]
605    fn median3_picks_middle() {
606        assert_eq!(median3(3.0, 1.0, 2.0), 2.0);
607    }
608}