cleverly.datasets.make_longitudinal_weighted#

cleverly.datasets.make_longitudinal_weighted(n: int = 2000, *, seed: int | Generator | None = None, backend: Literal['pandas', 'polars'] | str | None = None) → tuple[Any, dict[str, float]][source]#

A biased sample of make_longitudinal(), with the design weights that undo it.

Each unit is kept with a known probability \(\pi(W_1)\) and carries \(w = 1/\pi\), which is the survey case: the sampling law is \(dP_S = \pi\,dP / E[\pi]\), so tilting it by \(w\) gives \(dP_{S,w} = w\,dP_S/E_S[w] = dP\) exactly. The truth is therefore make_longitudinal()’s unchanged, and that is what makes this a real end-to-end check of the weighting rather than a restatement of it: a fit that ignored w would estimate the selected population’s parameter and miss its nominal coverage, while one that applies it is estimating the parameter this truth names.

n is the number of units drawn before selection, so the returned frame has about (pi_low + pi_high) / 2 * n rows. Returned rather than resampled to a fixed size because the retained count is part of the experiment: forcing it would condition on something the design did not.

Parameters:
nint

Number of units in the population the sample is drawn from.

seedint, Generator, or None

Seed or NumPy random generator.

backend{“pandas”, “polars”, “pyarrow”} or None, default=None

Dataframe backend. None uses pandas when installed, then the first available backend.

Returns:
dataframe

A biased sample of make_longitudinal(), with its design weights.

truthdict of str to float

The population regimen means, which the weights recover.