cleverly.datasets.make_biased_sample#
- cleverly.datasets.make_biased_sample(n_population: int = 4000, *, seed: int | Generator | None = None, heterogeneity: float = 1.2, backend: Literal['pandas', 'polars'] | str | None = None) tuple[Any, dict[str, float]][source]#
A sample selected with known, unequal probabilities from a known population.
Draws
n_populationrows, keeps each with probabilityP(S = 1 | W1), and returns only the kept rows – so the frame is smaller thann_population, by design. It carries two extra columns:sampling_prob, the known selection probability, andsampling_weight, its reciprocal.This is the survey/selection-bias case with everything known, which makes it the process that can actually test the claim in
cleverly.data.weighting: because selection depends only on observed data andw = 1 / P(S = 1 | W1), the tilted lawdP_wis the population law, so a weighted fit estimates the population ATE. An unweighted fit estimates the ATE among the selected, which is a different number here – reported astruth["ate_selected"]– and that gap is what a test asserts the weighting closes.- Parameters:
- n_population
int Size of the population the sample is drawn from, not of the sample.
- seed
int,Generator,orNone Seed or NumPy random generator.
- heterogeneity
float Strength of the effect modification that makes the sampled population’s estimand differ from the population one.
- backend{“pandas”, “polars”, “pyarrow”}
orNone, default=None Dataframe backend.
Noneuses pandas when installed, then the first available backend.
- n_population
- Returns: