.\" -*-nroff-*- .\" .\" Manual for linear regression .\" .\" (c) 2024 Straylight/Edgeware .\" . .\"----- Licensing notice --------------------------------------------------- .\" .\" This file is part of the mLib utilities library. .\" .\" mLib is free software: you can redistribute it and/or modify it under .\" the terms of the GNU Library General Public License as published by .\" the Free Software Foundation; either version 2 of the License, or (at .\" your option) any later version. .\" .\" mLib is distributed in the hope that it will be useful, but WITHOUT .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public .\" License for more details. .\" .\" You should have received a copy of the GNU Library General Public .\" License along with mLib. If not, write to the Free Software .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, .\" USA. . .\"-------------------------------------------------------------------------- .so ../defs.man \" @@@PRE@@@ . .\"-------------------------------------------------------------------------- .TH linreg 3mLib "9 March 2024" "Straylight/Edgeware" "mLib utilities library" .\" @linreg_init .\" @linreg_update .\" @linreg_fit .\" @LINREG_INIT . .\"-------------------------------------------------------------------------- .SH NAME lineag \- linear regression . .\"-------------------------------------------------------------------------- .SH SYNOPSIS .nf .B "#include " .PP .B "struct linreg { ...\& };" .B "#define LINREG_INIT ..." .PP .BI "void linreg_init(struct linreg *" lr ); .BI "void linreg_update(struct linreg *" lr ", double " x ", double " y ); .ta \w'void linreg_fit('u .BI "void linreg_fit(struct linreg *" lr , .BI " double *" m_out ", double *" c_out ", double *" r_out ); .fi . .\"-------------------------------------------------------------------------- .SH DESCRIPTION . The functions declared in the .B header perform simple linear regression. .PP The state for a linear regression is held in a .BR "struct linreg" . Such a structure can be initialized statically, using the .B LINREG_INIT macro, or dynamically, by calling the .B linreg_init function. .PP Once a state is initialized, points .RI ( x ",\ " y ) can be added by calling .BR linreg_update . Each call just performs a small and constant amount of computation; the linear regression state uses a constant amount of storage independent of the number of points. .P Finally, the .B linreg_fit function will return the results of the regression. It calculates quantities .I m and .I c such that the line .IR y "\ =\ " m "\ " x "\ +\ " c is a reasonable approximation to the data points provided, and a correlation coefficient .I r quantifying how good this approximation is. These quantities are stored in .BI * m_out \fR, .BI * c_out \fR, and .BI * r_out \fR, respectively; any (or all, but that wouldn't be useful) of these pointers may be null, to discard the corresponding output. .PP The linear regression state can be discarded without need for ceremony: it holds no external resources. .PP Any half-decent introduction to statistics will explain these concepts. . .\"-------------------------------------------------------------------------- .SH SEE ALSO . .BR mLib (3). . .\"-------------------------------------------------------------------------- .SH AUTHOR . Mark Wooding, . .\"----- That's all, folks --------------------------------------------------