Math::GSL::Fit(3pm) | User Contributed Perl Documentation | Math::GSL::Fit(3pm) |
Math::GSL::Fit - Least-squares functions for a general linear model with one- or two-parameter regression
use Math::GSL::Fit qw/:all/;
The functions in this module perform least-squares fits to a general linear model, y = X c where y is a vector of n observations, X is an n by p matrix of predictor variables, and the elements of the vector c are the p unknown best-fit parameters which are to be estimated.
Here is a list of all the functions in this module :
For more information on the functions, we refer you to the GSL official documentation: <http://www.gnu.org/software/gsl/manual/html_node/>
This example shows how to use the function gsl_fit_linear. It's important to see that the array passed to to function must be an array reference, not a simple array. Also when you use strides, you need to initialize all the value in the range used, otherwise you will get warnings.
my @norris_x = (0.2, 337.4, 118.2, 884.6, 10.1, 226.5, 666.3, 996.3, 448.6, 777.0, 558.2, 0.4, 0.6, 775.5, 666.9, 338.0, 447.5, 11.6, 556.0, 228.1, 995.8, 887.6, 120.2, 0.3, 0.3, 556.8, 339.1, 887.2, 999.0, 779.0, 11.1, 118.3, 229.2, 669.1, 448.9, 0.5 ) ; my @norris_y = ( 0.1, 338.8, 118.1, 888.0, 9.2, 228.1, 668.5, 998.5, 449.1, 778.9, 559.2, 0.3, 0.1, 778.1, 668.8, 339.3, 448.9, 10.8, 557.7, 228.3, 998.0, 888.8, 119.6, 0.3, 0.6, 557.6, 339.3, 888.0, 998.5, 778.9, 10.2, 117.6, 228.9, 668.4, 449.2, 0.2); my $xstride = 2; my $wstride = 3; my $ystride = 5; my ($x, $w, $y); for my $i (0 .. 175) { $x->[$i] = 0; $w->[$i] = 0; $y->[$i] = 0; } for my $i (0 .. 35) { $x->[$i*$xstride] = $norris_x[$i]; $w->[$i*$wstride] = 1.0; $y->[$i*$ystride] = $norris_y[$i]; } my ($status, @results) = gsl_fit_linear($x, $xstride, $y, $ystride, 36);
Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
Copyright (C) 2008-2021 Jonathan "Duke" Leto and Thierry Moisan
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2022-10-20 | perl v5.36.0 |