cleverly.dose_response.DoseResponse#

class cleverly.dose_response.DoseResponse(doses: tuple[float, ...], bandwidths: tuple[float, ...], support: tuple[float, float], kernel: Literal['epanechnikov', 'triweight', 'uniform'] = 'epanechnikov', nodes_per_piece: int = 8, support_floor: float = 50.0)[source]#

The declaration of a kernel-smoothed dose-response curve.

Every field is part of the estimand and must be chosen without reading the data, as cleverly.msm.MSM.doses is. A dose interval taken from sample quantiles of the treatment moves the target at boundary pairs by an amount of order \(n^{-1/2}\) that the reported influence curve omits.

The target at each pair \((h, a_0)\) is the smoothed curve \(\theta_h(a_0) = \int_D w_{h,a_0}(a)\theta(a)\,da\) (equivalent_kernel()), not the curve \(\theta(a_0)\) itself. The two differ by \(O(h^2)\) where the curve is twice differentiable.

Parameters:
dosestuple of float

The evaluation doses, strictly increasing and inside support.

bandwidthstuple of float

The bandwidths, positive and distinct.

supporttuple of float

The dose interval \(D = (a_\mathrm{lo}, a_\mathrm{hi})\). It must lie inside the observed dose range, with a margin, because the fitted density is zero outside it.

kernel{“epanechnikov”, “triweight”, “uniform”}

The kernel.

nodes_per_pieceint

Gauss-Legendre nodes on each piece of the quadrature partition.

support_floorfloat

The Kish effective size below which a pair’s interval carries the "low_dose_support_plugin" label.

Examples

>>> from cleverly.dose_response import DoseResponse
>>> curve = DoseResponse(doses=(1.0, 2.0), bandwidths=(0.5,), support=(0.0, 3.0))
>>> curve.pairs
((0.5, 1.0), (0.5, 2.0))

Methods#

DoseResponse.breaks() → NDArray[float64][source]#

The break points the declaration puts into the quadrature partition.

Returns:
ndarray

The interval’s endpoints and every \(a_0 \pm h\) inside it, sorted.

DoseResponse.quadrature(extra_breaks: Sequence[float] | NDArray[float64] = (), *, refine: int = 1) → QuadratureRule[source]#

The composite Gauss-Legendre rule shared by every pair.

Parameters:
extra_breakssequence of float

More break points, such as a binned density’s edges, so that each piece sees a density that is constant in the dose.

refineint

Multiplies nodes_per_piece; the doubling diagnostic passes 2.

Returns:
QuadratureRule

Nodes and per-pair weights.

classmethod DoseResponse.spanning(support: tuple[float, float], n_doses: int = 9, fractions: Sequence[float] = (0.1, 0.15, 0.2, 0.3), **kwargs: object) → DoseResponse[source]#

Build doses and bandwidths from the declared interval alone.

The doses are n_doses equally spaced points from the lower to the upper end of support, and the bandwidths are fractions of its length.

Parameters:
supporttuple of float

The dose interval.

n_dosesint

The number of evaluation doses.

fractionssequence of float

Bandwidths as fractions of the interval’s length.

**kwargsobject

The remaining fields of DoseResponse.

Returns:
DoseResponse

The declaration.

DoseResponse.weight(h: float, a0: float, a: NDArray[float64]) → NDArray[float64][source]#

The equivalent kernel of one pair at doses a.

Parameters:
hfloat

The bandwidth.

a0float

The dose.

andarray

Doses at which to evaluate the weight.

Returns:
ndarray

The weight, with the shape of a.

Attributes#

DoseResponse.kernel: Literal['epanechnikov', 'triweight', 'uniform'] = 'epanechnikov'#
DoseResponse.names#

The parameter name of each pair, in pairs order.

DoseResponse.nodes_per_piece: int = 8#
DoseResponse.pairs#

Every declared (bandwidth, dose) pair, bandwidth-major.

DoseResponse.support_floor: float = 50.0#
DoseResponse.doses: tuple[float, ...]#
DoseResponse.bandwidths: tuple[float, ...]#
DoseResponse.support: tuple[float, float]#