Loading...
Searching...
No Matches
pappso::LinearRegression Class Reference

`#include <linearregression.h>`

## Public Member Functions

| LinearRegression (const Trace &data)
| LinearRegression (const LinearRegression &other)
double | getYfromX (double score) const
double | getIntercept () const
double | getSlope () const
double | getRmsd () const
| get Root-Mean-Square Deviation
double | getNrmsd () const
| get Normalized Root-Mean-Square Deviation
double | getCoefficientOfDetermination () const
| get Coefficient of determination (R2)
std::size_t | getSize () const
| get data size

## Private Attributes

double | m_slope = 0
double | m_intercept = 0
Trace | m_data

## Detailed Description

Definition at line 32 of file linearregression.h.

## Constructor & Destructor Documentation

## LinearRegression() [1/2]

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

Definition at line 40 of file linearregression.cpp.

{
m_data = data;
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);
}
m_slope = sxy / sx;
m_intercept = y_vec_mean - (m_slope * x_vec_mean);
}
}
pappso::LinearRegression::m_data
Trace m_data
Definition linearregression.h:60
pappso::LinearRegression::m_slope
double m_slope
Definition linearregression.h:58
pappso::LinearRegression::m_intercept
double m_intercept
Definition linearregression.h:59
pappso::PeptideIonNter::a
@ a
pappso::PeptideIonNter::b
@ b
pappso::PeptideIonCter::y
@ y
pappso::PeptideIonCter::x
@ x
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition types.h:50
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:244
pappso::DataPoint
Definition datapoint.h:22

References pappso::a, pappso::b, m_data, m_intercept, m_slope, pappso::sumYTrace(), pappso::x, and pappso::y.

## LinearRegression() [2/2]

pappso::LinearRegression::LinearRegression | ( | const LinearRegression & | other | ) |

Definition at line 33 of file linearregression.cpp.

: m_slope(other.m_slope), m_intercept(other.m_intercept), m_data(other.m_data)
{
}

## Member Function Documentation

## getCoefficientOfDetermination()

double LinearRegression::getCoefficientOfDetermination | ( |  | ) | const

get Coefficient of determination (R2)

Definition at line 120 of file linearregression.cpp.

{
std::size_t size = m_data.size();
if(size > 2)
{
double meanY = meanYTrace(m_data.begin(), m_data.end());
pappso::pappso_double sum_square_deviation = 0;
for(size_t i = 0; i < size; i++)
{
sum_square_deviation +=
std::pow((m_data[i].y - getYfromX(m_data[i].x)), 2);
}
pappso::pappso_double sum_square_total = 0;
for(size_t i = 0; i < size; i++)
{
sum_square_total += std::pow((m_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:88
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:253

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

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

## getIntercept()

pappso::pappso_double LinearRegression::getIntercept | ( |  | ) | const

Definition at line 78 of file linearregression.cpp.

{
return m_intercept;
}

References m_intercept.

## getNrmsd()

double LinearRegression::getNrmsd | ( |  | ) | const

get Normalized Root-Mean-Square Deviation

Definition at line 113 of file linearregression.cpp.

{
return (getRmsd() / (maxYDataPoint(m_data.begin(), m_data.end())->y -
minYDataPoint(m_data.begin(), m_data.end())->y));
}
pappso::LinearRegression::getRmsd
double getRmsd() const
get Root-Mean-Square Deviation
Definition linearregression.cpp:94
pappso::maxYDataPoint
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:180
pappso::minYDataPoint
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:158

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

## getRmsd()

double LinearRegression::getRmsd | ( |  | ) | const

get Root-Mean-Square Deviation

Definition at line 94 of file linearregression.cpp.

{
std::size_t size = m_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((m_data[i].y - getYfromX(m_data[i].x)), 2);
}
return sqrt(sum_square_deviation / (double)size);
}
return 0;
}

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

Referenced by getNrmsd().

## getSize()

std::size_t pappso::LinearRegression::getSize | ( |  | ) | const

get data size

Definition at line 71 of file linearregression.cpp.

{
return m_data.size();
}

## getSlope()

pappso::pappso_double LinearRegression::getSlope | ( |  | ) | const

Definition at line 83 of file linearregression.cpp.

{
return m_slope;
}

References m_slope.

## getYfromX()

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

Definition at line 88 of file linearregression.cpp.

{
return (m_slope * x + m_intercept);
}

References m_intercept, m_slope, and pappso::x.

Referenced by getCoefficientOfDetermination(), and getRmsd().

## Member Data Documentation

## m_data

Trace pappso::LinearRegression::m_data

private

Definition at line 60 of file linearregression.h.

Referenced by LinearRegression(), getCoefficientOfDetermination(), getNrmsd(), and getRmsd().

## m_intercept

double pappso::LinearRegression::m_intercept = 0

private

Definition at line 59 of file linearregression.h.

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

## m_slope

double pappso::LinearRegression::m_slope = 0

private

Definition at line 58 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