in reply to Re: finding R-squared..please help
in thread finding R-squared..please help

Very nice code thank you so much Eliya! A question in passing do you know why this online calculator http://ea +sycalculation.com/statistics/r-squared.php can find r^2 (but not r) o +n values: "2,2,2,2" "2,2,2,1" Is that a bug on their software? Thanks again for your help!

Replies are listed 'Best First'.
Re^3: finding R-squared..please help
by Eliya (Vicar) on Feb 20, 2012 at 01:10 UTC

    Strictly speaking, neither r nor R^2 can be computed with those vectors (so yes, you could consider it a bug).   This is because no line can be fitted with finite values for $c0 and $c1.  And when there's no line, there are no residuals, etc.

    When you change the values slightly to

    2,2,2,2.0001 2,2,2,1

    a line can be fitted (so you also get correct values on that site), but the fitted line parameters are already rather large:

    my $c0 = 20001.9999999578; # as computed by gsl_fit_linear() my $c1 = -9999.9999999789; say $c0 + $c1 * $_ for 2, 2.0001; __END__ 2 1

    The smaller you make the deviation from 2 for the last value of vector x, the larger the fitted parameters become, eventually approaching delicately balancing +/- "infinities".  And when all values are exactly 2, no fit can be computed any longer...   (try 2.0000001 and 2.00000001 on the linked site, and you'll already get nonsensical values (correct values should always be r = -1, r^2 = 1) — which means numerical precision is rather low).

      Thanks you very much for you help.... All the best!