#!/usr/bin/perl

use Statistics::Table::t;

@data = (0.98, 1.17, 1.44, 0.57, 1.00, 1.20);
$t = t(\@data, 1);
($lo, $hi) = t_significance($t, scalar(@data) - 1, 1);
print "The probability that your data is not due to chance: \n";
print "More than $lo and less than $hi. \n";

print "\n";

@data = (3, 4, 3, 6, 3, 2, 8, 10, 4, 5, 6);
$t = t(\@data, 2);
($lo, $hi) = t_significance($t, scalar(@data) - 1, 1);
print "The probability that your data is not due to chance: \n";
print "More than $lo and less than $hi. \n";

# $mean = mean(\@array) computes the mean of an array of numbers.
#
sub mean {
    my ($arrayref) = @_;
    my $result;
    foreach (@$arrayref) { $result += $_ }
    return $result / @$arrayref;
}

sub estimate_variance {
    my ($arrayref) = @_;
    my ($mean, $result) = (mean($arrayref), 0);
    foreach (@$arrayref) { $result += ($_ - $mean) ** 2 }
    return $result / $#{$arrayref};
}
