Skip to content

Commit

Permalink
new dataset and improvements to plotting.plot_lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jan 10, 2019
1 parent 04b1e20 commit b7c7734
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
- new `print_summary`
- `weights_col` is added
- `nn_cumulative_hazard` is removed (may add back)
- some plotting improvemnts to `plotting.plot_lifetimes`


#### 0.16.3
Expand Down
23 changes: 23 additions & 0 deletions lifelines/datasets/__init__.py
Expand Up @@ -49,6 +49,29 @@ def load_recur(**kwargs):
"""
return load_dataset("recur.csv", **kwargs)

def multicenter_aids_cohort_study(**kwargs):
"""
Originally in [1]
Siz: (78, 4)
AIDSYi: date of AIDS diagnosis
Wi: years from AIDS diagnosis to study entry
Ti: years from AIDS diagnosis to minimum of death or censoring
Di: indicator of death during follow up
i AIDSYi Wi Ti Di
1 1990.425 4.575 7.575 0
2 1991.250 3.750 6.750 0
3 1992.014 2.986 5.986 0
4 1992.030 2.970 5.970 0
5 1992.072 2.928 5.928 0
6 1992.220 2.780 4.688 1
[1] Cole SR, Hudgens MG. Survival analysis in infectious disease research: describing events in time. AIDS. 2010;24(16):2423-31.
"""
return load_dataset("multicenter_aids_cohort.tsv", sep="\t", index_col=0, **kwargs)

def load_holly_molly_polly(**kwargs):
"""
Expand Down
79 changes: 79 additions & 0 deletions lifelines/datasets/multicenter_aids_cohort.tsv
@@ -0,0 +1,79 @@
i AIDSYi Wi Ti Di
1 1990.425 4.575 7.575 0
2 1991.250 3.750 6.750 0
3 1992.014 2.986 5.986 0
4 1992.030 2.970 5.970 0
5 1992.072 2.928 5.928 0
6 1992.220 2.780 4.688 1
7 1992.374 2.626 5.626 0
8 1992.389 2.611 5.611 0
9 1992.450 2.550 5.550 0
10 1992.653 2.347 5.347 0
11 1992.825 2.175 3.842 0
12 1992.906 2.094 3.655 1
13 1992.911 2.089 3.062 1
14 1992.958 2.042 5.042 0
15 1993.264 1.736 4.653 0
16 1993.384 1.616 2.729 1
17 1993.436 1.564 4.564 0
18 1993.439 1.561 2.897 1
19 1993.444 1.556 4.556 0
20 1993.503 1.497 2.024 1
21 1993.533 1.467 2.400 1
22 1993.637 1.363 3.043 1
23 1993.700 1.300 4.300 0
24 1994.081 0.919 1.169 1
25 1994.137 0.863 3.863 0
26 1994.189 0.811 3.811 0
27 1994.212 0.788 3.788 0
28 1994.228 0.772 3.772 0
29 1994.253 0.747 1.894 1
30 1994.358 0.642 1.951 1
31 1994.538 0.462 3.462 0
32 1994.664 0.336 3.336 0
33 1994.708 0.292 1.125 0
34 1994.734 0.266 1.258 1
35 1994.742 0.258 3.258 0
36 1994.798 0.202 3.202 0
37 1994.814 0.186 3.186 0
38 1994.836 0.164 0.973 1
39 1994.872 0.128 3.128 0
40 1994.903 0.097 1.794 1
41 1994.933 0.067 0.962 1
42 1994.950 0.050 1.255 1
43 1995.059 0.000 2.941 0
44 1995.070 0.000 1.619 1
45 1995.103 0.000 2.897 0
46 1995.169 0.000 1.619 1
47 1995.178 0.000 2.456 1
48 1995.189 0.000 1.752 1
49 1995.202 0.000 2.798 0
50 1995.231 0.000 2.769 0
51 1995.239 0.000 0.791 1
52 1995.247 0.000 2.753 0
53 1995.280 0.000 2.720 0
54 1995.286 0.000 1.881 0
55 1995.286 0.000 2.714 0
56 1995.309 0.000 1.322 1
57 1995.342 0.000 2.658 0
58 1995.384 0.000 1.216 1
59 1995.478 0.000 0.269 1
60 1995.481 0.000 2.500 1
61 1995.664 0.000 2.336 0
62 1995.869 0.000 2.131 0
63 1995.897 0.000 2.103 0
64 1995.914 0.000 0.086 0
65 1995.936 0.000 2.064 0
66 1995.941 0.000 2.059 0
67 1996.027 0.000 1.107 1
68 1996.350 0.000 0.067 0
69 1996.384 0.000 1.616 0
70 1996.486 0.000 1.431 0
71 1996.530 0.000 1.470 0
72 1996.572 0.000 0.820 1
73 1997.011 0.000 0.989 0
74 1997.422 0.000 0.578 0
75 1997.511 0.000 0.489 0
76 1997.597 0.000 0.403 0
77 1997.650 0.000 0.350 0
78 1997.847 0.000 0.153 0
1 change: 1 addition & 0 deletions lifelines/fitters/aalen_additive_fitter.py
Expand Up @@ -409,6 +409,7 @@ def plot(self, columns=None, loc=None, iloc=None, **kwargs):
specify a location-based subsection of the curves to plot, ex:
``.plot(iloc=slice(0,10))`` will plot the first 10 time points.
"""
set_kwargs_ax
from matplotlib import pyplot as plt

assert loc is None or iloc is None, "Cannot set both loc and iloc in call to .plot"
Expand Down
19 changes: 11 additions & 8 deletions lifelines/plotting.py
Expand Up @@ -191,11 +191,11 @@ def plot_lifetimes(
"""
set_kwargs_ax(kwargs)
ax = kwargs["ax"]
ax = kwargs.pop("ax")

N = duration.shape[0]
if N > 100:
warnings.warn("For less visual clutter, you may want to subsample to less than 100 individuals.")
if N > 75:
warnings.warn("For less visual clutter, you may want to subsample to less than 75 individuals.")

if event_observed is None:
event_observed = np.ones(N, dtype=bool)
Expand All @@ -206,15 +206,18 @@ def plot_lifetimes(
if sort_by_duration:
# order by length of lifetimes; probably not very informative.
ix = np.argsort(duration, 0)
duration = duration[ix, 0]
event_observed = event_observed[ix, 0]
duration = duration[ix]
event_observed = event_observed[ix]
entry = entry[ix]

for i in range(N):
c = event_observed_color if event_observed[i] else event_censored_color
ax.hlines(N - 1 - i, entry[i], entry[i] + duration[i], color=c, lw=3)
m = "|" if not event_observed[i] else "o"
ax.scatter((entry[i]) + duration[i], N - 1 - i, color=c, s=30, marker=m)
ax.hlines(N - 1 - i, entry[i], entry[i] + duration[i], color=c, lw=1.5)
ax.hlines(N - 1 - i, 0, entry[i], color=c, lw=1.0, linestyle='--')
m = "" if not event_observed[i] else "o"
ax.scatter(entry[i] + duration[i], N - 1 - i, color=c, marker=m, s=10)



ax.set_ylim(-0.5, N)
return ax
Expand Down

0 comments on commit b7c7734

Please sign in to comment.