Skip to content

Commit

Permalink
few more doc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jul 20, 2017
1 parent 8995d59 commit 6f85e2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions docs/Survival analysis with lifelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ as the censorship event. This is also an example where the current time
is not the only cause of censorship -- there are alternative
events (eg: death in office) that can censor.)

To estimate the survival function, we use the `Kaplan-Meier
To estimate the survival function, we first will use the `Kaplan-Meier
Estimate <http://en.wikipedia.org/wiki/Kaplan%E2%80%93Meier_estimator>`__,
defined:

Expand All @@ -44,6 +44,7 @@ where :math:`d_i` are the number of death events at time :math:`t` and
:math:`n_i` is the number of subjects at risk of death just prior to time
:math:`t`.


Let's bring in our dataset.

.. code:: python
Expand All @@ -60,7 +61,6 @@ Let's bring in our dataset.
#was observed or not.
.. raw:: html

<div style="max-height:1000px;max-width:1500px;overflow:auto;">
Expand Down Expand Up @@ -188,6 +188,8 @@ From the ``lifelines`` library, we'll need the
from lifelines import KaplanMeierFitter
kmf = KaplanMeierFitter()
.. note:: Other ways to estimate the survival function in lifelines are ``BreslowFlemingHarringtonFitter``, ``WeibullFitter``, ``ExponentialFitter``

For this estimation, we need the duration each leader was/has been in
office, and whether or not they were observed to have left office
(leaders who died in office or were in office in 2008, the latest date
Expand Down
7 changes: 5 additions & 2 deletions tests/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
from lifelines import statistics as stats
from lifelines.datasets import load_waltons, load_g3


def test_sample_size_necessary_under_cph():
assert stats.sample_size_necessary_under_cph(0.8, 1, 0.8, 0.2, 0.139) == (14, 14)
assert stats.sample_size_necessary_under_cph(0.8, 1, 0.5, 0.5, 1.2) == (950, 950)
assert stats.sample_size_necessary_under_cph(0.8, 1.5, 0.5, 0.5, 1.2) == (1231, 821)
assert stats.sample_size_necessary_under_cph(0.8, 1.5, 0.5, 0.5, 1.2, alpha=0.01) == (1832, 1221)


def test_power_under_cph():
assert abs(stats.power_under_cph(12,12, 0.8, 0.2, 0.139) - 0.744937) < 10e-6
assert abs(stats.power_under_cph(12,20, 0.8, 0.2, 1.2) - 0.05178317) < 10e-6
assert abs(stats.power_under_cph(12, 12, 0.8, 0.2, 0.139) - 0.744937) < 10e-6
assert abs(stats.power_under_cph(12, 20, 0.8, 0.2, 1.2) - 0.05178317) < 10e-6


def test_unequal_intensity_with_random_data():
data1 = np.random.exponential(5, size=(2000, 1))
Expand Down

0 comments on commit 6f85e2c

Please sign in to comment.