KaplanMeier.test_diff in survival2 raises IndexError #547

Open
kshedden opened this Issue Oct 28, 2012 · 3 comments

Projects

None yet

2 participants

@kshedden
Contributor

An index error occurs at this line when calling KaplanMeier.test_diff (only for certain data sets):

dk = dk[:,list(tind)]

It appears to be easily fixed by changing this line (4 lines up)

if np.max(tind) != len(dk):

to this:

if np.max(tind) > len(dk)-1:

This occurs in two different places, once in the "if self.censoring == None" condition and once in the following "else" condition.

@josef-pkt
Member

The fix looks correct to me.

A simple test case that triggers the bug would be useful.

Note: survival2 has been rewritten and enhance in a branch. code is not yet merged into master
I opened PR #548 to keep track of that.

comments on and help with #548 would be very useful to get this properly included in statsmodels.

@kshedden
Contributor

Here is some code that produces this error:

import numpy as np
from statsmodels.sandbox.survival2 import KaplanMeier
T = [0.5, 0.14, 0.36, 0.13, 0.19, 1.92, 0.02, 1.77, 0.05, 1.08]
C = np.ones(10)
G = np.array([0]_5 + [1]_5)
Z = np.vstack((T, G, C)).T
km = KaplanMeier(Z, 0, exog=1, censoring=2)
km.fit()
p = km.test_diff([0,1])

@josef-pkt josef-pkt added this to the 0.8 milestone Jan 11, 2015
@josef-pkt
Member

Needs to be checked against whatever version of survival2 will be the final PR to be merged.
I don't think anything will happen for 0.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment