1 #ifndef _VECTORSTATISTICS_H_
2 #define _VECTORSTATISTICS_H_
5 #include "mspass/utility/MsPASSError.h"
56 +
"input vector has insufficient data to compute statistics",
57 mspass::utility::ErrorSeverity::Invalid);
59 std::sort(d.begin(),d.end());
64 +
"input vector has insufficient data to compute statistics",
65 mspass::utility::ErrorSeverity::Invalid);
67 for(
int i=0;i<n;++i) d.push_back(din[i]);
68 std::sort(d.begin(),d.end());
73 int medposition=count/2;
75 return(d[medposition]);
77 return( (d[medposition]+d[medposition-1])/2 );
83 for(
int i=0;i<d.size();++i)
87 return (result/d.size());
101 result=
static_cast<double>(d[nover4]);
104 result=0.75*
static_cast<double>(d[nover4]) + 0.25*
static_cast<double>(d[nover4+1]);
107 result=
static_cast<double>(d[nover4]) +
static_cast<double>(d[nover4+1]);
111 result=0.25*
static_cast<double>(d[nover4]) + 0.75*
static_cast<double>(d[nover4+1]);
114 return(
static_cast<T
>(result));
128 result=
static_cast<double>(d[n3_4]);
131 result=0.75*
static_cast<double>(d[n3_4]) + 0.25*
static_cast<double>(d[n3_4+1]);
134 result=
static_cast<double>(d[n3_4]) +
static_cast<double>(d[n3_4+1]);
138 result=0.25*
static_cast<double>(d[n3_4]) + 0.75*
static_cast<double>(d[n3_4+1]);
141 return(
static_cast<T
>(result));
153 std::vector<T> absdiff;
160 if(diff<0) diff=-diff;
161 absdiff.push_back(diff);
170 for(i=0;i<d.size();++i) result=d[i]*d[i];
175 return(d[d.size()-1]);
184 result=this->upper_bound();
185 result-=this->lower_bound();
192 std::stringstream ss;
193 ss <<
"VectorStatistics::quantile method: asked for 1-quantile number "
194 << n<<
" but data vecotor length is only "<<d.size()<<std::endl;
Base class for error object thrown by MsPASS library routines.
Definition: MsPASSError.h:40
Generic object to compute common robust statistics from a vector container of data.
Definition: VectorStatistics.h:16
T median()
Definition: VectorStatistics.h:70
T q3_4()
Definition: VectorStatistics.h:116
T ssq()
Definition: VectorStatistics.h:166
T q1_4()
Definition: VectorStatistics.h:89
T quantile(size_t n)
Definition: VectorStatistics.h:188
T mad(T center)
Definition: VectorStatistics.h:151
T interquartile()
Definition: VectorStatistics.h:143
T range()
Definition: VectorStatistics.h:181
T upper_bound()
Definition: VectorStatistics.h:173
T lower_bound()
Definition: VectorStatistics.h:177
VectorStatistics(std::vector< T > din)
Definition: VectorStatistics.h:53
T mean()
Definition: VectorStatistics.h:79