yat  0.14.5pre
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
theplu::yat::regression::Linear Class Reference

linear regression. More...

#include <yat/regression/Linear.h>

Inheritance diagram for theplu::yat::regression::Linear:
theplu::yat::regression::OneDimensional

Public Member Functions

 Linear (void)
 The default constructor.
 
virtual ~Linear (void)
 The destructor.
 
double alpha (void) const
 
double alpha_var (void) const
 
double beta (void) const
 
double beta_var (void) const
 
void fit (const utility::VectorBase &x, const utility::VectorBase &y)
 
double predict (const double x) const
 
double s2 (void) const
 
double standard_error2 (const double x) const
 
double chisq (void) const
 Chi-squared. More...
 
double prediction_error2 (const double x) const
 
std::ostream & print (std::ostream &os, const double min, double max, const unsigned int n) const
 print output to ostream os More...
 
double r2 (void) const
 

Protected Member Functions

double variance (void) const
 

Protected Attributes

statistics::AveragerPair ap_
 
double chisq_
 

Detailed Description

linear regression.

Data are modeled as $ y_i = \alpha + \beta (x_i-m_x) + \epsilon_i $.

Member Function Documentation

double theplu::yat::regression::Linear::alpha ( void  ) const

The parameter $ \alpha $ is estimated as $ \frac{1}{n}\sum y_i $

Returns
the parameter $ \alpha $
double theplu::yat::regression::Linear::alpha_var ( void  ) const

The variance is estimated as $ \frac{s^2}{n} $ where $ s^2 = \frac{\sum \epsilon^2}{n-2} $

Returns
variance of parameter $ \alpha $
double theplu::yat::regression::Linear::beta ( void  ) const

The parameter $ \beta $ is estimated as $ \frac{\textrm{Cov}(x,y)}{\textrm{Var}(x)} $

Returns
the parameter $ \beta $
double theplu::yat::regression::Linear::beta_var ( void  ) const

The variance is estimated as $ \frac{s^2}{\sum (x-m_x)^2} $ where $ s^2 = \frac{\sum \epsilon^2}{n-2} $

Returns
variance of parameter $ \beta $
double theplu::yat::regression::OneDimensional::chisq ( void  ) const
inherited

Chi-squared.

Chi-squared is defined as the $ \sum{(\hat{y_i}-y_i)^2} $

void theplu::yat::regression::Linear::fit ( const utility::VectorBase x,
const utility::VectorBase y 
)
virtual

Model is fitted by minimizing $ \sum{(y_i - \alpha - \beta (x-m_x))^2} $. By construction $ \alpha $ and $ \beta $ are independent.

Implements theplu::yat::regression::OneDimensional.

double theplu::yat::regression::Linear::predict ( const double  x) const
virtual
double theplu::yat::regression::OneDimensional::prediction_error2 ( const double  x) const
inherited

The prediction error is defined as the expected squared deviation a new data point will have from value the model provides: $ E(Y|x - \hat{y}(x))^2 $ and is typically divided into the conditional variance ( see s2() ) given $ x $ and the squared standard error ( see standard_error2() ) of the model estimation in $ x $.

Returns
expected squared prediction error for a new data point in x
std::ostream& theplu::yat::regression::OneDimensional::print ( std::ostream &  os,
const double  min,
double  max,
const unsigned int  n 
) const
inherited

print output to ostream os

Printing estimated model to os in the points defined by min, max, and n. The values printed for each point is the x-value, the estimated y-value, and the estimated standard deviation of a new data poiunt will have from the y-value given the x-value (see prediction_error()).

Parameters
osOstream printout is sent to
nnumber of points printed
minsmallest x-value for which the model is printed
maxlargest x-value for which the model is printed
double theplu::yat::regression::OneDimensional::r2 ( void  ) const
inherited

r2 is defined as $ 1 - \frac{Var(Y|x)}{Var(Y)} $ or the fraction of the variance explained by the regression model.

See Also
s2()
double theplu::yat::regression::Linear::s2 ( void  ) const
virtual

$ \frac{\sum \epsilon_i^2}{N-2} $

Returns
variance of residuals

Implements theplu::yat::regression::OneDimensional.

double theplu::yat::regression::Linear::standard_error2 ( const double  x) const
virtual

The error of the model is estimated as $ \textrm{alpha\_err}^2+\textrm{beta\_err}^2*(x-m_x)*(x-m_x)$

Returns
estimated error of model in x

Implements theplu::yat::regression::OneDimensional.

double theplu::yat::regression::OneDimensional::variance ( void  ) const
protectedinherited

Variance of y

Member Data Documentation

statistics::AveragerPair theplu::yat::regression::OneDimensional::ap_
protectedinherited

Averager for pair of x and y

double theplu::yat::regression::OneDimensional::chisq_
protectedinherited
See Also
chisq()

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

Generated on Tue Sep 26 2017 02:33:30 for yat by  doxygen 1.8.5