Skip to content

Instantly share code, notes, and snippets.

@erikbern
Created May 22, 2017 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikbern/3985e840a136949544a0971ed696a75c to your computer and use it in GitHub Desktop.
Save erikbern/3985e840a136949544a0971ed696a75c to your computer and use it in GitHub Desktop.
Kaplan-Meier snippet
n, k = len(te), 0
ts, ys = [], []
p = 1.0
for t, e in te:
if e: # whether the event was "observed" (converted) or not observed (may convert in the future)
p *= (n-1) / n
n -= 1
ts.append(t)
ys.append(100. * (1-p))
pyplot.plot(ts, ys, 'b')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment