Regression Classes
Here is a simple example of how to perform a multiple linear regression using class RWLinearRegression:
 
int main()
{
RWGenMat<double> predictorMatrix; // Values of the predictor
// variables.
RWMathVec<double> observationVector; // Values of the dependent
// variable.
 
// A routine that reads in the regression data from a file.
if ( !getDataFromFile("lnrexam.dat",
predictorMatrix, observationVector) )
{
return 0;
}
 
RWLinearRegression lr( predictorMatrix, observationVector );
// Make sure parameter calculation succeeded.
if ( lr.fail() )
{
return 0;
}
 
// Print out model parameters.
cout << "Model Parameters: " << lr.parameters();
return 0;
}
Performing a logistic regression using class RWLogisticRegression is almost identical:
 
int main()
{
RWGenMat<double> predictorMatrix; // Values of the predictor
// variables.
RWMathVec<bool> observationVector; // Values of the
// dependent variable.
 
// A routine that reads in the regression data from a file.
if ( !getDataFromFile("lnrlog.dat", predictorMatrix,
observationVector) )
{
return 0;
}
 
RWLogisticRegression lr( predictorMatrix, observationVector );
// Make sure parameter calculation succeeded.
if ( lr.fail() )
{
return 0;
}
 
// Print out model parameters.
cout << "Model Parameters: " << lr.parameters();
return 0;
}