cleverly.plotting.influence#
- cleverly.plotting.influence(source: Any, *, name: str | None = None, cluster: Any = None, max_points: 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, ax: Axes | None = None) Figure[source]#
Plot how concentrated the uncertainty is in a few rows or clusters.
Rank the units by their squared centred influence value, largest first, and plot the share of the sum of squares that the top
kpercent carry againstk. The sum is the numerator of the influence-curve variance. A curve on the dashed diagonal means every unit contributes equally; a curve that rises steeply means a few units carry the standard error, which is how a Wald interval misleads even without a bootstrap. On a clustered fit the influence values are summed within clusters and the unit is the cluster. The subtitle names the top 1% of units, or the smallest whole number of units above it when the count is not a multiple of 100.The curve describes the stored influence values. On a fit with several cross-fitting repeats the stored curve is the median draw’s (the mean of the two central draws for an even count), and on a fit evaluated within folds, or on an estimate that adds the boundary-node supplement, the reported variance is not computed from this curve alone;
notes()says so.- Parameters:
- source
ParameterEstimateorTMLEResult An estimate, or a fit and the
nameof one of its estimates.- name
strorNone, default=None The estimate to draw from a fit; the first one when omitted.
- clusterarray_like or
None, default=None Cluster codes, one per row. A fit supplies its own; a bare estimate from a clustered fit needs them.
- max_points
intorNone, default=None The most points the line is drawn through, at least 16; every point when omitted. With a large data set this keeps the figure and its exported file small. The ranking, the top share and the Kish count still use every unit; only the drawn line is thinned, through points spread evenly along its length that always include both ends and the top-share point, and it stays within
2 / (max_points - 4)of the exact curve on the axes’ unit scale. The notes give the number of points drawn.- 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.
- source
- Returns:
FigureOne panel.
- Raises:
ValueErrorWhen the estimate’s interval is withheld (the reason is given), when a clustered estimate comes without cluster codes, or when the values cannot be ranked.
See also
cleverly.assessment.DiagnosticsFacade.influenceThe Kish effective count, skewness and kurtosis of the same curve.
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 curve is descriptive, whether influence values are summed within clusters, when the curve is not the reported variance, and how many points the line passes through whenmax_pointsthins it.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 influence >>> 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), ... cross_fit=False, ... random_state=0, ... ) >>> fig = influence(result) >>> fig.texts[0].get_text() 'Concentration of the uncertainty' >>> plt.close(fig)