cleverly.plotting.repeats#
- cleverly.plotting.repeats(result: Any, *, name: str | None = None, outcome_label: str | None = None, units: str | 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, ax: Axes | None = None) Figure[source]#
Plot the estimate from each cross-fitting repeat against the reported estimate.
A fit run with
repeats=RdrawsRindependent fold splits and reports their combined estimate. Use the plot to see whether the answer depends on how the data were split: each repeat is a point, the reported estimate is a line and its confidence interval is a shaded span. The repeats are descriptive points; none carries an interval of its own. When the fit withholds the interval, no span is drawn and the subtitle names the plug-in spread as the summary does, not as a standard error.- Parameters:
- result
TMLEResultorLongitudinalResult A fit with at least two cross-fitting repeats.
- name
strorNone, default=None The estimand to draw; the first one when omitted.
- outcome_label
strorNone, default=None Words for the quantity in the axis label, such as
"transition score", read as"Difference in transition score";"Difference in mean"the outcome column’s name when omitted.- units
strorNone, default=None Units of the outcome, for the axis label.
- 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.
- ax
AxesorNone, default=None Axes to draw on.
- result
- Returns:
FigureOne panel with a point per repeat.
- Raises:
ValueErrorWhen the fit has one repeat, the estimand is unknown, or a repeat does not hold the estimand.
CapabilityErrorWhen the result was not fitted with repeated cross-fitting splits.
See also
cleverly.estimators.TMLEResult.repeat_spreadThe spread of the repeats as numbers.
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 say the points are descriptive and which estimates are experimental.Examples
>>> import matplotlib >>> matplotlib.use("Agg") >>> import matplotlib.pyplot as plt >>> from sklearn.linear_model import LinearRegression, LogisticRegression >>> from cleverly import ATE, CausalStudy, PointTreatment >>> from cleverly.datasets import make_linear_ate >>> from cleverly.plotting import repeats >>> frame, _ = make_linear_ate(n=200, seed=0) >>> study = CausalStudy( ... frame, ... design=PointTreatment(outcome="Y", treatment="A", adjustment=("W1", "W2", "W3", "W4")), ... ) >>> result = study.identify(ATE()).estimate( ... outcome_learner=LinearRegression(), ... treatment_learner=LogisticRegression(max_iter=1000), ... n_folds=3, ... repeats=3, ... q_bounds=(-10.0, 10.0), ... random_state=0, ... ) >>> fig = repeats(result) >>> fig.texts[0].get_text() 'Estimate across repeated splits' >>> plt.close(fig)