balance.weighting_methods.poststratify

balance.weighting_methods.poststratify.poststratify(sample_df: DataFrame, sample_weights: Series, target_df: DataFrame, target_weights: Series, variables: List[str] | None = None, transformations: str = 'default', transformations_drop: bool = True, *args, **kwargs) Dict[str, Dict[str, str] | Series][source]

Perform cell-based post-stratification. The output weights take into account the design weights and the post-stratification weights. Reference: https://docs.wfp.org/api/documents/WFP-0000121326/download/

Parameters:
  • sample_df (pd.DataFrame) – a dataframe representing the sample

  • sample_weights (pd.Series) – design weights for sample

  • target_df (pd.DataFrame) – a dataframe representing the target

  • target_weights (pd.Series) – design weights for target

  • variables (Optional[List[str]], optional) – list of variables to include in the model. If None all joint variables of sample_df and target_df are used

  • transformations (str, optional) – what transformations to apply to data before fitting the model. Default is “default” (see apply_transformations function)

  • transformations_drop (bool, optional) – whether the function should drop non-transformed variables. Default is True.

Raises:
  • ValueError – _description_

  • ValueError – _description_

Returns:

weight (pd.Series): final weights (sum up to target’s sum of weights) model (dict): method of adjustment

Dict shape: {

”weight”: w, “model”: {“method”: “poststratify”},

}

Return type:

Dict[str, Union[pd.Series, Dict[str, str]]]