1Statistics::Basic::CovaUrsiearncCeo(n3t)ributed Perl DocSutmaetnitsattiicosn::Basic::Covariance(3)
2
3
4
6 Statistics::Basic::Covariance - find the covariance between two lists
7
9 Invoke it this way:
10
11 my $covariance = covariance( [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 $cov = cov($v1,$v2);
18
19 And then either query the values or print them like so:
20
21 print "The covariance between $v1 and $v2: $covariance\n";
22 my $cq = $cov->query;
23 my $c0 = 0+$cov;
24
25 Create a 20 point "moving" covariance 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 $cov = cov();
32 $cov->set_size($len);
33
34 $sth->execute or die $dbh->errstr;
35 $sth->bind_columns( my ($lhs, $rhs) ) or die $dbh->errstr;
36
37 my $count = $len;
38 while( $sth->fetch ) {
39 $cov->insert( $lhs, $rhs );
40 if( defined( my $c = $cov->query ) ) {
41 print "Covariance: $c\n";
42 }
43
44 # This would also work:
45 # print "Covariance: $cov\n" if $cov->query_filled;
46 }
47
49 This list of methods skips the methods inherited from
50 Statistics::Basic::_TwoVectorBase (things like query(), insert(), and
51 ginsert()).
52
53 new()
54 Create a new Statistics::Basic::Covariance object. This function
55 takes two arguments -- which can either be arrayrefs or
56 Statistics::Basic::Vector objects. This function is called when
57 the covariance() shortcut-function is called.
58
59 query_vector1()
60 Return the Statistics::Basic::Vector for the first vector.
61
62 query_vector2()
63 Return the Statistics::Basic::Vector object for the second vector.
64
65 query_mean1()
66 Returns the Statistics::Basic::Mean object for the first vector.
67
68 query_mean2()
69 Returns the Statistics::Basic::Mean object for the second vector.
70
72 This object is overloaded. It tries to return an appropriate string
73 for the calculation or the value of the computation in numeric context.
74
75 In boolean context, this object is always true (even when empty).
76
78 Paul Miller "<jettero@cpan.org>"
79
81 Copyright 2012 Paul Miller -- Licensed under the LGPL
82
84 perl(1), Statistics::Basic, Statistics::Basic::_TwoVectorBase,
85 Statistics::Basic::Vector
86
87
88
89perl v5.30.0 2019-07-26 Statistics::Basic::Covariance(3)