Statis...ariance(3pm)

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

πŸ’– 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 new Statistics::Basic::Covariance object πŸ¦‹. it takes two arguments, and those arguments can be either arrayrefs or Statistics::Basic::Vector objects, dealer's choice. this is the function that gets called when the covariance() 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 the Statistics::Basic::Vector for the first vector 🌈.
  • query_vector2() β€” hands you back 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, 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 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 🌸πŸ’