2 #include "creativity/data/Equation.hpp"    20         template <
class... Eqns>
    21         explicit SUR(Eqns... eqns);
    29         template <
class... MoreEqns>
    38         template <
class... MoreEqns>
    43         const std::vector<Equation>& 
equations() 
const;
    53         unsigned int n()
 const { 
return eqs_.empty() ? 0 : 
eqs_.front().depVar()->size(); }
    77         Eigen::VectorBlock<const Eigen::VectorXd> 
beta(
unsigned i) 
const;
    80         std::vector<std::string> 
varNames(
unsigned i) 
const;
    85         const unsigned& 
k(
unsigned i) 
const;
    90         int df(
unsigned i) 
const;
    93         Eigen::Block<const Eigen::MatrixXd> 
covariance(
unsigned i) 
const;
   100         Eigen::VectorBlock<const Eigen::VectorXd> 
se(
unsigned i) 
const;
   107         Eigen::VectorBlock<const Eigen::VectorXd> 
tRatios(
unsigned i) 
const;
   113         Eigen::VectorBlock<const Eigen::VectorXd> 
pValues(
unsigned i) 
const;
   134         std::vector<std::string> 
pStars(
unsigned i, 
const std::map<double, std::string> &threshold = default_pstar_threshold) 
const;
   140         const double& 
s2(
unsigned i) 
const;
   143         Eigen::VectorBlock<const Eigen::VectorXd> 
residuals(
unsigned i) 
const;
   146         const double& 
ssr(
unsigned i) 
const;
   154         const double& 
Rsq(
unsigned i) 
const;
   162         const Eigen::VectorXd& 
y() 
const;
   168         Eigen::VectorBlock<const Eigen::VectorXd> 
y(
unsigned i) 
const;
   176         const std::vector<Eigen::MatrixXd>& 
X() 
const;
   189         Eigen::MatrixX4d 
summary(
unsigned i) 
const;
   195         friend std::ostream& 
operator<<(std::ostream &os, 
const SUR &ols);
   211         std::vector<Eigen::MatrixXd> 
X_;
   214         std::vector<unsigned> 
k_;
   246         void requireGathered()
 const { 
if (!gathered_) 
throw std::logic_error(
"Cannot access model data before calling gather()"); }
   249         void requireSolved()
 const { 
if (!solved_) 
throw std::logic_error(
"Cannot obtain model estimates before calling solve()"); }
   252         void requireEquation(
unsigned i)
 const { 
if (i >= eqs_.size()) 
throw std::out_of_range(
"Equation " + std::to_string(i) + 
" does not exist"); }
   262 template <
class... Eqns>
   264     add(std::forward<Eqns>(eqns)...);
   267 template <
class... MoreEqns>
   273     add(std::forward<MoreEqns>(eqns)...);
   276 template <
class... MoreEqns>
   280     k_.push_back(eq1.numVars());
   281     eqs_.push_back(std::move(eq1));
   282     add(std::forward<MoreEqns>(eqns)...);
 Eigen::MatrixX4d summary(unsigned i) const
Constructs and returns a matrix of estimation results for equation i. 
 
static const std::map< double, std::string > default_pstar_threshold
Specifies the default threshold/string map for pStars, to be used if pStars is called without an expl...
Definition: SUR.hpp:120
 
Eigen::VectorXd residuals_
Residuals (all equations) 
Definition: SUR.hpp:238
 
Eigen::VectorBlock< const Eigen::VectorXd > beta(unsigned i) const
Returns the vector of beta values for equation i 
 
void clear()
Resets any values obtained or calculated by gather() or solve(), forcing the next gather() or solve()...
 
SUR(Eqns... eqns)
Constructs an SUR solver with one or more models. 
Definition: SUR.hpp:263
 
Eigen::VectorBlock< const Eigen::VectorXd > residuals(unsigned i) const
Returns the residuals for equation i 
 
Eigen::VectorXd beta_
The whole beta vector (all equations) 
Definition: SUR.hpp:223
 
Primary namespace for all Creativity library code. 
Definition: config.hpp:4
 
const double & Rsq(unsigned i) const
Returns the  value for the regression for equation i. 
 
const double & s2(unsigned i) const
Returns , the square of the regression standard error, for equation i. 
 
void requireSolved() const
Throws a std::logic_error if the model hasn't been solved. 
Definition: SUR.hpp:249
 
void solve()
Attempts to solve the model, if not already done. 
 
Eigen::VectorXd p_values_
p-values 
Definition: SUR.hpp:235
 
Eigen::VectorXd y_
The y vector generated from the model. 
Definition: SUR.hpp:208
 
bool solved_
Whether solve() has been called, to populate the below. 
Definition: SUR.hpp:220
 
Eigen::VectorXd se_
The standard errors of the betas (all equations) 
Definition: SUR.hpp:229
 
std::vector< double > ssr_
SSR for each equation. 
Definition: SUR.hpp:241
 
Class to store a equation. 
Definition: Equation.hpp:33
 
std::vector< unsigned > k_
The model sizes. 
Definition: SUR.hpp:214
 
bool gathered_
Whether gather() has been called, to populate y_ and X_. 
Definition: SUR.hpp:205
 
unsigned int n() const
Returns the number of observations for this SUR object. 
Definition: SUR.hpp:53
 
Eigen::VectorBlock< const Eigen::VectorXd > tRatios(unsigned i) const
Returns the t-ratios for =0 tests for equation i, i.e. 
 
Class for running a seemingly-unrelated regressions model. 
Definition: SUR.hpp:13
 
void requireSolved(unsigned i) const
Shortcut for requiredSolved(); requireEquation(i); 
Definition: SUR.hpp:258
 
void requireEquation(unsigned i) const
Throws an std::out_of_range error if the model does not have an equation with index i ...
Definition: SUR.hpp:252
 
Eigen::VectorXd t_ratios_
t-ratios 
Definition: SUR.hpp:232
 
Eigen::VectorBlock< const Eigen::VectorXd > pValues(unsigned i) const
Returns the p-values of the t-ratios returned by tRatios(i) 
 
const unsigned & k(unsigned i) const
Returns the number of variables for equation i in this SUR object. 
 
const Eigen::VectorXd & y() const
Returns the y data (without solving the model); gather() must have been called either explicitly or b...
 
const std::vector< Equation > & equations() const
Accesses the equations used for this SUR object. 
 
Eigen::VectorBlock< const Eigen::VectorXd > se(unsigned i) const
Returns the standard errors (the square roots of the diagonal of covariance()) of the beta estimates ...
 
std::vector< double > R2_
R^2 value for each equation. 
Definition: SUR.hpp:241
 
const std::vector< Eigen::MatrixXd > & X() const
Returns the X data (without solving the model); gather() must have been called either explicitly or b...
 
void gather()
Calculates and stores the final numerical values from the model. 
 
std::vector< double > s2_
sigma^2 estimates for each equation 
Definition: SUR.hpp:241
 
std::vector< Equation > eqs_
The model, given during construction. 
Definition: SUR.hpp:202
 
Eigen::Block< const Eigen::MatrixXd > covariance(unsigned i) const
Returns the covariance estimate of the beta estimators for equation i 
 
std::vector< Eigen::MatrixXd > X_
The X matrix generated from the model. 
Definition: SUR.hpp:211
 
int df(unsigned i) const
Returns the degrees of freedom for equation i. 
 
friend std::ostream & operator<<(std::ostream &os, const SUR &ols)
Overloaded so that an SUR object can be sent to an output stream; the output consists of the model fo...
 
Eigen::MatrixXd var_beta_
The estimated covariance of the beta estimators (all equations) 
Definition: SUR.hpp:226
 
const double & ssr(unsigned i) const
Returns the sum-of-squared residuals for equation i 
 
void requireGathered() const
Throws a std::logic_error if the model hasn't been gathered. 
Definition: SUR.hpp:246
 
void add()
Terminating recursive version of add(), not publically callable. 
Definition: SUR.hpp:199
 
unsigned int numVars() const
Returns the number of independent variables. 
 
void requireGathered(unsigned i) const
Shortcut for requiredGathered(); requireEquation(i); 
Definition: SUR.hpp:255
 
std::vector< unsigned > offset_
Model beginning offsets (in beta_, var_beta_, etc.) 
Definition: SUR.hpp:217
 
std::vector< std::string > pStars(unsigned i, const std::map< double, std::string > &threshold=default_pstar_threshold) const
Returns a vector of star values associated with p-value thresholds. 
 
std::vector< std::string > varNames(unsigned i) const
Returns a vector of strings of the variable names associated with the beta(i) elements.