SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
LeastSqFit Class Reference

Constructs a linear least squares fit to a straight line from input data. More...

#include <rw/lsqfit.h>

Public Member Functions

 LeastSqFit (const RWMathVec< double > &x, const RWMathVec< double > &y)
 
 LeastSqFit (const RWMathVec< double > &x, const RWMathVec< double > &y, const RWMathVec< double > &sigmay)
 
double correlationCoeff () const
 
double intercept () const
 
double interceptStandardDev () const
 
double slope () const
 
double slopeStandardDev () const
 
double xPosition (double y) const
 
double yPosition (double x) const
 

Friends

std::ostream & operator<< (std::ostream &s, const LeastSqFit &f)
 

Detailed Description

The class LeastSqFit constructs a linear least squares fit to a straight line from input data, with or without weighting factors. This class is of precision double. Once a LeastSqFit is constructed, various methods are provided to interrogate it.

Synopsis
#include <rw/lsqfit.h>
#include <rw/math/mathvec.h>
LeastSqFit lsf(x, y);
Constructs a linear least squares fit to a straight line from input data.
Definition lsqfit.h:38
A templatized vector class.
Definition mathvec.h:667

Constructor & Destructor Documentation

◆ LeastSqFit() [1/2]

LeastSqFit::LeastSqFit ( const RWMathVec< double > & x,
const RWMathVec< double > & y )

Constructs a linear least squares fit to the data in vectors x and y, without weights. Similar indices of the vectors x(i) and y(i) are assumed to represent (x,y) pairs. The vectors need not be the same length; trailing unmatched points are ignored.

◆ LeastSqFit() [2/2]

LeastSqFit::LeastSqFit ( const RWMathVec< double > & x,
const RWMathVec< double > & y,
const RWMathVec< double > & sigmay )

Constructs a linear least squares fit to the data in vectors x and y, using a set of known standard deviations for the y values. Similar indices of the vectors x(i) and y(i) are assumed to represent (x,y) pairs. These values are weighted according to the y standard deviations given as \(1/sigmay(i)^{2}\). The vectors need not be the same length; trailing unmatched points are ignored.

Member Function Documentation

◆ correlationCoeff()

double LeastSqFit::correlationCoeff ( ) const
inline

Returns the sample linear correlation coefficient of the fit.

◆ intercept()

double LeastSqFit::intercept ( ) const
inline

Returns the intercept of the line.

◆ interceptStandardDev()

double LeastSqFit::interceptStandardDev ( ) const
inline

Returns the standard deviation of the calculated intercept. If the standard deviations of the data is given, the standard deviation for the intercept is calculated appropriately. In the unweighted case, the standard deviation is estimated by factoring in the variance of the data from the calculated line.

◆ slope()

double LeastSqFit::slope ( ) const
inline

Returns the slope of the line.

◆ slopeStandardDev()

double LeastSqFit::slopeStandardDev ( ) const
inline

Returns the standard deviation of the calculated slope. If the standard deviations of the data are given, the standard deviation for the slope is calculated appropriately. In the unweighted case, the standard deviation is estimated by factoring in the variance of the data from the calculated line.

◆ xPosition()

double LeastSqFit::xPosition ( double y) const
inline

Using the linear fit, returns the value x corresponding to y.

◆ yPosition()

double LeastSqFit::yPosition ( double x) const
inline

Using the linear fit, returns the value y corresponding to x.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const LeastSqFit & f )
friend

Outputs a summary of the linear fit f on std::ostream s.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.