{"id":8964,"library":"dowhy","title":"DoWhy","description":"DoWhy is a Python library for causal inference that supports explicit modeling and testing of causal assumptions, following a four-step framework: Model, Identify, Estimate, and Refute. It aims to bridge econometric and machine learning approaches to causality. The current version is 0.14, and it sees regular releases, typically every few months, incorporating new features, estimators, and compatibility updates.","status":"active","version":"0.14","language":"en","source_language":"en","source_url":"https://github.com/py-why/dowhy","tags":["causal-inference","causality","machine-learning","statistics","pywhy"],"install":[{"cmd":"pip install dowhy","lang":"bash","label":"Install core library"},{"cmd":"pip install dowhy[all]","lang":"bash","label":"Install with all optional dependencies (e.g., for plotting, advanced estimators)"}],"dependencies":[{"reason":"Required for visualizing causal graphs when calling 'model.plot_causal_graph()'","package":"graphviz","optional":true},{"reason":"Python interface for Graphviz, needed for graph visualization.","package":"pydot","optional":true},{"reason":"Used by many built-in causal estimators for regression and classification tasks.","package":"scikit-learn","optional":true},{"reason":"Provides statistical models and tests used by several estimators and refuters.","package":"statsmodels","optional":true},{"reason":"Provides advanced causal inference estimators, integrated with DoWhy.","package":"econml","optional":true}],"imports":[{"symbol":"CausalModel","correct":"from dowhy import CausalModel"},{"note":"Introduced in v0.8 for Graphical Causal Models (GCMs) functionalities.","symbol":"gcm","correct":"from dowhy import gcm"}],"quickstart":{"code":"import dowhy\nfrom dowhy import CausalModel\nimport pandas as pd\nimport numpy as np\n\n# 1. Generate some sample data\nnp.random.seed(1)\nn_samples = 100\ntreatment = np.random.randint(0, 2, n_samples)\nconfounder = np.random.normal(0, 1, n_samples)\noutcome = 2 * treatment + 3 * confounder + np.random.normal(0, 1, n_samples)\ndata = pd.DataFrame({'treatment': treatment, 'confounder': confounder, 'outcome': outcome})\n\n# 2. Model the causal problem\n# Using a simple string-based GML representation of the graph\nmodel=CausalModel(data=data,\n                    graph=\"digraph { confounder -> treatment; confounder -> outcome; treatment -> outcome;}\",\n                    treatment=['treatment'],\n                    outcome=['outcome'])\n\n# 3. Identify a causal effect\nidentified_estimand = model.identify_effect(estimand_type=\"nonparametric-ate\")\n\n# 4. Estimate the causal effect using a statistical method\ncausal_estimate = model.estimate_effect(identified_estimand,\n                                        method_name=\"backdoor.linear_regression\",\n                                        control_value=0,\n                                        treatment_value=1)\n\nprint(f\"Causal Estimate: {causal_estimate.value}\")\n\n# 5. Refute the obtained estimate\n# Using a refutation method to check robustness\nrefutation = model.refute_estimate(identified_estimand, causal_estimate,\n                                    method_name=\"random_common_cause\")\nprint(f\"Refutation (random common cause): {refutation.refutation_result}\")","lang":"python","description":"This quickstart demonstrates the core DoWhy workflow: defining a causal graph, identifying the effect using an estimand, estimating the effect with a specified method (e.g., linear regression), and finally refuting the estimate to check its robustness. It uses synthetic data to illustrate a simple causal model."},"warnings":[{"fix":"Carefully consider domain knowledge and potential confounding variables. Use tools like `DoWhy`'s `gcm` module or external causal discovery libraries to assist, but always validate assumptions with domain experts. DoWhy helps make assumptions explicit, but it cannot fix incorrect input.","message":"Defining an accurate causal graph is critical. Incorrectly specified graphs, especially neglecting unobserved confounders or including colliders, will lead to invalid causal effect estimates, which is the biggest footgun in causal inference.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your Python environment is between 3.9 and 3.13. Check DoWhy's official documentation for updated compatibility once Python 3.14 is officially released and supported.","message":"DoWhy currently supports Python versions up to 3.13. Attempting to install or run DoWhy on Python 3.14 (when released) will likely encounter dependency conflicts or `ImportError` due to package compatibility constraints.","severity":"breaking","affected_versions":">=0.14 (for future Python 3.14+)"},{"fix":"For plotting, install `graphviz` executables on your system and `pydot` via pip. For specific estimators or full functionality, consult the DoWhy documentation and install the required packages (e.g., `pip install dowhy[all]` or `pip install dowhy[econml]`).","message":"While `pip install dowhy` installs core functionality, advanced features like plotting causal graphs or using certain estimators (e.g., from `econml`) require extra dependencies that are not installed by default.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the `pydot` Python package (`pip install pydot`) and ensure the Graphviz executables are installed and available in your system's PATH. On Linux, run `sudo apt-get install graphviz`; on macOS, `brew install graphviz`; on Windows, install from `graphviz.org`.","cause":"Graphviz executable or the `pydot` Python package is missing. DoWhy relies on Graphviz for visualizing causal graphs.","error":"ModuleNotFoundError: No module named 'graphviz' OR pydot.InvocationException: Program terminated with status: 1. stderr: 'dot: command not found'"},{"fix":"Double-check all column names in your `data` DataFrame and ensure they exactly match the strings used in `CausalModel` initialization and the causal graph string.","cause":"Mismatch between column names specified in `treatment`, `outcome`, or the causal graph string and the actual column names in the input DataFrame.","error":"KeyError: '[column_name]' OR ValueError: Column [column_name] not found in the data."},{"fix":"Verify the exact spelling of the method name. Use `model.list_supported_methods()` after identifying the estimand to see the available options that are compatible with your specific problem and estimand type.","cause":"The specified estimation method name for `estimate_effect` is incorrect or not supported for the identified estimand type or current DoWhy version.","error":"ValueError: Method `[method_name]` is not a valid estimation method. Check `DoWhy.list_supported_methods()`"}]}