libpappsomspp
Library for mass spectrometry
pappso::LinearRegression Class Reference

#include <linearregression.h>

Public Member Functions

 LinearRegression (const Trace &data)
 
double getYfromX (double score) const
 
double getIntercept () const
 
double getSlope () const
 
double getRmsd (const Trace &data) const
 get Root-Mean-Square Deviation More...
 
double getNrmsd (const Trace &data) const
 get Normalized Root-Mean-Square Deviation More...
 
double getCoefficientOfDetermination (const Trace &data) const
 get Coefficient of determination (R2) More...
 

Private Attributes

double _slope = 0
 
double _intercept = 0
 

Detailed Description

Definition at line 32 of file linearregression.h.

Constructor & Destructor Documentation

◆ LinearRegression()

LinearRegression::LinearRegression ( const Trace data)

Definition at line 32 of file linearregression.cpp.

33 {
34 
35  std::size_t size = data.size();
36  if(size > 2)
37  {
38  pappso::pappso_double x_vec_mean =
39 
40  (std::accumulate(data.begin(),
41  data.end(),
42  0,
43  [](double a, const DataPoint &b) { return a + b.x; }) /
44  size);
45  pappso::pappso_double y_vec_mean =
46  (sumYTrace(data.begin(), data.end(), 0) / size);
47 
48  pappso::pappso_double sx = 0;
49  pappso::pappso_double sxy = 0;
50  for(size_t i = 0; i < size; i++)
51  {
52  sx += std::pow((data[i].x - x_vec_mean), 2);
53  sxy += (data[i].x - x_vec_mean) * (data[i].y - y_vec_mean);
54  }
55  _slope = sxy / sx;
56 
57  _intercept = y_vec_mean - (_slope * x_vec_mean);
58  }
59 }
double pappso_double
A type definition for doubles.
Definition: types.h:49
double sumYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double init)
calculate the sum of y value of a trace
Definition: trace.cpp:244

References _intercept, _slope, pappso::a, pappso::b, pappso::sumYTrace(), pappso::x, and pappso::y.

Member Function Documentation

◆ getCoefficientOfDetermination()

double LinearRegression::getCoefficientOfDetermination ( const Trace data) const

get Coefficient of determination (R2)

Definition at line 105 of file linearregression.cpp.

106 {
107  std::size_t size = data.size();
108  if(size > 2)
109  {
110  double meanY = meanYTrace(data.begin(), data.end());
111  pappso::pappso_double sum_square_deviation = 0;
112  for(size_t i = 0; i < size; i++)
113  {
114  sum_square_deviation +=
115  std::pow((data[i].y - getYfromX(data[i].x)), 2);
116  }
117  pappso::pappso_double sum_square_total = 0;
118  for(size_t i = 0; i < size; i++)
119  {
120  sum_square_total += std::pow((data[i].y - meanY), 2);
121  }
122  return ((double)1.0 - (sum_square_deviation / sum_square_total));
123  }
124  return 0;
125 }
double getYfromX(double score) const
double meanYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the mean of y value of a trace
Definition: trace.cpp:253

References getYfromX(), pappso::meanYTrace(), pappso::x, and pappso::y.

Referenced by pappso::IonIsotopeRatioScore::IonIsotopeRatioScore().

◆ getIntercept()

pappso::pappso_double LinearRegression::getIntercept ( ) const

Definition at line 63 of file linearregression.cpp.

64 {
65  return _intercept;
66 }

References _intercept.

◆ getNrmsd()

double LinearRegression::getNrmsd ( const Trace data) const

get Normalized Root-Mean-Square Deviation

Definition at line 98 of file linearregression.cpp.

99 {
100  return (getRmsd(data) / (maxYDataPoint(data.begin(), data.end())->y -
101  minYDataPoint(data.begin(), data.end())->y));
102 }
double getRmsd(const Trace &data) const
get Root-Mean-Square Deviation
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:180
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:158

References getRmsd(), pappso::maxYDataPoint(), and pappso::minYDataPoint().

◆ getRmsd()

double LinearRegression::getRmsd ( const Trace data) const

get Root-Mean-Square Deviation

Definition at line 79 of file linearregression.cpp.

80 {
81 
82  std::size_t size = data.size();
83  if(size > 2)
84  {
85 
86  pappso::pappso_double sum_square_deviation = 0;
87  for(size_t i = 0; i < size; i++)
88  {
89  sum_square_deviation +=
90  std::pow((data[i].y - getYfromX(data[i].x)), 2);
91  }
92  return sqrt(sum_square_deviation / (double)size);
93  }
94  return 0;
95 }

References getYfromX(), pappso::x, and pappso::y.

Referenced by getNrmsd().

◆ getSlope()

pappso::pappso_double LinearRegression::getSlope ( ) const

Definition at line 68 of file linearregression.cpp.

69 {
70  return _slope;
71 }

References _slope.

◆ getYfromX()

pappso::pappso_double LinearRegression::getYfromX ( double  score) const

Definition at line 73 of file linearregression.cpp.

74 {
75  return (_slope * x + _intercept);
76 }

References _intercept, _slope, and pappso::x.

Referenced by getCoefficientOfDetermination(), and getRmsd().

Member Data Documentation

◆ _intercept

double pappso::LinearRegression::_intercept = 0
private

Definition at line 52 of file linearregression.h.

Referenced by LinearRegression(), getIntercept(), and getYfromX().

◆ _slope

double pappso::LinearRegression::_slope = 0
private

Definition at line 51 of file linearregression.h.

Referenced by LinearRegression(), getSlope(), and getYfromX().


The documentation for this class was generated from the following files: