use Statistics::Regression; # Create regression object my $reg = Statistics::Regression->new( 3, "sample regression", [ "const", "someX", "someY" ] ); # Add data points $reg->include( 2.0, [ 1.0, 3.0, -1.0 ] ); $reg->include( 1.0, [ 1.0, 5.0, 2.0 ] ); $reg->include( 20.0, [ 1.0, 31.0, 0.0 ] ); $reg->include( 15.0, [ 1.0, 11.0, 2.0 ] ); # Print the result $reg->print(); # Prints the following: # **************************************************************** # Regression 'sample regression' # **************************************************************** # Theta[0='const']= 0.2950 # Theta[1='someX']= 0.6723 # Theta[2='someY']= 1.0688 # R^2= 0.808, N= 4 # **************************************************************** # Or, to get the values of the coefficients and R^2 my @theta = $reg->theta; my $rsq = $reg->rsq;