Your method of calculating variance can result in loss of significant
digits. For example, the following data produces a variance of 0 for
X on my machine (causing div-by-zero errors later). The variance
should be the same for both X and Y (as the data differs only by a
constant).
999999997 9999997
999999998 9999998
999999999 9999999
Better results may be achieved by "centering" your variance
calculation about the mean.
my $VX = 0;
$VX += ($_ - $MX)**2 for @x;
$VX /= $Xn;
You are also making far more passes over the data than necessary.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|