42 #include "Wm5Vector2.h"
43 #include "Wm5ApprLineFit2.h"
44 #include "Wm5LinearSystem.h"
82 stand_dev_residuals_(0),
84 stand_error_slope_(0),
114 template <
typename Iterator>
115 void computeRegression(
double confidence_interval_P,
Iterator x_begin,
Iterator x_end,
Iterator y_begin,
bool compute_goodness =
true);
139 template <
typename Iterator>
140 void computeRegressionWeighted(
double confidence_interval_P,
Iterator x_begin,
Iterator x_end,
Iterator y_begin,
Iterator w_begin,
bool compute_goodness =
true);
168 static inline double computePointY(
double x,
double slope,
double intercept)
170 return slope * x + intercept;
202 void computeGoodness_(
const std::vector<Wm5::Vector2d>& points,
double confidence_interval_P);
205 template <
typename Iterator>
209 template <
typename Iterator>
222 template <
typename Iterator>
225 double chi_squared = 0.0;
228 for (; xIter != x_end; ++xIter, ++yIter)
230 chi_squared += std::pow(*yIter -
computePointY(*xIter, slope, intercept), 2);
237 template <
typename Iterator>
240 double chi_squared = 0.0;
244 for (; xIter != x_end; ++xIter, ++yIter, ++wIter)
246 chi_squared += *wIter * std::pow(*yIter -
computePointY(*xIter, slope, intercept), 2);
252 template <
typename Iterator>
260 bool pass = Wm5::HeightLineFit2<double>(
static_cast<int>(points.size()), &points.front(),
slope_,
intercept_);
265 if (compute_goodness && points.size() > 2)
computeGoodness_(points, confidence_interval_P);
270 "UnableToFit-LinearRegression",
String(
"Could not fit a linear model to the data (") + points.size() +
" points).");
274 template <
typename Iterator>
283 int numPoints =
static_cast<int>(points.size());
284 double sumX = 0, sumY = 0;
285 double sumXX = 0, sumXY = 0;
289 for (
int i = 0; i < numPoints; ++i, ++wIter)
291 sumX += (*wIter) * points[i].X();
292 sumY += (*wIter) * points[i].Y();
293 sumXX += (*wIter) * points[i].X() * points[i].X();
294 sumXY += (*wIter) * points[i].X() * points[i].Y();
310 bool nonsingular = Wm5::LinearSystem<double>().Solve2(A, B, X);
320 if (compute_goodness && points.size() > 2)
computeGoodness_(points, confidence_interval_P);
325 "UnableToFit-LinearRegression",
"Could not fit a linear model to the data");
Exception used if an error occurred while fitting a model to a given dataset.
Definition: Exception.h:684
This class offers functions to perform least-squares fits to a straight line model,...
Definition: LinearRegression.h:70
void computeRegression(double confidence_interval_P, Iterator x_begin, Iterator x_end, Iterator y_begin, bool compute_goodness=true)
This function computes the best-fit linear regression coefficients of the model for the dataset .
Definition: LinearRegression.h:253
double r_squared_
The squared correlation coefficient (Pearson)
Definition: LinearRegression.h:188
double getRSquared() const
Non-mutable access to the squared Pearson coefficient.
void computeGoodness_(const std::vector< Wm5::Vector2d > &points, double confidence_interval_P)
Computes the goodness of the fitted regression line.
double getIntercept() const
Non-mutable access to the y-intercept of the straight line.
double x_intercept_
The intercept of the fitted line with the x-axis.
Definition: LinearRegression.h:180
double getUpper() const
Non-mutable access to the upper border of confidence interval.
LinearRegression()
Constructor.
Definition: LinearRegression.h:74
double lower_
The lower bound of the confidence interval.
Definition: LinearRegression.h:182
virtual ~LinearRegression()=default
Destructor.
double getXIntercept() const
Non-mutable access to the x-intercept of the straight line.
static double computePointY(double x, double slope, double intercept)
given x compute y = slope * x + intercept
Definition: LinearRegression.h:168
double upper_
The upper bound of the confidence interval.
Definition: LinearRegression.h:184
LinearRegression & operator=(const LinearRegression &arg)
Not implemented.
double computeWeightedChiSquare(Iterator x_begin, Iterator x_end, Iterator y_begin, Iterator w_begin, double slope, double intercept)
Compute the chi squared of a weighted linear fit.
Definition: LinearRegression.h:238
double t_star_
The value of the t-statistic.
Definition: LinearRegression.h:186
double getRSD() const
Non-mutable access to relative standard deviation.
double computeChiSquare(Iterator x_begin, Iterator x_end, Iterator y_begin, double slope, double intercept)
Compute the chi squared of a linear fit.
Definition: LinearRegression.h:223
double getTValue() const
Non-mutable access to the value of the t-distribution.
double getStandErrSlope() const
Non-mutable access to the standard error of the slope.
double getSlope() const
Non-mutable access to the slope of the straight line.
double getChiSquared() const
Non-mutable access to the chi squared value.
double chi_squared_
The value of the Chi Squared statistic.
Definition: LinearRegression.h:196
double intercept_
The intercept of the fitted line with the y-axis.
Definition: LinearRegression.h:176
double slope_
The slope of the fitted line.
Definition: LinearRegression.h:178
double getLower() const
Non-mutable access to the lower border of confidence interval.
double mean_residuals_
Mean of residuals.
Definition: LinearRegression.h:192
double stand_dev_residuals_
The standard deviation of the residuals.
Definition: LinearRegression.h:190
void computeRegressionWeighted(double confidence_interval_P, Iterator x_begin, Iterator x_end, Iterator y_begin, Iterator w_begin, bool compute_goodness=true)
This function computes the best-fit linear regression coefficients of the model for the weighted da...
Definition: LinearRegression.h:275
LinearRegression(const LinearRegression &arg)
Not implemented.
double rsd_
the relative standard deviation
Definition: LinearRegression.h:198
double getMeanRes() const
Non-mutable access to the residual mean.
double stand_error_slope_
The standard error of the slope.
Definition: LinearRegression.h:194
double getStandDevRes() const
Non-mutable access to the standard deviation of the residuals.
A more convenient string class.
Definition: String.h:61
std::vector< Wm5::Vector2d > iteratorRange2Wm5Vectors(Iterator x_begin, Iterator x_end, Iterator y_begin)
Copies the distance(x_begin,x_end) elements starting at x_begin and y_begin into the Wm5::Vector.
Definition: RegressionUtils.h:44
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47