-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcorrelation
More file actions
executable file
·55 lines (41 loc) · 1.17 KB
/
correlation
File metadata and controls
executable file
·55 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
use strict;
use Getopt::Std;
use Statistics::Basic::Correlation;
#my $co = new Statistics::Basic::Correlation( [1..3], [1..3] );
#print $co->query, "\n";
# Jonathan Ledlie
# June 16 2004
##################################################
my $usage = "Usage: cat file | correlation [options] > result\n";
$usage .= " -a first column of input to use\n";
$usage .= " -b second column of input to use\n";
$usage .= " First column is 1 (not 0)\n";
my $colA = -1;
my $colB = -1;
my %para = ();
getopts('a:b:', \%para);
if ( !defined($para{'a'}) || !defined($para{'b'})) {
die ($usage);
}
$colA = $para{'a'};
$colB = $para{'b'};
my @A = ();
my @B = ();
while (my $line = <>) {
my @items = split (/\s+/, $line);
if (defined ($items[$colA-1]) && defined ($items[$colB-1])) {
my $itemA = $items[$colA-1];
my $itemB = $items[$colB-1];
if ($itemA !~ /-?\d+\.?\d*/) {
die ("NaN->A A $itemA B $itemB l $line");
}
if ($itemB !~ /-?\d+\.?\d*/) {
die ("NaN->B A $itemA B $itemB l $line");
}
$A[$#A+1] = $itemA;
$B[$#B+1] = $itemB;
}
}
my $co = new Statistics::Basic::Correlation( \@A, \@B );
print $co->query, "\n";