Ttest

From Biolecture.org

use Math::Complex;

#@numbers = (1,2,3,4,5);
@group1 = (2,4,6,8);
@group2 = (3,5,7,9);

$sum1=sum(@group1);
$sum2=sum(@group2);
print "$sum1 $sum2\n";

$mean1=mean(@group1);
$mean2=mean(@group2);
print "$mean1 $mean2\n";

$numer = numer(mean(@group1),mean(@group2));
print "$numer\n";

$var1 = var(@group1);
$var2 = var(@group2);
print "$var1 $var2\n" ;

$denom = denom(@group1,@group2);
print "$denom\n";

$ttest = ttest(@group1,@group2);
print "$ttest\n";

sub sum{
    $sum = 0;
    foreach(@_){
             $sum +=$_;
    }
    #print "$sum\n";
    return $sum;
}

sub mean{
    $mean = sum(@_)/scalar(@_);
    return $mean;
}

sub numer{
    return ($_[0]-$_[1]);
}

sub var{
    $dev = 0;
    foreach(@_){
             $dev += ($_-mean(@_))**2;
    }


    return $dev/(scalar(@_)-1);
}

sub denom{
    return sqrt($var1/scalar(@group1)+$var2/scalar(@group2))
}

sub ttest{
    return (numer(mean(@group1),mean(@group2))/denom());

}