Class LeastSqFit can be used to calculate linear regressions with or without weighting factors. Once constructed, a LeastSqFit can be interrogated for various properties of the fit. Here's an example:
#include <rw/lsqfit.h> #include <rw/math/mathvec.h> #include <rw/rand.h> #include <iostream.h>
main() { // Two straight lines: RWMathVec<double> x(50, 0, 1); RWMathVec<double> y(50, 0, 1);
// Random number generator: RWTRandUniform<RWRandGenerator> ru;
// Add some noise to y: y += ru.randValue(50);
// Construct the fit, without using weighting factors: LeastSqFit lsf(x, y);
// Now get various properties of the fit: cout << "Correlation coefficient is " << lsf.correlationCoeff() << endl; cout << "The slope of the fit is "<< lsf.slope() << endl;
}>
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.