blib/lib/Statistics/LogRank.pm

filter: Statementstmt 95.0% 57 / 60 Branchbran 70.0% 7 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 84.5% 71 / 84 CC 7 SCAR 13.1
CC
7
Cov
89%
perform_log_rank_test
6.1
new
2.1
BEGIN
1.0
CRAP 3.7
↑ Summary
1 package Statistics::LogRank;
2  
3 1 $VERSION = '0.03';
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Statistics::Distributions;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 ##############
10 sub new
11 1 ▶{
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
12 1 my $proto = shift;
13 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
14 1 my $self= {};
15  
16 1 bless($self,$class);
17 1 return $self;
18 }
19 ##############
20  
21 ##############
22 4 ▶sub load_data {
Subroutine load_data: called CC=1 SCAR=0.0
Pod undocumented
23 4 my $self = shift;
24 4 my $sample_name = shift;
25  
26 4 my (@sample_data)=@_;
27  
28 4 $self->{sample_data}->{$sample_name}=\@sample_data;
29  
30 4 return $self;
31 } # end sub load_data
32 ##############
33  
34 ##############
35 1 ▶sub perform_log_rank_test {
Subroutine perform_log_rank_test: called CC=6 SCAR=18.0
Pod undocumented
36 1 my $self=shift;
37  
38 1 my ($first_survive_name,$first_fail_name,$second_survive_name,$second_fail_name)=@_;
39  
40 1 my (@e,@d,@v);
41 1 my ($N1,$D,$N2,$N);
42  
43 1 my $count=0;
44 1 ▶ while ($count < @{$self->{sample_data}->{$first_survive_name}})
Branch: 1 branch
BranchTrueFalseTotal
if ($count < @{$self->{"sample_data"}{$first_survive_name};}) 6 1 7
45 {
46 6 $N1 = ${$self->{sample_data}->{$first_survive_name}}[$count];
47  
48 6 $D = ${$self->{sample_data}->{$first_fail_name}}[$count] + ${$self->{sample_data}->{$second_fail_name}}[$count];
49  
50 6 $N2 = ${$self->{sample_data}->{$second_survive_name}}[$count];
51  
52 6 $N = $N1 + $N2;
53  
54 0 ▶ if ($N1 + $N2 == 0) {$e[$count]=0;}
Branch: 1 branch
BranchTrueFalseTotal
if ($N1 + $N2 == 0) { } 0 6 6
55 6 else {$e[$count] = $N1 * $D / ( $N1 + $N2);}
56 6 $d[$count] = ${$self->{sample_data}->{$first_fail_name}}[$count] - $e[$count];
57 0 ▶ if (($N**2 * ($N-1))==0) {$v[$count]=0;}
Branch: 1 branch
BranchTrueFalseTotal
if ($N ** 2 * ($N - 1) == 0) { } 0 6 6
58 6 else {$v[$count] = ($N1 * $N2 * $D *($N - $D)) / ($N**2 * ($N-1));}
59  
60 6 $count++;
61 } # end while
62  
63  
64 1 my $total_e=0;
65 1 my $total_d=0;
66 1 my $total_v=0;
67  
68 1 my $count=0;
69 1 ▶ while ($count < @{$self->{sample_data}->{$first_survive_name}})
Branch: 1 branch
BranchTrueFalseTotal
if ($count < @{$self->{"sample_data"}{$first_survive_name};}) 6 1 7
70 {
71 6 $total_e += $e[$count];
72 6 $total_d += $d[$count];
73 6 $total_v += $v[$count];
74 6 $count++
75 }
76  
77 0 ▶if ($total_v ==0) {$total_v = 0.000000000001;}
Branch: 1 branch
BranchTrueFalseTotal
if ($total_v == 0) 0 1 1
78  
79 1 my $log_rank_statistic = $total_d**2 / $total_v;
80 1 my $chi_prob=Statistics::Distributions::chisqrprob (1,$log_rank_statistic);
81  
82 1 return ($log_rank_statistic,$chi_prob);
83 } # end sub perform_log_rank_test
84 ##############
85 1 1;
86  
87 __END__
↑ Summary