Class for running a basic OLS regression.  
 More...
#include <creativity/data/OLS.hpp>
 | 
| 
  | OLS ()=delete | 
|   | No default constructor. 
  | 
|   | 
|   | OLS (const Equation &model) | 
|   | Constructs an OLS solver with a model.  More...
  | 
|   | 
| 
  | OLS (Equation &&model) | 
|   | Constructs an OLS solver, taking over the given model. 
  | 
|   | 
| 
const Equation &  | model () const | 
|   | Accesses the model used for this OLS object. 
  | 
|   | 
| 
unsigned int  | n () const | 
|   | Returns the number of observations for this OLS object. 
  | 
|   | 
| 
unsigned int  | k () const | 
|   | Returns the number of variables for this OLS object. 
  | 
|   | 
| int  | df () const | 
|   | Returns the degrees of freedom of the model; this is simply n() - k().  More...
  | 
|   | 
| void  | gather () | 
|   | Calculates and stores the final numerical values from the model.  More...
  | 
|   | 
| void  | solve () | 
|   | Attempts to solve the model, if not already done.  More...
  | 
|   | 
| const Eigen::VectorXd &  | beta () const | 
|   | Returns the vector of coefficients (i.e.  More...
  | 
|   | 
| const Eigen::MatrixXd &  | covariance () const | 
|   | Returns the covariance estimate of the beta estimators.  More...
  | 
|   | 
| const Eigen::VectorXd &  | se () const | 
|   | Returns the standard errors (the square roots of the diagonal of covariance()) of the beta() values.  More...
  | 
|   | 
| const Eigen::VectorXd &  | tRatios () const | 
|   | Returns the t-ratios for =0 tests, i.e.  More...
  | 
|   | 
| const Eigen::VectorXd &  | pValues () const | 
|   | Returns the p-values of the t-ratios returned by tRatios()  More...
  | 
|   | 
| const double &  | s2 () const | 
|   | Returns \(s^2\), the square of the regression standard error.  More...
  | 
|   | 
| const Eigen::VectorXd &  | residuals () const | 
|   | Returns the residuals.  More...
  | 
|   | 
| const double &  | ssr () const | 
|   | Returns the sum-of-squared residuals.  More...
  | 
|   | 
| const double &  | Rsq () const | 
|   | Returns the \(R^2\) value for the regression.  More...
  | 
|   | 
| ftest  | fTest () const | 
|   | Calculates and returns the F-test of all non-constant coefficients in the model being equal to 0.  More...
  | 
|   | 
| const Eigen::VectorXd &  | y () const | 
|   | Returns the y data used to solve the model.  More...
  | 
|   | 
| const Eigen::MatrixXd &  | X () const | 
|   | Returns the X data used to solve the model.  More...
  | 
|   | 
 | 
| 
void  | requireGathered () const | 
|   | Throws a std::logic_error if the model hasn't been gathered. 
  | 
|   | 
| 
void  | requireSolved () const | 
|   | Throws a std::logic_error if the model hasn't been solved. 
  | 
|   | 
 | 
| 
Equation  | model_ | 
|   | The model, given during construction. 
  | 
|   | 
| 
bool  | gathered_ = false | 
|   | Whether gather() has been called, to populate y_ and X_. 
  | 
|   | 
| 
Eigen::VectorXd  | y_ | 
|   | The y vector generated from the model. 
  | 
|   | 
| 
Eigen::MatrixXd  | X_ | 
|   | The X matrix generated from the model. 
  | 
|   | 
| 
bool  | solved_ = false | 
|   | Whether solve() has been called, to populate the below. 
  | 
|   | 
| 
Eigen::VectorXd  | beta_ | 
|   | The beta vector. 
  | 
|   | 
| 
Eigen::MatrixXd  | var_beta_ | 
|   | The estimated covariance of the beta estimators. 
  | 
|   | 
| 
Eigen::VectorXd  | se_ | 
|   | Cached standard errors. 
  | 
|   | 
| 
Eigen::VectorXd  | t_ratios_ | 
|   | Cached t ratios. 
  | 
|   | 
| 
Eigen::VectorXd  | p_values_ | 
|   | Cached p-values. 
  | 
|   | 
| 
Eigen::VectorXd  | residuals_ | 
|   | Residuals. 
  | 
|   | 
| 
double  | ssr_ = 0 | 
|   | SSR. 
  | 
|   | 
| 
double  | s2_ = 0 | 
|   | sigma^2 estimate 
  | 
|   | 
| 
double  | R2_ = 0 | 
|   | R^2 value. 
  | 
|   | 
 | 
| 
std::ostream &  | operator<< (std::ostream &os, const OLS &ols) | 
|   | Overloaded so that an OLS object can be sent to an output stream; the output consists of the model followed by the model results if the model has been solved; just the model itself if the model hasn't been solved. 
  | 
|   | 
Class for running a basic OLS regression. 
Example: 
OLS mymodel(Equation(y) + 1 + x1 + x2);
mymodel.solve();
// Do something with mymodel.beta(), etc.
std::cout << mymodel << "\n";
  
§ OLS()
      
        
          | creativity::data::OLS::OLS  | 
          ( | 
          const Equation &  | 
          model | ) | 
           | 
        
      
 
Constructs an OLS solver with a model. 
The model object is copied. 
 
 
§ beta()
      
        
          | const Eigen::VectorXd& creativity::data::OLS::beta  | 
          ( | 
           | ) | 
           const | 
        
      
 
Returns the vector of coefficients (i.e. 
the beta vector) that solve the model.
- Exceptions
 - 
  
    | std::logic_error | if the model has not been solved yet by calling solve().  | 
  
   
 
 
§ covariance()
      
        
          | const Eigen::MatrixXd& creativity::data::OLS::covariance  | 
          ( | 
           | ) | 
           const | 
        
      
 
Returns the covariance estimate of the beta estimators. 
- Exceptions
 - 
  
    | std::logic_error | if the model has not been solved yet by calling solve().  | 
  
   
 
 
§ df()
  
  
      
        
          | int creativity::data::OLS::df  | 
          ( | 
           | ) | 
           const | 
         
       
   | 
  
inline   | 
  
 
Returns the degrees of freedom of the model; this is simply n() - k(). 
Note that this can be negative, but that such a model is certainly unsolvable. 
 
 
§ fTest()
      
        
          | ftest creativity::data::OLS::fTest  | 
          ( | 
           | ) | 
           const | 
        
      
 
Calculates and returns the F-test of all non-constant coefficients in the model being equal to 0. 
- Exceptions
 - 
  
    | std::logic_error | if the model has not been solved yet by calling solve().  | 
  
   
 
 
§ gather()
      
        
          | void creativity::data::OLS::gather  | 
          ( | 
           | ) | 
           | 
        
      
 
Calculates and stores the final numerical values from the model. 
This is called when needed by solve(), and does not typically need to be called explicitly.
- Exceptions
 - 
  
  
 
 
 
§ pValues()
      
        
          | const Eigen::VectorXd& creativity::data::OLS::pValues  | 
          ( | 
           | ) | 
           const | 
        
      
 
Returns the p-values of the t-ratios returned by tRatios() 
- Exceptions
 - 
  
    | std::logic_error | if the model has not been solved yet by calling solve().  | 
  
   
 
 
§ residuals()
      
        
          | const Eigen::VectorXd& creativity::data::OLS::residuals  | 
          ( | 
           | ) | 
           const | 
        
      
 
Returns the residuals. 
- Exceptions
 - 
  
    | std::logic_error | if the model has not been solved yet by calling solve().  | 
  
   
 
 
§ Rsq()
      
        
          | const double& creativity::data::OLS::Rsq  | 
          ( | 
           | ) | 
           const | 
        
      
 
Returns the \(R^2\) value for the regression. 
This is centered if the model contains a constant, uncentered if it does not. Note that this constant detection depends on the model's hasConstant() method; a model constructed without a constant but with a SimpleVariable that only takes on a single value will not be considered a constant for the purposes of using centering here.
- Exceptions
 - 
  
    | std::logic_error | if the model has not been solved yet by calling solve().  | 
  
   
 
 
§ s2()
      
        
          | const double& creativity::data::OLS::s2  | 
          ( | 
           | ) | 
           const | 
        
      
 
Returns \(s^2\), the square of the regression standard error. 
- Exceptions
 - 
  
    | std::logic_error | if the model has not been solved yet by calling solve().  | 
  
   
 
 
§ se()
      
        
          | const Eigen::VectorXd& creativity::data::OLS::se  | 
          ( | 
           | ) | 
           const | 
        
      
 
Returns the standard errors (the square roots of the diagonal of covariance()) of the beta() values. 
- Exceptions
 - 
  
    | std::logic_error | if the model has not been solved yet by calling solve().  | 
  
   
 
 
§ solve()
      
        
          | void creativity::data::OLS::solve  | 
          ( | 
           | ) | 
           | 
        
      
 
Attempts to solve the model, if not already done. 
- Exceptions
 - 
  
    | RankError | if X has too few rows, or has non-full-rank columns.  | 
  
   
 
 
§ ssr()
      
        
          | const double& creativity::data::OLS::ssr  | 
          ( | 
           | ) | 
           const | 
        
      
 
Returns the sum-of-squared residuals. 
- Exceptions
 - 
  
    | std::logic_error | if the model has not been solved yet by calling solve().  | 
  
   
 
 
§ tRatios()
      
        
          | const Eigen::VectorXd& creativity::data::OLS::tRatios  | 
          ( | 
           | ) | 
           const | 
        
      
 
Returns the t-ratios for =0 tests, i.e. 
beta().array() / se().array()
- Exceptions
 - 
  
    | std::logic_error | if the model has not been solved yet by calling solve().  | 
  
   
 
 
§ X()
      
        
          | const Eigen::MatrixXd& creativity::data::OLS::X  | 
          ( | 
           | ) | 
           const | 
        
      
 
Returns the X data used to solve the model. 
gather() must have been called either explicitly or by a previous call to solve().
- Exceptions
 - 
  
  
 
 
 
§ y()
      
        
          | const Eigen::VectorXd& creativity::data::OLS::y  | 
          ( | 
           | ) | 
           const | 
        
      
 
Returns the y data used to solve the model. 
gather() must have been called either explicitly or by a previous call to solve().
- Exceptions
 - 
  
  
 
 
 
The documentation for this class was generated from the following file: