SNAP Library 2.1, Developer Reference
2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <xmath.h>
Static Public Member Functions | |
static void | ChiSquareOne (const TFltV &ObservedBinV, const TFltV &ExpectedBinV, double &ChiSquareVal, double &SignificancePrb) |
static void | ChiSquareTwo (const TFltV &ObservedBin1V, const TFltV &ObservedBin2V, double &ChiSquareVal, double &SignificancePrb) |
static void | TTest (const TFltV &ValV1, const TFltV &ValV2, double &TTestVal, double &TTestPrb) |
static void | KsTest (const TFltV &ValV1, const TFltV &ValV2, double &DStat, double &PVal) |
static void | KsTest (const TFltPrV &ValCntV1, const TFltPrV &ValCntV2, double &DStat, double &PVal) |
Static Private Member Functions | |
static void | AveVar (const TFltV &ValV, double &Ave, double &Var) |
static double | KsProb (const double &Alam) |
void TStatTest::AveVar | ( | const TFltV & | ValV, |
double & | Ave, | ||
double & | Var | ||
) | [static, private] |
Definition at line 579 of file xmath.cpp.
References TVec< TVal, TSizeTy >::Len().
{ Ave=0; for (int ValN=0; ValN<ValV.Len(); ValN++){ Ave+=ValV[ValN];} Ave/=ValV.Len(); Var=0; double ep=0; for (int ValN=0; ValN<ValV.Len(); ValN++){ double s=ValV[ValN]-Ave; ep+=s; Var+=s*s; } Var=(Var-ep*ep/ValV.Len())/(ValV.Len()-1); }
void TStatTest::ChiSquareOne | ( | const TFltV & | ObservedBinV, |
const TFltV & | ExpectedBinV, | ||
double & | ChiSquareVal, | ||
double & | SignificancePrb | ||
) | [static] |
Definition at line 609 of file xmath.cpp.
References TSpecFunc::GammaQ(), IAssert, and TVec< TVal, TSizeTy >::Len().
{ IAssert(ObservedBinV.Len()==ExpectedBinV.Len()); int Bins=ObservedBinV.Len(); int Constraints=0; int DegreesOfFreedom=Bins-Constraints; ChiSquareVal=0.0; for (int BinN=0; BinN<Bins; BinN++){ IAssert(ExpectedBinV[BinN]>0); double BinDiff=ObservedBinV[BinN]-ExpectedBinV[BinN]; ChiSquareVal+=BinDiff*BinDiff/ExpectedBinV[BinN]; } SignificancePrb= TSpecFunc::GammaQ(0.5*(DegreesOfFreedom), 0.5*(ChiSquareVal)); }
void TStatTest::ChiSquareTwo | ( | const TFltV & | ObservedBin1V, |
const TFltV & | ObservedBin2V, | ||
double & | ChiSquareVal, | ||
double & | SignificancePrb | ||
) | [static] |
Definition at line 626 of file xmath.cpp.
References TSpecFunc::GammaQ(), IAssert, and TVec< TVal, TSizeTy >::Len().
{ IAssert(ObservedBin1V.Len()==ObservedBin1V.Len()); int Bins=ObservedBin1V.Len(); int Constraints=0; int DegreesOfFreedom=Bins-Constraints; ChiSquareVal=0.0; for (int BinN=0; BinN<Bins; BinN++){ if ((ObservedBin1V[BinN]==0.0) && (ObservedBin2V[BinN]==0.0)){ DegreesOfFreedom--; } else { double BinDiff=ObservedBin1V[BinN]-ObservedBin2V[BinN]; ChiSquareVal+=BinDiff*BinDiff/(ObservedBin1V[BinN]+ObservedBin2V[BinN]); } } SignificancePrb= TSpecFunc::GammaQ(0.5*(DegreesOfFreedom),0.5*(ChiSquareVal)); }
double TStatTest::KsProb | ( | const double & | Alam | ) | [static, private] |
Definition at line 594 of file xmath.cpp.
Referenced by KsTest().
{ const double EPS1 = 0.001; const double EPS2 = 1.0e-8; double a2 = -2.0*Alam*Alam, fac = 2.0, sum = 0.0, term, termbf = 0.0; for (int j=1; j <= 100; j++) { term = fac*exp(a2*j*j); sum += term; if (fabs(term) <= EPS1*termbf || fabs(term) <= EPS2*sum) return sum; fac = -fac; termbf = fabs(term); } return 1.0; }
void TStatTest::KsTest | ( | const TFltV & | ValV1, |
const TFltV & | ValV2, | ||
double & | DStat, | ||
double & | PVal | ||
) | [static] |
Definition at line 667 of file xmath.cpp.
References IAssert, TVec< TVal, TSizeTy >::IsSorted(), KsProb(), TVec< TVal, TSizeTy >::Len(), and TMath::Mx().
{ IAssert(ValV1.IsSorted() && ValV2.IsSorted()); int i1=0, i2=0; double CumSum1=0.0, CumSum2=0.0, Cdf1=0.0, Cdf2=0.0; const double N1 = ValV1.Len(); const double N2 = ValV2.Len(); if (! (N1 > 0.0 && N2 > 0.0)) { DStat = 1.0; PVal = 0.0; return; } DStat=0.0; PVal=0.0; while (i1 < ValV1.Len() && i2 < ValV2.Len()) { const double X1 = ValV1[i1]; const double X2 = ValV2[i2]; if (X1 <= X2) { CumSum1 += 1; Cdf1 = (CumSum1 / N1); i1++; } if (X2 <= X1) { CumSum2 += 1; Cdf2 = (CumSum2 / N2); i2++; } DStat = TMath::Mx(DStat, fabs(Cdf1 - Cdf2)); } const double En = sqrt( N1*N2 / (N1+N2)); PVal = TStatTest::KsProb((En+0.12+0.11/En)*DStat); }
void TStatTest::KsTest | ( | const TFltPrV & | ValCntV1, |
const TFltPrV & | ValCntV2, | ||
double & | DStat, | ||
double & | PVal | ||
) | [static] |
Definition at line 694 of file xmath.cpp.
References IAssert, TVec< TVal, TSizeTy >::IsSorted(), KsProb(), TVec< TVal, TSizeTy >::Len(), and TMath::Mx().
{ IAssert(ValCntV1.IsSorted() && ValCntV2.IsSorted()); int i1=0, i2=0; double N1=0.0, N2=0.0, CumSum1=0.0, CumSum2=0.0, Cdf1=0.0, Cdf2=0.0; DStat=0.0; PVal=0.0; for (int i = 0; i < ValCntV1.Len(); i++) N1 += ValCntV1[i].Val2; for (int i = 0; i < ValCntV2.Len(); i++) N2 += ValCntV2[i].Val2; if (! (N1 > 0.0 && N2 > 0.0)) { DStat = 1.0; PVal = 0.0; return; } while (i1 < ValCntV1.Len() && i2 < ValCntV2.Len()) { const double X1 = ValCntV1[i1].Val1; const double X2 = ValCntV2[i2].Val1; if (X1 <= X2) { CumSum1 += ValCntV1[i1].Val2; Cdf1 = (CumSum1 / N1); i1++; } if (X2 <= X1) { CumSum2 += ValCntV2[i2].Val2; Cdf2 = (CumSum2 / N2); i2++; } DStat = TMath::Mx(DStat, fabs(Cdf1 - Cdf2)); } const double En = sqrt( N1*N2 / (N1+N2)); PVal = TStatTest::KsProb((En+0.12+0.11/En)*DStat); }
void TStatTest::TTest | ( | const TFltV & | ValV1, |
const TFltV & | ValV2, | ||
double & | TTestVal, | ||
double & | TTestPrb | ||
) | [static] |
Definition at line 646 of file xmath.cpp.
References TSpecFunc::BetaI(), TVec< TVal, TSizeTy >::Len(), TMom::New(), and TMath::Sqr().
{ /*double Ave1; double Var1; AveVar(ValV1, Ave1, Var1); double Ave2; double Var2; AveVar(ValV2, Ave2, Var2);*/ PMom Val1Mom=TMom::New(ValV1); PMom Val2Mom=TMom::New(ValV2); double ave1=Val1Mom->GetMean(); double ave2=Val2Mom->GetMean(); double var1=Val1Mom->GetVari(); double var2=Val2Mom->GetVari(); int n1=ValV1.Len(); int n2=ValV2.Len(); TTestVal=(ave1-ave2)/sqrt(var1/n1+var2/n2); double df=TMath::Sqr(var1/n1+var2/n2)/(TMath::Sqr(var1/n1)/(n1-1)+TMath::Sqr(var2/n2)/(n2-1)); TTestPrb=TSpecFunc::BetaI(0.5*df, 0.5, df/(df+TMath::Sqr(TTestVal))); }