Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

statistics::basic::_twovectorbase(3pm) [debian man page]

Statistics::Basic::_TwoVectorBase(3pm)			User Contributed Perl Documentation		    Statistics::Basic::_TwoVectorBase(3pm)

NAME
Statistics::Basic::_TwoVectorBase - base class objects like Correlation METHODS
query() Query the value of the object. It will return the undefined value until there's something to calculate. insert() Insert two new new values into the vectors. This function must be given precisely two arguments and probably shouldn't be undefined values in most cases. # insert a 4 in one vector and a 3 in the other $object_instance->insert( 4, 3 ); append() ginsert() The growing insert inserts new elements, growing the max size of the vector to accommodate the new elements (if necessary). This function must be given precisely two arguments and probably shouldn't be undefined values in most cases. # append a 4 in one vector and a 3 in the other $object_instance->ginsert( 4, 3 ); query_size() The current size of the vectors -- regardless of their max size (as set by "set_size()"). This function returns a list, i.e.: my @s = $obj->query_size; # two values my $s = $obj->query_size; # the right hand value of the list set_size() Set the maximum size for the underlying Statistics::Basic::Vector objects. This function requires two arguments. set_vector() Set the vector objects used to calculate the object's value. This function takes two arguments -- which can either be arrayrefs or Statistics::Basic::Vector objects. They must have the same number of elements. my $v1 = vector my $v2 = $v1->copy; $example_correlation->set_vector($v1, $v2); OVERLOADS
This class provides overloads. If evaluated as a string, it will attempt to print a pretty value for the object (or "n/a", see "query()" above). the resulting string can be tuned, in terms of precision, see ipres for further information. If evaluated as a number, it will try to return the raw result of "query()", possibly turning the resulting "undef" (if applicable) into a 0 in the process -- note that Perl does this 0-izing, not the overload. The "eq" and "==" operators are also overloaded, trying to do the right thing. Also see toler for further information. AUTHOR
Paul Miller "<jettero@cpan.org>" COPYRIGHT
Copyright 2012 Paul Miller -- Licensed under the LGPL SEE ALSO
perl(1), Statistics::Basic, Statistics::Basic::Vector perl v5.14.2 2012-01-23 Statistics::Basic::_TwoVectorBase(3pm)

Check Out this Related Man Page

Statistics::Basic::LeastSquareFit(3pm)			User Contributed Perl Documentation		    Statistics::Basic::LeastSquareFit(3pm)

NAME
Statistics::Basic::LeastSquareFit - find the least square fit for two lists SYNOPSIS
A machine to calculate the Least Square Fit of given vectors x and y. The module returns the alpha and beta filling this formula: $y = $beta * $x + $alpha for a given set of x and y co-ordinate pairs. Say you have the set of Cartesian coordinates: my @points = ( [1,1], [2,2], [3,3], [4,4] ); The simplest way to find the LSF is as follows: my $lsf = lsf()->set_size(int @points); $lsf->insert(@$_) for @points; Or this way: my $xv = vector( map {$_->[0]} @points ); my $yv = vector( map {$_->[1]} @points ); my $lsf = lsf($xv, $yv); And then either query the values or print them like so: print "The LSF for $xv and $yv: $lsf "; my ($yint, $slope) = my ($alpha, $beta) = $lsf->query; LSF is meant for finding a line of best fit. $beta is the slope of the line and $alpha is the y-offset. Suppose you want to draw the line. Use these to calculate the "x" for a given "y" or vice versa: my $y = $lsf->y_given_x( 7 ); my $x = $lsf->x_given_y( 7 ); (Note that "x_given_y()" can sometimes produce a divide-by-zero error since it has to divide by the $beta.) Create a 20 point "moving" LSF like so: use Statistics::Basic qw(:all nofill); my $sth = $dbh->prepare("select x,y from points where something"); my $len = 20; my $lsf = lsf()->set_size($len); $sth->execute or die $dbh->errstr; $sth->bind_columns( my ($x, $y) ) or die $dbh->errstr; my $count = $len; while( $sth->fetch ) { $lsf->insert( $x, $y ); if( defined( my ($yint, $slope) = $lsf->query ) { print "LSF: y= $slope*x + $yint "; } # This would also work: # print "$lsf " if $lsf->query_filled; } METHODS
This list of methods skips the methods inherited from Statistics::Basic::_TwoVectorBase (things like insert(), and ginsert()). new() Create a new Statistics::Basic::LeastSquareFit object. This function takes two arguments -- which can either be arrayrefs or Statistics::Basic::Vector objects. This function is called when the leastsquarefirt() shortcut-function is called. query() LSF is meant for finding a line of best fit. $beta is the slope of the line and $alpha is the y-offset. my ($alpha, $beta) = $lsf->query; y_given_x() Automatically calculate the y-value on the line for a given x-value. my $y = $lsf->y_given_x( 7 ); x_given_y() Automatically calculate the x-value on the line for a given y-value. my $x = $lsf->x_given_y( 7 ); "x_given_y()" can sometimes produce a divide-by-zero error since it has to divide by the $beta. This might be helpful: if( defined( my $x = eval { $lsf->x_given_y(7) } ) ) { warn "there is no x value for 7"; } else { print "x (given y=7): $x "; } query_vector1() Return the Statistics::Basic::Vector for the first vector used in the computation of alpha and beta. query_vector2() Return the Statistics::Basic::Vector object for the second vector used in the computation of alpha and beta. query_mean1() Returns the Statistics::Basic::Mean object for the first vector used in the computation of alpha and beta. query_variance1() Returns the Statistics::Basic::Variance object for the first vector used in the computation of alpha and beta. query_covariance() Returns the Statistics::Basic::Covariance object used in the computation of alpha and beta. OVERLOADS
This object is overloaded. It tries to return an appropriate string for the calculation, but raises an error in numeric context. In boolean context, this object is always true (even when empty). 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 perl v5.14.2 2012-01-23 Statistics::Basic::LeastSquareFit(3pm)
Man Page