causal_agent.methods.propensity_score package

causal_agent.methods.propensity_score.estimate_propensity_scores(df, treatment, covariates, model_type='logistic', **kwargs)[source]

Estimate propensity scores using a specified model.

Parameters:
  • df (DataFrame) – DataFrame containing the data

  • treatment (str) – Name of the treatment variable

  • covariates (List[str]) – List of covariate variable names

  • model_type (str) – Type of model to use (‘logistic’ supported for now)

  • **kwargs – Additional arguments for the model

Returns:

Array of propensity scores

Return type:

ndarray

causal_agent.methods.propensity_score.estimate_matching_effect(df, treatment, outcome, covariates, **kwargs)

Estimate ATT using Propensity Score Matching. Tries DoWhy’s PSM first, falls back to custom implementation if DoWhy fails. Uses bootstrap SE based on the custom implementation regardless.

causal_agent.methods.propensity_score.estimate_weighting_effect(df, treatment, outcome, covariates, **kwargs)

Generic propensity score weighting (IPW) implementation.

Parameters:
  • df (DataFrame) – Dataset containing causal variables

  • treatment (str) – Name of treatment variable

  • outcome (str) – Name of outcome variable

  • covariates (List[str]) – List of covariate names

  • **kwargs – Method-specific parameters (e.g., weight_type, trim_threshold, query)

Returns:

Dictionary with effect estimate and diagnostics

Return type:

Dict[str, Any]

causal_agent.methods.propensity_score.assess_balance(df_original, df_matched_or_weighted, treatment, covariates, method, propensity_scores_original=None, propensity_scores_matched=None, weights=None)[source]

Assesses covariate balance before and after matching/weighting.

Placeholder: Returns dummy diagnostic data.

causal_agent.methods.propensity_score.plot_overlap(df, treatment, propensity_scores, save_path='overlap_plot.png')[source]

Generates plot showing propensity score overlap. Placeholder: Does nothing.

causal_agent.methods.propensity_score.plot_balance(balance_metrics_before, balance_metrics_after, save_path='balance_plot.png')[source]

Generates plot showing covariate balance before/after. Placeholder: Does nothing.

Submodules

causal_agent.methods.propensity_score.base module

causal_agent.methods.propensity_score.base.select_propensity_model(df, treatment, covariates, query=None)[source]

Selects the appropriate propensity score model type (e.g., logistic, GBM).

Placeholder: Currently defaults to Logistic Regression.

causal_agent.methods.propensity_score.base.estimate_propensity_scores(df, treatment, covariates, model_type='logistic', **kwargs)[source]

Estimate propensity scores using a specified model.

Parameters:
  • df (DataFrame) – DataFrame containing the data

  • treatment (str) – Name of the treatment variable

  • covariates (List[str]) – List of covariate variable names

  • model_type (str) – Type of model to use (‘logistic’ supported for now)

  • **kwargs – Additional arguments for the model

Returns:

Array of propensity scores

Return type:

ndarray

causal_agent.methods.propensity_score.base.format_ps_results(effect_estimate, effect_se, diagnostics, method_details, parameters)[source]

Standard formatter for PS method results.

causal_agent.methods.propensity_score.diagnostics module

causal_agent.methods.propensity_score.diagnostics.assess_balance(df_original, df_matched_or_weighted, treatment, covariates, method, propensity_scores_original=None, propensity_scores_matched=None, weights=None)[source]

Assesses covariate balance before and after matching/weighting.

Placeholder: Returns dummy diagnostic data.

causal_agent.methods.propensity_score.diagnostics.assess_weight_distribution(weights, treatment_indicator)[source]

Assesses the distribution of IPW weights.

Placeholder: Returns dummy diagnostic data.

causal_agent.methods.propensity_score.diagnostics.plot_overlap(df, treatment, propensity_scores, save_path='overlap_plot.png')[source]

Generates plot showing propensity score overlap. Placeholder: Does nothing.

causal_agent.methods.propensity_score.diagnostics.plot_balance(balance_metrics_before, balance_metrics_after, save_path='balance_plot.png')[source]

Generates plot showing covariate balance before/after. Placeholder: Does nothing.

causal_agent.methods.propensity_score.llm_assist module

causal_agent.methods.propensity_score.llm_assist.determine_optimal_caliper(df, treatment, covariates, query=None)[source]

Determines optimal caliper for PSM using data or LLM.

Placeholder: Returns a default value.

causal_agent.methods.propensity_score.llm_assist.determine_optimal_weight_type(df, treatment, query=None)[source]

Determines the optimal type of IPW weights (ATE, ATT, etc.).

Placeholder: Defaults to ATE.

causal_agent.methods.propensity_score.llm_assist.determine_optimal_trim_threshold(df, treatment, propensity_scores=None, query=None)[source]

Determines optimal threshold for trimming extreme propensity scores.

Placeholder: Defaults to no trimming (None).

causal_agent.methods.propensity_score.llm_assist.get_llm_parameters(df, query, method)[source]

Placeholder to get parameters via LLM based on dataset and query.

causal_agent.methods.propensity_score.matching module

causal_agent.methods.propensity_score.matching.estimate_effect(df, treatment, outcome, covariates, **kwargs)[source]

Estimate ATT using Propensity Score Matching. Tries DoWhy’s PSM first, falls back to custom implementation if DoWhy fails. Uses bootstrap SE based on the custom implementation regardless.

causal_agent.methods.propensity_score.weighting module

causal_agent.methods.propensity_score.weighting.estimate_effect(df, treatment, outcome, covariates, **kwargs)[source]

Generic propensity score weighting (IPW) implementation.

Parameters:
  • df (DataFrame) – Dataset containing causal variables

  • treatment (str) – Name of treatment variable

  • outcome (str) – Name of outcome variable

  • covariates (List[str]) – List of covariate names

  • **kwargs – Method-specific parameters (e.g., weight_type, trim_threshold, query)

Returns:

Dictionary with effect estimate and diagnostics

Return type:

Dict[str, Any]