Exemple #1
0
 def __init__(self, dtxns=None, ulims=None, llims=None, all=None, ind=None):
     """
     Find the Kaplan-Meier CDF estimate from right-censored (upper limits)
     or left-censored (lower limits) data.  The data may be entered as
     detected values (dtxns) and EITHER uppler (ulims) or lower (llims)
     limits, or as a single set of data values (all) accompanied by
     an array of integer indicators (0=dtxn, -1=lower limit, 1=upper limit).
     """
     if all != None:
         if dtxns or ulims or llims:
             raise ValueError, 'Illegal selection of input parameters!'
         if (ind == None) or (len(ind) != len(all)):
             raise ValueError, '"all" values must be accompanied by indicators!'
         self.all = all
         self.ind = ind
         self.ntot = len(all)
     else:
         if (ulims != None) and (llims != None):
             raise ValueError, 'Only one of upper or lower limits allowed!'
         if ulims != None:
             nlim = len(ulims)
             self.limit = 'Upper'
             self.all = concatenate([dtxns, ulims])
         elif llims != None:
             nlim = len(llims)
             self.limit = 'Lower'
             self.all = concatenate([dtxs, llims])
         else:
             raise ValueError, 'Must specify dtxns and 1 of ulims/llims!'
         nd = len(dtxns)
         self.ntot = nd + nlim
         self.ind = zeros(self.ntot)
         if self.limit == 'Upper':
             self.ind[nd:] = 1
         else:
             self.ind[nd:] = -1
     ierr, self.km_cdf, self.cdf_err, self.mean, self.std, self.nu, \
         self.uncens, self.nc, self.cens = kmestm(self.ind, self.all)
     if ierr != 0:
         raise ValueError, 'Invalid indicator array!'
     # Trim sizes of returned arrays.
     self.km_cdf = self.km_cdf[:self.nu]
     self.cdf_err = self.cdf_err[:self.nu]
     self.uncens = self.uncens[:self.nu]
     self.cens = self.cens[:self.nc]
     # Note there is no binned dist'n (yet).
     self.nbins = None
     # Define a Population1D object
     wts = zeros(len(self.uncens), Float)
     for i in range(len(self.uncens)-1):
         wts[i] = self.km_cdf[i]-self.km_cdf[i+1]
     wts[-1] = self.km_cdf[-1]
     Population1D.__init__(self, self.uncens, wts)
Exemple #2
0
from numpy import *
from _asurvkm import kmestm, kmdif, quart

# Censoring index (-1 = censored):
gal1_ind = array([0, 0, -1, -1, 0, -1])
# IR abs. magnitudes for galaxies:
gal1_mag = array([28.5, 26.9, 29.7, 28.1, 30.1, 27.6])

# Diff'l KM estimate bin params:
nb, w, m_l = 5, 2., 25.

ierr,sx,vx,smean,err,nu,su,nc,sc =  kmestm(gal1_ind,gal1_mag)
sx = sx[:nu]
su = su[:nu]
sc = sc[:nc]
ntot = gal1_mag.shape[0]
print 'KM CDF:'
print su
print sc
print

# Diff'l:
bin_l,bin_u,diff = kmdif(sx, su, ntot, m_l, w, nb) 
print 'Diff\'l:'
print bin_l
print bin_u
print diff
print

# Quartiles:
q = quart(su, sc)
Exemple #3
0
from numpy import *
from _asurvkm import kmestm, kmdif, quart

# Censoring index (-1 = censored):
gal1_ind = array([0, 0, -1, -1, 0, -1])
# IR abs. magnitudes for galaxies:
gal1_mag = array([28.5, 26.9, 29.7, 28.1, 30.1, 27.6])

# Diff'l KM estimate bin params:
nb, w, m_l = 5, 2., 25.

ierr, sx, vx, smean, err, nu, su, nc, sc = kmestm(gal1_ind, gal1_mag)
sx = sx[:nu]
su = su[:nu]
sc = sc[:nc]
ntot = gal1_mag.shape[0]
print 'KM CDF:'
print su
print sc
print

# Diff'l:
bin_l, bin_u, diff = kmdif(sx, su, ntot, m_l, w, nb)
print 'Diff\'l:'
print bin_l
print bin_u
print diff
print

# Quartiles:
q = quart(su, sc)