cleverly.sensitivity.MissingnessTilt#

class cleverly.sensitivity.MissingnessTilt(rows: tuple[tuple[str, tuple[Any, ...]], ...], backend: str | None, outcome: str = '', n_missing: int = 0, n: int = 0, arm_gamma: tuple[tuple[Any, float], ...] | None = None, level: float = 0.95, statuses: tuple[tuple[str, str], ...] = (), ratios: tuple[str, ...] = (), scales: tuple[tuple[str, str], ...] = (), readings: tuple[tuple[str, Resolution], ...] = ())[source]#

Estimates under departures from outcomes missing at random.

Returned by missingness_tilt(). to_frame() gives one row per (gamma, estimand), with the spread columns the estimate’s inference status names and one gamma[<level>] column per arm.

Parameters:
rowstuple

The frame’s columns, as (name, values) pairs.

backendstr or None

The dataframe backend to_frame() emits.

outcomestr

The outcome column.

n_missingint

Rows whose outcome is missing.

nint

Rows in the fit.

arm_gammatuple of tuple or None

The declared (arm, multiplier) pairs, or None when every arm is tilted alike.

levelfloat

The coverage level of the intervals.

statusestuple of tuple of str

Each estimand’s inference status, as (estimand, status) pairs.

ratiostuple of str

The estimands on a ratio scale, whose spread is on the log scale.

scalestuple of tuple of str

Each estimand’s scale ("difference", "ratio", "level" or "fraction"), as (estimand, scale) pairs, which sets its no-effect value.

readingstuple of tuple

For each estimand whose interval off gamma = 0 comes from the targeted tilt, the registry’s reading of that interval, as (estimand, Resolution) pairs.

Attributes:
descriptivetuple of str

The estimands whose interval off gamma = 0 no validation study licenses.

Methods#

classmethod MissingnessTilt.build(payload: Mapping[str, Sequence[Any]], *, backend: str | None, outcome: str, n_missing: int, n: int, arm_gamma: tuple[tuple[Any, float], ...] | None, level: float, statuses: tuple[tuple[str, str], ...], ratios: tuple[str, ...] = (), scales: tuple[tuple[str, str], ...] = (), readings: tuple[tuple[str, Resolution], ...] = ()) → MissingnessTilt[source]#

Build the tilt from its columns and the fit facts its summary prints.

Parameters:
payloadmapping of str to sequence

The frame’s columns.

backendstr or None

The backend to_frame() emits.

outcomestr

The outcome column.

n_missingint

Rows whose outcome is missing.

nint

Rows in the fit.

arm_gammatuple of tuple or None

The declared (arm, multiplier) pairs, or None.

levelfloat

The coverage level of the intervals.

statusestuple of tuple of str

Each estimand’s inference status.

ratiostuple of str

The estimands on a ratio scale.

scalestuple of tuple of str

Each estimand’s scale, as (estimand, scale) pairs.

readingstuple of tuple

The registry’s reading of each targeted interval off gamma = 0.

Returns:
MissingnessTilt

The tilt.

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

Plot one estimate against the tilt γ, with its interval where one is reported.

Parameters:
**kwargs

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

Returns:
Figure

One panel over the grid of γ.

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_missing_outcome
>>> frame, _ = make_missing_outcome(n=300, seed=61)
>>> design = PointTreatment(
...     outcome="Y", treatment="A", adjustment=["W1", "W2", "W3"], missingness="Delta"
... )
>>> result = CausalStudy(frame, design=design).identify(ATE()).estimate(
...     outcome_learner=LinearRegression(),
...     treatment_learner=LogisticRegression(max_iter=1000),
...     cross_fit=False,
...     random_state=4,
... )
>>> fig = result.sensitivity.missingness(gamma=[-1.0, 0.0, 1.0]).plot()
>>> fig.axes[0].get_ylabel()
'Average effect'
>>> plt.close(fig)
MissingnessTilt.summary(*, detail: Detail = 'short') → Summary[source]#

Return the printed summary.

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

"full" adds the tilt formula and the per-arm tilts.

Returns:
Summary

A str with one table per estimand and how to read it.

Attributes#

MissingnessTilt.arm_gamma: tuple[tuple[Any, float], ...] | None = None#
MissingnessTilt.descriptive#

The estimands whose interval off gamma = 0 no validation study licenses.

MissingnessTilt.estimands#

The estimands the tilt reports, in order.

MissingnessTilt.level: float = 0.95#
MissingnessTilt.n: int = 0#
MissingnessTilt.n_missing: int = 0#
MissingnessTilt.outcome: str = ''#
MissingnessTilt.ratios: tuple[str, ...] = ()#
MissingnessTilt.readings: tuple[tuple[str, Resolution], ...] = ()#
MissingnessTilt.scales: tuple[tuple[str, str], ...] = ()#
MissingnessTilt.statuses: tuple[tuple[str, str], ...] = ()#
MissingnessTilt.rows#
MissingnessTilt.backend#