Class: SurvivalSample

Inherits:
Object
  • Object
show all
Defined in:
lib/survival/SurvivalSample.rb

Overview

Object for holding survival data.

Roman Eisner

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(censored, event) ⇒ SurvivalSample

Returns a new instance of SurvivalSample.



13
14
15
16
# File 'lib/survival/SurvivalSample.rb', line 13

def initialize(censored, event)
  @censored = censored
  @event = event
end

Instance Attribute Details

#censoredObject

Returns the value of attribute censored.



11
12
13
# File 'lib/survival/SurvivalSample.rb', line 11

def censored
  @censored
end

#eventObject

Returns the value of attribute event.



11
12
13
# File 'lib/survival/SurvivalSample.rb', line 11

def event
  @event
end

Class Method Details

.bin_survivals(survs) ⇒ Object

Takes an array of Survival objects, and returns a binned hash.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/survival/SurvivalSample.rb', line 40

def SurvivalSample.bin_survivals(survs)
  bins = Hash.new

  survs.each do |s|
    bins[s.event] ||= Array.new

    bins[s.event] << s
  end

  return bins
end

.create_survival_objects(surv_array) ⇒ Object

Takes an array of hashes, each has must have two keys: :event => The event time :censored => A boolean, true if this patient has been right-censored.



55
56
57
# File 'lib/survival/SurvivalSample.rb', line 55

def SurvivalSample.create_survival_objects(surv_array)
  return surv_array.map { |s| SurvivalSample.new(s[:censored], s[:event]) }
end

Instance Method Details

#<=>(o) ⇒ Object

Sort method:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/survival/SurvivalSample.rb', line 23

def <=>(o)

  if self.event != o.event
    return self.event <=> o.event
  else
    if (self.censored == o.censored)
      return 0
    elsif self.censored
      return 1
    else
      return -1
    end
  end

end

#to_sObject



18
19
20
# File 'lib/survival/SurvivalSample.rb', line 18

def to_s
  "Survival: {Event: #{@event}, Censored: #{@censored}}"
end