cleverly.interventions.Shift#

class cleverly.interventions.Shift(delta: float, cap: float | DoseQuantile | SupportBoundary | None, name: str = '', target: Literal['population', 'fold_average'] | None = None)[source]#

Add delta to everyone’s treatment, up to cap.

Parameters:
deltafloat

How far to move the treatment. 0.0 is the natural course – the policy that changes nothing – whose mean is \(E[Y]\) and which is the usual reference.

capfloat, DoseQuantile, SupportBoundary or None

The largest treatment value the policy will assign; a unit whose shifted dose would exceed it keeps its own. Required, with no default, and it is a declaration rather than something estimated.

Estimating \(u(w)\) from the data would make the parameter data-dependent: the reported standard error would condition on a fitted support boundary, and every bootstrap replicate would target a slightly different policy. Defaulting it to max(A) is worse, pinning the estimand to an extreme order statistic. So the analyst says what dose is achievable, which is a question about the world.

cap=None means no cap. It is allowed, it is the same arithmetic with the indicator zeroed, and it warns with the share of rows whose shifted dose leaves the observed range – because there \(\bar Q\) is being extrapolated and identification needs \(A + \delta\) to be supported. A tuner, DoseQuantile or SupportBoundary, reads the cap from the treatment law; target then declares the parameter.

namestr

What this policy is called in reported parameter names. Defaults to "+0.5" / "-1" style, with "natural course" for delta=0.

target{“population”, “fold_average”} or None

The parameter of a map whose cap is a tuner, and None for a declared cap. A fit refuses a tuned map with no target (cleverly.interventions.tuning). The interval of the "population" target needs a consistent outcome regression near the boundary at each tuned node: the variance term of the tuner reads it.

Methods#

Shift.apply(treatment: ndarray[tuple[Any, ...], dtype[float64]]) → tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[bool]]][source]#

(shifted, capped) – the assigned dose, and which rows the cap held back.

Parameters:
treatmentndarray

(n,) observed dose.

Returns:
shiftedndarray

(n,) dose the policy assigns.

cappedndarray

(n,) boolean, true where the cap held the row at its own dose.

Attributes#

Shift.name: str = ''#
Shift.target: Literal['population', 'fold_average'] | None = None#
Shift.delta: float#
Shift.cap: float | DoseQuantile | SupportBoundary | None#