cleverly.plotting.zipper#
- cleverly.plotting.zipper(study: Any, *, estimand: str | Sequence[str] | None = None, labels: dict[str, str] | None = None, max_intervals: int | None = None, title: str | Literal[False] | None = None, subtitle: str | Literal[False] | None = None, xlabel: str | Sequence[str] | None = None, ylabel: str | Sequence[str] | None = None, legend: str | Literal[False] = 'top', figsize: tuple[float, float] | None = None) Figure[source]#
Plot every replication’s interval, sorted by centre, with the misses coloured.
Use it to see how a study’s coverage was lost. Each line is one replication’s interval, drawn relative to the true value (the dashed line) and sorted by its centre. Intervals that miss are orange. Misses piled at one end mean the estimator is biased; misses split between the ends mean the intervals are too narrow. The subtitle gives the coverage and the level it was aimed at.
A difference is drawn as the limit minus the true value, a ratio as the limit divided by it on a log axis. Both are drawn from the limits each record holds, and the figure refuses a study whose limits disagree with the coverage it recorded.
- Parameters:
- study
StudyResult A finished coverage study.
- estimand
str, sequenceofstrorNone, default=None The estimands to draw, one panel each; every estimand of the study when omitted.
- labels
dictorNone, default=None Words for each estimand, keyed by its alias.
- max_intervals
intorNone, default=None The most intervals each panel draws, at least 2; every interval when omitted. With a large study the lines merge and the exported file grows with every replication; a number draws that many intervals at evenly spaced places in the sorted order, both ends included, each at its own height. The coverage in the subtitle and the counts in the notes still use every replication, and the notes give how many intervals were drawn and how many of them miss.
- title
str,FalseorNone, default=None The title; a short description of the figure when omitted, and none when
False.- subtitle
str,FalseorNone, default=None The line under the title; the plot’s own, which names the estimate and its headline number, when omitted, and none when
False.- xlabel
str, sequenceofstrorNone, default=None The x-axis label. A string replaces the first labelled panel’s label and the same label wherever it repeats; a sequence gives each labelled panel its own, in reading order.
- ylabel
str, sequenceofstrorNone, default=None The y-axis label, given as for
xlabel.- legend{“top”, “right”, “bottom”}
orFalse, default=”top” Where the key goes: above the axes, right of them, or under the figure;
Falsedraws no key.- figsize
tupleoffloatorNone, default=None Width and height in inches of a figure the plot creates.
- study
- Returns:
FigureOne panel per estimand, up to three across.
- Raises:
DataErrorWhen the study’s records hold no finite interval limits, or the limits disagree with the recorded coverage.
KeyErrorWhen
estimandnames an estimand the study did not measure.
See also
cleverly.validation.CoverageStudyThe study that produces the records.
Notes
The figure carries no note text. It does not mark an experimental fit or band, one whose interval has no checked coverage because no registered study covers it or a stated condition applies, such as too few clusters: read
notes()on the figure before you publish it. For this plot the notes count the intervals that miss below and above the true value, say which estimates are experimental, and, withmax_intervals, how many intervals were drawn and how many of those miss.Examples
>>> import matplotlib >>> matplotlib.use("Agg") >>> import matplotlib.pyplot as plt >>> from sklearn.linear_model import LinearRegression, LogisticRegression >>> from cleverly.datasets import nonlinear_dgp >>> from cleverly.estimators import TMLE >>> from cleverly.plotting import zipper >>> from cleverly.validation import CoverageStudy >>> study = CoverageStudy( ... dgp=nonlinear_dgp(), ... estimator=lambda: TMLE( ... outcome_learner=LinearRegression(), ... treatment_learner=LogisticRegression(max_iter=1000), ... cross_fit=False, ... ), ... n=200, ... n_replicates=12, ... estimands=("ate",), ... seed=0, ... ).run() >>> fig = zipper(study) >>> fig.axes[0].get_title(loc="left") 'Interval coverage' >>> plt.close(fig)