1Statistics::Basic::CorrUesleartiCoonn(t3r)ibuted Perl DoSctuamteinsttaitciso:n:Basic::Correlation(3)
2
3
4
6 Statistics::Basic::Correlation - find the correlation between two lists
7
9 Invoke it this way:
10
11 my $correlation = correlation( [1,2,3], [1,2,3] );
12
13 Or this way:
14
15 my $v1 = vector(1,2,3);
16 my $v2 = vector(1,2,3);
17 my $cor = corr($v1,$v2);
18
19 And then either query the values or print them like so:
20
21 print "The correlation between $v1 and $v2: $correlation\n";
22 my $cq = $cor->query;
23 my $c0 = 0+$correlation;
24
25 Create a 20 point "moving" correlation like so:
26
27 use Statistics::Basic qw(:all nofill);
28
29 my $sth = $dbh->prepare("select col1,col2 from data where something");
30 my $len = 20;
31 my $cor = corr()->set_size($len);
32
33 $sth->execute or die $dbh->errstr;
34 $sth->bind_columns( my ($lhs, $rhs) ) or die $dbh->errstr;
35
36 my $count = $len;
37 while( $sth->fetch ) {
38 $cor->insert( $lhs, $rhs );
39 if( defined( my $c = $cor->query ) ) {
40 print "Correlation: $c\n";
41 }
42
43 # This would also work:
44 # print "Correlation: $cor\n" if $cor->query_filled;
45 }
46
48 This list of methods skips the methods inherited from
49 Statistics::Basic::_TwoVectorBase (things like query(), insert(), and
50 ginsert()).
51
52 new()
53 Create a new Statistics::Basic::Correlation object. This function
54 takes two arguments -- which can either be arrayrefs or
55 Statistics::Basic::Vector objects. This function is called when
56 the correlation() shortcut-function is called.
57
58 query_covariance()
59 Returns the Statistics::Basic::Covariance object used to calculate
60 the correlation.
61
62 query_vector1()
63 Return the Statistics::Basic::Vector for the first vector.
64
65 query_vector2()
66 Return the Statistics::Basic::Vector object for the second vector.
67
68 query_mean1()
69 Returns the Statistics::Basic::Mean object for the first vector.
70
71 query_mean2()
72 Returns the Statistics::Basic::Mean object for the second vector.
73
75 This object is overloaded. It tries to return an appropriate string
76 for the calculation or the value of the computation in numeric context.
77
78 In boolean context, this object is always true (even when empty).
79
81 Paul Miller "<jettero@cpan.org>"
82
84 Copyright 2012 Paul Miller -- Licensed under the LGPL
85
87 perl(1), Statistics::Basic, Statistics::Basic::_TwoVectorBase,
88 Statistics::Basic::Vector
89
90
91
92perl v5.30.0 2019-07-26 Statistics::Basic::Correlation(3)