@@@ man wip
[mLib] / utils / linreg.3
CommitLineData
adec5584
MW
1.\" -*-nroff-*-
2.TH linreg 3 "9 March 2024" "Straylight/Edgeware" "mLib utilities library"
3.\" @linreg_init
4.\" @linreg_update
5.\" @linreg_fit
6.\" @LINREG_INIT
7.
8.SH SYNOPSIS
9.nf
10.B "#include <mLib/linreg.h>"
d056fbdf 11.PP
adec5584
MW
12.B "struct linreg { ...\& };"
13.B "#define LINREG_INIT ..."
d056fbdf 14.PP
adec5584
MW
15.BI "void linreg_init(struct linreg *" lr );
16.BI "void linreg_update(struct linreg *" lr ", double " x ", double " y );
17.ta \w'void linreg_fit('u
18.BI "void linreg_fit(struct linreg *" lr ,
19.BI " double *" m_out ", double *" c_out ", double *" r_out );
20.fi
21.
22.SH DESCRIPTION
23The functions declared in the
24.B <mLib/linreg.h>
25header perform simple linear regression.
26.PP
27The state for a linear regression is held in a
28.BR "struct linreg" .
29Such a structure can be initialized statically,
30using the
31.B LINREG_INIT macro,
32or dynamically, by calling the
33.B linreg_init
34function.
35.PP
36Once a state is initialized,
37points
38.RI ( x ",\ " y )
39can be added by calling
40.BR linreg_update .
41Each call just performs a small and constant amount of computation;
42the linear regression state uses a constant amount of storage
43independent of the number of points.
44.P
45Finally, the
46.B linreg_fit
47function will return the results of the regression.
48It calculates quantities
49.I m
50and
51.I c
52such that the line
53.IR y "\ =\ " m "\ " x "\ +\ " c
54is a reasonable approximation to the data points provided,
55and a correlation coefficient
56.I r
57quantifying how good this approximation is.
58These quantities are stored in
59.BI * m_out \fR,
60.BI * c_out \fR,
61and
62.BI * r_out \fR,
63respectively;
64any (or all, but that wouldn't be useful) of these pointers may be null,
65to discard the corresponding output.
66.PP
67The linear regression state can be discarded without need for ceremony:
68it holds no external resources.
69.PP
70Any half-decent introduction to statistics will explain these concepts.
71.
72.SH AUTHOR
73Mark Wooding, <mdw@distorted.org.uk>