simpleLinearRegression.hpp
Go to the documentation of this file.
1 #ifndef JULIAN_SIMPLELINEARREGRESSION_HPP
2 #define JULIAN_SIMPLELINEARREGRESSION_HPP
3 
5 #include <iostream>
6 #include <vector>
7 #include <string>
8 #include <gsl/gsl_fit.h>
9 
10 namespace julian {
11 
29  class SimpleLinearRegression : public DeeplyCopyableRegression<SimpleLinearRegression> {
30  public:
31  SimpleLinearRegression(): chi_sq_(0.0), cov00_(0.0), cov01_(0.0), cov11_(0.0), c0_(0.0), c1_(0.0) {};
32 
33  void estimate(const std::vector<double>& x,const std::vector<double>& y);
34  void estimate(const std::vector<double>& x,const std::vector<double>& y,const std::vector<double>& w);
35 
36  double getSlope();
37  double getIntercept();
38  std::vector<double> getCoefficient() const;
39  double operator()(double) const;
40 
41  private:
42  double chi_sq_;
43  double cov00_;
44  double cov01_;
45  double cov11_;
46  double c0_;
47  double c1_;
48  };
49 } // namespace julian
50 
55 std::ostream& operator<<(std::ostream& s, julian::SimpleLinearRegression& r);
56 
57 #endif
double operator()(double) const
evaluates the linear regression model for x
Definition: simpleLinearRegression.cpp:8
std::ostream & operator<<(std::ostream &s, julian::SimpleLinearRegression &r)
Overloads stream operator.
Definition: simpleLinearRegression.cpp:46
double getIntercept()
returns intercept
Definition: simpleLinearRegression.cpp:20
Definition: cadHoliday.cpp:3
double c1_
Slope of linear regression.
Definition: simpleLinearRegression.hpp:47
Class implements simple linear regression.
Definition: simpleLinearRegression.hpp:29
double chi_sq_
The sum of squares of the residuals from the best-fit line.
Definition: simpleLinearRegression.hpp:42
void estimate(const std::vector< double > &x, const std::vector< double > &y)
estimates the parameters basing on provided data
Definition: simpleLinearRegression.cpp:26
double cov00_
Variance of the slope estimate.
Definition: simpleLinearRegression.hpp:43
double cov01_
Covariance of the slope/intercept estimates.
Definition: simpleLinearRegression.hpp:44
double cov11_
Variance of the intercept estimate.
Definition: simpleLinearRegression.hpp:45
Class uses Curiously Recurring Template Pattern to implement polymorphic copy construction in every d...
Definition: regression.hpp:60
double c0_
Intercept of linear regression.
Definition: simpleLinearRegression.hpp:46
double getSlope()
returns slope
Definition: simpleLinearRegression.cpp:14
std::vector< double > getCoefficient() const
return coefficients of the regression
Definition: simpleLinearRegression.cpp:40
File contains interface of regressions.