Statis...lation(3pm)

πŸ“¦
version 1.6611 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 new Statistics::Basic::Correlation object. This function takes two arguments β€” which can either be arrayrefs or Statistics::Basic::Vector objects. This function is called when the correlation() shortcut-function is called. so yeah, it's doing the heavy lifting behind the scenes πŸ”₯
  • query_covariance() β€” Returns the Statistics::Basic::Covariance object used to calculate the correlation.
  • query_vector1() β€” Return the Statistics::Basic::Vector for the first vector.
  • query_vector2() β€” Return the Statistics::Basic::Vector object for the second vector.
  • query_mean1() β€” Returns the Statistics::Basic::Mean object for the first vector.
  • query_mean2() β€” Returns the Statistics::Basic::Mean object 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 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 πŸ’œβœ¨