>>> import numpy as np
>>> from statsmodels.sandbox.survival2 import KaplanMeier
>>> dta = sm.datasets.strikes.load()
- >>> dta = dta.values()[-1]
+ >>> dta = dta['raw_data']
>>> dta[range(5),:]
array([[ 7.00000000e+00, 1.13800000e-02],
[ 9.00000000e+00, 1.13800000e-02],
if self.censoring == None:
events = np.bincount(t)
t = np.unique(t)
- events = events[:,list(t)]
+ events = events[list(t)]
events = events.astype(float)
eventsSum = np.cumsum(events)
eventsSum = np.r_[0,eventsSum]
events = np.bincount(t,censoring)
censored = np.bincount(t,reverseCensoring)
t = np.unique(t)
- censored = censored[:,list(t)]
+ censored = censored[list(t)]
censored = censored.astype(float)
censoredSum = np.cumsum(censored)
censoredSum = np.r_[0,censoredSum]
- events = events[:,list(t)]
+ events = events[list(t)]
events = events.astype(float)
eventsSum = np.cumsum(events)
eventsSum = np.r_[0,eventsSum]
>>> import numpy as np
>>> from statsmodels.sandbox.survival2 import KaplanMeier
>>> dta = sm.datasets.strikes.load()
- >>> dta = dta.values()[-1]
+ >>> dta = dta['raw_data']
>>> censoring = np.ones_like(dta[:,0])
>>> censoring[dta[:,0] > 80] = 0
>>> dta = np.c_[dta,censoring]
if np.max(tind) != len(dk):
dif = np.max(tind) - len(dk) + 1
dk = np.r_[dk,[0]*dif]
- dk = dk[:,list(tind)]
- d = d[:,list(tind)]
+ dk = dk[list(tind)]
+ d = d[list(tind)]
dk = dk.astype(float)
d = d.astype(float)
dkSum = np.cumsum(dk)
d = d[n>1]
dk = dk[n>1]
nk = nk[n>1]
+ if s.shape == tind.shape: # s is calculated once, so only filter it once, not per-group
+ s = s[n>1]
n = n[n>1]
- s = s[n>1]
ek = (nk * d)/(n)
Z.append(np.sum(s * (dk - ek)))
NK.append(nk)
dif = np.max(tind) - len(dk) + 1
dk = np.r_[dk,[0]*dif]
ck = np.r_[ck,[0]*dif]
- dk = dk[:,list(tind)]
- ck = ck[:,list(tind)]
- d = d[:,list(tind)]
+ dk = dk[list(tind)]
+ ck = ck[list(tind)]
+ d = d[list(tind)]
dk = dk.astype(float)
d = d.astype(float)
ck = ck.astype(float)
ck = np.r_[0,ck]
dkSum = np.r_[0,dkSum]
dSum = np.r_[0,dSum]
- censored = censored[:,list(tind)]
+ censored = censored[list(tind)]
censored = censored.astype(float)
censoredSum = np.cumsum(censored)
censoredSum = np.r_[0,censoredSum]
d = d[n>1]
dk = dk[n>1]
nk = nk[n>1]
+ if s.shape == tind.shape: # s is calculated once, so only filter it once, not per-group
+ s = s[n>1]
n = n[n>1]
- s = s[n>1]
ek = (nk * d)/(n)
Z.append(np.sum(s * (dk - ek)))
NK.append(nk)