|
OpenMS
2.6.0
|
Go to the documentation of this file.
42 #include "Wm5Vector2.h"
43 #include "Wm5ApprLineFit2.h"
44 #include "Wm5LinearSystem.h"
82 stand_dev_residuals_(0),
84 stand_error_slope_(0),
116 template <
typename Iterator>
117 void computeRegression(
double confidence_interval_P,
Iterator x_begin,
Iterator x_end,
Iterator y_begin,
bool compute_goodness =
true);
141 template <
typename Iterator>
142 void computeRegressionWeighted(
double confidence_interval_P,
Iterator x_begin,
Iterator x_end,
Iterator y_begin,
Iterator w_begin,
bool compute_goodness =
true);
145 double getIntercept()
const;
147 double getSlope()
const;
149 double getXIntercept()
const;
151 double getLower()
const;
153 double getUpper()
const;
155 double getTValue()
const;
157 double getRSquared()
const;
159 double getStandDevRes()
const;
161 double getMeanRes()
const;
163 double getStandErrSlope()
const;
165 double getChiSquared()
const;
167 double getRSD()
const;
198 void computeGoodness_(
const std::vector<Wm5::Vector2d>& points,
double confidence_interval_P);
201 template <
typename Iterator>
205 template <
typename Iterator>
221 double computePointY(
double x,
double slope,
double intercept)
223 return slope * x + intercept;
229 template <
typename Iterator>
232 double chi_squared = 0.0;
235 for (; xIter != x_end; ++xIter, ++yIter)
237 chi_squared += std::pow(*yIter - computePointY(*xIter, slope, intercept), 2);
244 template <
typename Iterator>
247 double chi_squared = 0.0;
251 for (; xIter != x_end; ++xIter, ++yIter, ++wIter)
253 chi_squared += *wIter * std::pow(*yIter - computePointY(*xIter, slope, intercept), 2);
259 template <
typename Iterator>
267 bool pass = Wm5::HeightLineFit2<double>(static_cast<int>(points.size()), &points.front(),
slope_,
intercept_);
272 if (compute_goodness && points.size() > 2)
computeGoodness_(points, confidence_interval_P);
277 "UnableToFit-LinearRegression",
String(
"Could not fit a linear model to the data (") + points.size() +
" points).");
281 template <
typename Iterator>
290 int numPoints = static_cast<int>(points.size());
291 double sumX = 0, sumY = 0;
292 double sumXX = 0, sumXY = 0;
296 for (
int i = 0; i < numPoints; ++i, ++wIter)
298 sumX += (*wIter) * points[i].X();
299 sumY += (*wIter) * points[i].Y();
300 sumXX += (*wIter) * points[i].X() * points[i].X();
301 sumXY += (*wIter) * points[i].X() * points[i].Y();
317 bool nonsingular = Wm5::LinearSystem<double>().Solve2(A, B, X);
327 if (compute_goodness && points.size() > 2)
computeGoodness_(points, confidence_interval_P);
332 "UnableToFit-LinearRegression",
"Could not fit a linear model to the data");
double t_star_
The value of the t-statistic.
Definition: LinearRegression.h:182
double chi_squared_
The value of the Chi Squared statistic.
Definition: LinearRegression.h:192
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:260
double x_intercept_
The intercept of the fitted line with the x-axis.
Definition: LinearRegression.h:176
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:230
double mean_residuals_
Mean of residuals.
Definition: LinearRegression.h:188
A more convenient string class.
Definition: String.h:59
double stand_error_slope_
The standard error of the slope.
Definition: LinearRegression.h:190
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:245
double r_squared_
The squared correlation coefficient (Pearson)
Definition: LinearRegression.h:184
double stand_dev_residuals_
The standard deviation of the residuals.
Definition: LinearRegression.h:186
void computeGoodness_(const std::vector< Wm5::Vector2d > &points, double confidence_interval_P)
Computes the goodness of the fitted regression line.
double lower_
The lower bound of the confidence interval.
Definition: LinearRegression.h:178
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
This class offers functions to perform least-squares fits to a straight line model,...
Definition: LinearRegression.h:69
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:282
virtual ~LinearRegression()
Destructor.
Definition: LinearRegression.h:91
double intercept_
The intercept of the fitted line with the y-axis.
Definition: LinearRegression.h:172
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
LinearRegression()
Constructor.
Definition: LinearRegression.h:74
Exception used if an error occurred while fitting a model to a given dataset.
Definition: Exception.h:676
double slope_
The slope of the fitted line.
Definition: LinearRegression.h:174
double rsd_
the relative standard deviation
Definition: LinearRegression.h:194
double upper_
The upper bound of the confidence interval.
Definition: LinearRegression.h:180