SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TStatTest Class Reference

#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)
 

Detailed Description

Definition at line 294 of file xmath.h.

Member Function Documentation

void TStatTest::AveVar ( const TFltV ValV,
double &  Ave,
double &  Var 
)
staticprivate

Definition at line 590 of file xmath.cpp.

590  {
591  Ave=0;
592  for (int ValN=0; ValN<ValV.Len(); ValN++){
593  Ave+=ValV[ValN];}
594  Ave/=ValV.Len();
595  Var=0;
596  double ep=0;
597  for (int ValN=0; ValN<ValV.Len(); ValN++){
598  double s=ValV[ValN]-Ave;
599  ep+=s;
600  Var+=s*s;
601  }
602  Var=(Var-ep*ep/ValV.Len())/(ValV.Len()-1);
603 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
void TStatTest::ChiSquareOne ( const TFltV ObservedBinV,
const TFltV ExpectedBinV,
double &  ChiSquareVal,
double &  SignificancePrb 
)
static

Definition at line 620 of file xmath.cpp.

622  {
623  IAssert(ObservedBinV.Len()==ExpectedBinV.Len());
624  int Bins=ObservedBinV.Len();
625  int Constraints=0;
626  int DegreesOfFreedom=Bins-Constraints;
627  ChiSquareVal=0.0;
628  for (int BinN=0; BinN<Bins; BinN++){
629  IAssert(ExpectedBinV[BinN]>0);
630  double BinDiff=ObservedBinV[BinN]-ExpectedBinV[BinN];
631  ChiSquareVal+=BinDiff*BinDiff/ExpectedBinV[BinN];
632  }
633  SignificancePrb=
634  TSpecFunc::GammaQ(0.5*(DegreesOfFreedom), 0.5*(ChiSquareVal));
635 }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
static double GammaQ(const double &a, const double &x)
Definition: xmath.cpp:68
void TStatTest::ChiSquareTwo ( const TFltV ObservedBin1V,
const TFltV ObservedBin2V,
double &  ChiSquareVal,
double &  SignificancePrb 
)
static

Definition at line 637 of file xmath.cpp.

639  {
640  IAssert(ObservedBin1V.Len()==ObservedBin1V.Len());
641  int Bins=ObservedBin1V.Len();
642  int Constraints=0;
643  int DegreesOfFreedom=Bins-Constraints;
644  ChiSquareVal=0.0;
645  for (int BinN=0; BinN<Bins; BinN++){
646  if ((ObservedBin1V[BinN]==0.0) && (ObservedBin2V[BinN]==0.0)){
647  DegreesOfFreedom--;
648  } else {
649  double BinDiff=ObservedBin1V[BinN]-ObservedBin2V[BinN];
650  ChiSquareVal+=BinDiff*BinDiff/(ObservedBin1V[BinN]+ObservedBin2V[BinN]);
651  }
652  }
653  SignificancePrb=
654  TSpecFunc::GammaQ(0.5*(DegreesOfFreedom),0.5*(ChiSquareVal));
655 }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
static double GammaQ(const double &a, const double &x)
Definition: xmath.cpp:68
double TStatTest::KsProb ( const double &  Alam)
staticprivate

Definition at line 605 of file xmath.cpp.

605  {
606  const double EPS1 = 0.001;
607  const double EPS2 = 1.0e-8;
608  double a2 = -2.0*Alam*Alam, fac = 2.0, sum = 0.0, term, termbf = 0.0;
609  for (int j=1; j <= 100; j++) {
610  term = fac*exp(a2*j*j);
611  sum += term;
612  if (fabs(term) <= EPS1*termbf || fabs(term) <= EPS2*sum)
613  return sum;
614  fac = -fac;
615  termbf = fabs(term);
616  }
617  return 1.0;
618 }
void TStatTest::KsTest ( const TFltV ValV1,
const TFltV ValV2,
double &  DStat,
double &  PVal 
)
static

Definition at line 678 of file xmath.cpp.

678  {
679  IAssert(ValV1.IsSorted() && ValV2.IsSorted());
680  int i1=0, i2=0;
681  double CumSum1=0.0, CumSum2=0.0, Cdf1=0.0, Cdf2=0.0;
682  const double N1 = ValV1.Len();
683  const double N2 = ValV2.Len();
684  if (! (N1 > 0.0 && N2 > 0.0)) { DStat = 1.0; PVal = 0.0; return; }
685  DStat=0.0; PVal=0.0;
686  while (i1 < ValV1.Len() && i2 < ValV2.Len()) {
687  const double X1 = ValV1[i1];
688  const double X2 = ValV2[i2];
689  if (X1 <= X2) {
690  CumSum1 += 1;
691  Cdf1 = (CumSum1 / N1);
692  i1++;
693  }
694  if (X2 <= X1) {
695  CumSum2 += 1;
696  Cdf2 = (CumSum2 / N2);
697  i2++;
698  }
699  DStat = TMath::Mx(DStat, fabs(Cdf1 - Cdf2));
700  }
701  const double En = sqrt( N1*N2 / (N1+N2));
702  PVal = TStatTest::KsProb((En+0.12+0.11/En)*DStat);
703 }
#define IAssert(Cond)
Definition: bd.h:262
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
static double KsProb(const double &Alam)
Definition: xmath.cpp:605
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
bool IsSorted(const bool &Asc=true) const
Checks whether the vector is sorted in ascending (if Asc=true) or descending (if Asc=false) order...
Definition: ds.h:1259
void TStatTest::KsTest ( const TFltPrV ValCntV1,
const TFltPrV ValCntV2,
double &  DStat,
double &  PVal 
)
static

Definition at line 705 of file xmath.cpp.

705  {
706  IAssert(ValCntV1.IsSorted() && ValCntV2.IsSorted());
707  int i1=0, i2=0;
708  double N1=0.0, N2=0.0, CumSum1=0.0, CumSum2=0.0, Cdf1=0.0, Cdf2=0.0;
709  DStat=0.0; PVal=0.0;
710  for (int i = 0; i < ValCntV1.Len(); i++) N1 += ValCntV1[i].Val2;
711  for (int i = 0; i < ValCntV2.Len(); i++) N2 += ValCntV2[i].Val2;
712  if (! (N1 > 0.0 && N2 > 0.0)) { DStat = 1.0; PVal = 0.0; return; }
713 
714  while (i1 < ValCntV1.Len() && i2 < ValCntV2.Len()) {
715  const double X1 = ValCntV1[i1].Val1;
716  const double X2 = ValCntV2[i2].Val1;
717  if (X1 <= X2) {
718  CumSum1 += ValCntV1[i1].Val2;
719  Cdf1 = (CumSum1 / N1);
720  i1++;
721  }
722  if (X2 <= X1) {
723  CumSum2 += ValCntV2[i2].Val2;
724  Cdf2 = (CumSum2 / N2);
725  i2++;
726  }
727  DStat = TMath::Mx(DStat, fabs(Cdf1 - Cdf2));
728  }
729  const double En = sqrt( N1*N2 / (N1+N2));
730  PVal = TStatTest::KsProb((En+0.12+0.11/En)*DStat);
731 }
#define IAssert(Cond)
Definition: bd.h:262
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
static double KsProb(const double &Alam)
Definition: xmath.cpp:605
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
bool IsSorted(const bool &Asc=true) const
Checks whether the vector is sorted in ascending (if Asc=true) or descending (if Asc=false) order...
Definition: ds.h:1259
void TStatTest::TTest ( const TFltV ValV1,
const TFltV ValV2,
double &  TTestVal,
double &  TTestPrb 
)
static

Definition at line 657 of file xmath.cpp.

658  {
659  /*double Ave1; double Var1;
660  AveVar(ValV1, Ave1, Var1);
661  double Ave2; double Var2;
662  AveVar(ValV2, Ave2, Var2);*/
663 
664  PMom Val1Mom=TMom::New(ValV1);
665  PMom Val2Mom=TMom::New(ValV2);
666  double ave1=Val1Mom->GetMean();
667  double ave2=Val2Mom->GetMean();
668  double var1=Val1Mom->GetVari();
669  double var2=Val2Mom->GetVari();
670  int n1=ValV1.Len();
671  int n2=ValV2.Len();
672 
673  TTestVal=(ave1-ave2)/sqrt(var1/n1+var2/n2);
674  double df=TMath::Sqr(var1/n1+var2/n2)/(TMath::Sqr(var1/n1)/(n1-1)+TMath::Sqr(var2/n2)/(n2-1));
675  TTestPrb=TSpecFunc::BetaI(0.5*df, 0.5, df/(df+TMath::Sqr(TTestVal)));
676 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
static double Sqr(const double &x)
Definition: xmath.h:12
static PMom New()
Definition: xmath.h:160
static double BetaI(const double &a, const double &b, const double &x)
Definition: xmath.cpp:137
Definition: bd.h:196

The documentation for this class was generated from the following files: