cleverly.TruncationCurve#

class cleverly.TruncationCurve(frame: Any)[source]#

The estimate re-computed at other limits on the probabilities that weight it.

result.diagnostics.truncation_curve() returns one. It holds the frame the curve computes and reads like it: attribute access, [], len and iteration go to the frame, so curve["psi"] and curve.columns work. Pass to_frame() where a dataframe itself is needed, such as isinstance or a frame comparison. Two curves compare by identity.

Parameters:
framedataframe

One row per limits pair and estimand. A point-treatment curve carries the estimate, its spread, the share of units capped and the fitted reference; a longitudinal curve carries the estimate, the fitted reference and the capped score-cell counts.

See also

cleverly.sensitivity.positivity.truncation_curve

The frame of a point-treatment fit.

cleverly.plotting.sensitivity

The plot plot() draws.

Methods#

TruncationCurve.plot(**kwargs: Any) → Any[source]#

Plot the estimate against the probability limits, with the share of units capped.

Parameters:
**kwargs

Passed to cleverly.plotting.sensitivity(): estimand=, outcome_label=, units= and title=.

Returns:
Figure

Two panels with a shared x axis.

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
>>> 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 = result.diagnostics.truncation_curve().plot()
>>> fig.axes[0].get_ylabel()
'Average effect'
>>> plt.close(fig)
TruncationCurve.summary(detail: Literal['short', 'full'] = 'short') → Summary[source]#

Return the printed summary of the curve.

Parameters:
detail{“short”, “full”}

"short" prints one row per estimand and limits, with the change from the fitted estimate and how much the limits capped. "full" adds every limits pair to six significant figures.

Returns:
Summary

A str whose value is the printed text. Its facts, tables, notes and reading hold the parts as data.

TruncationCurve.to_frame() → Any[source]#

Return the curve’s frame.

Returns:
dataframe

The frame, in the fit’s backend.

Attributes#

TruncationCurve.frame: Any#