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.dosesis. 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:
- doses
tupleoffloat The evaluation doses, strictly increasing and inside
support.- bandwidths
tupleoffloat The bandwidths, positive and distinct.
- support
tupleoffloat 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_piece
int Gauss-Legendre nodes on each piece of the quadrature partition.
- support_floor
float The Kish effective size below which a pair’s interval carries the
"low_dose_support_plugin"label.
- doses
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:
ndarrayThe 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
offloat More break points, such as a binned density’s edges, so that each piece sees a density that is constant in the dose.
- refine
int Multiplies
nodes_per_piece; the doubling diagnostic passes 2.
- extra_breakssequence
- Returns:
QuadratureRuleNodes 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_dosesequally spaced points from the lower to the upper end ofsupport, and the bandwidths arefractionsof its length.- Parameters:
- Returns:
DoseResponseThe declaration.
Attributes#
- DoseResponse.pairs#
Every declared
(bandwidth, dose)pair, bandwidth-major.