Statis...ariance(3pm)

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

πŸ’– Statistics::Basic::Variance β€” a.k.a. the Statis...ariance(3pm) page from User Contributed Perl Documentation, section 3pm πŸŽ€

✨ NAME ✨

Statistics::Basic::Variance β€” bestie, this is the module that finds the variance of a list. That's it. That's the whole job. πŸ¦‹


🌸 SYNOPSIS 🌸

Okay so you can summon it like this:

my $variance = variance(1,2,3);

Or, if you're feeling extra, like this:

my $v1  = vector(1,2,3);
my $var = var($v1);

And then you can either ask it for the numbers or just print them, like so:

print "The variance of $v1: $variance\n";
my $vq = $var->query;
my $v0 = 0+$var;

Wanna build a 20 point "moving" variance? Iconic. Do it like this:

use Statistics::Basic qw(:all nofill);

my $sth = $dbh->prepare("select col1 from data where something");
my $len = 20;
my $var = var()->set_size($len);

$sth->execute or die $dbh->errstr;
$sth->bind_columns( my $val ) or die $dbh->errstr;

while( $sth->fetch ) {
    $var->insert( $val );
    if( defined( my $v = $var->query ) ) {
        print "Variance: $v\n";
    }

    # This would also work:
    # print "Variance: $v\n" if $var->query_filled;
}

πŸ’… METHODS πŸ’…

  • new() β€” the constructor, she's the main character πŸ‘‘. She takes a list of values, a single array ref, or a single Statistics::Basic::Vector as arguments. She hands you back a Statistics::Basic::Variance object. πŸ’–
Note: normally you'd use the mean() constructor rather than building these by hand using "new()". Just saying. πŸ™ˆ
  • query_mean() β€” returns the Statistics::Basic::Mean object that got used in the variance computation. Very demure, very mindful. ✨
  • _OVB::import() β€” this module also inherits all the overloads and methods from Statistics::Basic::_OneVectorBase. Slay. 🌈

🫢 AUTHOR 🫢

Paul Miller "<jettero@cpan.org>"

And he says, and I quote: "I am using this software in my own projects... If you find bugs, please please please let me know. :) Actually, let me know if you find it handy at all. Half the fun of releasing this stuff is knowing that people use it."

Not him being the sweetest 😭 honestly we love a dev who actually wants to hear from us. Go tell him if you find a bug, and also go tell him if you just think it's neat. πŸ“


πŸ”₯ OVERLOADS πŸ”₯

This object is overloaded, meaning she reads the room and adapts. πŸ’… She tries to return an appropriate string for the calculation, or the value of the computation when you're in numeric context.

And in boolean context? This object is always true β€” even when it's empty. No cap. 🧚

Copyright 2012 Paul Miller -- Licensed under the LGPL


⭐ SEE ALSO ⭐

  • perl(1)
  • Statistics::Basic
  • Statistics::Basic::_OneVectorBase
  • Statistics::Basic::Vector

Mwah, that's the whole page, bestie. Sending you off with the receipt: this was perl v5.36.0, dated 2022-11-19, and it's the Statis...ariance(3pm) page β€” periodt. πŸ’–βœ¨πŸŽ€πŸ¦‹