Checks#
- coverage_check(X, A, Y, groups=None, outcome_model=None, weights=None, n_reps=20, shape='inverted_u', effect_size=None, level_points=40, n_folds=5, add_group_codes=True, random_state=0, verbose=True)[source]#
Plasmode check of the curve’s 95% intervals on your own data.
Keeps your confounders and doses, replaces the outcome with a simulated one whose dose-response curve is known, reruns the whole pipeline
n_repstimes and counts how often the intervals contain the truth (Franklin et al. 2014).- Parameters:
- X, A, Yarray-like
Your confounders, dose and outcome. Y is used only to build the simulated outcome’s baseline and noise.
- groupsDataFrame, optional
Hierarchy, top to bottom. If given, curves are fitted with partial pooling and every group’s curve is scored against the common true shape (balancing weights are skipped, as they support one population only).
- outcome_modelsklearn regressor, optional
Default
default_model().- weightsdict, optional
name -> callable(seed)returning a weight model. Default density (GPS) and balancing (BalancingWeights).- n_repsint, default 20
Replications. With few, the calibrated critical values are noisy; use 30 or more for reporting.
- shape{“inverted_u”, “saturating”, “linear”} or callable, default “inverted_u”
The true curve, as a function of the standardised dose
z = (a - median) / sd.- effect_sizefloat, optional
Peak-to-trough size of the true curve; default
0.5 * sd(Y).- level_pointsint, default 40
Grid points at which coverage is scored.
- n_foldsint, default 5
Cross-fitting folds.
- add_group_codesbool, default True
Add the group labels to X.
- random_stateint, default 0
Seed.
- verbosebool, default True
Print progress.
- Returns:
- summaryDataFrame
One row per weight model. Read
pointwiseandsimultaneous(share of 95% intervals containing the truth),se_ratio(reported standard error / actual spread; below 1 means overconfident) andabs_bias.critical_pointwiseandcritical_simultaneousare the critical values that gave 95% coverage on your data: pass one tomodel.band(..., critical=...)for calibrated intervals (compare with 1.96 and the usual sup-t value).- repsDataFrame
The same measures for every replication.
- bootstrap_curves(X, A, Y, outcome_model, gps, a_grid, paths=(None,), groups=None, pooling='partial', n_boot=100, refit_nuisances=True, retune=True, n_folds=5, n_basis=10, level=0.95, centre=False, random_state=0, verbose=False)[source]#
Percentile bootstrap bands for one or more curves.
Rows are resampled within each leaf group, so every group appears in every replicate and its curve stays defined. The band is pointwise; use the stored draws for any other summary.
- Parameters:
- Xarray-like
Confounders, already numeric (see
drcurves.prepare_X).- A, Yarray-like
Dose and outcome.
- outcome_modelsklearn regressor or None
None uses
default_model().- gpsGPS, DiscreteGPS or None
None uses
GPS.- a_gridarray-like
Doses at which to evaluate the curves.
- pathssequence of tuples, default (None,)
Group paths to return, e.g.
[None, ("north",), ("north", "s17")].- groupsDataFrame, optional
Hierarchy, top to bottom.
- pooling{“partial”, “none”, “complete”}, default “partial”
- n_bootint, default 100
Bootstrap replicates.
- refit_nuisancesbool, default True
Refit the outcome model and GPS in every replicate (slow, complete), or keep the original pseudo-outcomes (fast, misses nuisance noise).
- retunebool, default True
Re-select the penalties by GCV in every replicate.
- n_foldsint, default 5
Cross-fitting folds.
- n_basisint, default 10
B-spline basis functions.
- levelfloat, default 0.95
Band level.
- centrebool, default False
Bands for the shapes.
- random_stateint, default 0
Seed.
- verbosebool, default False
Print progress.
- Returns:
- dict
{path: {"est", "lo", "hi", "draws"}}.
- placebo_check(X, A, y_pre, y_prepre, main=None, a_grid=None, groups=None, path=None, **fit_kwargs)[source]#
Fit the curve on the change between two pre-periods, before the dose could act.
Under (strong) parallel trends the placebo curve is flat. Judge it by its size relative to the effect you care about, not by whether its band excludes zero: with a well-fitted model the band is narrow enough to flag deviations too small to matter.
- Parameters:
- X, Aarray-like
Confounders and the (later) dose.
- y_prearray-like
Outcome in the last period before the dose.
- y_preprearray-like
Outcome in an earlier period before the dose.
- mainHierarchicalDoseResponse, optional
Fitted model of the real effect (e.g.
fit_dose_response(..., y_pre=...)), used to express the placebo’s size relative to the effect.- a_gridarray-like, optional
Doses at which to compare; default the 5th to 95th percentile of A.
- groupsDataFrame, optional
Hierarchy, top to bottom.
- pathtuple, optional
Group path whose curves to compare.
- **fit_kwargs
Passed to
fit_dose_response()(models, weights,n_jobs, …).
- Returns:
- dict
grid; the centred placebo curve and its standard errors;max_abs(largest deviation from flat);effect_range(range of the main curve, if given);relative(max_abs / effect_range; small is good) andshare_band_excludes_zero(for reference only).