Skip to content

Instantly share code, notes, and snippets.

@jberger
Created July 12, 2012 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/3098830 to your computer and use it in GitHub Desktop.
Save jberger/3098830 to your computer and use it in GitHub Desktop.
PDL::Stats linear regression
use strict;
use warnings;
use PDL;
use PDL::Stats;
my $x = pdl [ 1, 2, 3, 4 ];
my $y = pdl [ 1.3, 2.9, 4.2, 5.4 ];
# get just the coeffs:
my $coeffs = $y->ols( $x );
print $coeffs;
# or get the entire results in list (hash) context
my %results = $y->ols( $x );
print "$_\t$m{$_}\n" for (sort keys %m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment