Performs linear regression to fit a straight line to data points.
More...
#include <gin_linearregression.h>
Performs linear regression to fit a straight line to data points.
This class fits a linear equation y = a + bx to a set of data points using the least squares method. It calculates the coefficients (a, b) that minimize the sum of squared differences between the data points and the line.
The class also computes:
- Coefficient of determination (R²): Measures goodness of fit (0 to 1)
- Coefficient of correlation: Measures strength of linear relationship (-1 to 1)
- Standard error of estimate: Measures typical prediction error
Example usage:
Performs linear regression to fit a straight line to data points.
Definition gin_linearregression.h:41
double a
Definition gin_linearregression.h:124
double b
Definition gin_linearregression.h:125
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25
- See also
- getA, getB, estimateY, getCoefDeterm
◆ LinearRegression() [1/2]
| LinearRegression::LinearRegression |
( |
| ) |
|
Creates an empty linear regression object.
◆ LinearRegression() [2/2]
| LinearRegression::LinearRegression |
( |
juce::Array< Point< double > > |
points | ) |
|
Creates a linear regression object and adds the given points.
- Parameters
-
| points | Initial set of data points |
◆ addPoint()
Adds a data point to the regression.
- Parameters
-
◆ calculate()
| void LinearRegression::calculate |
( |
| ) |
|
Calculates the regression coefficients from the added points.
Must be called after adding points and before retrieving results.
◆ clear()
| void LinearRegression::clear |
( |
| ) |
|
Removes all data points and resets the regression.
◆ haveData()
| bool LinearRegression::haveData |
( |
| ) |
const |
Checks if enough data points have been added.
- Returns
- true if more than 2 points have been added
References n.
◆ items()
| int LinearRegression::items |
( |
| ) |
const |
Returns the number of data points.
- Returns
- The number of points added
References n.
◆ getA()
| double LinearRegression::getA |
( |
| ) |
const |
Returns the intercept of the fitted line.
- Returns
- The 'a' coefficient in y = a + bx
References a.
◆ getB()
| double LinearRegression::getB |
( |
| ) |
const |
Returns the slope of the fitted line.
- Returns
- The 'b' coefficient in y = a + bx
References b.
◆ getCoefDeterm()
| double LinearRegression::getCoefDeterm |
( |
| ) |
const |
Returns the coefficient of determination (R²).
- Returns
- R² value (0 to 1), where 1 indicates perfect fit
References coefD.
◆ getCoefCorrel()
| double LinearRegression::getCoefCorrel |
( |
| ) |
const |
Returns the coefficient of correlation.
- Returns
- Correlation coefficient (-1 to 1)
References coefC.
◆ getStdErrorEst()
| double LinearRegression::getStdErrorEst |
( |
| ) |
const |
Returns the standard error of estimate.
- Returns
- The typical prediction error
References stdError.
◆ estimateY()
Estimates the y value for a given x using the fitted line.
- Parameters
-
- Returns
- The estimated y value
References a, and b.
| int LinearRegression::n = 0 |
|
protected |
◆ sumX
| double LinearRegression::sumX = 0 |
|
protected |
◆ sumY
| double LinearRegression::sumY = 0 |
|
protected |
◆ sumXsquared
| double LinearRegression::sumXsquared = 0 |
|
protected |
◆ sumYsquared
| double LinearRegression::sumYsquared = 0 |
|
protected |
◆ sumXY
| double LinearRegression::sumXY = 0 |
|
protected |
| double LinearRegression::a = 0 |
|
protected |
| double LinearRegression::b = 0 |
|
protected |
◆ coefD
| double LinearRegression::coefD = 0 |
|
protected |
◆ coefC
| double LinearRegression::coefC = 0 |
|
protected |
◆ stdError
| double LinearRegression::stdError = 0 |
|
protected |
The documentation for this class was generated from the following file: