causal_agent.methods.backdoor_adjustment package

Submodules

causal_agent.methods.backdoor_adjustment.diagnostics module

Diagnostic checks for Backdoor Adjustment models (typically OLS).

causal_agent.methods.backdoor_adjustment.diagnostics.run_backdoor_diagnostics(results, X)[source]

Runs diagnostic checks on a fitted OLS model used for backdoor adjustment.

Parameters:
  • results (RegressionResultsWrapper) – A fitted statsmodels OLS results object.

  • X (DataFrame) – The design matrix (including constant and all predictors) used.

Returns:

Dictionary containing diagnostic metrics.

Return type:

Dict[str, Any]

causal_agent.methods.backdoor_adjustment.estimator module

Backdoor Adjustment Estimator using Regression.

Estimates the Average Treatment Effect (ATE) by regressing the outcome on the treatment and a set of covariates assumed to satisfy the backdoor criterion.

causal_agent.methods.backdoor_adjustment.estimator.estimate_effect(df, treatment, outcome, covariates, query=None, llm=None, **kwargs)[source]

Estimates the causal effect using Backdoor Adjustment (via OLS regression).

Assumes the provided covariates list satisfies the backdoor criterion.

Parameters:
  • df (DataFrame) – Input DataFrame.

  • treatment (str) – Name of the treatment variable column.

  • outcome (str) – Name of the outcome variable column.

  • covariates (List[str]) – List of covariate names forming the backdoor adjustment set.

  • query (str | None) – Optional user query for context (e.g., for LLM).

  • llm (langchain.chat_models.base.BaseChatModel | None) – Optional Language Model instance.

  • **kwargs – Additional keyword arguments.

Returns:

  • ‘effect_estimate’: The estimated coefficient for the treatment variable.

  • ’p_value’: The p-value associated with the treatment coefficient.

  • ’confidence_interval’: The 95% confidence interval for the effect.

  • ’standard_error’: The standard error of the treatment coefficient.

  • ’formula’: The regression formula used.

  • ’model_summary’: Summary object from statsmodels.

  • ’diagnostics’: Placeholder for diagnostic results.

  • ’interpretation’: LLM interpretation.

Return type:

Dictionary containing estimation results

causal_agent.methods.backdoor_adjustment.llm_assist module

LLM assistance functions for Backdoor Adjustment analysis.

causal_agent.methods.backdoor_adjustment.llm_assist.identify_backdoor_set(df_cols, treatment, outcome, query=None, existing_covariates=None, llm=None)[source]

Use LLM to suggest a potential backdoor adjustment set (confounders).

Tries to identify variables that affect both treatment and outcome.

Parameters:
  • df_cols (List[str]) – List of available column names in the dataset.

  • treatment (str) – Treatment variable name.

  • outcome (str) – Outcome variable name.

  • query (str | None) – User’s causal query text (provides context).

  • existing_covariates (List[str] | None) – Covariates already considered/provided by user.

  • llm (langchain.chat_models.base.BaseChatModel | None) – Optional LLM model instance.

Returns:

List of suggested variable names for the backdoor adjustment set.

Return type:

List[str]

causal_agent.methods.backdoor_adjustment.llm_assist.interpret_backdoor_results(results, diagnostics, treatment_var, covariates, llm=None)[source]

Use LLM to interpret Backdoor Adjustment results.

Parameters:
  • results (RegressionResultsWrapper) – Fitted statsmodels OLS results object.

  • diagnostics (Dict[str, Any]) – Dictionary of diagnostic results.

  • treatment_var (str) – Name of the treatment variable.

  • covariates (List[str]) – List of covariates used in the adjustment set.

  • llm (langchain.chat_models.base.BaseChatModel | None) – Optional LLM model instance.

Returns:

String containing natural language interpretation.

Return type:

str