Class RWLinearRegressionANOVA
Class
RWLinearRegressionANOVA may be used to conduct an analysis of variance for a linear regression. The quantities calculated include: overall F statistic, residual sum of squares, regression sum of squares, degrees of freedom for the regression and residuals, mean square error, coefficient of determination, and adjusted coefficient of determination.
Using the class is fairly easy. You simply specify a linear regression object, either at construction time or via the member function setLinearRegression(), and query the object for the various ANOVA quantities. Here is a simple example:
RWGenMat<double> predictorMatrix; // Values for the predictor
// variables
RWMathVec<double> observationVector; // Values for the dependent
// variable
.
.
.
RWLinearRegression lr( predictorMatrix, observationVector );
if ( lr.fail() ) // Make sure the parameters were calculated
{
cerr << "linear regression calculation failed" << endl;
}
else
{
// Construct an ANOVA object from the linear regression model
// and print the results.
RWLinearRegressionANOVA lrANOVA( lr );
cout << "F statistic: " << lrANOVA.FStatistic() << endl;
cout << "F statistic p-value: " << lrANOVA.FStatisticPValue()
<< endl;
cout << "F statistic critical value: "
<< lrANOVA.FStatisticCriticalValue(.05) << endl;
cout << "mean square residual " << lrANOVA.meanSquareResidual() << endl;
cout << "mean square regression " << lrANOVA.meanSquareRegression() << endl;
cout << "Rsquare: " << lrANOVA.RSquare() << endl;
cout << "adjusted Rsquare: " << lrANOVA.adjRSquare()
<< '\n' << endl;
}
.
.
.