def impute_ros(observations, censorship, df=None, min_uncensored=2, max_fraction_censored=0.8, substitution_fraction=0.5, transform_in=numpy.log, transform_out=numpy.exp, as_array=True):
 if (df is None):
  df = pandas.DataFrame({'obs': observations, 'cen': censorship})
  observations = 'obs'
  censorship = 'cen'
 N_observations = df.shape[0]
 N_censored = df[censorship].astype(int).sum()
 N_uncensored = (N_observations - N_censored)
 fraction_censored = (N_censored / N_observations)
 if (N_censored == 0):
  output = df[[observations, censorship]].copy()
  output.loc[:, 'final'] = df[observations]
 elif ((N_uncensored < min_uncensored) or (fraction_censored > max_fraction_censored)):
  output = df[[observations, censorship]].copy()
  output.loc[:, 'final'] = df[observations]
  output.loc[(df[censorship], 'final')] *= substitution_fraction
 else:
  output = _do_ros(df, observations, censorship, transform_in, transform_out)
 if as_array:
  output = output['final'].values
 return output

def impute_ros ( observations , censorship , df = None , min_uncensored = 2 , max_fraction_censored = 0.8 , substitution_fraction = 0.5 , transform_in = numpy . log , transform_out = numpy . exp , as_array = True ) : if ( df is None ) : df = pandas . DataFrame ( { 'obs' : observations , 'cen' : censorship } ) observations = 'obs' censorship = 'cen' N_observations = df . shape [ 0 ] N_censored = df [ censorship ] . astype ( int ) . sum ( ) N_uncensored = ( N_observations - N_censored ) fraction_censored = ( N_censored / N_observations ) if ( N_censored == 0 ) : output = df [ [ observations , censorship ] ] . copy ( ) output . loc [ : , 'final' ] = df [ observations ] elif ( ( N_uncensored < min_uncensored ) or ( fraction_censored > max_fraction_censored ) ) : output = df [ [ observations , censorship ] ] . copy ( ) output . loc [ : , 'final' ] = df [ observations ] output . loc [ ( df [ censorship ] , 'final' ) ] *= substitution_fraction else : output = _do_ros ( df , observations , censorship , transform_in , transform_out ) if as_array : output = output [ 'final' ] . values return output
impute censored dataset using regression on order statistics .