Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Python package for causal inference in quasi-experimental settings

License

NotificationsYou must be signed in to change notification settings

pymc-labs/CausalPy

Repository files navigation


Build StatusRuffPyPI versionGitHub Repo starsRead the DocsPyPI - DownloadsInterrogatecodecov

CausalPy

A Python package focussing on causal inference in quasi-experimental settings. The package allows for sophisticated Bayesian model fitting methods to be used in addition to traditional OLS.

Installation

To get the latest release:

pip install CausalPy

Alternatively, if you want the very latest version of the package you can install from GitHub:

pip install git+https://github.com/pymc-labs/CausalPy.git

Quickstart

importcausalpyascpimportmatplotlib.pyplotasplt# Import and process datadf= (cp.load_data("drinking")    .rename(columns={"agecell":"age"})    .assign(treated=lambdadf_:df_.age>21)    )# Run the analysisresult=cp.RegressionDiscontinuity(df,formula="all ~ 1 + age + treated",running_variable_name="age",model=cp.pymc_models.LinearRegression(),treatment_threshold=21,    )# Visualize outputsfig,ax=result.plot();# Get a results summaryresult.summary()plt.show()

Roadmap

Plans for the repository can be seen in theIssues.

Videos

Click on the thumbnail below to watch a video about CausalPy on YouTube.Youtube video thumbnail image

Features

CausalPy has a broad range of quasi-experimental methods for causal inference:

MethodDescription
Synthetic controlConstructs a synthetic version of the treatment group from a weighted combination of control units. Used for causal inference in comparative case studies when a single unit is treated, and there are multiple control units.
Geographical liftMeasures the impact of an intervention in a specific geographic area by comparing it to similar areas without the intervention. Commonly used in marketing to assess regional campaigns.
ANCOVAAnalysis of Covariance combines ANOVA and regression to control for the effects of one or more quantitative covariates. Used when comparing group means while controlling for other variables.
Differences in DifferencesCompares the changes in outcomes over time between a treatment group and a control group. Used in observational studies to estimate causal effects by accounting for time trends.
Regression discontinuityIdentifies causal effects by exploiting a cutoff or threshold in an assignment variable. Used when treatment is assigned based on a threshold value of an observed variable, allowing comparison just above and below the cutoff.
Regression kink designsFocuses on changes in the slope (kinks) of the relationship between variables rather than jumps at cutoff points. Used to identify causal effects when treatment intensity changes at a threshold.
Interrupted time seriesAnalyzes the effect of an intervention by comparing time series data before and after the intervention. Used when data is collected over time and an intervention occurs at a known point, allowing assessment of changes in level or trend.
Instrumental variable regressionAddresses endogeneity by using an instrument variable that is correlated with the endogenous explanatory variable but uncorrelated with the error term. Used when explanatory variables are correlated with the error term, providing consistent estimates of causal effects.
Inverse Propensity Score WeightingWeights observations by the inverse of the probability of receiving the treatment. Used in causal inference to create a synthetic sample where the treatment assignment is independent of measured covariates, helping to adjust for confounding variables in observational studies.

License

Apache License 2.0


Support

This repository is supported byPyMC Labs.

If you are interested in seeing what PyMC Labs can do for you, then please emailben.vincent@pymc-labs.com. We work with companies at a variety of scales and with varying levels of existing modeling capacity. We also run corporate workshop training events and can provide sessions ranging from introduction to Bayes to more advanced topics.


[8]ページ先頭

©2009-2025 Movatter.jp