In [17]:
import numpy as np
import chap01ex_soln
import pandas
import thinkstats2
import thinkplot
In [10]:
np.asarray([])
Out[10]:
array([], dtype=float64)
In [6]:
resp = chap01ex_soln.ReadFemResp()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-6-95e751963061> in <module>()
1 import chap01ex_soln
2 resp = chap01ex_soln.ReadFemResp()
----> 3 sum(np.isnull(resp.cmmarrhx))
AttributeError: 'module' object has no attribute 'isnull'
In [11]:
sum(pandas.isnull(resp.cmmarrhx))
Out[11]:
3525
In [13]:
resp.cmmarrhx.replace([9997, 9998, 9999], np.nan, inplace=True)
sum(pandas.isnull(resp.cmmarrhx))
Out[13]:
3554
In [15]:
sum(pandas.isnull(resp.cmbirth))
Out[15]:
0
In [37]:
resp['agemarr'] = (resp.cmmarrhx - resp.cmbirth) / 12.0
# resp.agemarr.fillna(45, inplace=True)
In [38]:
cdf = thinkstats2.Cdf(resp.agemarr)
thinkplot.Cdf(cdf)
Out[38]:
{'xscale': 'linear', 'yscale': 'linear'}
In [39]:
cdf = thinkstats2.Cdf(resp.ager)
thinkplot.Cdf(cdf)
Out[39]:
{'xscale': 'linear', 'yscale': 'linear'}
In [40]:
resp['age'] = (resp.cmintvw - resp.cmbirth) / 12.0
sum(pandas.isnull(resp.age))
Out[40]:
0
In [41]:
cdf = thinkstats2.Cdf(resp.age)
thinkplot.Cdf(cdf)
Out[41]:
{'xscale': 'linear', 'yscale': 'linear'}
In [45]:
past = resp[resp.evrmarry==1].agemarr
current = resp[resp.evrmarry==0].age
sum(pandas.isnull(past))
Out[45]:
37
In [47]:
cdf1 = thinkstats2.Cdf(past, label='past')
cdf2 = thinkstats2.Cdf(current, label='current')
thinkplot.Cdfs([cdf1, cdf2])
thinkplot.Show()
<matplotlib.figure.Figure at 0xa977250>
In [48]:
import survival
reload(survival)
hf = survival.EstimateHazardFunction(past, current)
sf = hf.MakeSurvival()
thinkplot.Plot(hf)
thinkplot.Plot(sf)
thinkplot.Show()
11.5 1.00904866716 7641.99095133
11.75 1.00904866716 7640.98190267
12.5 1.00904866716 7639.972854
13.1666666667 1.00904866716 7638.96380533
13.5 1.00904866716 7637.95475666
13.9166666667 1.00904866716 7636.945708
14.0 3.02714600147 7633.918562
14.25 2.01809733431 7631.90046466
14.4166666667 1.00904866716 7630.89141599
14.5 3.02714600147 7627.86426999
14.5833333333 1.00904866716 7626.85522133
14.75 3.02714600147 7623.82807532
14.8333333333 3.02714600147 7620.80092932
14.9166666667 2.01809733431 7618.78283199
15.0 3.02714600147 7610.75568599
15.0833333333 5.04524333578 7593.71044265
15.1666666667 4.03619466862 7575.67424798
15.25 3.02714600147 7558.64710198
15.3333333333 4.03619466862 7530.61090731
15.4166666667 2.01809733431 7507.59280998
15.5 4.03619466862 7491.55661531
15.5833333333 2.01809733431 7478.53851798
15.6666666667 5.04524333578 7447.49327464
15.75 7.06334067009 7416.42993397
15.8333333333 7.06334067009 7389.3665933
15.9166666667 3.02714600147 7367.3394473
16.0 4.03619466862 7338.30325263
16.0833333333 8.07238933725 7317.23086329
16.1666666667 13.117632673 7291.11323062
16.25 7.06334067009 7263.04988995
16.3333333333 7.06334067009 7234.98654928
16.4166666667 15.1357300073 7199.85081927
16.5 8.07238933725 7165.77842993
16.5833333333 9.0814380044 7138.69699193
16.6666666667 10.0904866716 7113.60650526
16.75 9.0814380044 7086.52506725
16.8333333333 14.1266813402 7046.39838591
16.9166666667 11.0995353387 7020.29885057
17.0 18.1628760088 6984.13597457
17.0833333333 6.05429200293 6954.08168256
17.1666666667 20.1809733431 6911.90070922
17.25 12.1085840059 6878.79212521
17.3333333333 15.1357300073 6841.65639521
17.4166666667 15.1357300073 6807.5206652
17.5 7.06334067009 6783.45732453
17.5833333333 14.1266813402 6746.33064319
17.6666666667 11.0995353387 6718.23110785
17.75 13.117632673 6689.11347518
17.8333333333 17.1538273416 6655.95964784
17.9166666667 24.2171680117 6615.74247982
18.0 45.407190022 6545.3352898
18.0833333333 34.3076546833 6488.02763512
18.1666666667 27.2443140132 6442.78332111
18.25 28.2533626804 6402.52995843
18.3333333333 29.2624113475 6361.26754708
18.4166666667 30.2714600147 6311.99608706
18.5 20.1809733431 6274.81511372
18.5833333333 35.3167033505 6228.49841037
18.6666666667 21.1900220103 6187.30838836
18.75 22.1990706774 6144.10931768
18.8333333333 27.2443140132 6089.86500367
18.9166666667 23.2081193446 6048.65688432
19.0 26.2352653461 6003.42161898
19.0833333333 28.2533626804 5957.1682563
19.1666666667 20.1809733431 5918.98728295
19.25 20.1809733431 5876.80630961
19.3333333333 29.2624113475 5826.54389826
19.4166666667 24.2171680117 5780.32673025
19.5 23.2081193446 5740.11861091
19.5833333333 32.289557349 5681.82905356
19.6666666667 39.3528980191 5625.47615554
19.75 26.2352653461 5587.24089019
19.8333333333 29.2624113475 5537.97847885
19.9166666667 32.289557349 5490.6889215
20.0 31.2805086818 5440.40841281
20.0833333333 28.2533626804 5398.15505013
20.1666666667 22.1990706774 5356.95597946
20.25 28.2533626804 5315.70261678
20.3333333333 28.2533626804 5271.4492541
20.4166666667 27.2443140132 5224.20494008
20.5 35.3167033505 5161.88823673
20.5833333333 44.3981413549 5105.49009538
20.6666666667 31.2805086818 5058.2095867
20.75 27.2443140132 5014.96527268
20.8333333333 23.2081193446 4971.75715334
20.9166666667 27.2443140132 4921.51283933
21.0 30.2714600147 4864.24137931
21.0833333333 24.2171680117 4825.0242113
21.1666666667 27.2443140132 4776.77989729
21.25 30.2714600147 4733.50843727
21.3333333333 37.3348006848 4682.17363659
21.4166666667 26.2352653461 4633.93837124
21.5 27.2443140132 4591.69405723
21.5833333333 43.3890926877 4531.30496454
21.6666666667 22.1990706774 4491.10589386
21.75 39.3528980191 4435.75299584
21.8333333333 30.2714600147 4388.48153583
21.9166666667 27.2443140132 4334.23722181
22.0 36.3257520176 4284.9114698
22.0833333333 42.3800440205 4227.53142578
22.1666666667 17.1538273416 4192.37759843
22.25 32.289557349 4136.08804109
22.3333333333 28.2533626804 4085.83467841
22.4166666667 24.2171680117 4046.61751039
22.5 36.3257520176 3993.29175838
22.5833333333 38.3438493519 3943.94790902
22.6666666667 16.1447786745 3904.80313035
22.75 34.3076546833 3848.49547567
22.8333333333 41.3709953534 3785.12448031
22.9166666667 35.3167033505 3734.80777696
23.0 33.2986060161 3682.50917095
23.0833333333 28.2533626804 3644.25580827
23.1666666667 24.2171680117 3606.03864025
23.25 25.2262166789 3558.81242358
23.3333333333 27.2443140132 3511.56810956
23.4166666667 34.3076546833 3469.26045488
23.5 42.3800440205 3418.88041086
23.5833333333 28.2533626804 3369.62704818
23.6666666667 20.1809733431 3333.44607483
23.75 34.3076546833 3287.13842015
23.8333333333 30.2714600147 3242.86696014
23.9166666667 34.3076546833 3202.55930545
24.0 30.2714600147 3161.28784544
24.0833333333 31.2805086818 3119.00733676
24.1666666667 18.1628760088 3092.84446075
24.25 20.1809733431 3059.66348741
24.3333333333 28.2533626804 3013.41012472
24.4166666667 21.1900220103 2975.22010271
24.5 28.2533626804 2936.96674003
24.5833333333 23.2081193446 2901.75862069
24.6666666667 25.2262166789 2861.53240401
24.75 15.1357300073 2835.396674
24.8333333333 22.1990706774 2801.19760333
24.9166666667 21.1900220103 2766.00758132
25.0 33.2986060161 2723.7089753
25.0833333333 20.1809733431 2696.52800196
25.1666666667 29.2624113475 2656.26559061
25.25 21.1900220103 2624.0755686
25.3333333333 16.1447786745 2595.93078992
25.4166666667 21.1900220103 2560.74076791
25.5 14.1266813402 2531.61408657
25.5833333333 20.1809733431 2500.43311323
25.6666666667 13.117632673 2471.31548056
25.75 21.1900220103 2436.12545855
25.8333333333 24.2171680117 2394.90829054
25.9166666667 27.2443140132 2356.66397652
26.0 33.2986060161 2304.36537051
26.0833333333 17.1538273416 2277.21154316
26.1666666667 20.1809733431 2248.03056982
26.25 13.117632673 2223.91293715
26.3333333333 16.1447786745 2196.76815847
26.4166666667 22.1990706774 2155.5690878
26.5 21.1900220103 2126.37906579
26.5833333333 21.1900220103 2095.18904378
26.6666666667 14.1266813402 2074.06236244
26.75 23.2081193446 2037.85424309
26.8333333333 14.1266813402 2010.72756175
26.9166666667 16.1447786745 1984.58278308
27.0 14.1266813402 1958.45610174
27.0833333333 21.1900220103 1926.26607973
27.1666666667 10.0904866716 1908.17559305
27.25 8.07238933725 1894.10320372
27.3333333333 16.1447786745 1872.95842504
27.4166666667 15.1357300073 1844.82269504
27.5 16.1447786745 1819.67791636
27.5833333333 13.117632673 1796.56028369
27.6666666667 19.171924676 1764.38835901
27.75 14.1266813402 1739.26167767
27.8333333333 15.1357300073 1721.12594766
27.9166666667 14.1266813402 1698.99926632
28.0 10.0904866716 1679.90877965
28.0833333333 19.171924676 1656.73685498
28.1666666667 11.0995353387 1640.63731964
28.25 18.1628760088 1610.47444363
28.3333333333 17.1538273416 1585.32061629
28.4166666667 14.1266813402 1558.19393495
28.5 7.06334067009 1540.13059428
28.5833333333 10.0904866716 1522.04010761
28.6666666667 16.1447786745 1499.89532893
28.75 10.0904866716 1479.80484226
28.8333333333 11.0995353387 1463.70530692
28.9166666667 5.04524333578 1447.66006359
29.0 17.1538273416 1418.50623624
29.0833333333 12.1085840059 1398.39765224
29.1666666667 16.1447786745 1374.25287356
29.25 8.07238933725 1357.18048423
29.3333333333 14.1266813402 1336.05380289
29.4166666667 7.06334067009 1324.99046222
29.5 10.0904866716 1310.89997554
29.5833333333 10.0904866716 1297.80948887
29.6666666667 6.05429200293 1283.75519687
29.75 11.0995353387 1266.65566153
29.8333333333 7.06334067009 1251.59232086
29.9166666667 9.0814380044 1234.51088286
30.0 13.117632673 1209.39325018
30.0833333333 9.0814380044 1193.31181218
30.1666666667 7.06334067009 1177.24847151
30.25 9.0814380044 1161.1670335
30.3333333333 10.0904866716 1138.07654683
30.4166666667 9.0814380044 1119.99510883
30.5 6.05429200293 1101.94081683
30.5833333333 12.1085840059 1079.83223282
30.6666666667 7.06334067009 1069.76889215
30.75 3.02714600147 1056.74174615
30.8333333333 6.05429200293 1041.68745415
30.9166666667 5.04524333578 1028.64221081
31.0 8.07238933725 1008.56982147
31.0833333333 4.03619466862 996.533626804
31.1666666667 6.05429200293 982.479334801
31.25 7.06334067009 968.415994131
31.3333333333 5.04524333578 958.370750795
31.4166666667 6.05429200293 946.316458792
31.5 5.04524333578 931.271215456
31.5833333333 5.04524333578 922.22597212
31.6666666667 6.05429200293 910.171680117
31.75 5.04524333578 901.126436782
31.8333333333 7.06334067009 891.063096112
31.9166666667 4.03619466862 875.026901443
32.0 4.03619466862 861.990706774
32.0833333333 6.05429200293 848.936414771
32.1666666667 7.06334067009 837.873074101
32.25 4.03619466862 829.836879433
32.3333333333 2.01809733431 821.818782098
32.4166666667 4.03619466862 814.78258743
32.5 2.01809733431 806.764490095
32.5833333333 2.01809733431 798.746392761
32.6666666667 6.05429200293 786.692100758
32.75 5.04524333578 776.646857422
32.8333333333 1.00904866716 771.637808755
32.9166666667 5.04524333578 766.592565419
33.0 4.03619466862 754.556370751
33.0833333333 6.05429200293 745.502078748
33.1666666667 5.04524333578 730.456835412
33.25 2.01809733431 725.438738078
33.3333333333 5.04524333578 716.393494742
33.4166666667 3.02714600147 708.366348741
33.5 3.02714600147 701.339202739
33.5833333333 6.05429200293 689.284910736
33.6666666667 4.03619466862 678.248716067
33.75 6.05429200293 671.194424065
33.8333333333 2.01809733431 664.17632673
33.9166666667 2.01809733431 656.158229396
34.0 5.04524333578 650.11298606
34.1666666667 7.06334067009 634.04964539
34.25 3.02714600147 626.022499389
34.3333333333 6.05429200293 611.968207386
34.5 4.03619466862 598.932012717
34.75 1.00904866716 573.92296405
34.8333333333 3.02714600147 569.895818048
35.0 1.00904866716 560.886769381
35.0833333333 2.01809733431 555.868672047
35.1666666667 1.00904866716 543.85962338
35.25 4.03619466862 533.823428711
35.3333333333 7.06334067009 518.760088041
35.4166666667 2.01809733431 514.741990707
35.5 5.04524333578 502.696747371
35.5833333333 4.03619466862 492.660552702
35.6666666667 2.01809733431 487.642455368
35.75 5.04524333578 479.597212032
35.8333333333 1.00904866716 473.588163365
36.0 1.00904866716 461.579114698
36.0833333333 2.01809733431 458.561017364
36.25 3.02714600147 448.533871362
36.4166666667 1.00904866716 436.524822695
36.5 1.00904866716 430.515774028
36.5833333333 2.01809733431 425.497676694
36.6666666667 1.00904866716 418.488628026
36.75 1.00904866716 411.479579359
36.8333333333 1.00904866716 406.470530692
36.9166666667 1.00904866716 399.461482025
37.0 1.00904866716 396.452433358
37.0833333333 2.01809733431 389.434336023
37.1666666667 1.00904866716 382.425287356
37.3333333333 2.01809733431 369.407190022
37.4166666667 2.01809733431 364.389092688
37.5 1.00904866716 357.380044021
37.5833333333 1.00904866716 350.370995353
37.75 2.01809733431 341.352898019
37.8333333333 2.01809733431 336.334800685
38.0 1.00904866716 330.325752018
38.0833333333 1.00904866716 323.31670335
38.1666666667 1.00904866716 317.307654683
38.25 1.00904866716 310.298606016
38.3333333333 2.01809733431 303.280508682
38.4166666667 1.00904866716 292.271460015
38.5 1.00904866716 286.262411348
38.6666666667 1.00904866716 274.25336268
38.75 1.00904866716 269.244314013
39.0 1.00904866716 257.235265346
39.0833333333 2.01809733431 253.217168012
39.25 1.00904866716 246.208119345
39.6666666667 2.01809733431 229.19002201
39.75 2.01809733431 222.171924676
39.8333333333 1.00904866716 219.162876009
39.9166666667 1.00904866716 216.153827342
40.0 2.01809733431 210.135730007
40.0833333333 1.00904866716 204.12668134
40.5 1.00904866716 188.117632673
40.5833333333 1.00904866716 183.108584006
40.75 1.00904866716 173.099535339
40.9166666667 1.00904866716 171.090486672
41.0833333333 1.00904866716 162.081438004
41.4166666667 1.00904866716 145.072389337
41.5833333333 2.01809733431 137.054292003
42.0 1.00904866716 120.045243336
42.5833333333 1.00904866716 101.036194669
42.8333333333 1.00904866716 93.0271460015
43.3333333333 1.00904866716 74.0180973343
43.6666666667 1.00904866716 56.0090486672
43.8333333333 1.00904866716 37.0
<matplotlib.figure.Figure at 0xaf66c90>
In [ ]:
Content source: wavelets/ThinkStats2
Similar notebooks: