causal_agent.methods.linear_regression package

Submodules

causal_agent.methods.linear_regression.diagnostics module

Diagnostic checks for Linear Regression models.

causal_agent.methods.linear_regression.diagnostics.run_lr_diagnostics(results, X)[source]

Runs diagnostic checks on a fitted OLS model.

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

  • X (DataFrame) – The design matrix (including constant) used for the regression. Needed for heteroskedasticity tests.

Returns:

Dictionary containing diagnostic metrics.

Return type:

Dict[str, Any]

causal_agent.methods.linear_regression.estimator module

Linear Regression Estimator for Causal Inference.

Uses Ordinary Least Squares (OLS) to estimate the treatment effect, potentially adjusting for covariates.

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

Estimates the causal effect using Linear Regression (OLS).

Parameters:
  • df (DataFrame) – Input DataFrame.

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

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

  • covariates (List[str] | None) – Optional list of covariate names.

  • query_str (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’: Placeholder for LLM interpretation.

Return type:

Dictionary containing estimation results

causal_agent.methods.linear_regression.llm_assist module

LLM assistance functions for Linear Regression analysis.

causal_agent.methods.linear_regression.llm_assist.suggest_lr_covariates(df_cols, treatment, outcome, query, llm=None)[source]

(Placeholder) Use LLM to suggest relevant covariates for linear regression.

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

  • treatment (str) – Treatment variable name.

  • outcome (str) – Outcome variable name.

  • query (str) – User’s causal query text.

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

Returns:

List of suggested covariate names.

Return type:

List[str]

causal_agent.methods.linear_regression.llm_assist.interpret_lr_results(results, diagnostics, treatment_var, llm=None)[source]

Use LLM to interpret Linear Regression results.

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

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

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

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

Returns:

String containing natural language interpretation.

Return type:

str