Skip to content

Commit

Permalink
#55 add a quickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
drbenvincent committed Nov 19, 2022
1 parent 8f39903 commit 5d16fae
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,40 @@ Alternatively, if you want the very latest version of the package you can instal
pip install git+https://github.com/pymc-labs/CausalPy.git
```

## Quickstart

```python
from causalpy.pymc_experiments import RegressionDiscontinuity
from causalpy.pymc_models import LinearRegression
import pandas as pd
import pathlib


# Import and process data
rd_data_path = pathlib.Path.cwd().parents[1] / "causalpy" / "data" / "drinking.csv"
df = (
pd.read_csv(rd_data_path)[["agecell", "all", "mva", "suicide"]]
.rename(columns={"agecell": "age"})
.assign(treated=lambda df_: df_.age > 21)
.dropna(axis=0)
)

# Run the analysis
result = RegressionDiscontinuity(
df,
formula="all ~ 1 + age + treated",
running_variable_name="age",
prediction_model=LinearRegression(),
treatment_threshold=21,
)

# Visualize outputs
fig, ax = result.plot();

# Get a results summary
result.summary()
```

## Roadmap

Plans for the repository can be seen in the [Issues](https://github.com/pymc-labs/CausalPy/issues).
Expand Down
35 changes: 35 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,41 @@ Alternatively, if you want the very latest version of the package you can instal
pip install git+https://github.com/pymc-labs/CausalPy.git
Quickstart
----------

.. code-block:: python
from causalpy.pymc_experiments import RegressionDiscontinuity
from causalpy.pymc_models import LinearRegression
import pandas as pd
import pathlib
# Import and process data
rd_data_path = pathlib.Path.cwd().parents[1] / "causalpy" / "data" / "drinking.csv"
df = (
pd.read_csv(rd_data_path)[["agecell", "all", "mva", "suicide"]]
.rename(columns={"agecell": "age"})
.assign(treated=lambda df_: df_.age > 21)
.dropna(axis=0)
)
# Run the analysis
result = RegressionDiscontinuity(
df,
formula="all ~ 1 + age + treated",
running_variable_name="age",
prediction_model=LinearRegression(),
treatment_threshold=21,
)
# Visualize outputs
fig, ax = result.plot();
# Get a results summary
result.summary()
Features
--------

Expand Down

0 comments on commit 5d16fae

Please sign in to comment.