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.

{
std::size_t size = data.size();
if(size > 2)
{
pappso::pappso_double x_vec_mean =
(std::accumulate(data.begin(),
data.end(),
0,
[](double a, const DataPoint &b) { return a + b.x; }) /
size);
pappso::pappso_double y_vec_mean =
(sumYTrace(data.begin(), data.end(), 0) / size);
pappso::pappso_double sx = 0;
pappso::pappso_double sxy = 0;
for(size_t i = 0; i < size; i++)
{
sx += std::pow((data[i].x - x_vec_mean), 2);
sxy += (data[i].x - x_vec_mean) * (data[i].y - y_vec_mean);
}
_slope = sxy / sx;
_intercept = y_vec_mean - (_slope * x_vec_mean);
}
}
pappso::LinearRegression::_slope
double _slope
Definition: linearregression.h:51
pappso::LinearRegression::_intercept
double _intercept
Definition: linearregression.h:52
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48
pappso::sumYTrace
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:203
pappso::DataPoint
Definition: datapoint.h:21

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.

{
std::size_t size = data.size();
if(size > 2)
{
double meanY = meanYTrace(data.begin(), data.end());
pappso::pappso_double sum_square_deviation = 0;
for(size_t i = 0; i < size; i++)
{
sum_square_deviation +=
std::pow((data[i].y - getYfromX(data[i].x)), 2);
}
pappso::pappso_double sum_square_total = 0;
for(size_t i = 0; i < size; i++)
{
sum_square_total += std::pow((data[i].y - meanY), 2);
}
return ((double)1.0 - (sum_square_deviation / sum_square_total));
}
return 0;
}
pappso::LinearRegression::getYfromX
double getYfromX(double score) const
Definition: linearregression.cpp:73
pappso::meanYTrace
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:212

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.

{
return _intercept;
}

References _intercept.

## getNrmsd()

double LinearRegression::getNrmsd | ( | const Trace & | data | ) | const

get Normalized Root-Mean-Square Deviation

Definition at line 98 of file linearregression.cpp.

{
return (getRmsd(data) / (maxYDataPoint(data.begin(), data.end())->y -
minYDataPoint(data.begin(), data.end())->y));
}
pappso::LinearRegression::getRmsd
double getRmsd(const Trace &data) const
get Root-Mean-Square Deviation
Definition: linearregression.cpp:79
pappso::maxYDataPoint
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:139
pappso::minYDataPoint
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:117

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.

{
std::size_t size = data.size();
if(size > 2)
{
pappso::pappso_double sum_square_deviation = 0;
for(size_t i = 0; i < size; i++)
{
sum_square_deviation +=
std::pow((data[i].y - getYfromX(data[i].x)), 2);
}
return sqrt(sum_square_deviation / (double)size);
}
return 0;
}

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.

{
return _slope;
}

References _slope.

## getYfromX()

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

Definition at line 73 of file linearregression.cpp.

{
return (_slope * x + _intercept);
}

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:

- pappsomspp/trace/linearregression.h
- pappsomspp/trace/linearregression.cpp