Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with subroutine 1

Status
Not open for further replies.

3inen

Technical User
May 26, 2005
51
US
Hi! I am trying to use the Perl module on t-test in a subroutine for working on my genetics data sets (not class work though) and am not able to direct the output to the OUTFILE. it prints to the console.

Here are my two arrays and here is how i am calling the subroutine from within the program. also i have included the subroutine that i am using.

print FILEW2 &t_test(@C, @B), "\n";



sub t_test{
my (@C) = @_;
my (@B) = @_;
my ($result);
my ($ttest);
use Statistics::pointEstimation;
use Statistics::TTest;
$ttest = new Statistics::TTest;
$ttest->set_significance(90);
$ttest->load_data(\@C,\@B);
$ttest->output_t_test();
$ttest->set_significance(99);
$ttest->print_t_test(); #list out t-test related data

#the following thes same as calling output_t_test()
my $s1=$ttest->{s1}; #sample 1 a Statistics::pointEstimation object
my $s2=$ttest->{s2}; #sample 2 a Statistics::pointEstimation object
print "*****************************************************\n\n";
$s1->output_confidence_interval('1');
$s2->output_confidence_interval('2');
print "\t F-statistic=",$ttest->f_statistic()," , cutoff F-statistic=",$ttest->f_cutoff(),
" with alpha level=",$ttest->alpha*2," and df =(",$ttest->df1,",",$ttest->df2,")\t";
if($ttest->{equal_variance})
{ print "\tequal variance assumption is accepted(not rejected) since F-statistic < cutoff F-statistic\t";}
else
{ print "\tequal variance assumption is rejected since F-statistic > cutoff F-statistic\t";}
print "\tdegree of freedom=",$ttest->df," , t-statistic=T=",$ttest->t_statistic," Prob >|T|=",$ttest->{t_prob},"\t";
print "\tthe null hypothesis (the 2 samples have the same mean) is ",$ttest->null_hypothesis(),
" since the alpha level is ",$ttest->alpha()*2,"\t";
print "\there difference of the mean=",$ttest->mean_difference(),", standard error=",$ttest->standard_error(),"\t";
print "\t the estimate of the difference of the mean is ", $ttest->mean_difference()," +/- ",$ttest->delta(),"\t",
" or (",$ttest->lower_clm()," to ",$ttest->upper_clm," ) with ",$ttest->significance," % of confidence\n";
print "*****************************************************\n\n";

}


Any help is appreciated.
Thanks!
 
I assume FILEW2 is the filehandle where you want to print the output? You could try something like:
Code:
select FILEW2;
&t_test(@C, @B);
select STDOUT;
 

Hi! I have a problem running this subroutine on arrays. I have 4 arrays @arr1, @arr2, @arr3, @arr4.
I am trying to use the T-test subroutine to compare the statistical significance of these arrays.

select FILEW2;
&t_test(@arr1, @arr2), &t_test(@arr1, @arr3), &t_test(@arr1, @arr4), &t_test(@arr2, @arr3), &t_test(@arr2, @arr4), &t_test(@arr3, @arr4),"\n";
select STDOUT;

here is my subroutine (now simplified)

sub t_test{
my @set1=();
my @set2=();
use Statistics::pointEstimation;
use Statistics::TTest;
my $ttest = new Statistics::TTest;
$ttest->set_significance(90);
$ttest->load_data(\@set1,\@set2);
$ttest->set_significance(99);
print "\t F-statistic=",$ttest->f_statistic()," , cutoff F-statistic=",$ttest->f_cutoff(),
" with alpha level=",$ttest->alpha*2," and df =(",$ttest->df1,",",$ttest->df2,")\t";
}

problem is I am not able to call the data sets in to the subroutine using the alias names such as @set1, @set2. how do i correct this.

thanks
 
Can't see how are you even only trying to get your arrays into the subroutine. You probably want to pass them by reference:
[tt]t_test(\@arr1,\@arr2);[/tt]
then
[tt]sub t_test{
my($ref1,$ref2)=@_;[/tt]
and
[tt]$ttest->load_data($ref1,$ref2);[/tt]

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 

Learning one thing at a time. Now it works. Thanks a lot prex1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top