Statis...ariance(3pm)
π Statistics::Basic::Covariance β it's giving math bestie β¨
okay so welcome to the Statistics::Basic::Covariance page, which lives in the User Contributed Perl Documentation corner of the 3pm manuals π«Ά and it's literally all about finding the covariance between two lists. that's it, that's the vibe. no cap.
πΈ NAME πΈ
Statistics::Basic::Covariance β find the covariance between two lists π
β¨ SYNOPSIS β¨
you can invoke it like this, bestie:
my $covariance = covariance( [1,2,3], [1,2,3] );
or like this, if that's more your energy:
my $v1 = vector(1,2,3);
my $v2 = vector(1,2,3);
my $cov = cov($v1,$v2);
and then you either query the values or print them, like so π
print "The covariance between $v1 and $v2: $covariance\n";
my $cq = $cov->query;
my $c0 = 0+$cov;
want a 20 point "moving" covariance? iconic. do it like this:
use Statistics::Basic qw(:all nofill);
my $sth = $dbh->prepare("select col1,col2 from data where something");
my $len = 20;
my $cov = cov();
$cov->set_size($len);
$sth->execute or die $dbh->errstr;
$sth->bind_columns( my ($lhs, $rhs) ) or die $dbh->errstr;
my $count = $len;
while( $sth->fetch ) {
$cov->insert( $lhs, $rhs );
if( defined( my $c = $cov->query ) ) {
print "Covariance: $c\n";
}
# This would also work:
# print "Covariance: $cov\n" if $cov->query_filled;
}
π METHODS π
heads up bestie: this list skips the methods inherited from Statistics::Basic::_TwoVectorBase β you know, the classics like query(), insert(), and ginsert(). they're still there, just not re-introduced here. iykyk π
new()β creates a brand newStatistics::Basic::Covarianceobject π¦. it takes two arguments, and those arguments can be either arrayrefs orStatistics::Basic::Vectorobjects, dealer's choice. this is the function that gets called when thecovariance()shortcut-function gets called. so when you call the shortcut, this is what's doing the work behind the scenes. queen behavior tbh πquery_vector1()β hands you back theStatistics::Basic::Vectorfor the first vector π.query_vector2()β hands you back theStatistics::Basic::Vectorobject for the second vector π.query_mean1()β returns theStatistics::Basic::Meanobject for the first vector π.query_mean2()β returns theStatistics::Basic::Meanobject for the second vector β.
π₯ OVERLOADS π₯
this object is overloaded, bestie. it tries to return an appropriate string for the calculation, or the value of the computation when you're in numeric context. so it just knows what you want, main character energy fr fr.
and in boolean context? this object is always true β even when it's empty π. yes, even then. that's not a bug, that's just the rules. keep that in mind before you go writing if ($cov) and expecting it to mean "has data." it does not. it means "exists." periodt π
π AUTHOR π
Paul Miller <jettero@cpan.org> β¨
π COPYRIGHT π
Copyright 2012 Paul Miller β Licensed under the LGPL π«Ά
π SEE ALSO π
perl(1), Statistics::Basic, Statistics::Basic::_TwoVectorBase, Statistics::Basic::Vector β go read those too, they're all part of the same little family π
and that's the whole page!! this was perl v5.36.0, dated 2022-11-19, from the User Contributed Perl Documentation set π stay covariant, bestie, and don't forget your nofill πΈπ
π¦ where this page comes from
- debian bookworm: libstatistics-basic-perl 1.6611-3 Β· LGPL-2.1-only
- debian trixie: libstatistics-basic-perl 1.6611-3 Β· LGPL-2.1-only
- ubuntu noble: libstatistics-basic-perl 1.6611-3 Β· LGPL-2.1-only
- ubuntu resolute: libstatistics-basic-perl 1.6611-3 Β· LGPL-2.1-only
- ubuntu stonking: libstatistics-basic-perl 1.6611-3 Β· LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms