chiark / gitweb /
@@@ much mess, mostly manpages
[mLib] / utils / linreg.3.in
1 .\" -*-nroff-*-
2 .\"
3 .\" Manual for linear regression
4 .\"
5 .\" (c) 2024 Straylight/Edgeware
6 .\"
7 .
8 .\"----- Licensing notice ---------------------------------------------------
9 .\"
10 .\" This file is part of the mLib utilities library.
11 .\"
12 .\" mLib is free software: you can redistribute it and/or modify it under
13 .\" the terms of the GNU Library General Public License as published by
14 .\" the Free Software Foundation; either version 2 of the License, or (at
15 .\" your option) any later version.
16 .\"
17 .\" mLib is distributed in the hope that it will be useful, but WITHOUT
18 .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 .\" FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
20 .\" License for more details.
21 .\"
22 .\" You should have received a copy of the GNU Library General Public
23 .\" License along with mLib.  If not, write to the Free Software
24 .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 .\" USA.
26 .
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
29 .
30 .\"--------------------------------------------------------------------------
31 .TH linreg 3mLib "9 March 2024" "Straylight/Edgeware" "mLib utilities library"
32 .\" @linreg_init
33 .\" @linreg_update
34 .\" @linreg_fit
35 .\" @LINREG_INIT
36 .
37 .\"--------------------------------------------------------------------------
38 .SH NAME
39 lineag \- linear regression
40 .
41 .\"--------------------------------------------------------------------------
42 .SH SYNOPSIS
43 .nf
44 .B "#include <mLib/linreg.h>"
45 .PP
46 .B "struct linreg { ...\& };"
47 .B "#define LINREG_INIT ..."
48 .PP
49 .BI "void linreg_init(struct linreg *" lr );
50 .BI "void linreg_update(struct linreg *" lr ", double " x ", double " y );
51 .ta \w'void linreg_fit('u
52 .BI "void linreg_fit(struct linreg *" lr ,
53 .BI "   double *" m_out ", double *" c_out ", double *" r_out );
54 .fi
55 .
56 .\"--------------------------------------------------------------------------
57 .SH DESCRIPTION
58 .
59 The functions declared in the
60 .B <mLib/linreg.h>
61 header perform simple linear regression.
62 .PP
63 The state for a linear regression is held in a
64 .BR "struct linreg" .
65 Such a structure can be initialized statically,
66 using the
67 .B LINREG_INIT macro,
68 or dynamically, by calling the
69 .B linreg_init
70 function.
71 .PP
72 Once a state is initialized,
73 points
74 .RI ( x ",\ " y )
75 can be added by calling
76 .BR linreg_update .
77 Each call just performs a small and constant amount of computation;
78 the linear regression state uses a constant amount of storage
79 independent of the number of points.
80 .P
81 Finally, the
82 .B linreg_fit
83 function will return the results of the regression.
84 It calculates quantities
85 .I m
86 and
87 .I c
88 such that the line
89 .IR y "\ =\ " m "\ " x "\ +\ " c
90 is a reasonable approximation to the data points provided,
91 and a correlation coefficient
92 .I r
93 quantifying how good this approximation is.
94 These quantities are stored in
95 .BI * m_out \fR,
96 .BI * c_out \fR,
97 and
98 .BI * r_out \fR,
99 respectively;
100 any (or all, but that wouldn't be useful) of these pointers may be null,
101 to discard the corresponding output.
102 .PP
103 The linear regression state can be discarded without need for ceremony:
104 it holds no external resources.
105 .PP
106 Any half-decent introduction to statistics will explain these concepts.
107 .
108 .\"--------------------------------------------------------------------------
109 .SH SEE ALSO
110 .
111 .BR mLib (3).
112 .
113 .\"--------------------------------------------------------------------------
114 .SH AUTHOR
115 .
116 Mark Wooding, <mdw@distorted.org.uk>
117 .
118 .\"----- That's all, folks --------------------------------------------------