Plots

rd_stream.rd_plot(fml, data, *, cutoff=0.0, polynomial_order=4, n_bins=None, bin_method='esmv', bin_scale=None, kernel='uniform', bandwidth=None, weights=None, covariates=None, covariates_at='mean', support=None, mass_points='adjust', ci=95.0, donut=None, donut_closed='none', memory='auto', max_memory_gb=None, memory_reserve=None, workdir=None, n_threads=None, profile=False)[source]

RD plot data, as R’s rdplot computes them: the outcome’s means in bins of the running variable on each side of the cutoff, and a global polynomial fit on each side. Draw it with .plot().

Parameters:
  • fml (str) – "y ~ x": the outcome and the running variable; several outcomes as "y1 + y2 ~ x", from one read and sort, each with its own bins and fit (on its own complete rows).

  • data (str, path, polars.DataFrame or polars.LazyFrame)

  • cutoff (float, default 0)

  • polynomial_order (int, default 4) – The global polynomial’s order (rdplot’s p).

  • n_bins (int or (left, right) pair, optional) – The number of evenly spaced bins, instead of a selected number (rdplot’s nbins).

  • bin_method (str, default "esmv") – rdplot’s binselect: “es” or “qs”, evenly spaced or quantile spaced bins, IMSE-optimal; “esmv” or “qsmv”, the number of bins that mimics the outcome’s variance. With “pr” appended (“espr”, …) the variance comes from a polynomial regression instead of spacings. With mass_points="adjust" and mass points, the “pr” variant is used.

  • bin_scale (float or (left, right) pair, optional) – Multiplies the selected number of bins (rdplot’s scale); the result is rounded up to a whole number.

  • kernel ({"uniform", "triangular", "epanechnikov"}, default "uniform") – Weights the global polynomial fit.

  • bandwidth (float or (left, right) pair, optional) – The global polynomial’s window around the cutoff (rdplot’s h); default the whole range.

  • weights (str, optional) – Sampling weights for the global polynomial fit (as in rdplot, the bins are unweighted).

  • covariates (str or list of str, optional) – Covariates for the polynomial fit (rdplot’s covs), which then shows the covariate-adjusted fit at the covariates’ means (covariates_at="mean") or at zero ("zero"). The binned means are the outcome’s, as in rdplot.

  • support ((low, high), optional) – Extends the range the bins cover (rdplot’s support).

  • mass_points ({"adjust", "check", "off"})

  • ci (float, default 95) – The level of the bins’ intervals: in percent (95), or as a fraction below 1 (0.95), which is the same.

  • donut (float or (left, right) pair, optional) – A donut hole, as in rd_estimate: the observations within this distance of the cutoff are left out of the bins and the fits.

  • donut_closed ({"none", "left", "right", "both"}, default "none") – As in rd_estimate.

  • memory – As in rd_estimate. The by-value path takes the “pr” bin methods only. The window path writes the rows to slabs on disk and reads them a slab at a time, in order (every bin method needs each side’s rows in order), with the same results as holding them.

  • max_memory_gb – As in rd_estimate. The by-value path takes the “pr” bin methods only. The window path writes the rows to slabs on disk and reads them a slab at a time, in order (every bin method needs each side’s rows in order), with the same results as holding them.

  • memory_reserve – As in rd_estimate. The by-value path takes the “pr” bin methods only. The window path writes the rows to slabs on disk and reads them a slab at a time, in order (every bin method needs each side’s rows in order), with the same results as holding them.

  • workdir – As in rd_estimate. The by-value path takes the “pr” bin methods only. The window path writes the rows to slabs on disk and reads them a slab at a time, in order (every bin method needs each side’s rows in order), with the same results as holding them.

  • n_threads – As in rd_estimate. The by-value path takes the “pr” bin methods only. The window path writes the rows to slabs on disk and reads them a slab at a time, in order (every bin method needs each side’s rows in order), with the same results as holding them.

  • profile – As in rd_estimate. The by-value path takes the “pr” bin methods only. The window path writes the rows to slabs on disk and reads them a slab at a time, in order (every bin method needs each side’s rows in order), with the same results as holding them.

Returns:

  • RDPlot, RDPlotMulti with several outcomes, or a Profile with

  • profile=True.