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

Dear Monks,

I've had a look at the documentation for Statistics::LineFit and I can't find anything about p-values for correlation coefficients. Does anyone know if I can calculate p-values using this module?
my $lfit = Statistics::LineFit->new(); $lfit->setData($x_ref, $y_ref); my ($intercept, $slope) = $lfit->coefficients(); my $rSquared = $lfit->rSquared(); my $pValue = $lfit->pValue(); # I need a line like this

Replies are listed 'Best First'.
Re: Calculating p-values using Statistics::LineFit
by apl (Monsignor) on May 01, 2008 at 16:24 UTC
    Statistics hasn't been my bag for over 30 years, but a quick Google of Perl p-values turns up this comment about Statistics::Distribution and this review about Math-Cephes. HTH.
Re: Calculating p-values using Statistics::LineFit
by educated_foo (Vicar) on May 01, 2008 at 16:36 UTC
    Unless you're dealing with enormous datasets, you can just use permutation for p-values, e.g. (untested):
    use List::Util 'shuffle'; $rSquared = $lfit->setData($xref, $yref)->rSquared; @rsq = map { $lfit->setData($xref, [shuffle @$yref])->rSquared } 1..10 +00; print "pretty good\n" if (grep { $_ > $rSquared } @rsq) > 950;
Re: Calculating p-values using Statistics::LineFit
by KurtSchwind (Chaplain) on May 01, 2008 at 15:48 UTC

    I've scanned CPAN and nearly all the least square packages only give the rSquared value.

    I don't recall offhand, but is there a numerical recipe for that? I don't see one in my 'Numerical Recipes in C' book.

    --
    I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.