source: trunk/yat/regression/Linear.h @ 1454

Last change on this file since 1454 was 1454, checked in by Peter, 13 years ago

fixes #429 - the problem was that the implementation had been moved to base class, so I removed the declaration in Linear.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1#ifndef _theplu_yat_regression_linear_
2#define _theplu_yat_regression_linear_
3
4// $Id: Linear.h 1454 2008-08-29 19:17:16Z peter $
5
6/*
7  Copyright (C) 2004, 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2008 Peter Johansson
9
10  This file is part of the yat library, http://dev.thep.lu.se/yat
11
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 2 of the
15  License, or (at your option) any later version.
16
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25  02111-1307, USA.
26*/
27
28#include "OneDimensional.h"
29
30#include <cmath>
31
32namespace theplu {
33namespace yat {
34  namespace utility {
35    class VectorBase;
36  }
37namespace regression {
38
39  /**
40     @brief linear regression.   
41     
42     Data are modeled as \f$ y_i = \alpha + \beta (x_i-m_x) +
43     \epsilon_i \f$.
44  */
45  class Linear : public OneDimensional
46  {
47 
48  public:
49    ///
50    /// @brief The default constructor
51    ///
52    Linear(void);
53
54    ///
55    /// @brief The destructor
56    ///
57    virtual ~Linear(void);
58         
59    /**
60       The parameter \f$ \alpha \f$ is estimated as \f$
61       \frac{1}{n}\sum y_i \f$
62       
63       @return the parameter \f$ \alpha \f$
64    */
65    double alpha(void) const;
66
67    /**
68       The standard deviation is estimated as \f$ \sqrt{\frac{s^2}{n}}
69       \f$ where \f$ s^2 = \frac{\sum \epsilon^2}{n-2} \f$
70       
71       @return standard deviation of parameter \f$ \alpha \f$
72    */
73    double alpha_var(void) const;
74
75    /**
76       The parameter \f$ \beta \f$ is estimated as \f$
77       \frac{\textrm{Cov}(x,y)}{\textrm{Var}(x)} \f$
78       
79       @return the parameter \f$ \beta \f$
80    */
81    double beta(void) const;
82
83    /**
84       The standard deviation is estimated as \f$ \frac{s^2}{\sum
85       (x-m_x)^2} \f$ where \f$ s^2 = \frac{\sum \epsilon^2}{n-2} \f$
86
87       @return standard deviation of parameter \f$ \beta \f$
88    */
89    double beta_var(void) const;
90
91    /**
92       Model is fitted by minimizing \f$ \sum{(y_i - \alpha - \beta
93       (x-m_x))^2} \f$. By construction \f$ \alpha \f$ and \f$ \beta \f$
94       are independent.
95    */
96    void fit(const utility::VectorBase& x, const utility::VectorBase& y) ;
97   
98    ///
99    /// @return \f$ \alpha + \beta x \f$
100    ///
101    double predict(const double x) const;
102
103    /**
104       \f$ \frac{\sum \epsilon_i^2}{N-2} \f$
105
106       @return variance of residuals
107    */
108    double s2(void) const;
109
110    /**
111       The error of the model is estimated as \f$
112       \textrm{alpha\_err}^2+\textrm{beta\_err}^2*(x-m_x)*(x-m_x)\f$
113   
114       @return estimated error of model in @a x
115    */
116    double standard_error2(const double x) const;
117
118
119  private:
120    ///
121    /// Copy Constructor. (not implemented)
122    ///
123    Linear(const Linear&);
124
125    double alpha_;
126    double alpha_var_;
127    double beta_;
128    double beta_var_;
129  };
130
131}}} // of namespaces regression, yat, and theplu
132
133#endif
Note: See TracBrowser for help on using the repository browser.