Go to the documentation of this file.00001 #ifndef mbl_jarque_bera_h_
00002 #define mbl_jarque_bera_h_
00003
00004 #include <vnl/vnl_gamma.h>
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 template <class InIt>
00021 double mbl_jarque_bera(InIt start, InIt finish)
00022 {
00023 unsigned count = 0;
00024 double mean = 0.0;
00025 double stddev = 0.0;
00026 for (InIt it=start; it!=finish; ++it)
00027 {
00028 ++count;
00029 const double x = *it;
00030 mean += x;
00031 stddev += x*x;
00032 }
00033
00034 const double n = count;
00035 mean /= n;
00036 stddev = vcl_sqrt((stddev - mean*mean*n)/(n-1));
00037
00038
00039 double S=0.0, K=0.0;
00040 for (InIt it=start; it!=finish; ++it)
00041 {
00042 const double x = ((*it) - mean)/stddev;
00043 const double x_cubed = x*x*x;
00044 S += x_cubed;
00045 K += x_cubed * x;
00046 }
00047 S /= n;
00048 K = K/n - 3;
00049
00050 const double jbstat = n * ( (S*S)/6 + (K*K)/24 );
00051
00052 return 1 - vnl_cum_prob_chi2(2, jbstat);
00053 }
00054
00055
00056 #endif // mbl_jarque_bera_h_