#include <CommonTools/Statistics/interface/LinearFitErrorsIn2Coord.h>
Public Member Functions | |
float | intercept (const vector< float > &x, const vector< float > &y, int ndat, const vector< float > &sigx, const vector< float > &sigy) const |
Approached intercept computed with approached slope. | |
float | slope (const vector< float > &x, const vector< float > &y, int ndat, const vector< float > &sigx, const vector< float > &sigy) const |
Approached slope:
| |
Private Member Functions | |
float | variance (const vector< float > &x, int ndat) const |
Definition at line 11 of file LinearFitErrorsIn2Coord.h.
float LinearFitErrorsIn2Coord::intercept | ( | const vector< float > & | x, | |
const vector< float > & | y, | |||
int | ndat, | |||
const vector< float > & | sigx, | |||
const vector< float > & | sigy | |||
) | const |
Approached intercept computed with approached slope.
Definition at line 33 of file LinearFitErrorsIn2Coord.cc.
00036 { 00037 00038 float fs = slope(x, y, ndat, sigx, sigy); 00039 float fi = 0; 00040 float sumWi = 0; 00041 for (int i = 0; i != ndat; i++) { 00042 float wi = 1./(sigy[i] + fs*fs*sigx[i]); 00043 fi += wi*(y[i] - fs*x[i]); 00044 sumWi += wi; 00045 } 00046 00047 return fi / sumWi; 00048 00049 }
float LinearFitErrorsIn2Coord::slope | ( | const vector< float > & | x, | |
const vector< float > & | y, | |||
int | ndat, | |||
const vector< float > & | sigx, | |||
const vector< float > & | sigy | |||
) | const |
Approached slope:
Definition at line 5 of file LinearFitErrorsIn2Coord.cc.
References LinearFit::fit(), i, scale, funct::sqrt(), and variance().
Referenced by intercept().
00008 { 00009 00010 // scale y and sigy, compute scaled errors 00011 float scale = sqrt(variance(x, ndat) / variance(y, ndat)); 00012 vector<float> yScaled = y; 00013 vector<float> sigyScaled = sigy; 00014 vector<float> sig(ndat); 00015 for (int i = 0; i != ndat; i++) { 00016 yScaled[i] *= scale; 00017 sigyScaled[i] *= scale; 00018 sig[i] = sqrt(sigx[i]*sigx[i] + sigyScaled[i]*sigyScaled[i]); 00019 } 00020 00021 // usual linear fit 00022 LinearFit lf; 00023 float fs, fi, covss, covii, covsi; 00024 lf.fit(x, yScaled, ndat, sig, fs, fi, covss, covii, covsi); 00025 00026 // unscale result 00027 fs /= scale; 00028 return fs; 00029 00030 }
float LinearFitErrorsIn2Coord::variance | ( | const vector< float > & | x, | |
int | ndat | |||
) | const [private] |