File Coverage

blib/lib/Statistics/LogRank.pm
Criterion Covered Total %
statement 54 58 93.1
branch 3 6 50.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 0 3 0.0
total 64 76 84.2


line stmt bran cond sub pod time code
1             package Statistics::LogRank;
2              
3             $VERSION = '0.03';
4              
5 1     1   22636 use strict;
  1         2  
  1         37  
6 1     1   6 use Carp;
  1         2  
  1         99  
7 1     1   933 use Statistics::Distributions;
  1         3674  
  1         480  
8              
9             ##############
10             sub new
11             {
12 1     1 0 18 my $proto = shift;
13 1   33     7 my $class = ref($proto) || $proto;
14 1         3 my $self= {};
15              
16 1         2 bless($self,$class);
17 1         7 return $self;
18             }
19             ##############
20              
21             ##############
22             sub load_data {
23 4     4 0 5 my $self = shift;
24 4         5 my $sample_name = shift;
25              
26 4         10 my (@sample_data)=@_;
27              
28 4         16 $self->{sample_data}->{$sample_name}=\@sample_data;
29              
30 4         10 return $self;
31             } # end sub load_data
32             ##############
33              
34             ##############
35             sub perform_log_rank_test {
36 1     1 0 3 my $self=shift;
37              
38 1         3 my ($first_survive_name,$first_fail_name,$second_survive_name,$second_fail_name)=@_;
39              
40 1         1 my (@e,@d,@v);
41 0         0 my ($N1,$D,$N2,$N);
42              
43 1         3 my $count=0;
44 1         4 while ($count < @{$self->{sample_data}->{$first_survive_name}})
  7         24  
45             {
46 6         7 $N1 = ${$self->{sample_data}->{$first_survive_name}}[$count];
  6         12  
47              
48 6         7 $D = ${$self->{sample_data}->{$first_fail_name}}[$count] + ${$self->{sample_data}->{$second_fail_name}}[$count];
  6         12  
  6         10  
49              
50 6         7 $N2 = ${$self->{sample_data}->{$second_survive_name}}[$count];
  6         9  
51              
52 6         10 $N = $N1 + $N2;
53              
54 6 50       12 if ($N1 + $N2 == 0) {$e[$count]=0;}
  0         0  
  6         14  
55             else {$e[$count] = $N1 * $D / ( $N1 + $N2);}
56 6         7 $d[$count] = ${$self->{sample_data}->{$first_fail_name}}[$count] - $e[$count];
  6         18  
57 6 50       15 if (($N**2 * ($N-1))==0) {$v[$count]=0;}
  0         0  
  6         23  
58             else {$v[$count] = ($N1 * $N2 * $D *($N - $D)) / ($N**2 * ($N-1));}
59              
60 6         7 $count++;
61             } # end while
62              
63              
64 1         2 my $total_e=0;
65 1         3 my $total_d=0;
66 1         2 my $total_v=0;
67              
68 1         9 my $count=0;
69 1         2 while ($count < @{$self->{sample_data}->{$first_survive_name}})
  7         30  
70             {
71 6         7 $total_e += $e[$count];
72 6         9 $total_d += $d[$count];
73 6         7 $total_v += $v[$count];
74 6         7 $count++
75             }
76              
77 1 50       6 if ($total_v ==0) {$total_v = 0.000000000001;}
  0         0  
78              
79 1         12 my $log_rank_statistic = $total_d**2 / $total_v;
80 1         7 my $chi_prob=Statistics::Distributions::chisqrprob (1,$log_rank_statistic);
81              
82 1         93 return ($log_rank_statistic,$chi_prob);
83             } # end sub perform_log_rank_test
84             ##############
85             1;
86              
87             __END__