Statis...lation(3pm)
π Statistics::Basic::Correlation β the 3pm page, bestie edition π
okay so. you know how two lists be vibing and you're like "are they actually related tho??" π That's this. Statistics::Basic::Correlation is a lil Perl module that finds the correlation between two lists. It lives in the User Contributed Perl Documentation, it's a .3pm page, and it's genuinely so useful. periodt.
β¨ NAME β¨
Statistics::Basic::Correlation β find the correlation between two lists π¦
πΈ SYNOPSIS πΈ
Invoke it this way, bestie:
my $correlation = correlation( [1,2,3], [1,2,3] );
Or this way, if that's more your vibe:
my $v1 = vector(1,2,3);
my $v2 = vector(1,2,3);
my $cor = corr($v1,$v2);
And then either query the values or print them like so:
print "The correlation between $v1 and $v2: $correlation\n";
my $cq = $cor->query;
my $c0 = 0+$correlation;
Create a 20 point "moving" correlation like so β yes, a moving one, it's giving main character energy:
use Statistics::Basic qw(:all nofill);
my $sth = $dbh->prepare("select col1,col2 from data where something");
my $len = 20;
my $cor = corr()->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 ) {
$cor->insert( $lhs, $rhs );
if( defined( my $c = $cor->query ) ) {
print "Correlation: $c\n";
}
# This would also work:
# print "Correlation: $cor\n" if $cor->query_filled;
}
π METHODS π
heads up bestie: this list of methods skips the methods inherited from Statistics::Basic::_TwoVectorBase β you know, the classics like query(), insert(), and ginsert(). those are still yours, they're just not re-explained here. iykyk.
new()β Create a newStatistics::Basic::Correlationobject. This function takes two arguments β which can either be arrayrefs orStatistics::Basic::Vectorobjects. This function is called when thecorrelation()shortcut-function is called. so yeah, it's doing the heavy lifting behind the scenes π₯query_covariance()β Returns theStatistics::Basic::Covarianceobject used to calculate the correlation.query_vector1()β Return theStatistics::Basic::Vectorfor the first vector.query_vector2()β Return 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. It tries to return an appropriate string for the calculation, or the value of the computation when you're in numeric context. it's bilingual, basically π
In boolean context, this object is always true (even when empty). like, always. even when it's empty. do not come for it, it said what it said.
π AUTHOR π
Paul Miller "<jettero@cpan.org>" β absolute legend, fr fr.
π COPYRIGHT π
Copyright 2012 Paul Miller -- Licensed under the LGPL
π«Ά SEE ALSO π«Ά
perl(1), Statistics::Basic, Statistics::Basic::_TwoVectorBase, Statistics::Basic::Vector
k that's the whole page, no cap. this one's perl v5.36.0, dated 2022-11-19, straight from the User Contributed Perl Documentation β go forth and correlate, bestie πβ¨
π¦ 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