2 #include "creativity/data/Equation.hpp" 45 int df()
const {
return n() -
k(); }
64 const Eigen::VectorXd&
beta()
const;
77 const Eigen::VectorXd&
se()
const;
83 const Eigen::VectorXd&
tRatios()
const;
89 const Eigen::VectorXd&
pValues()
const;
95 const double&
s2()
const;
101 const Eigen::VectorXd&
residuals()
const;
107 const double&
ssr()
const;
117 const double&
Rsq()
const;
139 const Eigen::VectorXd&
y()
const;
146 const Eigen::MatrixXd&
X()
const;
152 friend std::ostream&
operator<<(std::ostream &os,
const OLS &ols);
192 void requireGathered()
const {
if (!gathered_)
throw std::logic_error(
"Cannot access model data before calling gather()"); }
195 void requireSolved()
const {
if (!solved_)
throw std::logic_error(
"Cannot obtain model estimates before calling solve()"); }
Class for running a basic OLS regression.
Definition: OLS.hpp:17
Equation model_
The model, given during construction.
Definition: OLS.hpp:155
const Equation & model() const
Accesses the model used for this OLS object.
Definition: OLS.hpp:32
double p
The p-value of the test.
Definition: OLS.hpp:124
Eigen::VectorXd y_
The y vector generated from the model.
Definition: OLS.hpp:161
double f
The F value.
Definition: OLS.hpp:121
The return value of fStat()
Definition: OLS.hpp:120
const double & ssr() const
Returns the sum-of-squared residuals.
Eigen::VectorXd p_values_
Cached p-values.
Definition: OLS.hpp:182
Eigen::MatrixXd X_
The X matrix generated from the model.
Definition: OLS.hpp:164
friend 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 fo...
Primary namespace for all Creativity library code.
Definition: config.hpp:4
bool gathered_
Whether gather() has been called, to populate y_ and X_.
Definition: OLS.hpp:158
Eigen::VectorXd beta_
The beta vector.
Definition: OLS.hpp:170
double ssr_
SSR.
Definition: OLS.hpp:187
Eigen::VectorXd se_
Cached standard errors.
Definition: OLS.hpp:176
const Eigen::VectorXd & se() const
Returns the standard errors (the square roots of the diagonal of covariance()) of the beta() values...
Eigen::VectorXd residuals_
Residuals.
Definition: OLS.hpp:185
int df() const
Returns the degrees of freedom of the model; this is simply n() - k().
Definition: OLS.hpp:45
Class to store a equation.
Definition: Equation.hpp:33
const Eigen::VectorXd & y() const
Returns the y data used to solve the model.
double R2_
R^2 value.
Definition: OLS.hpp:189
bool solved_
Whether solve() has been called, to populate the below.
Definition: OLS.hpp:167
void gather()
Calculates and stores the final numerical values from the model.
std::shared_ptr< const Variable > depVar() const
Accesses the dependent variable.
const Eigen::VectorXd & tRatios() const
Returns the t-ratios for =0 tests, i.e.
const Eigen::MatrixXd & covariance() const
Returns the covariance estimate of the beta estimators.
const double & Rsq() const
Returns the value for the regression.
const double & s2() const
Returns , the square of the regression standard error.
OLS()=delete
No default constructor.
Eigen::MatrixXd var_beta_
The estimated covariance of the beta estimators.
Definition: OLS.hpp:173
void requireSolved() const
Throws a std::logic_error if the model hasn't been solved.
Definition: OLS.hpp:195
unsigned df_denominator
Denominator d.f.
Definition: OLS.hpp:123
ftest fTest() const
Calculates and returns the F-test of all non-constant coefficients in the model being equal to 0...
void requireGathered() const
Throws a std::logic_error if the model hasn't been gathered.
Definition: OLS.hpp:192
void solve()
Attempts to solve the model, if not already done.
Eigen::VectorXd t_ratios_
Cached t ratios.
Definition: OLS.hpp:179
double s2_
sigma^2 estimate
Definition: OLS.hpp:188
unsigned int n() const
Returns the number of observations for this OLS object.
Definition: OLS.hpp:36
const Eigen::MatrixXd & X() const
Returns the X data used to solve the model.
unsigned int numVars() const
Returns the number of independent variables.
const Eigen::VectorXd & residuals() const
Returns the residuals.
unsigned int k() const
Returns the number of variables for this OLS object.
Definition: OLS.hpp:40
unsigned df_numerator
Numerator d.f.
Definition: OLS.hpp:122
const Eigen::VectorXd & beta() const
Returns the vector of coefficients (i.e.
const Eigen::VectorXd & pValues() const
Returns the p-values of the t-ratios returned by tRatios()