Skip to content

Commit

Permalink
v0.17.5 (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon authored Jan 25, 2019
1 parent 89f1264 commit 94a78df
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
### Changelogs

### 0.17.5
- more bugs in `plot_covariate_groups` fixed when using non-numeric strata.

#### 0.17.4
- Fix bug in `plot_covariate_groups` that wasn't allowing for strata to be used.
- change name of `multicenter_aids_cohort_study` to `load_multicenter_aids_cohort_study`
- `groups` is now called `values` in `CoxPHFitter.plot_covariate_groups`

#### 0.17.3
- Fix in `compute_residuals` when using `schoenfeld` and the minumum duration has only censored subjects.
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#
# The short X.Y version.

version = "0.17.4"
version = "0.17.5"
# The full version, including dev info
release = version

Expand Down
4 changes: 2 additions & 2 deletions lifelines/fitters/coxph_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from lifelines.utils import (
_get_index,
_to_list,
_to_array,
_to_tuple,
survival_table_from_events,
inv_normal_cdf,
normalize,
Expand Down Expand Up @@ -1580,7 +1580,7 @@ def plot_covariate_groups(self, covariate, values, **kwargs):
ax = plt.figure().add_subplot(1, 1, 1)
x_bar = self._norm_mean.to_frame().T

for name, value in zip(self.strata, _to_array(stratum)):
for name, value in zip(_to_list(self.strata), _to_tuple(stratum)):
x_bar[name] = value

X = pd.concat([x_bar] * len(values))
Expand Down
17 changes: 13 additions & 4 deletions lifelines/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,22 @@ def logrank_test(durations_A, durations_B, event_observed_A=None, event_observed
"""
Measures and reports on whether two intensity processes are different. That is, given two
event series, determines whether the data generating processes are statistically different.
The test-statistic is chi-squared under the null hypothesis.
The test-statistic is chi-squared under the null hypothesis. Let h_i(t) be the hazard ratio of
group i at time t:
- H_0: both event series are from the same generating processes
- H_A: the event series are from different generating processes.
- H_0: h_1(t) = h_2(t)
- H_A: h_1(t) = k * h_2(t), k <> 1
This implicitly uses the log-rank weights.
Important
----------
The logrank test has maximum power when the assumption of proportional hazards is true. As a consquence, if the survival
curves cross, the logrank test will give an inaccurate assessment of differences.
Parameters
----------
Expand Down Expand Up @@ -326,7 +334,8 @@ def multivariate_logrank_test(
This test is a generalization of the logrank_test: it can deal with n>2 populations (and should
be equal when n=2):
- H_0: all event series are from the same generating processes
- H_0: h_1(t) = h_2(t) = h_3(t) = ... = h_n(t)
- H_A: there exist atleast one group that differs from the other.
Expand Down
6 changes: 6 additions & 0 deletions lifelines/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,12 @@ def _to_list(x):
return x


def _to_tuple(x):
if not isinstance(x, tuple):
return (x,)
return x


def format_p_value(decimals):
threshold = 0.5 * 10 ** (-decimals)
return lambda p: "<%s" % threshold if p < threshold else "{:4.{prec}f}".format(p, prec=decimals)
Expand Down
2 changes: 1 addition & 1 deletion lifelines/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

__version__ = "0.17.4"
__version__ = "0.17.5"
19 changes: 18 additions & 1 deletion tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,28 @@ def test_coxph_plot_covariate_groups(self, block):
def test_coxph_plot_covariate_groups_with_strata(self, block):
df = load_rossi()
cp = CoxPHFitter()
cp.fit(df, "week", "arrest", strata=["paro"])
cp.fit(df, "week", "arrest", strata=["paro", "fin"])
cp.plot_covariate_groups("age", [10, 50, 80])
self.plt.title("test_coxph_plot_covariate_groups_with_strata")
self.plt.show(block=block)

def test_coxph_plot_covariate_groups_with_single_strata(self, block):
df = load_rossi()
cp = CoxPHFitter()
cp.fit(df, "week", "arrest", strata="paro")
cp.plot_covariate_groups("age", [10, 50, 80])
self.plt.title("test_coxph_plot_covariate_groups_with_strata")
self.plt.show(block=block)

def test_coxph_plot_covariate_groups_with_nonnumeric_strata(self, block):
df = load_rossi()
df["strata"] = np.random.choice(["A", "B"], size=df.shape[0])
cp = CoxPHFitter()
cp.fit(df, "week", "arrest", strata="strata")
cp.plot_covariate_groups("age", [10, 50, 80])
self.plt.title("test_coxph_plot_covariate_groups_with_single_strata")
self.plt.show(block=block)

def test_coxtv_plotting_with_subset_of_columns(self, block):
df = load_stanford_heart_transplants()
ctv = CoxTimeVaryingFitter()
Expand Down

0 comments on commit 94a78df

Please sign in to comment.