35 #ifndef OPENMS_MATH_STATISTICS_LINEARREGRESSION_H
36 #define OPENMS_MATH_STATISTICS_LINEARREGRESSION_H
43 #include <gsl/gsl_fit.h>
44 #include <gsl/gsl_statistics.h>
45 #include <gsl/gsl_cdf.h>
82 stand_dev_residuals_(0),
84 stand_error_slope_(0),
111 template <
typename Iterator>
112 void computeRegression(
double confidence_interval_P, Iterator x_begin, Iterator x_end, Iterator y_begin);
129 template <
typename Iterator>
130 void computeRegressionNoIntercept(
double confidence_interval_P, Iterator x_begin, Iterator x_end, Iterator y_begin);
148 template <
typename Iterator>
149 void computeRegressionWeighted(
double confidence_interval_P, Iterator x_begin, Iterator x_end, Iterator y_begin, Iterator w_begin);
206 void computeGoodness_(
double * X,
double * Y,
int N,
double confidence_interval_P);
209 template <
typename Iterator>
210 void iteratorRange2Arrays_(Iterator x_begin, Iterator x_end, Iterator y_begin,
double * x_array,
double * y_array);
213 template <
typename Iterator>
214 void iteratorRange3Arrays_(Iterator x_begin, Iterator x_end, Iterator y_begin, Iterator w_begin,
double * x_array,
double * y_array,
double * w_array);
224 template <
typename Iterator>
227 int N = int(distance(x_begin, x_end));
229 double * X =
new double[N];
230 double * Y =
new double[N];
233 double cov00, cov01, cov11;
238 int error = gsl_fit_linear(X, 1, Y, 1, N, &
intercept_, &
slope_, &cov00, &cov01, &cov11, &
chi_squared_);
250 throw Exception::UnableToFit(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"UnableToFit-LinearRegression",
"Could not fit a linear model to the data");
254 template <
typename Iterator>
257 int N = int(distance(x_begin, x_end));
259 double * X =
new double[N];
260 double * Y =
new double[N];
281 throw Exception::UnableToFit(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"UnableToFit-LinearRegression",
"Could not fit a linear model to the data");
285 template <
typename Iterator>
288 int N = int(distance(x_begin, x_end));
290 double * X =
new double[N];
291 double * Y =
new double[N];
292 double * W =
new double[N];
295 double cov00, cov01, cov11;
300 int error = gsl_fit_wlinear(X, 1, W, 1, Y, 1, N, &
intercept_, &
slope_, &cov00, &cov01, &cov11, &
chi_squared_);
313 throw Exception::UnableToFit(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"UnableToFit-LinearRegression",
"Could not fit a linear model to the data");
317 template <
typename Iterator>
321 while (x_begin < x_end)
323 x_array[i] = *x_begin;
324 y_array[i] = *y_begin;
331 template <
typename Iterator>
335 while (x_begin < x_end)
337 x_array[i] = *x_begin;
338 y_array[i] = *y_begin;
339 w_array[i] = *w_begin;
virtual ~LinearRegression()
Destructor.
Definition: LinearRegression.h:91
LinearRegression()
Constructor.
Definition: LinearRegression.h:74
double rsd_
the relative standard deviation
Definition: LinearRegression.h:202
double upper_
The upper bound of the confidence intervall.
Definition: LinearRegression.h:188
double chi_squared_
The value of the Chi Squared statistic.
Definition: LinearRegression.h:200
void computeGoodness_(double *X, double *Y, int N, double confidence_interval_P)
Computes the goodness of the fitted regression line.
void computeRegressionWeighted(double confidence_interval_P, Iterator x_begin, Iterator x_end, Iterator y_begin, Iterator w_begin)
This function computes the best-fit linear regression coefficients of the model for the weighted da...
Definition: LinearRegression.h:286
This class offers functions to perform least-squares fits to a straight line model, .
Definition: LinearRegression.h:69
double x_intercept_
The intercept of the fitted line with the x-axis.
Definition: LinearRegression.h:184
double t_star_
The value of the t-statistic.
Definition: LinearRegression.h:190
double stand_error_slope_
The standard error of the slope.
Definition: LinearRegression.h:198
double mean_residuals_
Mean of residuals.
Definition: LinearRegression.h:196
double slope_
The slope of the fitted line.
Definition: LinearRegression.h:182
void iteratorRange3Arrays_(Iterator x_begin, Iterator x_end, Iterator y_begin, Iterator w_begin, double *x_array, double *y_array, double *w_array)
Copy the distance(x_begin,x_end) elements starting at x_begin, y_begin and w_begin into the arrays x_...
Definition: LinearRegression.h:332
Exception used if an error occurred while fitting a model to a given dataset.
Definition: Exception.h:662
void computeRegressionNoIntercept(double confidence_interval_P, Iterator x_begin, Iterator x_end, Iterator y_begin)
This function computes the best-fit linear regression coefficient of the model for the dataset ...
Definition: LinearRegression.h:255
double stand_dev_residuals_
The standard deviation of the residuals.
Definition: LinearRegression.h:194
void iteratorRange2Arrays_(Iterator x_begin, Iterator x_end, Iterator y_begin, double *x_array, double *y_array)
Copies the distance(x_begin,x_end) elements starting at x_begin and y_begin into the arrays x_array a...
Definition: LinearRegression.h:318
double lower_
The lower bound of the confidence intervall.
Definition: LinearRegression.h:186
double r_squared_
The squared correlation coefficient (Pearson)
Definition: LinearRegression.h:192
double intercept_
The intercept of the fitted line with the y-axis.
Definition: LinearRegression.h:180
void computeRegression(double confidence_interval_P, Iterator x_begin, Iterator x_end, Iterator y_begin)
This function computes the best-fit linear regression coefficients of the model for the dataset ...
Definition: LinearRegression.h:225