Skip to content

Commit

Permalink
chelsea's changes (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronikobrosly authored Aug 20, 2020
1 parent 93f9219 commit e1a1e3d
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 125 deletions.
23 changes: 13 additions & 10 deletions causal_curve/mediation.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,18 +508,21 @@ def calculate_mediation(self, ci=0.95):

bootstrap_overall_means = np.array(bootstrap_overall_means)

final_results = (
pd.DataFrame(
{
"Treatment_Value": self.t_bin_means,
"Proportion_Direct_Effect": self.prop_direct_list,
"Proportion_Indirect_Effect": self.prop_indirect_list,
}
)
.round(4)
.clip(lower=0, upper=1.0)
final_results = pd.DataFrame(
{
"Treatment_Value": self.t_bin_means,
"Proportion_Direct_Effect": self.prop_direct_list,
"Proportion_Indirect_Effect": self.prop_indirect_list,
}
).round(4)

# Clip Proportion_Direct_Effect and Proportion_Indirect_Effect
final_results["Proportion_Direct_Effect"].clip(lower=0, upper=1.0, inplace=True)
final_results["Proportion_Indirect_Effect"].clip(
lower=0, upper=1.0, inplace=True
)

# Calculate overall, mean, indirect effect
total_prop_mean = round(np.array(self.prop_indirect_list).mean(), 4)
total_prop_lower = self._clip_negatives(
round(np.percentile(bootstrap_overall_means, q=lower * 100), 4)
Expand Down
2 changes: 1 addition & 1 deletion docs/Mediation_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and mortality (Havumaki et al.):
At some point though, it's helpful to validate these ideas with empirical tests.
This tool provides a test that can estimate the amount of mediation that occurs between
a treatment, a purported mediator, and an outcome. In keeping with the causal curve theme,
this tool uses a test developed my Imai et al. when handling a continuous treatment and
this tool uses a test developed by Imai et al. when handling a continuous treatment and
mediator.

In this example we use the following simulated data, and assume that the `mediator`
Expand Down
8 changes: 8 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
Change Log
==========

Version 0.3.6
-------------
- Fixed bug in Mediation.calculate_mediation that would clip treatments < 0 or > 1
- Fixed incorrect horizontal axis labels in lead example
- Fixed typos in documentation
- Added links to resources so users could learn more about causal inference theory


Version 0.3.5
-------------
- Re-organized documentation
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Roni Kobrosly'

# The full version, including alpha/beta/rc tags
release = '0.3.5'
release = '0.3.6'

# -- General configuration ---------------------------------------------------

Expand Down
17 changes: 13 additions & 4 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
Introduction to causal-curve
============================

In academia and industry, randomized controlled experiments (or simply experiments or colloquially
known as "A/B tests") are considered the gold standard approach for assessing the true, causal impact
In academia and industry, randomized controlled experiments (or simply experiments or "A/B tests") are considered the gold standard approach for assessing the true, causal impact
of a treatment or intervention. For example:

* We want to increase the number of times per day new customers log into our business's website. Will it help if send daily emails out to our customers? We take a group of 2000 new business customers and half is randomly chosen to receive daily emails while the other half receives one email per week. We follow both groups forward in time for a month compare each group's average number of logins per day.
* We want to increase the number of times per day new customers log into our business's website. Will it help if we send daily emails out to our customers? We take a group of 2000 new business customers and half is randomly chosen to receive daily emails while the other half receives one email per week. We follow both groups forward in time for a month compare each group's average number of logins per day.

However, for ethical or financial reasons experiments may not always be feasible to carry out.
However, for ethical or financial reasons, experiments may not always be feasible to carry out.

* It's not ethical to randomly assign some people to receive a possible carcinogen in pill form while others receive a sugar pill, and then see which group is more likely to develop cancer.
* It's not feasible to increase the household incomes of some New York neighborhoods, while leaving others unchanged to see if changing a neighborhood's income inequality would improve the local crime rate.
Expand Down Expand Up @@ -67,6 +66,16 @@ None of the methods provided in causal-curve rely on inference via instrumental
rely on the data from the observed treatment, confounders, and the outcome of interest (like the above GPS example).


Additional resources
--------------------------------------------

There are a number of excellent blogs and books covering the math behind causal inference in more depth.
In addition to these, the following resources are recommended:

- Miguel Hernan and Jamie Robin's book `"Causal Inference: What if" <https://cdn1.sph.harvard.edu/wp-content/uploads/sites/1268/2020/07/ci_hernanrobins_31july20.pdf>`_.
- Cloudera Fast Forward Labs Research's `book on causal inference <https://ff13.fastforwardlabs.com/>`_.


References
----------

Expand Down
170 changes: 62 additions & 108 deletions examples/NHANES_BLL_example.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="causal-curve",
version="0.3.5",
version="0.3.6",
author="Roni Kobrosly",
author_email="[email protected]",
description="A python library with tools to perform causal inference using \
Expand Down

0 comments on commit e1a1e3d

Please sign in to comment.