Theory
Python Implementation
R Implementation