survival 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -18,10 +18,14 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- To generate a Kaplan-Meier survival plot:
22
-
23
- #survivals is an array of hashes. Each represents a sample, and must define :event (the event time) and :censored (boolean describing whether this sample is censored)
24
- points = KaplanMeier.generate_plot_points(SurvivalSample.create_survival_objects(survivals))
21
+ To generate a Kaplan-Meier survival curve:
22
+
23
+ #survivals is an array of hashes. Each hash represents a sample, and must define
24
+ # :event (the event time)
25
+ # :censored (boolean describing whether this sample is right-censored)
26
+ survivals = [{:event => 21, :censored => false}, {:event => 13, :censored => true}, ... ]
27
+ survival_objs = SurvivalSample.create_survival_objects(survivals) #Create survival sample objects
28
+ points = KaplanMeier.generate_plot_points(survival_objs) #Generate the x,y coordinates of the survival curve
25
29
 
26
30
  #points is an array of [x,y] pairs for plotting. Use your favorite plotting library to plot the line graph.
27
31
 
@@ -9,11 +9,12 @@ class KaplanMeier
9
9
 
10
10
  #Creates the x,y pairs for plotting a survival curve,
11
11
  #using the Kaplan-Meier method.
12
- def self.generate_plot_points(survivals)
12
+ def self.generate_plot_points(survivals, include_horizontal=true)
13
13
 
14
14
  bins = SurvivalSample.bin_survivals(survivals)
15
15
 
16
16
  points = [[0,100]]
17
+ median = nil
17
18
 
18
19
  terms = Array.new
19
20
  n = survivals.length #Number we are considering at this time point (total surviving minus censored)
@@ -43,14 +44,22 @@ class KaplanMeier
43
44
 
44
45
  s_t = s_t * 100.0
45
46
 
47
+ #The median survival time is calculated as the smallest survival time
48
+ #for which the survivor function is less than or equal to 0.5
49
+ if ( (s_t <= 50.0) && (median.nil?) ){
50
+ median = t
51
+ }
52
+
46
53
  #Add to plot points
47
- points << [t, prev] #Horizontal line from previous point
54
+ if include_horizontal
55
+ points << [t, prev] #Horizontal line from previous point
56
+ end
48
57
  points << [t, s_t] #Current point
49
58
  prev = s_t
50
59
 
51
60
  end
52
61
 
53
- return points
62
+ return points, median
54
63
  end
55
64
 
56
65
  end
@@ -15,7 +15,7 @@ class SurvivalSample
15
15
  @event = event
16
16
  end
17
17
 
18
- def to_s
18
+ def to_s
19
19
  "Survival: {Event: #{@event}, Censored: #{@censored}}"
20
20
  end
21
21
 
@@ -1,3 +1,3 @@
1
1
  module Survival
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: survival
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-23 00:00:00.000000000 Z
12
+ date: 2013-09-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A gem that provides survival analysis functionality
15
15
  email: