Skip to content

Commit

Permalink
finished mediation documenation, fixed mediation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ronikobrosly committed Jun 24, 2020
1 parent c38e405 commit 3b24225
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 21 deletions.
11 changes: 6 additions & 5 deletions causal_curve/mediation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import numpy as np
import pandas as pd
from pandas.api.types import is_float_dtype, is_numeric_dtype
from pandas.api.types import is_float_dtype
from pygam import LinearGAM, s
from tqdm import tqdm

from causal_curve.core import Core
from causal_curve.utils import rand_seed_wrapper
Expand Down Expand Up @@ -438,8 +437,8 @@ def calculate_mediation(self, ci=0.95):
Parameters
----------
ci: float (default = 0.95)
The desired bootstrap confidence interval to produce. Default value is 0.95, corresponding
to 95% confidence intervals. bounded (0, 1.0).
The desired bootstrap confidence interval to produce. Default value is 0.95,
corresponding to 95% confidence intervals. bounded (0, 1.0).
Returns
----------
Expand Down Expand Up @@ -532,7 +531,9 @@ def calculate_mediation(self, ci=0.95):
)

print(
f"\n\nMean indirect effect proportion: {total_prop_mean} ({total_prop_lower} - {total_prop_upper})"
f"""\n\nMean indirect effect proportion:
{total_prop_mean} ({total_prop_lower} - {total_prop_upper})
"""
)
return final_results

Expand Down
10 changes: 7 additions & 3 deletions docs/Mediation_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,17 @@ around 52% (+/- 1%) of the effect of the treatment on the outcome. This indicate
moderate mediation is occurring here. The remaining 48% occurs through a direct effect of the
treatment on the outcome.

The report also shows how this mediation effect various as a function of the continuous treatment.
In this case, it looks the effect is relatively flat (as expected).

So long as we are confident that the mediator doesn't play another role in the causal graph
(it isn't a confounder of the treatment and outcome association), this supports the idea that
the mediator is in fact a mediator.

The report also shows how this mediation effect various as a function of the continuous treatment.
In this case, it looks the effect is relatively flat (as expected). With a little processing
and some basic interpolation, we can plot this mediation effect:

.. image:: ../imgs/mediation/mediation_effect.png



References
----------
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
Change Log
==========

Version 0.2.1
-------------
- Fixed Mediation tool error / removed `tqdm` from requirements
- Misc documentation cleanup / revisions


Version 0.2.0
-------------
- Added new Mediation class
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.2.0'
release = '0.2.1'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Feature request
A good feature request usually contains:

- a description of the requested feature,
- a description of the relevance of this feature to time series classification,
- a description of the relevance of this feature to causal inference,
- references if applicable, with links to the papers if they are in open access.

This makes reviewing the relevance of the requested feature easier.
Expand Down
32 changes: 22 additions & 10 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Welcome to causal-curve's documentation!
:caption: Contents:


**causal-curve** is a Python package dedicated with tools to perform causal inference
**causal-curve** is a Python package with tools to perform causal inference
using observational data when the treatment of interest is continuous.


Expand Down Expand Up @@ -72,7 +72,7 @@ This library attempts to address this gap, providing tools to estimate causal cu


Quick example (of the ``GPS`` tool)
--------------------------------------
-----------------------------------

**causal-curve** uses a sklearn-like API that should feel familiar to python machine learning users.
The following example estimates the causal dose-response curve (CDRC) by calculating
Expand Down Expand Up @@ -105,18 +105,30 @@ generalized propensity scores.

6. Explore or plot your results!

None of the methods provided in causal-curve rely on inference via instrumental variables, they only
rely on the data from the observed treatment, confounders, and the outcome of interest (like the above GPS example).

`Getting started <install.html>`_
---------------------------------

Information to install, test, and contribute to the package.

A caution about assumptions
---------------------------

There is a well-documented set of assumptions one must make to infer causal effects from
observational data. These are covered elsewhere in more detail, but briefly:

- Causes always occur before effects: The treatment variable needs to have occurred before the outcome.
- SUTVA: The treatment status of a given individual does not affect the potential outcomes of any other individuals.
- Positivity: Any individual has a positive probability of receiving all values of the treatment variable.
- Ignorability: All major confounding variables are included in the data you provide.

Violations of these assumptions will lead to biased results and incorrect conclusions!

In addition, any covariates that are included in `causal-curve` models are assumed to only
be **confounding** variables.

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

`Getting started <install.html>`_
---------------------------------

Information to install, test, and contribute to the package.
Binary file added imgs/mediation/mediation_effect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.2.0",
version="0.2.1",
author="Roni Kobrosly",
author_email="[email protected]",
description="A python library with tools to perform causal inference using \
Expand Down

0 comments on commit 3b24225

Please sign in to comment.