Tutorial in Python targeted at Epidemiologists. Will discuss the basics of analysis in Python 3

Overview

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

Comments
  • Cochran-Mantel-Haenszel

    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!

    opened by opioiddatalab 2
  • Slight changes in Incidence Rate Ratio

    Slight changes in Incidence Rate Ratio

    Incidence Ratio Rate Paragraph

    • Fixed repetition
    • T1 & T0 are defined the same way. I believe that T0 is the person-time contributed by people NOT treated with ART
    opened by jaimiles23 0
  • Updates for v0.8.0

    Updates for v0.8.0

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

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

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

    • [x] Demonstrate g-bound argument

    • [x] 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

    opened by pzivich 0
  • Notebooks not rendering in GitHub

    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/

    opened by pzivich 0
  • Replicate

    Replicate "Causal Inference"

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

    • [x] Chapter 12: Inverse probability weights

    • [x] Chapter 13: Parametric g-formula

    • [x] Chapter 14: G-estimation of structural nested models

    • [x] ~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

    enhancement 
    opened by pzivich 0
  • Tutorials

    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

    • [x] Basic measures

    • [x] splines

    • [x] IPTW: time-fixed treatment

    • [ ] IPTW: stochastic treatment

    • [ ] IPTW: time-varying treatment

    • [x] IPCW

    • [x] IPMW: single variable

    • [ ] IPMW: monotone

    • [ ] IPMW: nonmonotone (to add after implemented)

    • [x] G-formula: time-fixed binary treatment, binary outcome

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

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

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

    • [x] G-formula: Monte Carlo

    • [x] G-formula: Iterative Conditional

    • [x] G-estimation of SNM

    • [x] AIPTW

    • [ ] AIPMW

    • [x] TMLE

    • [x] TMLE: stochastic treatment

    • [ ] LTMLE (to add after implemented)

    • [x] Quantitative bias analysis

    • [x] Functional form assessment

    • [x] Generalizability

    • [ ] Transportability (IPSW, g-transport, AIPSW)

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

    opened by pzivich 1
Releases(v0.8.0)
Owner
Paul Zivich
Epidemiology post-doc working in epidemiologic methods and infectious diseases.
Paul Zivich
Evaluation suite for large-scale language models.

This repo contains code for running the evaluations and reproducing the results from the Jurassic-1 Technical Paper (see blog post), with current support for running the tasks through both the AI21 S

71 Dec 17, 2022
TraND: Transferable Neighborhood Discovery for Unsupervised Cross-domain Gait Recognition.

TraND This is the code for the paper "Jinkai Zheng, Xinchen Liu, Chenggang Yan, Jiyong Zhang, Wu Liu, Xiaoping Zhang and Tao Mei: TraND: Transferable

Jinkai Zheng 32 Apr 04, 2022
A LiDAR point cloud cluster for panoptic segmentation

Divide-and-Merge-LiDAR-Panoptic-Cluster A demo video of our method with semantic prior: More information will be coming soon! As a PhD student, I don'

YimingZhao 65 Dec 22, 2022
Synthetic LiDAR sequential point cloud dataset with point-wise annotations

SynLiDAR dataset: Learning From Synthetic LiDAR Sequential Point Cloud This is official repository of the SynLiDAR dataset. For technical details, ple

78 Dec 27, 2022
Security evaluation module with onnx, pytorch, and SecML.

🚀 🐼 🔥 PandaVision Integrate and automate security evaluations with onnx, pytorch, and SecML! Installation Starting the server without Docker If you

Maura Pintor 11 Apr 12, 2022
Learning Representational Invariances for Data-Efficient Action Recognition

Learning Representational Invariances for Data-Efficient Action Recognition Official PyTorch implementation for Learning Representational Invariances

Virginia Tech Vision and Learning Lab 27 Nov 22, 2022
Tiny Object Detection in Aerial Images.

AI-TOD AI-TOD is a dataset for tiny object detection in aerial images. [Paper] [Dataset] Description AI-TOD comes with 700,621 object instances for ei

jwwangchn 116 Dec 30, 2022
Combining Automatic Labelers and Expert Annotations for Accurate Radiology Report Labeling Using BERT

CheXbert: Combining Automatic Labelers and Expert Annotations for Accurate Radiology Report Labeling Using BERT CheXbert is an accurate, automated dee

Stanford Machine Learning Group 51 Dec 08, 2022
Adversarial Learning for Semi-supervised Semantic Segmentation, BMVC 2018

Adversarial Learning for Semi-supervised Semantic Segmentation This repo is the pytorch implementation of the following paper: Adversarial Learning fo

Wayne Hung 464 Dec 19, 2022
We are More than Our JOints: Predicting How 3D Bodies Move

We are More than Our JOints: Predicting How 3D Bodies Move Citation This repo contains the official implementation of our paper MOJO: @inproceedings{Z

72 Oct 20, 2022
Classify the disease status of a plant given an image of a passion fruit

Passion Fruit Disease Detection I tried to create an accurate machine learning models capable of localizing and identifying multiple Passion Fruits in

3 Nov 09, 2021
CARL provides highly configurable contextual extensions to several well-known RL environments.

CARL (context adaptive RL) provides highly configurable contextual extensions to several well-known RL environments.

AutoML-Freiburg-Hannover 51 Dec 28, 2022
Radar-to-Lidar: Heterogeneous Place Recognition via Joint Learning

radar-to-lidar-place-recognition This page is the coder of a pre-print, implemented by PyTorch. If you have some questions on this project, please fee

Huan Yin 37 Oct 09, 2022
本步态识别系统主要基于GaitSet模型进行实现

本步态识别系统主要基于GaitSet模型进行实现。在尝试部署本系统之前,建立理解GaitSet模型的网络结构、训练和推理方法。 系统的实现效果如视频所示: 演示视频 由于模型较大,部分模型文件存储在百度云盘。 链接提取码:33mb 具体部署过程 1.下载代码 2.安装requirements.txt

16 Oct 22, 2022
Anagram Generator in Python

Anagrams Generator This is a program for computing multiword anagrams. It makes no effort to come up with sentences that make sense; it only finds ana

Day Fundora 5 Nov 17, 2022
Code release for Local Light Field Fusion at SIGGRAPH 2019

Local Light Field Fusion Project | Video | Paper Tensorflow implementation for novel view synthesis from sparse input images. Local Light Field Fusion

1.1k Dec 27, 2022
Collection of sports betting AI tools.

sports-betting sports-betting is a collection of tools that makes it easy to create machine learning models for sports betting and evaluate their perf

George Douzas 109 Dec 31, 2022
Code for the CVPR2022 paper "Frequency-driven Imperceptible Adversarial Attack on Semantic Similarity"

Introduction This is an official release of the paper "Frequency-driven Imperceptible Adversarial Attack on Semantic Similarity" (arxiv link). Abstrac

Leo 21 Nov 23, 2022
An executor that loads ONNX models and embeds documents using the ONNX runtime.

ONNXEncoder An executor that loads ONNX models and embeds documents using the ONNX runtime. Usage via Docker image (recommended) from jina import Flow

Jina AI 2 Mar 15, 2022
VolumeGAN - 3D-aware Image Synthesis via Learning Structural and Textural Representations

VolumeGAN - 3D-aware Image Synthesis via Learning Structural and Textural Representations 3D-aware Image Synthesis via Learning Structural and Textura

GenForce: May Generative Force Be with You 116 Dec 26, 2022