Theoretica
Scientific Computing
Loading...
Searching...
No Matches
theoretica::regression::linear_model Class Reference

structure for computation and storage of least squares linear regression results with model \(y = A + Bx\). More...

Public Member Functions

 linear_model ()
 Default constructor.
template<typename Dataset1, typename Dataset2>
 linear_model (const Dataset1 &X, const Dataset2 &Y)
 Construct a linear model from data and compute the fit.
template<typename Dataset1, typename Dataset2>
 linear_model (const Dataset1 &X, const Dataset2 &Y, real sigma_Y)
 Construct a linear model from data and compute the fit.
template<typename Dataset1, typename Dataset2, typename Dataset3>
 linear_model (const Dataset1 &X, const Dataset2 &Y, const Dataset3 &sigma_Y)
 Construct a linear model from data and compute the fit.
template<typename Dataset1, typename Dataset2>
 linear_model (const Dataset1 &X, const Dataset2 &Y, real sigma_X, real sigma_Y)
 Construct a linear model from data and compute the fit.
template<typename Dataset1, typename Dataset2>
void fit (const Dataset1 &X, const Dataset2 &Y)
 Compute the linear regression of two sets of data of the same size using ordinary least squares linear regression.
template<typename Dataset1, typename Dataset2>
void fit (const Dataset1 &X, const Dataset2 &Y, real sigma_Y)
 Compute the linear regression of two sets of data of the same size using ordinary least squares linear regression.
template<typename Dataset1, typename Dataset2, typename Dataset3>
void fit (const Dataset1 &X, const Dataset2 &Y, const Dataset3 &sigma)
 Compute the linear regression of two sets of data of the same size using least squares linear regression.
template<typename Dataset1, typename Dataset2>
void fit (const Dataset1 &X, const Dataset2 &Y, real sigma_X, real sigma_Y)
 Compute the linear regression of two sets of data of the same size using least squares linear regression.
real operator() (real x)
 Compute the expected Y value for the given X value, following the computed model.
std::string to_string () const
 Convert the vector to string representation.
 operator std::string ()
 Convert the vector to string representation.

Public Attributes

real A
 Intercept.
real sigma_A
 Estimated error on A.
real B
 Slope.
real sigma_B
 Estimated error on B.
mat2 covar_mat
 Covariance matrix of the coefficients A and B.
real err
 Total error on linearization.
real chi_squared
 Chi-squared on linearization.
unsigned int ndf
 Number of degrees of freedom of the linear regression.
real p_value
 The p-value associated to the computed Chi-squared.

Friends

std::ostream & operator<< (std::ostream &out, const linear_model &obj)
 Stream the vector in string representation to an output stream (std::ostream).

Detailed Description

structure for computation and storage of least squares linear regression results with model \(y = A + Bx\).

Member Function Documentation

◆ fit() [1/4]

template<typename Dataset1, typename Dataset2>
void theoretica::regression::linear_model::fit ( const Dataset1 & X,
const Dataset2 & Y )
inline

Compute the linear regression of two sets of data of the same size using ordinary least squares linear regression.

Without the error on the y axis, the chi-squared and the error on the coefficients cannot be computed.

Parameters
XThe set of values on the x axis
YThe set of values on the y axis

◆ fit() [2/4]

template<typename Dataset1, typename Dataset2, typename Dataset3>
void theoretica::regression::linear_model::fit ( const Dataset1 & X,
const Dataset2 & Y,
const Dataset3 & sigma )
inline

Compute the linear regression of two sets of data of the same size using least squares linear regression.

Parameters
XThe set of values on the x axis
YThe set of values on the y axis
sigmaThe different errors on the y axis

◆ fit() [3/4]

template<typename Dataset1, typename Dataset2>
void theoretica::regression::linear_model::fit ( const Dataset1 & X,
const Dataset2 & Y,
real sigma_X,
real sigma_Y )
inline

Compute the linear regression of two sets of data of the same size using least squares linear regression.

Parameters
XThe set of values on the x axis
YThe set of values on the y axis
sigmaThe different errors on the y axis

◆ fit() [4/4]

template<typename Dataset1, typename Dataset2>
void theoretica::regression::linear_model::fit ( const Dataset1 & X,
const Dataset2 & Y,
real sigma_Y )
inline

Compute the linear regression of two sets of data of the same size using ordinary least squares linear regression.

Parameters
XThe set of values on the x axis
YThe set of values on the y axis
sigma_YThe constant error on the y axis

The documentation for this class was generated from the following file: