- Timestamp:
- Jan 4, 2007, 3:38:56 PM (16 years ago)
- Location:
- trunk/yat/regression
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/regression/Linear.cc
r724 r726 32 32 Linear::Linear(void) 33 33 : OneDimensional(), alpha_(0), alpha_var_(0), beta_(0), beta_var_(0), 34 chisq_(0) , m_x_(0)34 chisq_(0) 35 35 { 36 36 } … … 45 45 } 46 46 47 double Linear::alpha_ err(void) const47 double Linear::alpha_var(void) const 48 48 { 49 return sqrt(alpha_var_);49 return alpha_var_; 50 50 } 51 51 … … 55 55 } 56 56 57 double Linear::beta_ err(void) const57 double Linear::beta_var(void) const 58 58 { 59 return sqrt(beta_var_);59 return beta_var_; 60 60 } 61 61 … … 75 75 76 76 // calculating deviation between data and model 77 chisq_ = ( (ap_.y_averager().sum_xx_centered() - ap_.sum_xy_centered()* 78 ap_.sum_xy_centered()/ap_.x_averager().sum_xx_centered() ) / 79 (x.size()-2) ); 80 r2_= 1-chisq_/ap_.x_averager().variance(); 81 alpha_var_ = chisq_ / x.size(); 82 beta_var_ = chisq_ / ap_.x_averager().sum_xx_centered(); 83 m_x_ = ap_.x_averager().mean(); 77 chisq_ = (ap_.y_averager().sum_xx_centered() - ap_.sum_xy_centered()* 78 ap_.sum_xy_centered()/ap_.x_averager().sum_xx_centered() ); 79 r2_= 1-chisq_/ap_.x_averager().sum_xx_centered(); 80 alpha_var_ = s2() / x.size(); 81 beta_var_ = s2() / ap_.x_averager().sum_xx_centered(); 84 82 } 85 83 86 84 double Linear::predict(const double x) const 87 85 { 88 return alpha_ + beta_ * (x -m_x_);86 return alpha_ + beta_ * (x - ap_.x_averager().mean()); 89 87 } 90 88 … … 94 92 } 95 93 94 double Linear::s2(void) const 95 { 96 return chisq()/(ap_.n()-2); 97 } 98 96 99 double Linear::standard_error(const double x) const 97 100 { 98 return sqrt( alpha_var_+beta_var_*(x-m_x_)*(x-m_x_)); 101 return sqrt( alpha_var_+beta_var_*(x-ap_.x_averager().mean())* 102 (x-ap_.x_averager().mean()) ); 99 103 } 100 104 -
trunk/yat/regression/Linear.h
r718 r726 65 65 66 66 /** 67 The standard deviation is estimated as \f$ 68 \ sqrt{\frac{\chi^2}{n}} \f$67 The standard deviation is estimated as \f$ \sqrt{\frac{s^2}{n}} 68 \f$ where \f$ s^2 = \frac{\sum \epsilon^2}{n-2} \f$ 69 69 70 70 @return standard deviation of parameter \f$ \alpha \f$ 71 71 */ 72 double alpha_ err(void) const;72 double alpha_var(void) const; 73 73 74 74 /** … … 81 81 82 82 /** 83 The standard deviation is estimated as \f$ 84 \sqrt{\frac{\chi^2}{\sum (x_i-m_x)^2}} \f$85 83 The standard deviation is estimated as \f$ \frac{s^2}{\sum 84 (x-m_x)^2} \f$ where \f$ s^2 = \frac{\sum \epsilon^2}{n-2} \f$ 85 86 86 @return standard deviation of parameter \f$ \beta \f$ 87 87 */ 88 double beta_ err(void) const;88 double beta_var(void) const; 89 89 90 90 /** 91 @brief Mean Squared Error 92 93 Chisq is calculated as \f$ \frac{\sum 94 (y_i-\alpha-\beta(x_i-m_x))^2}{n-2} \f$ 91 Chi-squared is calculated as \f$ \sum 92 (y_i-\alpha-\beta(x_i-m_x))^2 \f$ 95 93 */ 96 94 double chisq(void) const; … … 129 127 Linear(const Linear&); 130 128 129 double s2(void) const; 130 131 131 double alpha_; 132 132 double alpha_var_; … … 134 134 double beta_var_; 135 135 double chisq_; 136 double m_x_; // average of x values137 136 double r2_; // coefficient of determination 138 137 }; -
trunk/yat/regression/Local.h
r718 r726 102 102 103 103 /// 104 /// The output operator for the Regression Local class.104 /// The output operator for the Regression::Local class. 105 105 /// 106 106 std::ostream& operator<<(std::ostream&, const Local& ); -
trunk/yat/regression/MultiDimensional.cc
r718 r726 41 41 if (work_) 42 42 gsl_multifit_linear_free(work_); 43 } 44 45 46 const utility::matrix& MultiDimensional::covariance(void) const 47 { 48 return covariance_; 43 49 } 44 50 -
trunk/yat/regression/MultiDimensional.h
r718 r726 52 52 53 53 /// 54 /// @brief covariance of parameters 55 /// 56 const utility::matrix& covariance(void) const; 57 58 /// 54 59 /// Function fitting parameters of the linear model by miminizing 55 60 /// the quadratic deviation between model and data. -
trunk/yat/regression/Naive.cc
r713 r726 47 47 double Naive::chisq(void) const 48 48 { 49 return ap_.y_averager().sum_xx_centered() /(ap_.n()-1);49 return ap_.y_averager().sum_xx_centered(); 50 50 } 51 51 -
trunk/yat/regression/Naive.h
r713 r726 58 58 59 59 /** 60 \f$\frac{1}{N-1} \sum (x_i-m)^2 \f$ 61 62 @brief Mean Squared Error 60 Chi-squared \f$ \sum (x_i-m)^2 \f$ 63 61 */ 64 62 double chisq(void) const; -
trunk/yat/regression/OneDimensional.h
r718 r726 56 56 57 57 /** 58 @brief Mean Squared Error58 @brief Chi-squared 59 59 60 Mean Squared Error is defined as the \f$ \frac 61 {\sum{(\hat{y_i}-y_i)^2}}{df} \f$ where \f$ df \f$ number of 62 degree of freedom typically is number data points minus number 63 of paramers in model. 60 Chi-squared is defined as the \f$ \frac 61 {\sum{(\hat{y_i}-y_i)^2}}{1} \f$ 64 62 */ 65 63 virtual double chisq(void) const=0; -
trunk/yat/regression/Polynomial.cc
r713 r726 47 47 48 48 49 const utility::matrix& Polynomial::covariance(void) const 50 { 51 return md_.covariance(); 52 } 53 54 49 55 void Polynomial::fit(const utility::vector& x, const utility::vector& y) 50 56 { -
trunk/yat/regression/Polynomial.h
r713 r726 58 58 59 59 /// 60 /// @brief covariance of parameters 61 /// 62 const utility::matrix& covariance(void) const; 63 64 /// 60 65 /// Fit the model by minimizing the mean squared deviation between 61 66 /// model and data. … … 71 76 72 77 /// 73 /// @brief Variance ofresiduals78 /// @brief Sum of squared residuals 74 79 /// 75 80 double chisq(void) const;
Note: See TracChangeset
for help on using the changeset viewer.