LinearFitErrorsIn2Coord

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#ifndef LinearFitErrorsIn2Coord_H
#define LinearFitErrorsIn2Coord_H

#include <vector>

/** Straight line fit for data with errors on both coordinates
   *  source: Numerical Recipes
   */

class LinearFitErrorsIn2Coord {
public:
  /** Approached slope: 
   *  - rescale y and sigy by var(x)/var(y)
   *  - fit a straight line with weights derived from 
   *  the scaled sum sigx^2 + sigy^2
   */
  float slope(const std::vector<float>& x,
              const std::vector<float>& y,
              int ndat,
              const std::vector<float>& sigx,
              const std::vector<float>& sigy) const;

  /** Approached intercept computed with approached slope
   */
  float intercept(const std::vector<float>& x,
                  const std::vector<float>& y,
                  int ndat,
                  const std::vector<float>& sigx,
                  const std::vector<float>& sigy) const;

private:
  float variance(const std::vector<float>& x, int ndat) const;
};

#endif