Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
lfit.H File Reference

Linear regression (least squares fitting) using GSL. More...

#include <gsl/gsl_statistics_double.h>
#include <gsl/gsl_fit.h>
#include <string>
#include <ah-zip.H>
#include <tpl_array.H>
#include <ah-string-utils.H>
#include <aleph-exceptions.H>
Include dependency graph for lfit.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  LFit
 Linear regression calculator using least squares method. More...
 

Detailed Description

Linear regression (least squares fitting) using GSL.

This file provides the LFit struct for performing simple linear regression on paired (x, y) data using the GNU Scientific Library.

Features

  • Least squares linear fitting: y = c + m*x
  • Coefficient of determination (R²)
  • Mean squared error and standard deviation
  • Prediction with error estimates

Usage Example

Array<double> x = {1, 2, 3, 4, 5};
Array<double> y = {2.1, 3.9, 6.1, 8.0, 10.2};
LFit fit(x, y);
std::cout << "y = " << fit.c << " + " << fit.m << " * x\n";
std::cout << "R² = " << fit.r2 << "\n";
auto [predicted, error] = fit.predict(6.0);
static mpfr_t y
Definition mpfr_mul_d.c:3
void error(const char *file, int line, const char *format,...)
Print an error message with file and line info.
Definition ahDefs.C:105
Linear regression calculator using least squares method.
Definition lfit.H:99
See also
line.H Line equation class
Author
Leandro Rabindranath León

Definition in file lfit.H.