[1]
sub get_total_of (@) {
my $sum = 0;
for (@_) {
$sum += $_;
}
return $sum;
}
sub get_mean_of (@) {
return get_total_of (@_) / (scalar @_ or 1);
}
sub get_variance_of (@) {
my $mean = get_mean_of (@_);
return get_mean_of (map { ($_ - $mean) ** 2 } @_);
}
sub get_confidence_interval_of ($@) {
my $percentage = shift;
my $z = {
90 => 1.645, 95 => 1.960, 99 => 2.576, 99.9 => 3.29,
}->{$percentage};
return undef unless defined $z;
my $stddev = sqrt (get_variance_of (@_));
my $n = @_ || 1;
return $z * $stddev / sqrt $n;
} # get_confidence_interval_of