Giter VIP home page Giter VIP logo

python-for-epidemiologists's Introduction

Python-for-Epidemiologists

Join the chat at https://gitter.im/zEpid/community DOI

This repository is an introduction to epidemiology analyses in Python. Additionally, the tutorials for my library zEpid are hosted here. For more information on zEpid, see GitHub or ReadTheDocs.

The directory of this guide is

  1. Python Basics
  2. Basics of pandas (data management library)
  3. Epidemiology analyses in Python
    1. Basics
    2. Missing data
    3. Causal inference
      1. Time-fixed treatments
      2. Time-varying treatments
    4. Sensitivity analyses

Required packages for tutorial

To complete the tutorial, user must have the following packages installed: numpy, pandas, zepid, matplotlib, statsmodels, lifelines, and sklearn

IDE (Integrated Development Environment)

No IDE is required to complete the tutorial. All files are available in ipynb also known as jupyter notebooks. Code can be either downloaded or copied from the notebooks.

Here are some IDEs I have used in the past (and what I believe to be their advantages and disadvantages

Rodeo

This is the IDE I used for a long time. It is set up like RStudio

Advantages:

Basically RStudio but for Python, decent interface, easy to run line-by-line, easy to visualize plots (although it encourage bad habits)

Disadvantages:

Does not have all the features of RStudio (will delete changes if closed without saving), sucks up a lot of memory, sometimes the auto-complete would stop working if I hit more than 300+ lines of code, the environment tab is not great (don't expect it to open anything like RStudio)

Aside: their website has great tutorials how to run some basic stuff in Python if you are new to analysis in Python https://rodeo.yhat.com/

jupyter notebooks

Designed to be like a lab notebook, or like R markdown. Supports a pseudo-line-by-line concept Good for writing, since it allows for MarkDown. While I know a lot of people like jupyter, I only really use it for examples of code, not my personal programming. I never liked how it had to open via a Web Browser. I would rather have it be separate program. However, all guides were made using this IDE

PyCharm

This is the IDE I currently use

Advantages:

Easily set up virtual environments, interacts natively with Git, supports different file formats with plug-ins (e.g. .md), enforces certain coding conventions, better debug code features, organization of files under the project tab are convenient

Disadvantages:

Not great for running line-by-line code (it can do it, just not as elegantly), little more hardcore (I wouldn't really consider it a beginner's IDE. It requires some knowledge of set-up of Python)

IDLE

Ships with the basic Python 3.x installation. It is very basic and does not support line-by-line. Wouldn't recommend unless you are just starting with Python and don't want to commit to an IDE yet

Spyder

Ships with conda. Not bad but I didn't use it that much (I couldn't get the hang of it). Similarly it is an RStudio copy. Can't say too much since I haven't used it extensively

Basic Introduction to Python

If you have never used Python before, I have created some introductory materials to Python and the data management library I use, pandas. These are basic guides, but they also point to other resources. Please READ ALL OF THE BELOW BEFORE PROCEEDING.

Installing Python

To install, Python 3.x, we can download it directly from: https://www.python.org/downloads/

The installer provides an option to add Python3 to PATH, it is highly recommended you do this, since it allows you to avoid having to do it manually

Open Command Prompt / Terminal. When opened, type python and this should open Python in the same window. From here, you can quit by typing 'quit()' or closing the window. If this does NOT work, make sure your environmental variable was created properly

Installing Python Packages

Packages are what stores Python functions that we will use. These packages are contributed by various members of the community (including me)) and there is a wide array. To be able to download packages, we need to make sure we have an environmental variable created for python. We will discuss how to install packages

Python 3.x conveniently comes with a package manager. Basically it stores all the packages and we can use it to download new ones or update already downloaded ones.

To download a new package: Open Command Prompt/Terminal and use the following code (we will be installing pandas)

pip install pandas

To update a Python package, type the following command into Command Prompt. For example, we will update our pandas package

pip install pandas --upgrade

That concludes the basics. Please review parts 1 and 2 of the tutorials next

python-for-epidemiologists's People

Contributors

jaimiles23 avatar pzivich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-for-epidemiologists's Issues

Notebooks not rendering in GitHub

Sometimes GitHub has trouble rendering the notebooks. AFAIK the rendering system is behind the scenes at GitHub. Others have this same problem across repos and it sometimes occurs to me as well.

If the notebook won't render in GitHub, you can copy the URL to the notebook you want to view and use the following site to view the notebook: https://nbviewer.jupyter.org/

Updates for v0.8.0

Checklist for various notebooks to update with v0.8.0 release (hasn't released yet)

  • IPTW update. Lots of major changes, so notebook needs to be completely overhauled

  • Demonstrate new diagnostic functions for IPTW, g-formula, AIPW, TMLE

  • Demonstrate g-bound argument

  • Remove TMLE machine learning custom models. This is being removed in favor of cross-fitting. Can leave how to apply for now, but add the warning and mention will be cut in v0.9.0

Replicate "Causal Inference"

Issue to track progress on implementation of Hernan and Robins "Causal Inference" chapters

  • Chapter 12: Inverse probability weights

  • Chapter 13: Parametric g-formula

  • Chapter 14: G-estimation of structural nested models

  • Chapter 16: G-estimation for IV analysis

  • Chapter 17: Causal survival analysis

  • Part III: Time-varying treatments

G-estimation is not currently implemented. I will need to implement these before chapter 14 can be done.

Currently there are no plans to replicate Chapter 15 (propensity scores and regression) or Chapter 16 (instrumental variables) since the first method does not require zEpid and I am unfamiliar with the second. Maybe instrumental variables will be added in the future?

For Chapter 16, I am considering demonstrating the usage of g-estimation instead of two-stage least-squares. Specifically, using the same data as done in Chapter 16 but following Technical Point 16.3

Tutorials

On the website, create quick tutorials demonstrating each of the implemented estimators, descriptions of how they work, and why you might want to use them. Might be more digestible than the current docs (also better justify why to choose one over the other)

Reference to base on
https://lifelines.readthedocs.io/en/latest/jupyter_notebooks/Proportional%20hazard%20assumption.html
https://github.com/CamDavidsonPilon/lifelines/blob/master/docs/jupyter_notebooks/Proportional%20hazard%20assumption.ipynb

TODO

  • Basic measures

  • splines

  • IPTW: time-fixed treatment

  • IPTW: stochastic treatment

  • IPTW: time-varying treatment

  • IPCW

  • IPMW: single variable

  • IPMW: monotone

  • IPMW: nonmonotone (to add after implemented)

  • G-formula: time-fixed binary treatment, binary outcome

  • G-formula: time-fixed categorical treatment, binary outcome

  • G-formula: time-fixed continuous treatment, binary outcome (to add after implemented)

  • G-formula: time-fixed binary treatment, continuous outcome

  • G-formula: Monte Carlo

  • G-formula: Iterative Conditional

  • G-estimation of SNM

  • AIPTW

  • AIPMW

  • TMLE

  • TMLE: stochastic treatment

  • LTMLE (to add after implemented)

  • Quantitative bias analysis

  • Functional form assessment

  • Generalizability

  • Transportability (IPSW, g-transport, AIPSW)

  • Monte Carlo g-formula by-hand (helps to explain underlying process)

Cochran-Mantel-Haenszel

Thank you @pzivich for this amazing resource. Having the Hernan/Robbins causal model code in python is super helpful... g-estimation!

I have a request... do you have a Cochran-Mantel-Haenszel script? If you get the chance, please, it would be useful to us to have in this repo. Thank you in advance!

Data Basic Tutorials

Tutorials to create / add:

  • numpy / pandas basics

  • matplotlib basics

  • simulating data with numpy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.