Math::GSL::Fit(3pm)
โจ Math::GSL::Fit โจ
okay bestie, welcome to Math::GSL::Fit, part of the User Contributed Perl Documentation family ๐ this is where you do least-squares fits for a general linear model with one- or two-parameter regression, and honestly? it's giving math girlie excellence ๐ธ
๐ฆ NAME ๐ฆ
Math::GSL::Fit โ least-squares functions for a general linear model with one- or two-parameter regression. short, sweet, exactly what it says on the tin ๐
โจ SYNOPSIS โจ
use Math::GSL::Fit qw/:all/;
that's it. that's the whole vibe check. load it up and you're in business ๐
๐ DESCRIPTION ๐
so here's the tea โ 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 that we're trying to estimate. no cap, that's the whole game ๐ฅ
here is a list of all the functions in this module (yes, all of them, we are not skipping a single one, periodt):
โญ gsl_fit_linear($x, $xstride, $y, $ystride, $n)
this function computes the best-fit linear regression coefficients (c0,c1) of the model Y = c_0 + c_1 X for the dataset ($x, $y). that's two vectors (in form of arrays, bestie) of length $n with strides $xstride and $ystride. the errors on y are assumed unknown, so the variance-covariance matrix for the parameters (c0, c1) gets estimated from the scatter of the points around the best-fit line, and it comes back to you via the parameters (cov00, cov01, cov11). the sum of squares of the residuals from the best-fit line is returned in sumsq.
note: the correlation coefficient of the data can be computed using gsl_stats_correlation (see Correlation) โ and it does not depend on the fit, iykyk. ๐ซถ
the function returns the following values in this order: 0 if the operation succeeded, 1 otherwise, then c0, c1, cov00, cov01, cov11 and sumsq. slay.
๐ธ gsl_fit_wlinear($x, $xstride, $w, $wstride, $y, $ystride, $n)
this function computes the best-fit linear regression coefficients (c0,c1) of the model Y = c_0 + c_1 X for the weighted dataset ($x, $y) โ two vectors (in form of arrays) of length $n with strides $xstride and $ystride. the vector (also in the form of an array) $w, of length $n and stride $wstride, specifies the weight of each datapoint. and the weight is literally the reciprocal of the variance for each datapoint in y ๐
the covariance matrix for the parameters (c0, c1) is computed using the weights and returned via the parameters (cov00, cov01, cov11). the weighted sum of squares of the residuals from the best-fit line, \chi^2, is returned in chisq.
the function returns the following values in this order: 0 if the operation succeeded, 1 otherwise, c0, c1, cov00, cov01, cov11 and sumsq.
๐ gsl_fit_linear_est($x, $c0, $c1, $cov00, $cov01, $cov11)
this function uses the best-fit linear regression coefficients $c0, $c1 and their covariance $cov00, $cov01, $cov11 to compute the fitted function y and its standard deviation y_err for the model Y = c_0 + c_1 X at the point $x. it's giving prediction energy ๐ฎ
the function returns the following values in this order: 0 if the operation succeeded, 1 otherwise, y and y_err.
๐ฆ gsl_fit_mul($x, $xstride, $y, $ystride, $n)
this function computes the best-fit linear regression coefficient c1 of the model Y = c_1 X for the datasets ($x, $y) โ two vectors (in form of arrays) of length $n with strides $xstride and $ystride. note there's no intercept here, it's just c1, main character energy only โจ
the errors on y are assumed unknown so the variance of the parameter c1 is estimated from the scatter of the points around the best-fit line and returned via the parameter cov11. the sum of squares of the residuals from the best-fit line is returned in sumsq.
the function returns the following values in this order: 0 if the operation succeeded, 1 otherwise, c1, cov11 and sumsq.
๐ gsl_fit_wmul($x, $xstride, $w, $wstride, $y, $ystride, $n)
this function computes the best-fit linear regression coefficient c1 of the model Y = c_1 X for the weighted datasets ($x, $y) โ two vectors (in form of arrays) of length $n with strides $xstride and $ystride. the vector (also in the form of an array) $w, of length $n and stride $wstride, specifies the weight of each datapoint. the weight is the reciprocal of the variance for each datapoint in y. yes, same deal as before, she's consistent ๐
the variance of the parameter c1 is computed using the weights and returned via the parameter cov11. the weighted sum of squares of the residuals from the best-fit line, \chi^2, is returned in chisq.
the function returns the following values in this order: 0 if the operation succeeded, 1 otherwise, c1, cov11 and sumsq.
๐ gsl_fit_mul_est($x, $c1, $cov11)
this function uses the best-fit linear regression coefficient $c1 and its covariance $cov11 to compute the fitted function y and its standard deviation y_err for the model Y = c_1 X at the point $x. predicting the future but make it statistics ๐ง
the function returns the following values in this order: 0 if the operation succeeded, 1 otherwise, y and y_err.
for more information on the functions, we refer you to the GSL official documentation: <http://www.gnu.org/software/gsl/manual/html_node/> โ go read it, bestie, it's the source ๐ซถ
๐ EXAMPLES ๐
this example shows how to use the function gsl_fit_linear. it's important to see that the array passed to the function must be an array reference, not a simple array. also, when you use strides, you need to initialize all the values in the range used โ otherwise you will get warnings. learn from my mistakes, fr fr ๐
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);
๐ซถ AUTHORS ๐ซถ
Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>. icons, both of them ๐
โญ COPYRIGHT AND LICENSE โญ
Copyright (C) 2008-2024 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.
okay so lowkey the legal bit is short but she's important โ free software, same terms as Perl itself, no notes, periodt ๐
and that's the whole page, bestie!! ๐ this one shipped as perl v5.42.3, dated 2026-08-20, and it lives in the Math::GSL::Fit(3pm) corner of the manual-verse. go fit some lines, you've got this ๐โจ๐ธ
๐ฆ where this page comes from
- ubuntu stonking: libmath-gsl-perl 0.49-1build1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms