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

Dear Monks,

The following bit of code:
sub correlation { print "I am in the correlation subroutine"; my ($x_ref, $y_ref) = @_; print "\nWe are in the correlation subroutine\n\n"; # print Dumper ($x_ref, $y_ref); print Dumper length($x_ref); print Dumper length($y_ref); my $lfit = Statistics::LineFit->new(); $lfit->setData($x_ref, $y_ref); my ($intercept, $slope) = $lfit->coefficients(); my $rSquared = $lfit->rSquared();
Gives me the following output:
I am in the correlation subroutine We are in the correlation subroutine $VAR1 = 16; $VAR1 = 16; Length of x and y arrays must be equal! at rebuild.pl line 335 No valid data input - can't do regression at rebuild.pl line 337 No valid data input - can't do regression at rebuild.pl line 338
Why does it tell me 'that the Length of x and y arrays must be equal' when we know that the lengths are equal. ($VAR1 = 16; $VAR1 = 16;) -- see output.
When I use the:
print Dumper ($x_ref, $y_ref);
That seems fine also.

Update : I've just copied and pasted the array contents into Excel and it does seem that one array has one element more than the other. Sorry guys.

Replies are listed 'Best First'.
Re: Correlation using Statistics::LineFit
by johngg (Canon) on Dec 03, 2007 at 12:00 UTC
    I am guessing that $x_ref and $y_ref are array references and you are looking at the length of the string that represents the reference, eg ARRAY(0x132a5fd). Perhaps you need to look at scalar @$x_ref and scalar @$y_ref to compare the number of elements.

    Just a guess.

    Cheers,

    JohnGG

    Update: Corrected rubber-fingered typo.

Re: Correlation using Statistics::LineFit -- DISREGARD POST
by blazar (Canon) on Dec 03, 2007 at 16:46 UTC
    Correlation using Statistics::LineFit -- DISREGARD POST

    I personally believe that under different circumstances I would have sent to you a /msg, but I'm posting here for reference: instead of modifying the Subject like that, you can consider your own node for reaping if you feel it would better be deleted. If you just found the solution to your problem, instead, then perhaps "SOLVED" would be a better "tag", possibly with an update to the node explaining what the solution was.

    --
    If you can't understand the incipit, then please check the IPB Campaign.

      No, we don't reap nodes due to a question having been answered.

      Updating the title is much better than many of the possiblities. Purging the contents of the node is probably the worst course that we see from time to time. Certainly "solve" is more informative than "disregard", of course.

      - tye        

        No, we don't reap nodes due to a question having been answered.

        I personally believe that you misunderstood, which possibility bothers me because the OP easily may as well. I was talking about reaping a node due to the author wanting it to be reaped - which something like "DISREGARD POST" strongly suggests me. Specifically in the second part of my reply I suggested the use of a "SOLVED" tag as opposite to consideration. I hope it's clearer now.