Itatsumaki has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I would like to do some correlation analysis in perl. Basically, that just takes a pair of arrays and gives a measure of their "similarity" on a scale -1 to 1.

I found the Math::NumberCruncher module that does exactly this. All seemed good and well. When I use Math::NumberCruncher; I got this:

C:\dev>perl -w -mMath::NumberCruncher Can't locate object method "copy" via package "Math::BigFloat" (perhap +s you forgot to load "Math::BigFloat"?) at C:/Perl/site/lib/Math/Numb +erCruncher.pm line 33. Compilation failed in require. BEGIN failed--compilation aborted.

Now I'm at a bit of a loss on how to debug this. I have perl/site/lib/Math/BigFloat.pm on my machine. Any suggestions where to look would be very welcome!


Tats

Replies are listed 'Best First'.
Re: Method not found in package?
by Fletch (Bishop) on Apr 30, 2003 at 21:13 UTC

    Not related specifically to your problem, but for heavy duty numerical calculation in perl check out PDL and pdl.perl.org.

Re: Method not found in package?
by Jenda (Abbot) on Apr 30, 2003 at 20:37 UTC

    Try

    perl -w -MMath::BigFloat -mMath::NumberCruncher
    But this is kinda strange, I don't have any problems with Math::NumberCruncher (Not that I really tested it, but it does load). What versions of the two modules do you have? What version of Perl? And what OS are you using?

    I use:
      Math::NumberCruncher 5.00
      Math::BigFloat 1.35
      Perl 5.8 (ActivePerl build 805)
      Windows 2000 Server

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

      Hi, thanks for your reponse. Trying the -m option still gives me the:
      Can't locate object method "copy" via package "Math::BigFloat" (perhap +s you forgot to load "Math::BigFloat"?) at C:/Perl/site/lib/Math/Numb +erCruncher.pm line 33. Compilation failed in require. BEGIN failed--compilation aborted.

      The modules I'm using are:

      • Perl 5.6.1 (ActivePerl build 633)
      • Math::BigFloat 1.38
      • Math::NumberCruncher 5.00
      • Windows XP SP1 (5.1 Build 2600)
      Perhaps I should find the older version of Math::BigFloat on CPAN and see if that changes things. I'll let you know what happens.

      -Tats
Re: Method not found in package?
by bobdeath (Scribe) on Apr 30, 2003 at 16:50 UTC
    all that I can say for sure is that it worked when I used it. I would try to get Math::BigFloat from cpan again and try an install. It might also be that Math::BigFloat was never meant to work for windows. I am not sure. Hope this helped in some way.

      Thanks for your response. Below is a sub to estimate the Pearson correlation coefficient estimation.

      sub correlate($$) { # $_[0] = ref to x array # $_[1] = ref to y array my $x = $_[0]; my $y = $_[1]; if (scalar(@$x) != scalar(@$y)) { return; } my $s_xy = 0; my $s_xx = 0; my $s_yy = 0; my $s_x = 0; my $s_y = 0; my $n = scalar(@$x); foreach (my $i = 0; $i < scalar(@$x); $i++) { $s_xx += $$x[$i] * $$x[$i]; $s_xy += $$x[$i] * $$y[$i]; $s_yy += $$y[$i] * $$y[$i]; $s_x += $$x[$i]; $s_y += $$y[$i]; } my $S_xy = ($n * $s_xy) - ($s_x * $s_y); my $S_xx = ($n * $s_xx) - ($s_x * $s_x); my $S_yy = ($n * $s_yy) - ($s_y * $s_y); my $denm = ($S_xx**0.5) * ($S_yy**0.5); my $p = $S_xy / $denm; return $p; }