line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Statistics::Lite;
|
2
|
9
|
|
|
9
|
|
191659
|
use strict;
|
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
286
|
|
3
|
9
|
|
|
9
|
|
48
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
|
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
13556
|
|
4
|
|
|
|
|
|
|
require Exporter;
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '3.62';
|
7
|
|
|
|
|
|
|
@ISA = qw(Exporter);
|
8
|
|
|
|
|
|
|
@EXPORT = ();
|
9
|
|
|
|
|
|
|
@EXPORT_OK = qw(min max range sum count mean median mode variance stddev variancep stddevp statshash statsinfo frequencies);
|
10
|
|
|
|
|
|
|
%EXPORT_TAGS=
|
11
|
|
|
|
|
|
|
(
|
12
|
|
|
|
|
|
|
all => [ @EXPORT_OK ],
|
13
|
|
|
|
|
|
|
funcs => [qw],
|
14
|
|
|
|
|
|
|
stats => [qw],
|
15
|
|
|
|
|
|
|
);
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub definedvals
|
18
|
|
|
|
|
|
|
{
|
19
|
127
|
|
|
127
|
0
|
217
|
return grep{defined}@_;
|
|
600
|
|
|
|
|
1509
|
|
20
|
|
|
|
|
|
|
}
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub count
|
23
|
|
|
|
|
|
|
{
|
24
|
4
|
|
|
4
|
1
|
10
|
return scalar definedvals @_;
|
25
|
|
|
|
|
|
|
}
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub min
|
28
|
|
|
|
|
|
|
{
|
29
|
7
|
|
|
7
|
1
|
39
|
my @data = definedvals @_;
|
30
|
7
|
100
|
|
|
|
56
|
return unless @data;
|
31
|
4
|
50
|
|
|
|
14
|
return $data[0] unless @data > 1;
|
32
|
4
|
|
|
|
|
9
|
my $min= shift @data;
|
33
|
4
|
100
|
|
|
|
8
|
foreach(@data) { $min= $_ if $_ < $min; }
|
|
6
|
|
|
|
|
23
|
|
34
|
4
|
|
|
|
|
20
|
return $min;
|
35
|
|
|
|
|
|
|
}
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub max
|
38
|
|
|
|
|
|
|
{
|
39
|
11
|
|
|
11
|
1
|
31
|
my @data = definedvals @_;
|
40
|
11
|
100
|
|
|
|
49
|
return unless @data;
|
41
|
8
|
50
|
|
|
|
49
|
return $data[0] unless @data > 1;
|
42
|
8
|
|
|
|
|
18
|
my $max= shift @data;
|
43
|
8
|
100
|
|
|
|
20
|
foreach(@data) { $max= $_ if $_ > $max; }
|
|
23
|
|
|
|
|
59
|
|
44
|
8
|
|
|
|
|
35
|
return $max;
|
45
|
|
|
|
|
|
|
}
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub range
|
48
|
|
|
|
|
|
|
{
|
49
|
7
|
|
|
7
|
1
|
19
|
my @data = definedvals @_;
|
50
|
7
|
100
|
|
|
|
25
|
return unless @data;
|
51
|
6
|
100
|
|
|
|
36
|
return 0 unless @data > 1;
|
52
|
5
|
100
|
|
|
|
28
|
return abs($data[1]-$data[0]) unless @data > 2;
|
53
|
1
|
|
|
|
|
2
|
my $min= shift @data; my $max= $min;
|
|
1
|
|
|
|
|
2
|
|
54
|
1
|
50
|
|
|
|
3
|
foreach(@data) { $min= $_ if $_ < $min; $max= $_ if $_ > $max; }
|
|
2
|
50
|
|
|
|
6
|
|
|
2
|
|
|
|
|
6
|
|
55
|
1
|
|
|
|
|
4
|
return $max - $min;
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub sum
|
59
|
|
|
|
|
|
|
{
|
60
|
40
|
|
|
40
|
1
|
95
|
my @data = definedvals @_;
|
61
|
40
|
50
|
|
|
|
116
|
return unless @data;
|
62
|
40
|
50
|
|
|
|
102
|
return $data[0] unless @data > 1;
|
63
|
40
|
|
|
|
|
57
|
my $sum;
|
64
|
40
|
|
|
|
|
75
|
foreach(@data) { $sum+= $_; }
|
|
206
|
|
|
|
|
350
|
|
65
|
40
|
|
|
|
|
281
|
return $sum;
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub mean
|
69
|
|
|
|
|
|
|
{
|
70
|
25
|
|
|
25
|
1
|
72
|
my @data = definedvals @_;
|
71
|
25
|
100
|
|
|
|
78
|
return unless @data;
|
72
|
24
|
100
|
|
|
|
80
|
return $data[0] unless @data > 1;
|
73
|
22
|
|
|
|
|
61
|
return sum(@data)/scalar(@data);
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub median
|
77
|
|
|
|
|
|
|
{
|
78
|
3
|
|
|
3
|
1
|
22
|
my @data = definedvals @_;
|
79
|
3
|
50
|
|
|
|
11
|
return unless @data;
|
80
|
3
|
50
|
|
|
|
10
|
return $data[0] unless @data > 1;
|
81
|
3
|
|
|
|
|
13
|
@data= sort{$a<=>$b}@data;
|
|
23
|
|
|
|
|
31
|
|
82
|
3
|
100
|
|
|
|
15
|
return $data[$#data/2] if @data&1;
|
83
|
2
|
|
|
|
|
5
|
my $mid= @data/2;
|
84
|
2
|
|
|
|
|
13
|
return ($data[$mid-1]+$data[$mid])/2;
|
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub mode
|
88
|
|
|
|
|
|
|
{
|
89
|
2
|
|
|
2
|
1
|
8
|
my @data = definedvals @_;
|
90
|
2
|
50
|
|
|
|
10
|
return unless @data;
|
91
|
2
|
50
|
|
|
|
7
|
return $data[0] unless @data > 1;
|
92
|
2
|
|
|
|
|
4
|
my %count;
|
93
|
2
|
|
|
|
|
6
|
foreach(@data) { $count{$_}++; }
|
|
11
|
|
|
|
|
26
|
|
94
|
2
|
|
|
|
|
9
|
my $maxhits= max(values %count);
|
95
|
2
|
100
|
|
|
|
7
|
foreach(keys %count) { delete $count{$_} unless $count{$_} == $maxhits; }
|
|
8
|
|
|
|
|
23
|
|
96
|
2
|
|
|
|
|
8
|
return mean(keys %count);
|
97
|
|
|
|
|
|
|
}
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub variance
|
100
|
|
|
|
|
|
|
{
|
101
|
8
|
|
|
8
|
1
|
23
|
my @data = definedvals @_;
|
102
|
8
|
50
|
|
|
|
30
|
return unless @data;
|
103
|
8
|
50
|
|
|
|
24
|
return 0 unless @data > 1;
|
104
|
8
|
|
|
|
|
22
|
my $mean= mean @data;
|
105
|
8
|
|
|
|
|
38
|
return (sum map { ($_ - $mean)**2 } @data) / $#data;
|
|
44
|
|
|
|
|
1067602
|
|
106
|
|
|
|
|
|
|
}
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub variancep
|
109
|
|
|
|
|
|
|
{
|
110
|
8
|
|
|
8
|
1
|
32
|
my @data = definedvals @_;
|
111
|
8
|
50
|
|
|
|
49
|
return unless @data;
|
112
|
8
|
50
|
|
|
|
25
|
return 0 unless @data > 1;
|
113
|
8
|
|
|
|
|
28
|
my $mean= mean @data;
|
114
|
8
|
|
|
|
|
20
|
return (sum map { ($_ - $mean)**2 } @data) / ( $#data +1 );
|
|
46
|
|
|
|
|
112
|
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub stddev
|
118
|
|
|
|
|
|
|
{
|
119
|
4
|
|
|
4
|
1
|
31
|
my @data = definedvals @_;
|
120
|
4
|
50
|
|
|
|
21
|
return unless @data;
|
121
|
4
|
50
|
|
|
|
17
|
return 0 unless @data > 1;
|
122
|
4
|
|
|
|
|
39
|
return sqrt variance @data;
|
123
|
|
|
|
|
|
|
}
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub stddevp
|
126
|
|
|
|
|
|
|
{
|
127
|
4
|
|
|
4
|
1
|
14
|
my @data = definedvals @_;
|
128
|
4
|
50
|
|
|
|
19
|
return unless @data;
|
129
|
4
|
50
|
|
|
|
15
|
return 0 unless @data > 1;
|
130
|
4
|
|
|
|
|
19
|
return sqrt variancep @data;
|
131
|
|
|
|
|
|
|
}
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub statshash
|
134
|
|
|
|
|
|
|
{
|
135
|
3
|
|
|
3
|
1
|
35
|
my @data = definedvals @_;
|
136
|
3
|
50
|
|
|
|
10
|
return unless @data;
|
137
|
|
|
|
|
|
|
return
|
138
|
|
|
|
|
|
|
(
|
139
|
3
|
50
|
|
|
|
14
|
count => 1,
|
140
|
|
|
|
|
|
|
min => $data[0],
|
141
|
|
|
|
|
|
|
max => $data[0],
|
142
|
|
|
|
|
|
|
range => 0,
|
143
|
|
|
|
|
|
|
sum => $data[0],
|
144
|
|
|
|
|
|
|
mean => $data[0],
|
145
|
|
|
|
|
|
|
median => $data[0],
|
146
|
|
|
|
|
|
|
mode => $data[0],
|
147
|
|
|
|
|
|
|
variance => 0,
|
148
|
|
|
|
|
|
|
stddev => 0,
|
149
|
|
|
|
|
|
|
variancep => 0,
|
150
|
|
|
|
|
|
|
stddevp => 0
|
151
|
|
|
|
|
|
|
) unless @data > 1;
|
152
|
3
|
|
|
|
|
6
|
my $count= scalar(@data);
|
153
|
3
|
|
|
|
|
18
|
@data= sort{$a<=>$b}@data;
|
|
34
|
|
|
|
|
48
|
|
154
|
3
|
|
|
|
|
5
|
my $median;
|
155
|
3
|
100
|
|
|
|
12
|
if(@data&1) { $median= $data[$#data/2]; }
|
|
1
|
|
|
|
|
3
|
|
156
|
2
|
|
|
|
|
4
|
else { my $mid= @data/2; $median= ($data[$mid-1]+$data[$mid])/2; }
|
|
2
|
|
|
|
|
9
|
|
157
|
3
|
|
|
|
|
7
|
my $sum= 0;
|
158
|
3
|
|
|
|
|
5
|
my %count;
|
159
|
3
|
|
|
|
|
7
|
foreach(@data) { $sum+= $_; $count{$_}++; }
|
|
19
|
|
|
|
|
24
|
|
|
19
|
|
|
|
|
47
|
|
160
|
3
|
|
|
|
|
6
|
my $mean= $sum/$count;
|
161
|
3
|
|
|
|
|
15
|
my $maxhits= max(values %count);
|
162
|
3
|
|
|
|
|
11
|
foreach(keys %count)
|
163
|
16
|
100
|
|
|
|
43
|
{ delete $count{$_} unless $count{$_} == $maxhits; }
|
164
|
|
|
|
|
|
|
return
|
165
|
|
|
|
|
|
|
(
|
166
|
3
|
|
|
|
|
20
|
count => $count,
|
167
|
|
|
|
|
|
|
min => $data[0],
|
168
|
|
|
|
|
|
|
max => $data[-1],
|
169
|
|
|
|
|
|
|
range => ($data[-1] - $data[0]),
|
170
|
|
|
|
|
|
|
sum => $sum,
|
171
|
|
|
|
|
|
|
mean => $mean,
|
172
|
|
|
|
|
|
|
median => $median,
|
173
|
|
|
|
|
|
|
mode => mean(keys %count),
|
174
|
|
|
|
|
|
|
variance => variance(@data),
|
175
|
|
|
|
|
|
|
stddev => stddev(@data),
|
176
|
|
|
|
|
|
|
variancep => variancep(@data),
|
177
|
|
|
|
|
|
|
stddevp => stddevp(@data)
|
178
|
|
|
|
|
|
|
);
|
179
|
|
|
|
|
|
|
}
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub statsinfo
|
182
|
|
|
|
|
|
|
{
|
183
|
0
|
|
|
0
|
1
|
0
|
my %stats= statshash(@_);
|
184
|
0
|
|
|
|
|
0
|
return <<".";
|
185
|
|
|
|
|
|
|
min = $stats{min}
|
186
|
|
|
|
|
|
|
max = $stats{max}
|
187
|
|
|
|
|
|
|
range = $stats{range}
|
188
|
|
|
|
|
|
|
sum = $stats{sum}
|
189
|
|
|
|
|
|
|
count = $stats{count}
|
190
|
|
|
|
|
|
|
mean = $stats{mean}
|
191
|
|
|
|
|
|
|
median = $stats{median}
|
192
|
|
|
|
|
|
|
mode = $stats{mode}
|
193
|
|
|
|
|
|
|
variance = $stats{variance}
|
194
|
|
|
|
|
|
|
stddev = $stats{stddev}
|
195
|
|
|
|
|
|
|
variancep = $stats{variancep}
|
196
|
|
|
|
|
|
|
stddevp = $stats{stddevp}
|
197
|
|
|
|
|
|
|
.
|
198
|
|
|
|
|
|
|
}
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub frequencies
|
201
|
|
|
|
|
|
|
{
|
202
|
1
|
|
|
1
|
1
|
1076
|
my @data = definedvals @_;
|
203
|
1
|
50
|
|
|
|
7
|
return unless @data;
|
204
|
1
|
50
|
|
|
|
4
|
return ( $data[0], 1 ) unless @data > 1;
|
205
|
1
|
|
|
|
|
2
|
my %count;
|
206
|
1
|
|
|
|
|
2
|
foreach(@data) { $count{$_}++; }
|
|
4
|
|
|
|
|
10
|
|
207
|
1
|
|
|
|
|
8
|
return %count;
|
208
|
|
|
|
|
|
|
}
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
1;
|
211
|
|
|
|
|
|
|
__END__
|