forked from better/convoys
-
Notifications
You must be signed in to change notification settings - Fork 1
/
marriage.py
28 lines (22 loc) · 827 Bytes
/
marriage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from matplotlib import pyplot
import pandas
import convoys.plotting
import convoys.utils
def run():
print('loading data')
df = pandas.read_pickle('examples/marriage.pickle')
df = df.sample(1000) # speed up
print(df)
_, groups, (G, B, T) = convoys.utils.get_arrays(
df, groups='sex', created='born', converted='married')
pyplot.figure(figsize=(6, 6))
convoys.plotting.plot_cohorts(G, B, T, model='generalized-gamma',
groups=groups)
pyplot.legend()
pyplot.xlabel('Age of marriage')
convoys.plotting.plot_cohorts(G, B, T, model='kaplan-meier',
groups=groups,
plot_kwargs={'linestyle': '--'})
pyplot.savefig('marriage-combined.png')
if __name__ == '__main__':
run()