pub fn rdplot(
y: &[f64],
x: &[f64],
c: f64,
p: usize,
kernel: Kernel,
binselect: &str,
scale_l: f64,
scale_r: f64,
nbins_l: Option<usize>,
nbins_r: Option<usize>,
wt: Option<&[f64]>,
) -> RdPlotExpand description
Computes the data behind an RD plot for the evenly-spaced (ES) binselect family:
the global polynomial curve coefficients, the IMSE/MV bin counts, and the per-bin
scatter means. Ports R rdplot (rdplot.R), ES half only, no covariates and no CI.
Splits the sample at c (x < c left, x >= c right), fits one weighted
order-p polynomial per side over the full side range, selects J_l/J_r via the
order-4 ES pilot regressions, lays evenly-spaced breakpoints, assigns each point
with R’s findInterval convention, and returns per-bin x/y means (empty bins
dropped). Bin counts are exact vs R; coefficients and means match to ~1e-8.
§Arguments
y: outcome values.x: running variable, parallel toy, need not be sorted.c: cutoff; the pointx == cfalls on the right side.p: global polynomial order for the curve (R default 4).kernel: kernel for the polynomial-fit weights (uniform/triangular/Epanechnikov).binselect: ES variant string, one ofes,espr,esmv(also matched by""), oresmvpr. Any other value, including the QS variants, triggersunimplemented!.scale_l,scale_r: multipliers on the selected per-side bin count (R default 1). The scaled count is rounded up to an integer; R keeps a fractional count and produces fractional bin ids, so non-integer products diverge from R there.nbins_l,nbins_r: optional manual bin counts that override binselect per side. A side whose outcome has zero variance always gets one bin, as in R.wt: optional unit weights that multiply the kernel weights in the curve fit only; they do not enter the pilot regressions or bin construction.
§Panics
Panics via unimplemented! when binselect is not one of the four supported ES
strings (the QS family is a later increment), and when a selector diverges to an
infinite bin count (zero spacings variance with non-zero bias on a side, where R
errors inside seq).