Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members Related Pages Search
statinfo.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "statinfo.h"
00019
00020 #include "fungmath.h"
00021
00022 int StatInfo::dcompare (const void * a, const void * b)
00023 {
00024 return ( (int)*(double*)a - (int)*(double*)b );
00025 }
00026
00027 double StatInfo::smaller(double a, double b)
00028 {
00029 if (a < b)
00030 return a;
00031 else
00032 return b;
00033 }
00034
00035 double StatInfo::bigger(double a, double b)
00036 {
00037 if (a > b)
00038 return a;
00039 else
00040 return b;
00041 }
00042
00043 double StatInfo::mean(std::vector<double> & xList)
00044 {
00045 return sum(xList)/xList.size();
00046 }
00047
00048 double StatInfo::median(std::vector<double> & xList)
00049 {
00050 unsigned int items = xList.size();
00051 if (items % 2 == 0)
00052 return (xList[(items+1)/2]+xList[(items-1)/2])/2;
00053 else
00054 return xList[(items+1)/2-1];
00055 }
00056
00057 double StatInfo::mode(std::vector<double> & )
00058 {
00059 return 0;
00060 }
00061
00062 double StatInfo::range(std::vector<double> & xList)
00063 {
00064 return xList[xList.size()-1] - xList[0];
00065 }
00066
00067 double StatInfo::min(std::vector<double> & xList)
00068 {
00069 return xList[0];
00070 }
00071
00072 double StatInfo::max(std::vector<double> & xList)
00073 {
00074 return xList[xList.size()-1];
00075 }
00076
00077 double StatInfo::first_quartile(std::vector<double> & xList)
00078 {
00079 unsigned int items = xList.size();
00080 if (items % 2 == 0)
00081 {
00082 if (items % 4 == 0)
00083 return (xList[(items/4)]+xList[(items/4-1)])/2.0;
00084 else
00085 return xList[((items/2)-1)/2];
00086 }
00087 else
00088 {
00089 if ((items+1) % 4 == 0)
00090 return (xList[(items+1)/4]+xList[((items+1)/4-1)])/2.0;
00091 else
00092 return xList[((items+1)/2-1)/2];
00093 }
00094
00095 }
00096
00097 double StatInfo::third_quartile(std::vector<double> & xList)
00098 {
00099 unsigned int items = xList.size();
00100 if (items % 2 == 0)
00101 {
00102 if (items % 4 == 0)
00103 return (xList[(items/4)+items/2]+xList[(items/4-1)+items/2])/2.0;
00104 else
00105 return xList[((items/2)-1)/2+(items/2)];
00106 }
00107 else
00108 {
00109 if ((items+1) % 4 == 0)
00110 return (xList[(items+1)/4+(items+1)/2-1]+xList[((items+1)/4-1)+(items+1)/2-1])/2.0;
00111 else
00112 return xList[((items+1)/2-1)/2+((items+1)/2-1)];
00113 }
00114 }
00115
00116 double StatInfo::standard_dev(std::vector<double> & )
00117 {
00118 return 0;
00119 }
00120
00121 double StatInfo::sum(std::vector<double> & xList)
00122 {
00123 unsigned int items = xList.size();
00124 double sum = 0;
00125 for (unsigned int i=0; i<items; i++)
00126 {
00127 sum += xList[i];
00128 }
00129 return sum;
00130 }
00131
00132 double StatInfo::median_fit_line(std::vector<double> & , std::vector<double> &)
00133 {
00134 return 0;
00135 }
00136
00137 double StatInfo::correlation(std::vector<double> & , std::vector<double> & )
00138 {
00139 return 0;
00140 }
00141
00142 int StatInfo::frequency(std::vector<double> & list, double begin, double end)
00143 {
00144 unsigned int elements = list.size();
00145 int frequency = 0;
00146 for (unsigned int i=0; i<elements; i++)
00147 {
00148 if (list[i] >= begin && list[i] < end)
00149 frequency++;
00150 }
00151 return frequency;
00152 }
00153
|