#!/usr/bin/perl -w use strict; use Math::GSL::Fit "gsl_fit_linear"; use Math::GSL::Statistics "gsl_stats_tss"; my $x = [1,2,3,4,5]; my $y = [5,7,8,12,13]; my $n = @$y; my ($status, $c0, $c1, $cov00, $cov01, $cov11, $ss_resid) = gsl_fit_linear($x, 1, $y, 1, $n); my $ss_total = gsl_stats_tss($y, 1, $n); print "SS residual = $ss_resid\n"; print "SS total = $ss_total\n"; my $R2 = 1 - $ss_resid / $ss_total; print "R^2 = $R2\n";