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 ignoredwwould estimate the selected population’s parameter and miss its nominal coverage, while one that applies it is estimating the parameter thistruthnames.nis the number of units drawn before selection, so the returned frame has about(pi_low + pi_high) / 2 * nrows. 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:
- Returns:
dataframeA biased sample of
make_longitudinal(), with its design weights.- truth
dictofstrtofloat The population regimen means, which the weights recover.