cleverly.inference.delta_method#
- cleverly.inference.delta_method(function: Callable[[ndarray[tuple[Any, ...], dtype[float64]]], float], estimates: Sequence[float], influence_curves: Sequence[ndarray[tuple[Any, ...], dtype[float64]]], *, gradient: Callable[[ndarray[tuple[Any, ...], dtype[float64]]], ndarray[tuple[Any, ...], dtype[float64]]] | None = None, step: float = 1e-06) tuple[float, ndarray[tuple[Any, ...], dtype[float64]]][source]#
Influence curve of
functionapplied to several estimands.Returns
(value, influence_curve)where the influence curve is \(\nabla f(\hat\psi)^\top \mathrm{IC}\). Withgradient=Nonethe gradient is obtained by central differences, which is accurate enough here because the functions of interest are smooth and low-dimensional.- Parameters:
- function
callable() Maps the vector of estimates to the scalar of interest.
- estimatessequence
offloat The point estimates, in the order
functionreads.- influence_curvessequence
ofndarray One
(n,)influence curve per estimate, in the same order.- gradient
callable()orNone Gradient of
function.Nonetakes central differences.- step
float Relative step size for those differences.
- function
- Returns:
Examples
A ratio of two estimands, with the correlation between their influence curves carried through:
>>> import numpy as np >>> from cleverly.inference import delta_method >>> rng = np.random.default_rng(0) >>> ic_a = rng.normal(size=4) >>> ic_b = rng.normal(size=4) >>> value, ic = delta_method(lambda p: p[0] / p[1], [2.0, 4.0], [ic_a, ic_b]) >>> round(value, 6) 0.5 >>> ic.shape (4,)