JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtpstatbasics.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3
4 last modification: $LastChangedDate$ (revision $Rev$)
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License (LGPL) as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License (LGPL) for more details.
15
16 You should have received a copy of the GNU Lesser General Public License (LGPL)
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21#ifndef JKQTPSTATBASICS_H_INCLUDED
22#define JKQTPSTATBASICS_H_INCLUDED
23
24#include <stdint.h>
25#include <cmath>
26#include <stdlib.h>
27#include <string.h>
28#include <iostream>
29#include <stdio.h>
30#include <limits>
31#include <vector>
32#include <utility>
33#include <cfloat>
34#include <ostream>
35#include <iomanip>
36#include <sstream>
37#include "jkqtmath/jkqtmath_imexport.h"
38#include "jkqtmath/jkqtplinalgtools.h"
39#include "jkqtmath/jkqtparraytools.h"
40#include "jkqtcommon/jkqtpdebuggingtools.h"
41#include "jkqtcommon/jkqtpmathtools.h"
42
43
44/*! \brief calculates the average of a given data range \a first ... \a last
45 \ingroup jkqtptools_math_statistics_basic
46
47 \tparam InputIt standard iterator type of \a first and \a last.
48 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
49 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
50 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
51 \return Average of the data returned between \a first and \a last (excluding invalid doubles).
52 If the given range \a first ... \a last is empty, NAN is returned
53
54 This function implements:
55 \f[ \overline{X}=\frac{1}{N}\cdot\sum\limits_{i=1}^{N}X_i \f]
56
57 \note Each value is the specified range is converted to a double using jkqtp_todouble().
58 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
59 are ignored when calculating.
60*/
61template <class InputIt>
62inline double jkqtpstatAverage(InputIt first, InputIt last, size_t* Noutput=nullptr) {
63 double sum=0;
64 size_t NN=0;
65 for (auto it=first; it!=last; ++it) {
66 const double v=jkqtp_todouble(*it);
67 if (JKQTPIsOKFloat(v)) {
68 sum=sum+v;
69 NN++;
70 }
71 }
72 if (Noutput) *Noutput=NN;
73 if (NN==0) return JKQTP_DOUBLE_NAN;
74 else return sum/static_cast<double>(NN);
75}
76
77
78
79
80
81/*! \brief calculates the weighted average of a given data range \a first ... \a last
82 \ingroup jkqtptools_math_statistics_basic
83
84 \tparam InputIt standard iterator type of \a first and \a last.
85 \tparam InputWeightIt standard iterator type of \a firstWeight
86 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
87 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
88 \param firstWeight iterator pointing to the first item in the weights dataset \f$ w_i \f$
89 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
90 \return weighted average of the data returned between \a first and \a last (excluding invalid doubles).
91 If the given range \a first ... \a last is empty, NAN is returned
92
93 This function implements:
94 \f[ \overline{X}=\frac{\sum\limits_{i=1}^{N}w_i\cdot X_i}{\sum\limits_{i=1}^{N}w_i} \f]
95
96 \note Each value is the specified range is converted to a double using jkqtp_todouble().
97 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
98 are ignored when calculating.
99*/
100template <class InputIt, class InputWeightIt>
101inline double jkqtpstatWeightedAverage(InputIt first, InputIt last, InputWeightIt firstWeight, size_t* Noutput=nullptr) {
102 double sum=0;
103 double sumW=0;
104 size_t NN=0;
105 auto itW=firstWeight;
106 for (auto it=first; it!=last; ++it,++itW) {
107 const double v=jkqtp_todouble(*it);
108 const double w=jkqtp_todouble(*itW);
109 if (JKQTPIsOKFloat(v)) {
110 sum=sum+v*w;
111 sumW=sumW+w;
112 NN++;
113 }
114 }
115 if (Noutput) *Noutput=NN;
116 if (NN==0) return JKQTP_DOUBLE_NAN;
117 else return sum/sumW;
118}
119
120
121
122/*! \brief calculates the number of valid values in the given data range \a first ... \a last
123 \ingroup jkqtptools_math_statistics_basic
124
125 \tparam InputIt standard iterator type of \a first and \a last.
126 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
127 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
128 \return number of valid values between \a first and \a last (excluding invalid doubles).
129
130 \note Each value is the specified range is converted to a double using jkqtp_todouble().
131 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
132 are ignored when calculating.
133*/
134template <class InputIt>
135inline size_t jkqtpstatCount(InputIt first, InputIt last) {
136 double sum=0;
137 size_t NN=0;
138 for (auto it=first; it!=last; ++it) {
139 const double v=jkqtp_todouble(*it);
140 if (JKQTPIsOKFloat(v)) {
141 sum=sum+v;
142 NN++;
143 }
144 }
145 return NN;
146}
147
148
149
150
151/*! \brief calculates the minimum and maximum values in the given data range \a first ... \a last
152 \ingroup jkqtptools_math_statistics_basic
153
154 \tparam InputIt standard iterator type of \a first and \a last.
155 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
156 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
157 \param[out] min receives the minimum element value
158 \param[out] max receives the maximum element value
159 \param[out] minPos receives the location of the minimum element value
160 \param[out] maxPos receives the location of the minimum maximum element value
161 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
162
163 \note Each value is the specified range is converted to a double using jkqtp_todouble().
164 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
165 are ignored when calculating.
166*/
167template <class InputIt>
168inline void jkqtpstatMinMax(InputIt first, InputIt last, double& min, double& max, InputIt* minPos=nullptr, InputIt* maxPos=nullptr, size_t* Noutput=nullptr) {
169 size_t NN=0;
170 bool firstV=true;
171 InputIt minp=last;
172 InputIt maxp=last;
173 for (auto it=first; it!=last; ++it) {
174 const double v=jkqtp_todouble(*it);
175 if (JKQTPIsOKFloat(v)) {
176 if (firstV) {
177 min=v;
178 max=v;
179 minp=it;
180 maxp=it;
181 firstV=false;
182 } else {
183 if (v<min) {
184 min=v;
185 minp=it;
186 }
187 if (v>max) {
188 max=v;
189 maxp=it;
190 }
191 }
192 NN++;
193 }
194 }
195 if (NN==0) {
198 }
199 if (Noutput) *Noutput=NN;
200 if (minPos) *minPos=minp;
201 if (maxPos) *maxPos=maxp;
202}
203
204
205
206
207
208/*! \brief calculates the minimum value in the given data range \a first ... \a last
209 \ingroup jkqtptools_math_statistics_basic
210
211 \tparam InputIt standard iterator type of \a first and \a last.
212 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
213 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
214 \param[out] minPos receives the location of the minimum element value
215 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
216 \return the minimum value from the given range
217
218 \note Each value is the specified range is converted to a double using jkqtp_todouble().
219 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
220 are ignored when calculating.
221*/
222template <class InputIt>
223inline double jkqtpstatMinimum(InputIt first, InputIt last, InputIt* minPos=nullptr, size_t* Noutput=nullptr) {
224 size_t NN=0;
225 bool firstV=true;
226 InputIt minp=last;
227 double min=JKQTP_DOUBLE_NAN;
228 for (auto it=first; it!=last; ++it) {
229 const double v=jkqtp_todouble(*it);
230 if (JKQTPIsOKFloat(v)) {
231 if (firstV) {
232 min=v;
233 minp=it;
234 firstV=false;
235 } else {
236 if (v<min) {
237 min=v;
238 minp=it;
239 }
240 }
241 NN++;
242 }
243 }
244 if (Noutput) *Noutput=NN;
245 if (minPos) *minPos=minp;
246 return min;
247}
248
249
250/*! \brief calculates the maximum value in the given data range \a first ... \a last
251 \ingroup jkqtptools_math_statistics_basic
252
253 \tparam InputIt standard iterator type of \a first and \a last.
254 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
255 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
256 \param[out] maxPos receives the location of the maximum element value
257 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
258 \return the maximum value from the given range
259
260 \note Each value is the specified range is converted to a double using jkqtp_todouble().
261 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
262 are ignored when calculating.
263*/
264template <class InputIt>
265inline double jkqtpstatMaximum(InputIt first, InputIt last, InputIt* maxPos=nullptr, size_t* Noutput=nullptr) {
266 size_t NN=0;
267 bool firstV=true;
268 InputIt maxp=last;
269 double max=JKQTP_DOUBLE_NAN;
270 for (auto it=first; it!=last; ++it) {
271 const double v=jkqtp_todouble(*it);
272 if (JKQTPIsOKFloat(v)) {
273 if (firstV) {
274 max=v;
275 maxp=it;
276 firstV=false;
277 } else {
278 if (v>max) {
279 max=v;
280 maxp=it;
281 }
282 }
283 NN++;
284 }
285 }
286 if (Noutput) *Noutput=NN;
287 if (maxPos) *maxPos=maxp;
288 return max;
289}
290
291
292
293/*! \brief calculates the sum of a given data range \a first ... \a last of values,
294 modifying each value with a given functor \a modifierFunctor before accumulating
295 \ingroup jkqtptools_math_statistics_basic
296
297 \tparam InputIt standard iterator type of \a first and \a last.
298 \tparam FF a functor type
299 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
300 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
301 \param modifierFunctor the function to apply to each element in the range before summation (of type \a FF )
302 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
303 \return Sum of modified data returned between \a first and \a last (excluding invalid doubles).
304 If the given range \a first ... \a last is empty, 0 is returned
305
306 This function implements:
307 \f[ \sum(X)=\cdot\sum\limits_{i=1}^{N}\mbox{modifierFunctor}(X_i) \f]
308
309 This function allows to e.g. calculate the sum of squares by calling
310 \code
311 jkqtpstatModifiedSum(first, last, [](double v) { return v*v; });
312 jkqtpstatModifiedSum(first, last, &jkqtp_sqr<double>);
313 \endcode
314
315 \note Each value is the specified range is converted to a double using jkqtp_todouble().
316 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
317 are ignored when calculating.
318*/
319template <class InputIt, class FF>
320inline double jkqtpstatModifiedSum(InputIt first, InputIt last, FF modifierFunctor, size_t* Noutput=nullptr) {
321 double sum=0;
322 size_t NN=0;
323 for (auto it=first; it!=last; ++it) {
324 const double v=jkqtp_todouble(*it);
325 if (JKQTPIsOKFloat(v)) {
326 sum=sum+modifierFunctor(v);
327 NN++;
328 }
329 }
330 if (Noutput) *Noutput=NN;
331 if (NN==0) return 0;
332 else return sum;
333}
334
335
336
337/*! \brief calculates the sum of a given data range \a first ... \a last
338 \ingroup jkqtptools_math_statistics_basic
339
340 \tparam InputIt standard iterator type of \a first and \a last.
341 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
342 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
343 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
344 \return Sum of the data returned between \a first and \a last (excluding invalid doubles).
345 If the given range \a first ... \a last is empty, 0 is returned
346
347 This function implements:
348 \f[ \sum(X)=\cdot\sum\limits_{i=1}^{N}X_i \f]
349
350 \note Each value is the specified range is converted to a double using jkqtp_todouble().
351 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
352 are ignored when calculating.
353*/
354template <class InputIt>
355inline double jkqtpstatSum(InputIt first, InputIt last, size_t* Noutput=nullptr) {
356 return jkqtpstatModifiedSum(first, last, &jkqtp_identity<double>, Noutput);
357}
358
359/*! \brief calculates the sum of squares of a given data range \a first ... \a last
360 \ingroup jkqtptools_math_statistics_basic
361
362 \tparam InputIt standard iterator type of \a first and \a last.
363 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
364 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
365 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
366 \return Sum of squares of the data returned between \a first and \a last (excluding invalid doubles).
367 If the given range \a first ... \a last is empty, 0 is returned
368
369 This function implements:
370 \f[ \sum(X)=\cdot\sum\limits_{i=1}^{N}X_i^2 \f]
371
372 \note Each value is the specified range is converted to a double using jkqtp_todouble().
373 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
374 are ignored when calculating.
375*/
376template <class InputIt>
377inline double jkqtpstatSumSqr(InputIt first, InputIt last, size_t* Noutput=nullptr) {
378 return jkqtpstatModifiedSum(first, last, &jkqtp_sqr<double>, Noutput);
379}
380
381
382/*! \brief calculates the vector of cummulative (or partial) sums of a given data range \a first ... \a last
383 \ingroup jkqtptools_math_statistics_basic
384
385 \tparam InputIt standard iterator type of \a first and \a last.
386 \tparam OutputIt standard output iterator type
387 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
388 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
389 \param[out] output This iterator is used to store the results, use e.g. a std::back_inserter
390 Output is then a vector of cummulative (or partial) sums returned between
391 \a first and \a last (excluding invalid doubles).
392 For invalid values, the last sum is re-inserted, so the returned vector has
393 the same number of entries as the range \a first ... \a last
394
395 This function implements:
396 \f[ \sum(X)_j=\cdot\sum\limits_{i=1}^{j}X_i \f]
397
398 \note Each value is the specified range is converted to a double using jkqtp_todouble().
399 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
400 are ignored when calculating.
401*/
402template <class InputIt, class OutputIt>
403inline void jkqtpstatCumSum(InputIt first, InputIt last, OutputIt output) {
404 double sum=0;
405 for (auto it=first; it!=last; ++it) {
406 const double v=jkqtp_todouble(*it);
407 if (JKQTPIsOKFloat(v)) {
408 sum=sum+v;
409 }
410 *output=sum;
411 ++output;
412 }
413}
414
415
416/*! \brief filters the given data range \a first ... \a last for good floats (using JKQTPIsOKFloat() )
417 \ingroup jkqtptools_math_statistics_basic
418
419 \tparam InputIt standard iterator type of \a first and \a last.
420 \tparam OutputIt standard output iterator type
421 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
422 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
423 \param[out] output This iterator is used to store the results, use e.g. a std::back_inserter
424 \return number of elementes put into \a output
425
426 \note Each value is the specified range is converted to a double using jkqtp_todouble().
427 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
428 are ignored when calculating.
429*/
430template <class InputIt, class OutputIt>
431inline size_t jkqtpstatFilterGoodFloat(InputIt first, InputIt last, OutputIt output) {
432 size_t NN=0;
433 for (auto it=first; it!=last; ++it) {
434 const double v=jkqtp_todouble(*it);
435 if (JKQTPIsOKFloat(v)) {
436 *output=v;
437 ++output;
438 NN++;
439 }
440 }
441 return NN;
442}
443
444
445
446
447
448
449
450
451
452
453/*! \brief calculates the variance \f$ \sigma_X^2=\mbox{Var}(X) \f$ of a given data range \a first ... \a last
454 \ingroup jkqtptools_math_statistics_basic
455
456 \tparam InputIt standard iterator type of \a first and \a last.
457 \tparam InputWeightIt standard iterator type of \a firstWeight
458 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
459 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
460 \param[out] averageOut returns (optionally) the average of the dataset
461 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
462 \return Variance of the data returned between \a first and \a last (excluding invalid doubles).
463 If the given range \a first ... \a last is empty, 0 is returned
464
465 This function implements:
466 \f[ \sigma_X^2=\text{Var}(X)=\frac{1}{N-1}\cdot\sum\limits_{i=1}^{N}(X_i-\overline{X})^2=\frac{1}{N-1}\cdot\left(\sum_{i=1}^NX_i^2-\frac{1}{N}\cdot\left(\sum_{i=1}^NX_i\right)^2\right) \f]
467
468 \note Each value is the specified range is converted to a double using jkqtp_todouble().
469 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
470 are ignored when calculating.
471*/
472template <class InputIt>
473inline double jkqtpstatVariance(InputIt first, InputIt last, double* averageOut=nullptr, size_t* Noutput=nullptr) {
474 double sum=0;
475 double sum2=0;
476 size_t NN=0;
477 for (auto it=first; it!=last; ++it) {
478 const double v=jkqtp_todouble(*it);
479 if (JKQTPIsOKFloat(v)) {
480 sum=sum+v;
481 sum2=sum2+v*v;
482 NN++;
483 }
484 }
485 if (averageOut) {
486 if (NN==0) *averageOut=JKQTP_DOUBLE_NAN;
487 else *averageOut=sum/static_cast<double>(NN);
488 }
489 if (Noutput) *Noutput=NN;
490 if (NN<=1) return 0;
491 else return ( sum2 - sum*sum/static_cast<double>(NN) ) / static_cast<double>(NN-1);
492}
493
494
495
496/*! \brief calculates the standard deviation \f$ \sigma_X=\sqrt{\mbox{Var}(X)} \f$ of a given data range \a first ... \a last
497 \ingroup jkqtptools_math_statistics_basic
498
499 \tparam InputIt standard iterator type of \a first and \a last.
500 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
501 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
502 \param[out] averageOut returns (optionally) the average of the dataset
503 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
504 \return standard deviation of the data returned between \a first and \a last (excluding invalid doubles).
505 If the given range \a first ... \a last is empty, 0 is returned
506
507 This function implements:
508 \f[ \sigma_X=\sqrt{\frac{1}{N-1}\cdot\sum\limits_{i=1}^{N}(X_i-\overline{X})^2}= \f]
509
510 \note Each value is the specified range is converted to a double using jkqtp_todouble().
511 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
512 are ignored when calculating.
513*/
514template <class InputIt>
515inline double jkqtpstatStdDev(InputIt first, InputIt last, double* averageOut=nullptr, size_t* Noutput=nullptr) {
516 return sqrt(jkqtpstatVariance(first, last, averageOut, Noutput));
517}
518
519
520
521
522/*! \brief calculates the weighted variance \f$ \sigma_X^2=\mbox{Var}(X) \f$ of a given data range \a first ... \a last
523 \ingroup jkqtptools_math_statistics_basic
524
525 \tparam InputIt standard iterator type of \a first and \a last.
526 \tparam InputWeightIt standard iterator type of \a firstWeight
527 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
528 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
529 \param firstWeight iterator pointing to the first item in the weights dataset \f$ w_i \f$
530 \param[out] averageOut returns (optionally) the average of the dataset
531 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
532 \return weighted standard deviation of the data returned between \a first and \a last (excluding invalid doubles).
533 If the given range \a first ... \a last is empty, 0 is returned
534
535 This function implements:
536 \f[ \sigma_v^2=\text{Var}(v)=\frac{\sum\limits_{i=1}^{N}w_i\cdot (v_i-\overline{v})^2}{\sum\limits_{i=1}^{N}w_i} \f]
537
538 \note Each value is the specified range is converted to a double using jkqtp_todouble().
539 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
540 are ignored when calculating.
541*/
542template <class InputIt, class InputWeightIt>
543inline double jkqtpstatWeightedVariance(InputIt first, InputIt last, InputWeightIt firstWeight, double* averageOut=nullptr, size_t* Noutput=nullptr) {
544 double avg=jkqtpstatWeightedAverage(first, last, firstWeight);
545 double sum2=0;
546 double sumW=0;
547 size_t NN=0;
548 auto itW=firstWeight;
549 for (auto it=first; it!=last; ++it,++itW) {
550 const double v=jkqtp_todouble(*it)-avg;
551 const double w=jkqtp_todouble(*itW);
552 if (JKQTPIsOKFloat(v)) {
553 sum2=sum2+v*v*w;
554 sumW=sumW+w;
555 NN++;
556 }
557 }
558 if (averageOut) *averageOut=avg;
559 if (Noutput) *Noutput=NN;
560 if (NN==0) return 0;
561 else return sum2/sumW;
562}
563
564
565
566/*! \brief calculates the weighted standard deviation \f$ \sigma_X=\sqrt{\mbox{Var}(X)} \f$ of a given data range \a first ... \a last
567 \ingroup jkqtptools_math_statistics_basic
568
569 \tparam InputIt standard iterator type of \a first and \a last.
570 \tparam InputWeightIt standard iterator type of \a firstWeight
571 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
572 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
573 \param firstWeight iterator pointing to the first item in the weights dataset \f$ w_i \f$
574 \param[out] averageOut returns (optionally) the average of the dataset
575 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
576 \return weighted standard deviation of the data returned between \a first and \a last (excluding invalid doubles).
577 If the given range \a first ... \a last is empty, 0 is returned
578
579 This function implements:
580 \f[ \sigma_v=\sqrt{\frac{\sum\limits_{i=1}^{N}w_i\cdot (v_i-\overline{v})^2}{\sum\limits_{i=1}^{N}w_i}} \f]
581
582 \note Each value is the specified range is converted to a double using jkqtp_todouble().
583 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
584 are ignored when calculating.
585*/
586template <class InputIt, class InputWeightIt>
587inline double jkqtpstatWeightedStdDev(InputIt first, InputIt last, InputWeightIt firstWeight, double* averageOut=nullptr, size_t* Noutput=nullptr) {
588 return sqrt(jkqtpstatWeightedVariance(first, last, firstWeight, averageOut, Noutput));
589}
590
591
592
593
594/*! \brief calculates the skewness \f$ \gamma_1=\mathbb{E}\left[\left(\frac{X-\mu}{\sigma}\right)^3\right] \f$ of a given data range \a first ... \a last
595 \ingroup jkqtptools_math_statistics_basic
596
597 \tparam InputIt standard iterator type of \a first and \a last.
598 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
599 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
600 \param[out] averageOut returns (optionally) the average of the dataset
601 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
602 \return skewness \f$ \gamma_1 \f$ of the data returned between \a first and \a last (excluding invalid doubles).
603 If the given range \a first ... \a last is empty, 0 is returned
604
605 This function implements:
606 \f[ \gamma_1=\mathbb{E}\left[\left(\frac{X-\mu}{\sigma}\right)^3\right]= \frac{m_3}{m_2^{3/2}} = \frac{\frac{1}{n} \sum_{i=1}^n (x_i-\overline{x})^3}{\left(\frac{1}{n} \sum_{i=1}^n (x_i-\overline{x})^2\right)^{3/2}} \f]
607 where \f$\mu\f$ is the mean and \f$\sigma\f$ the standard deviation of a random variable \f$X\f$ and \f$\overline{x}\f$ is the average (calculated using jkqtpstatAverage() ) of
608 the input dataset \f$ x_i\f$.
609
610 \note Each value is the specified range is converted to a double using jkqtp_todouble().
611 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
612 are ignored when calculating.
613*/
614template <class InputIt>
615inline double jkqtpstatSkewness(InputIt first, InputIt last, double* averageOut=nullptr, size_t* Noutput=nullptr) {
616 double avg=jkqtpstatAverage(first, last);
617 double sum3=0;
618 double sum2=0;
619 size_t NN=0;
620 for (auto it=first; it!=last; ++it) {
621 const double v=jkqtp_todouble(*it)-avg;
622 if (JKQTPIsOKFloat(v)) {
623 sum3=sum3+jkqtp_cube(v);
624 sum2=sum2+jkqtp_sqr(v);
625 NN++;
626 }
627 }
628 if (averageOut) *averageOut=avg;
629 if (Noutput) *Noutput=NN;
630 if (NN==0) return 0;
631 const double down=jkqtp_cube(sum2/double(NN));
632 return sum3/double(NN)/sqrt(down);
633}
634
635
636
637
638/*! \brief calculates the given central moment \f$ \langle (X-\mu)^o\rangle \f$ of a given data range \a first ... \a last
639 \ingroup jkqtptools_math_statistics_basic
640
641 \tparam InputIt standard iterator type of \a first and \a last.
642 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
643 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
644 \param order oder \f$ o \f$ of the central moment \f$ \langle (X-\mu)^o\rangle \f$
645 \param[out] averageOut returns (optionally) the average of the dataset
646 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
647 \return the given central moment \f$ \langle (X-\mu)^o\rangle \f$ of the data returned between \a first and \a last (excluding invalid doubles).
648 If the given range \a first ... \a last is empty, 0 is returned
649
650 This function implements:
651 \f[ \langle (X-\mu)^o\rangle= \mathbb{E}\left[\left(X-\mu\right)^o\right] \f]
652 where \f$\mu\f$ is the mean of a random variable \f$X\f$ and \f$\overline{x}\f$ is the average (calculated using jkqtpstatAverage() ) of
653 the input dataset \f$ x_i\f$.
654
655 \note Each value is the specified range is converted to a double using jkqtp_todouble().
656 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
657 are ignored when calculating.
658*/
659template <class InputIt>
660inline double jkqtpstatCentralMoment(InputIt first, InputIt last, int order, double* averageOut=nullptr, size_t* Noutput=nullptr) {
661 double avg=jkqtpstatAverage(first, last);
662 double sum=0;
663 size_t NN=0;
664 for (auto it=first; it!=last; ++it) {
665 const double v=jkqtp_todouble(*it)-avg;
666 if (JKQTPIsOKFloat(v)) {
667 sum=sum+pow(v, order);
668 NN++;
669 }
670 }
671 if (averageOut) *averageOut=avg;
672 if (Noutput) *Noutput=NN;
673 if (NN==0) return 0;
674 return sum/double(NN);
675}
676
677
678
679
680/*! \brief calculates the given (non-central) moment \f$ \langle X^o\rangle \f$ of a given data range \a first ... \a last
681 \ingroup jkqtptools_math_statistics_basic
682
683 \tparam InputIt standard iterator type of \a first and \a last.
684 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
685 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
686 \param order oder \f$ o \f$ of the central moment \f$ \langle X^o\rangle \f$
687 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
688 \return the given moment \f$ \langle X^o\rangle \f$ of the data returned between \a first and \a last (excluding invalid doubles).
689 If the given range \a first ... \a last is empty, 0 is returned
690
691 This function implements:
692 \f[ \langle X^n\rangle= \mathbb{E}\left[X^n\right] \f]
693 where \f$\mu\f$ is the mean of a random variable \f$X\f$ and \f$\overline{x}\f$ is the average (calculated using jkqtpstatAverage() ) of
694 the input dataset \f$ x_i\f$.
695
696 \note Each value is the specified range is converted to a double using jkqtp_todouble().
697 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
698 are ignored when calculating.
699*/
700template <class InputIt>
701inline double jkqtpstatMoment(InputIt first, InputIt last, int order, size_t* Noutput=nullptr) {
702 double sum=0;
703 size_t NN=0;
704 for (auto it=first; it!=last; ++it) {
705 const double v=jkqtp_todouble(*it);
706 if (JKQTPIsOKFloat(v)) {
707 sum=sum+pow(v, order);
708 NN++;
709 }
710 }
711 if (Noutput) *Noutput=NN;
712 if (NN==0) return 0;
713 return sum/double(NN);
714}
715
716
717
718
719/*! \brief calculate empirical (Pearson's) correlation coefficient \f$ \rho_{x,y} \f$ between two given data ranges \a first1 ... \a last1 and \a first2 ... \a last2
720 \ingroup jkqtptools_math_statistics_basic
721
722 \tparam InputIt1 standard iterator type of \a first1 and \a last1.
723 \tparam InputIt2 standard iterator type of \a first2 and \a last2.
724 \param first1 iterator pointing to the first item in the first dataset to use \f$ X_1 \f$
725 \param last1 iterator pointing behind the last item in the first dataset to use \f$ X_N \f$
726 \param first2 iterator pointing to the second item in the first dataset to use \f$ Y_1 \f$
727 \param[out] averageOut1 returns (optionally) the average of the first dataset \f$ X_i \f$
728 \param[out] averageOut2 returns (optionally) the average of the second dataset \f$ Y_i \f$
729 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
730 \return pearson's correlation coefficient
731 If the given range \a first1 ... \a last1 is empty, JKQTP_DOUBLE_NAN is returned
732
733 This function implements:
734 \f[ \rho_{x,y}=\text{CorCoeff}_{\text{Pearson}}(x,y)=\frac{\sum\limits_{i=0}^{N-1}(x_i-\overline{x})(y_i-\overline{y})}{\sqrt{\sum\limits_{i=0}^{N-1}(x_i-\overline{x})^2\cdot\sum\limits_{i=0}^{N-1}(y_i-\overline{y})^2}} \f]
735
736 \note Each value is the specified range is converted to a double using jkqtp_todouble().
737 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
738 are ignored when calculating.
739
740 \see https://en.wikipedia.org/wiki/Pearson_correlation_coefficient
741*/
742template <class InputIt1,class InputIt2>
743inline double jkqtpstatCorrelationCoefficient(InputIt1 first1, InputIt1 last1, InputIt2 first2, double* averageOut1=nullptr, double* averageOut2=nullptr, size_t* Noutput=nullptr) {
744 double xbar=0;
745 double ybar=0;
746 size_t NN=0;
747 auto it2=first2;
748 for (auto it=first1; it!=last1; ++it,++it2) {
749 const double xm=jkqtp_todouble(*it);
750 const double ym=jkqtp_todouble(*it2);
751 if (JKQTPIsOKFloat(xm) && JKQTPIsOKFloat(ym)) {
752 xbar=xbar+xm;
753 ybar=ybar+ym;
754 NN++;
755 }
756 }
757 if (Noutput) *Noutput=NN;
758 if (averageOut1) {
759 if (NN==0) *averageOut1=JKQTP_DOUBLE_NAN;
760 else *averageOut1=xbar/static_cast<double>(NN);
761 }
762 if (averageOut2) {
763 if (NN==0) *averageOut2=JKQTP_DOUBLE_NAN;
764 else *averageOut2=ybar/static_cast<double>(NN);
765 }
766 if (NN==0) return JKQTP_DOUBLE_NAN;
767
768 xbar=xbar/NN;
769 ybar=ybar/NN;
770 double sumxy=0;
771 double sumx=0;
772 double sumy=0;
773 it2=first2;
774 for (auto it=first1; it!=last1; ++it,++it2) {
775 const double xm=jkqtp_todouble(*it);
776 const double ym=jkqtp_todouble(*it2);
777 if (JKQTPIsOKFloat(xm) && JKQTPIsOKFloat(ym)) {
778 sumxy=sumxy+xm*ym;
779 sumx=sumx+xm*xm;
780 sumy=sumy+ym*ym;
781 }
782 }
783 return sumxy/sqrt(sumx*sumy);
784}
785
786
787
788
789/*! \brief calculates the median of a given sorted (!) data vector
790 \ingroup jkqtptools_math_statistics_basic
791
792 \tparam TVector a type, compatible with std::vector (i,e, providing size(), []-element access and iterators)
793 \param data a sorted vector with values
794 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
795 \return the median of \a data
796 If \a data is empty, NAN is returned
797
798*/
799template <class TVector>
800inline double jkqtpstatMedianOfSortedVector(const TVector& data, size_t* Noutput=nullptr) {
801 if (data.size()<=0) {
802 if (Noutput) *Noutput=0;
803 return JKQTP_DOUBLE_NAN;
804 } else {
805 if (Noutput) *Noutput=data.size();
806 if (data.size()==1) return data[0];
807 else if (data.size()%2==0) return (data[(data.size()-1)/2]+data[(data.size()-1)/2+1])/2.0;
808 else return data[(data.size()-1)/2];
809 }
810}
811
812
813
814/*! \brief calculates the median of a given data range \a first ... \a last, this version partially sorts the range (i.e. no internal copy and checking for NAN-values is performed!)
815 \ingroup jkqtptools_math_statistics_basic
816
817 \tparam InputIt standard iterator type of \a first and \a last.
818 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
819 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
820 \return the median of the data returned between \a first and \a last (excluding invalid doubles).
821 If the given range \a first ... \a last is empty, NAN is returned
822
823 \note This operation implies uses std::nth_element() to calculate the median in linear time O(N)!
824 The given range is partially sorted after the call!
825
826*/
827template <class InputIt>
828inline double jkqtpstatMedianAndPartialSort(InputIt first, InputIt last) {
829 // filter out any NAN-values:
830 const size_t n=std::distance(first,last);
831
832 // handle empty range
833 if (n<=0) {
834 return JKQTP_DOUBLE_NAN;
835 }
836
837 // calculate median using nth_element() in linear timme!
838 const auto middleItr = first + n / 2;
839 std::nth_element(first, middleItr, last);
840 if (n % 2 == 0) {
841 // since nth_element() performs partial sorting,
842 // "All of the elements before this new nth element are less than or equal to the elements after the new nth element." (from cppreference.com)
843 const auto leftMiddleItr = std::max_element(first, middleItr);
844 // the second elemnt to average is the maximum on the left of middleItr!
845 return (*leftMiddleItr + *middleItr) / 2.0;
846 } else {
847 return *middleItr;
848 }
849}
850
851/*! \brief calculates the median of a given data range \a first ... \a last
852 \ingroup jkqtptools_math_statistics_basic
853
854 \tparam InputIt standard iterator type of \a first and \a last.
855 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
856 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
857 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
858 \return the median of the data returned between \a first and \a last (excluding invalid doubles).
859 If the given range \a first ... \a last is empty, NAN is returned
860
861 \note This operation implies an internal copy of the data, and then uses std::nth_element() to calculate the median in linear time O(N)!
862
863 \note Each value is the specified range is converted to a double using jkqtp_todouble().
864 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
865 are ignored when calculating.
866*/
867template <class InputIt>
868inline double jkqtpstatMedian(InputIt first, InputIt last, size_t* Noutput=nullptr) {
869 // filter out any NAN-values:
870 std::vector<double> dataFiltered;
871 jkqtpstatFilterGoodFloat(first, last, std::back_inserter(dataFiltered));
872 const size_t n=dataFiltered.size();
873
874 // handle empty range
875 if (n<=0) {
876 if (Noutput) *Noutput=0;
877 return JKQTP_DOUBLE_NAN;
878 }
879
880 // calculate median using nth_element() in linear timme!
881 return jkqtpstatMedianAndPartialSort(dataFiltered.begin(), dataFiltered.end());
882}
883
884/*! \brief calculates the Five-Number Statistical Summary (minimum, median, maximum and two user-defined quantiles (as well as derived from these the inter quartile range)) of a sorted vector
885 \ingroup jkqtptools_math_statistics_basic
886
887 \tparam TVector a type, compatible with std::vector (i,e, providing size(), []-element access and iterators)
888 \param data a sorted vector with values
889 \param[out] minimum optionally returns the minimum value of the array
890 \param minimumQuantile specifies a quantile for the return value minimum (default is 0 for the real minimum, but you could e.g. use 0.05 for the 5% quantile!
891 \param[out] median optionally returns the median value of the array
892 \param[out] maximum optionally returns the maximum value of the array
893 \param maximumQuantile specifies a quantile for the return value maximum (default is 1 for the real maximum, but you could e.g. use 0.95 for the 95% quantile!
894 \param quantile1Spec specifies which quantile to calculate for \a qantile1 (range: 0..1)
895 \param[out] quantile1 optionally returns the first quantile of the array (specified by \a quantile1Spec )
896 \param quantile2Spec specifies which quantile to calculate for \a qantile2 (range: 0..1)
897 \param[out] quantile2 optionally returns the second quantile of the array (specified by \a quantile2Spec )
898 \param[out] IQR interquartile range, i.e. the range between \a quantile1 and \a quantile2
899 \param[out] IQRSignificance significance range of the interquartile range, calculated as \f[ 2\cdot\frac{1.58\cdot \mbox{IQR}}{\sqrt{N}} \f] \see https://en.wikipedia.org/wiki/Box_plot
900 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
901
902 \note This operation implies an internal copy of the data, as well as sorting it!
903
904 \note Each value is the specified range is converted to a double using jkqtp_todouble().
905 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
906 are ignored when calculating.
907
908 \see https://en.wikipedia.org/wiki/Five-number_summary, jkqtpstatAddVBoxplotAndOutliers, jkqtpstatAddHBoxplotAndOutliers, jkqtpstatAddVBoxplot, jkqtpstatAddHBoxplot, \ref JKQTPlotterBasicJKQTPDatastoreStatistics
909*/
910template <class TVector>
911inline void jkqtpstat5NumberStatisticsOfSortedVector(const TVector& data, double* minimum=nullptr, double minimumQuantile=0, double* median=nullptr, double* maximum=nullptr, double maximumQuantile=1, double* quantile1=nullptr, double quantile1Spec=0.25, double* quantile2=nullptr, double quantile2Spec=0.75, double* IQR=nullptr, double* IQRSignificance=nullptr, size_t* Noutput=nullptr) {
912 if (data.size()<=0) {
913 if (minimum) *minimum=JKQTP_DOUBLE_NAN;
914 if (maximum) *maximum=JKQTP_DOUBLE_NAN;
915 if (median) *median=JKQTP_DOUBLE_NAN;
916 if (quantile1) *quantile1=JKQTP_DOUBLE_NAN;
917 if (quantile1) *quantile1=JKQTP_DOUBLE_NAN;
918 if (Noutput) *Noutput=0;
919 } else {
920 const double qmin=data[jkqtp_bounded<size_t>(0, static_cast<size_t>(minimumQuantile*static_cast<double>(data.size()-1)), data.size()-1)];
921 const double qmax=data[jkqtp_bounded<size_t>(0, static_cast<size_t>(maximumQuantile*static_cast<double>(data.size()-1)), data.size()-1)];
922 if (minimum) *minimum=qmin;
923 if (maximum) *maximum=qmax;
924 if (median) {
925 *median= jkqtpstatMedianOfSortedVector(data);
926 }
927 const double q1=data[jkqtp_bounded<size_t>(0, static_cast<size_t>(quantile1Spec*static_cast<double>(data.size()-1)), data.size()-1)];
928 const double q2=data[jkqtp_bounded<size_t>(0, static_cast<size_t>(quantile2Spec*static_cast<double>(data.size()-1)), data.size()-1)];
929 if (quantile1) {
930 *quantile1=q1;
931 }
932 if (quantile2) {
933 *quantile2=q2;
934 }
935 if (IQR) {
936 *IQR=q2-q1;
937 }
938 if (IQRSignificance) {
939 *IQRSignificance=2.0*(1.58*(q2-q1))/sqrt(static_cast<double>(data.size()));
940 }
941 if (Noutput) *Noutput=data.size();
942 }
943}
944
945/*! \brief calculates the Five-Number Statistical Summary (minimum, median, maximum and two user-defined quantiles (as well as derived from these the inter quartile range)) of a sorted vector
946 \ingroup jkqtptools_math_statistics_basic
947
948 \tparam TVector a type, compatible with std::vector (i,e, providing size(), []-element access and iterators)
949 \param data a sorted vector with values
950 \param outliersout output iterator that receives the outliers, smaller than minimum and larger than maximum
951 \param[out] minimum optionally returns the minimum value of the array
952 \param minimumQuantile specifies a quantile for the return value minimum (default is 0 for the real minimum, but you could e.g. use 0.05 for the 5% quantile!)
953 \param[out] median optionally returns the median value of the array
954 \param[out] maximum optionally returns the maximum value of the array
955 \param maximumQuantile specifies a quantile for the return value maximum (default is 1 for the real maximum, but you could e.g. use 0.95 for the 95% quantile!)
956 \param quantile1Spec specifies which quantile to calculate for \a qantile1 (range: 0..1)
957 \param[out] quantile1 optionally returns the first quantile of the array (specified by \a quantile1Spec )
958 \param quantile2Spec specifies which quantile to calculate for \a qantile2 (range: 0..1)
959 \param[out] quantile2 optionally returns the second quantile of the array (specified by \a quantile2Spec )
960 \param[out] IQR interquartile range, i.e. the range between \a quantile1 and \a quantile2
961 \param[out] IQRSignificance significance range of the interquartile range, calculated as \f[ 2\cdot\frac{1.58\cdot \mbox{IQR}}{\sqrt{N}} \f] \see https://en.wikipedia.org/wiki/Box_plot
962 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
963
964 \note This operation implies an internal copy of the data, as well as sorting it!
965
966 \note Each value is the specified range is converted to a double using jkqtp_todouble().
967 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
968 are ignored when calculating.
969
970 \see https://en.wikipedia.org/wiki/Five-number_summary, jkqtpstatAddVBoxplotAndOutliers, jkqtpstatAddHBoxplotAndOutliers, jkqtpstatAddVBoxplot, jkqtpstatAddHBoxplot, \ref JKQTPlotterBasicJKQTPDatastoreStatistics
971*/
972template <class TVector, class OutputIt>
973inline void jkqtpstat5NumberStatisticsAndOutliersOfSortedVector(const TVector& data, OutputIt outliersout, double* minimum=nullptr, double minimumQuantile=0, double* median=nullptr, double* maximum=nullptr, double maximumQuantile=1, double* quantile1=nullptr, double quantile1Spec=0.25, double* quantile2=nullptr, double quantile2Spec=0.75, double* IQR=nullptr, double* IQRSignificance=nullptr, size_t* Noutput=nullptr) {
974 if (data.size()<=0) {
975 if (minimum) *minimum=JKQTP_DOUBLE_NAN;
976 if (maximum) *maximum=JKQTP_DOUBLE_NAN;
977 if (median) *median=JKQTP_DOUBLE_NAN;
978 if (quantile1) *quantile1=JKQTP_DOUBLE_NAN;
979 if (quantile1) *quantile1=JKQTP_DOUBLE_NAN;
980 if (Noutput) *Noutput=0;
981 } else {
982 const double qmin=data[jkqtp_bounded<size_t>(0, static_cast<size_t>(minimumQuantile*static_cast<double>(data.size()-1)), data.size()-1)];
983 const double qmax=data[jkqtp_bounded<size_t>(0, static_cast<size_t>(maximumQuantile*static_cast<double>(data.size()-1)), data.size()-1)];
984 if (minimum) *minimum=qmin;
985 if (maximum) *maximum=qmax;
986 for (auto it=data.begin(); it!=data.end(); ++it) {
987 if (*it<qmin || *it>qmax) {
988 *outliersout=*it;
989 ++outliersout;
990 }
991 }
992 if (median) {
993 *median= jkqtpstatMedianOfSortedVector(data);
994 }
995 const double q1=data[jkqtp_bounded<size_t>(0, static_cast<size_t>(quantile1Spec*static_cast<double>(data.size()-1)), data.size()-1)];
996 const double q2=data[jkqtp_bounded<size_t>(0, static_cast<size_t>(quantile2Spec*static_cast<double>(data.size()-1)), data.size()-1)];
997 if (quantile1) {
998 *quantile1=q1;
999 }
1000 if (quantile2) {
1001 *quantile2=q2;
1002 }
1003 if (IQR) {
1004 *IQR=q2-q1;
1005 }
1006 if (IQRSignificance) {
1007 *IQRSignificance=2.0*(1.58*(q2-q1))/sqrt(static_cast<double>(data.size()));
1008 }
1009 if (Noutput) *Noutput=data.size();
1010 }
1011}
1012
1013
1014
1015/*! \brief calculates the Five-Number Statistical Summary (minimum, median, maximum and two user-defined quantiles (as well as derived from these the inter quartile range)) of a given data range \a first ... \a last (5-value statistics, e.g. used for boxplots)
1016 \ingroup jkqtptools_math_statistics_basic
1017
1018 \tparam InputIt standard iterator type of \a first and \a last.
1019 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
1020 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
1021 \param[out] minimum optionally returns the minimum value of the array
1022 \param minimumQuantile specifies a quantile for the return value minimum (default is 0 for the real minimum, but you could e.g. use 0.05 for the 5% quantile!
1023 \param[out] median optionally returns the median value of the array
1024 \param[out] maximum optionally returns the maximum value of the array
1025 \param maximumQuantile specifies a quantile for the return value maximum (default is 1 for the real maximum, but you could e.g. use 0.95 for the 95% quantile!
1026 \param quantile1Spec specifies which quantile to calculate for \a qantile1 (range: 0..1)
1027 \param[out] quantile1 optionally returns the first quantile of the array (specified by \a quantile1Spec )
1028 \param quantile2Spec specifies which quantile to calculate for \a qantile2 (range: 0..1)
1029 \param[out] quantile2 optionally returns the second quantile of the array (specified by \a quantile2Spec )
1030 \param[out] IQR interquartile range, i.e. the range between \a quantile1 and \a quantile2
1031 \param[out] IQRSignificance significance range of the interquartile range, calculated as \f[ 2\cdot\frac{1.58\cdot \mbox{IQR}}{\sqrt{N}} \f] \see https://en.wikipedia.org/wiki/Box_plot
1032 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
1033
1034 \note This operation implies an internal copy of the data, as well as sorting it!
1035
1036 \note Each value is the specified range is converted to a double using jkqtp_todouble().
1037 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
1038 are ignored when calculating.
1039
1040 \see https://en.wikipedia.org/wiki/Five-number_summary, jkqtpstatAddVBoxplotAndOutliers, jkqtpstatAddHBoxplotAndOutliers, jkqtpstatAddVBoxplot, jkqtpstatAddHBoxplot, \ref JKQTPlotterBasicJKQTPDatastoreStatistics
1041*/
1042template <class InputIt>
1043inline void jkqtpstat5NumberStatistics(InputIt first, InputIt last, double* minimum, double minimumQuantile=0, double* median=nullptr, double* maximum=nullptr, double maximumQuantile=1, double quantile1Spec=0.25, double* quantile1=nullptr, double quantile2Spec=0.75, double* quantile2=nullptr, double* IQR=nullptr, double* IQRSignificance=nullptr, size_t* Noutput=nullptr) {
1044 std::vector<double> dataFiltered;
1045 jkqtpstatFilterGoodFloat(first, last, std::back_inserter(dataFiltered));
1046 std::sort(dataFiltered.begin(), dataFiltered.end());
1047 jkqtpstat5NumberStatisticsOfSortedVector(dataFiltered, minimum, minimumQuantile, median, maximum, maximumQuantile, quantile1, quantile1Spec, quantile2, quantile2Spec, IQR, IQRSignificance, Noutput);
1048}
1049
1050/*! \brief calculates the Five-Number Statistical Summary (minimum, median, maximum and two user-defined quantiles (as well as derived from these the inter quartile range)) of a given data range \a first ... \a last (5-value statistics, e.g. used for boxplots)
1051 \ingroup jkqtptools_math_statistics_basic
1052
1053 \tparam InputIt standard iterator type of \a first and \a last.
1054 \tparam OutputIt standard output iterator type used for the outliers output \a outliersout, use e.g. std::back_inserter
1055 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
1056 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
1057 \param outliersout output iterator that receives the outliers, smaller than minimum and larger than maximum
1058 \param[out] minimum optionally returns the minimum value of the array
1059 \param minimumQuantile specifies a quantile for the return value minimum (default is 0 for the real minimum, but you could e.g. use 0.05 for the 5% quantile!)
1060 \param[out] median optionally returns the median value of the array
1061 \param[out] maximum optionally returns the maximum value of the array
1062 \param maximumQuantile specifies a quantile for the return value maximum (default is 1 for the real maximum, but you could e.g. use 0.95 for the 95% quantile!)
1063 \param quantile1Spec specifies which quantile to calculate for \a qantile1 (range: 0..1)
1064 \param[out] quantile1 optionally returns the first quantile of the array (specified by \a quantile1Spec )
1065 \param quantile2Spec specifies which quantile to calculate for \a qantile2 (range: 0..1)
1066 \param[out] quantile2 optionally returns the second quantile of the array (specified by \a quantile2Spec )
1067 \param[out] IQR interquartile range, i.e. the range between \a quantile1 and \a quantile2
1068 \param[out] IQRSignificance significance range of the interquartile range, calculated as \f[ 2\cdot\frac{1.58\cdot \mbox{IQR}}{\sqrt{N}} \f] \see https://en.wikipedia.org/wiki/Box_plot
1069 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
1070
1071 \note This operation implies an internal copy of the data, as well as sorting it!
1072
1073 \note Each value is the specified range is converted to a double using jkqtp_todouble().
1074 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
1075 are ignored when calculating.
1076
1077 \see https://en.wikipedia.org/wiki/Five-number_summary, jkqtpstatAddVBoxplotAndOutliers, jkqtpstatAddHBoxplotAndOutliers, jkqtpstatAddVBoxplot, jkqtpstatAddHBoxplot, \ref JKQTPlotterBasicJKQTPDatastoreStatistics
1078*/
1079template <class InputIt, class OutputIt>
1080inline void jkqtpstat5NumberStatisticsAndOutliers(InputIt first, InputIt last, OutputIt outliersout, double* minimum=nullptr, double minimumQuantile=0, double* median=nullptr, double* maximum=nullptr, double maximumQuantile=1, double* quantile1=nullptr, double quantile1Spec=0.25, double* quantile2=nullptr, double quantile2Spec=0.75, double* IQR=nullptr, double* IQRSignificance=nullptr, size_t* Noutput=nullptr) {
1081 std::vector<double> dataFiltered;
1082 jkqtpstatFilterGoodFloat(first, last, std::back_inserter(dataFiltered));
1083 std::sort(dataFiltered.begin(), dataFiltered.end());
1084 jkqtpstat5NumberStatisticsAndOutliersOfSortedVector(dataFiltered, outliersout, minimum, minimumQuantile, median, maximum, maximumQuantile, quantile1, quantile1Spec, quantile2, quantile2Spec, IQR, IQRSignificance, Noutput);
1085}
1086
1087/*! \brief represents the Five-Number Statistical Summary (minimum, median, maximum and two user-defined quantiles (as well as derived from these the inter quartile range))
1088 \ingroup jkqtptools_math_statistics_basic
1089 \see https://en.wikipedia.org/wiki/Five-number_summary, jkqtpstat5NumberStatistics()
1090*/
1093
1094 /** \brief minimum value */
1095 double minimum;
1096 /** \brief specifies a quantile for the return value minimum (default is 0 for the real minimum, but you could e.g. use 0.05 for the 5% quantile!) */
1098 /** \brief first quantile value (specified by quantile1Spec) */
1100 /** \brief specifies the first quantile (range: 0..1) */
1102 /** \brief median value */
1103 double median;
1104 /** \brief second quantile value (specified by quantile1Spec) */
1106 /** \brief specifies the second quantile (range: 0..1) */
1108 /** \brief maximum value */
1109 double maximum;
1110 /** \brief specifies a quantile for the return value maximum (default is 1 for the real maximum, but you could e.g. use 0.95 for the 95% quantile!) */
1112 /** \brief number of values used to calculate the summary */
1113 size_t N;
1114 /** \brief the interquarzile range */
1115 double IQR() const;
1116 /** \brief interquartile range, calculated as \f[ 2\cdot\frac{1.58\cdot \mbox{IQR}}{\sqrt{N}} \f] \see https://en.wikipedia.org/wiki/Box_plot */
1118 /** \brief list with the outlier values < minimum and > maximum */
1119 std::vector<double> outliers;
1120};
1121
1122/*! \brief calculates the Five-Number Statistical Summary (minimum, median, maximum and two user-defined quantiles (as well as derived from these the inter quartile range)) of a given data range \a first ... \a last (5-value statistics, e.g. used for boxplots)
1123 \ingroup jkqtptools_math_statistics_basic
1124
1125 \tparam InputIt standard iterator type of \a first and \a last.
1126 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
1127 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
1128 \param quantile1Spec specifies which quantile to calculate for \a qantile1 (range: 0..1)
1129 \param quantile2Spec specifies which quantile to calculate for \a qantile2 (range: 0..1)
1130 \param minimumQuantile specifies a quantile for the return value minimum (default is 0 for the real minimum, but you could e.g. use 0.05 for the 5% quantile!)
1131 \param maximumQuantile specifies a quantile for the return value maximum (default is 1 for the real maximum, but you could e.g. use 0.95 for the 95% quantile!)
1132 \return the Five-Number Statistical Summary in a JKQTPStat5NumberStatistics
1133
1134 \note This operation implies an internal copy of the data, as well as sorting it!
1135
1136 \note Each value is the specified range is converted to a double using jkqtp_todouble().
1137 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
1138 are ignored when calculating.
1139
1140 \see https://en.wikipedia.org/wiki/Five-number_summary, jkqtpstatAddVBoxplotAndOutliers, jkqtpstatAddHBoxplotAndOutliers, jkqtpstatAddVBoxplot, jkqtpstatAddHBoxplot, \ref JKQTPlotterBasicJKQTPDatastoreStatistics
1141*/
1142template <class InputIt>
1143inline JKQTPStat5NumberStatistics jkqtpstat5NumberStatistics(InputIt first, InputIt last, double quantile1Spec=0.25, double quantile2Spec=0.75, double minimumQuantile=0, double maximumQuantile=1.0) {
1145 jkqtpstat5NumberStatisticsAndOutliers(first, last, std::back_inserter(res.outliers), &(res.minimum), minimumQuantile, &(res.median), &(res.maximum), maximumQuantile, &(res.quantile1), quantile1Spec,&(res.quantile2),quantile2Spec, nullptr,nullptr,&(res.N));
1146 return res;
1147}
1148
1149
1150
1151
1152/*! \brief calculates the \a quantile -th quantile of a given data range \a first ... \a last
1153 \ingroup jkqtptools_math_statistics_basic
1154
1155 \tparam InputIt standard iterator type of \a first and \a last.
1156 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
1157 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
1158 \param quantile the given quantile, range 0..1 (e.g. 0.25 for the 25% quartile ...)
1159 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
1160 \return the \a quantile -th quantile of the data returned between \a first and \a last (excluding invalid doubles).
1161 If the given range \a first ... \a last is empty, NAN is returned
1162
1163 \note This operation implies an internal copy of the data, as well as sorting it!
1164
1165 \note Each value is the specified range is converted to a double using jkqtp_todouble().
1166 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
1167 are ignored when calculating.
1168*/
1169template <class InputIt>
1170inline double jkqtpstatQuantile(InputIt first, InputIt last, double quantile, size_t* Noutput=nullptr) {
1171 std::vector<double> dataFiltered;
1172 jkqtpstatFilterGoodFloat(first, last, std::back_inserter(dataFiltered));
1173 if (dataFiltered.size()<=0) {
1174 if (Noutput) *Noutput=0;
1175 return JKQTP_DOUBLE_NAN;
1176 } else {
1177 if (Noutput) *Noutput=dataFiltered.size();
1178 auto qelement=dataFiltered.begin()+jkqtp_bounded<size_t>(0, static_cast<size_t>(quantile*static_cast<double>(dataFiltered.size()-1)), dataFiltered.size()-1);
1179 std::nth_element(dataFiltered.begin(), qelement, dataFiltered.end());
1180 return *qelement;
1181 }
1182}
1183
1184
1185
1186/*! \brief calculates the median absolute deviation about the median (MAD) of a given data range \a first ... \a last
1187 \ingroup jkqtptools_math_statistics_basic
1188
1189 \tparam InputIt standard iterator type of \a first and \a last.
1190 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
1191 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
1192 \param[out] median optionally returns the median value in this variable
1193 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
1194 \return the median absolute deviation about the median (MAD) of the data returned between \a first and \a last (excluding invalid doubles).
1195 If the given range \a first ... \a last is empty, NAN is returned
1196
1197 This function calculates
1198 \f[ \mbox{MAD}(\vec{x})=\mbox{Med}\left\{|\vec{x}-\mbox{Med}(\vec{x})|\right\} \f]
1199
1200
1201 \note This operation implies an internal copy of the data, as well as sorting it!
1202
1203 \note Each value is the specified range is converted to a double using jkqtp_todouble().
1204 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
1205 are ignored when calculating.
1206
1207 \see https://en.wikipedia.org/wiki/Median_absolute_deviation and Ricardo A. Maronna, R. Douglas Martin, Victor J. Yohai: "Robust Statistics: Theory and Methods", Wiley, 2006, ISBN: 978-0-470-01092-1
1208*/
1209template <class InputIt>
1210inline double jkqtpstatMAD(InputIt first, InputIt last, double* median=nullptr, size_t* Noutput=nullptr) {
1211 std::vector<double> dataFiltered;
1212 jkqtpstatFilterGoodFloat(first, last, std::back_inserter(dataFiltered));
1213 if (dataFiltered.size()<=0) {
1214 if (Noutput) *Noutput=0;
1215 if (median) *median=JKQTP_DOUBLE_NAN;
1216 return JKQTP_DOUBLE_NAN;
1217 } else {
1218 if (Noutput) *Noutput=dataFiltered.size();
1219 const double med=jkqtpstatMedianAndPartialSort(dataFiltered.begin(), dataFiltered.end());
1220 if (median) *median=med;
1221 for(double& v: dataFiltered) {
1222 v=fabs(v-med);
1223 }
1224 return jkqtpstatMedianAndPartialSort(dataFiltered.begin(), dataFiltered.end());
1225 }
1226}
1227
1228
1229
1230/*! \brief calculates the normalized median absolute deviation about the median (NMAD) of a given data range \a first ... \a last
1231 \ingroup jkqtptools_math_statistics_basic
1232
1233 \tparam InputIt standard iterator type of \a first and \a last.
1234 \param first iterator pointing to the first item in the dataset to use \f$ X_1 \f$
1235 \param last iterator pointing behind the last item in the dataset to use \f$ X_N \f$
1236 \param[out] median optionally returns the median value in this variable
1237 \param[out] Noutput optionally returns the number of accumulated valid values in this variable
1238 \return the normalized median absolute deviation about the median (NMAD) of the data returned between \a first and \a last (excluding invalid doubles).
1239 If the given range \a first ... \a last is empty, NAN is returned
1240
1241 This function calculates
1242 \f[ \mbox{NMAD}(\vec{x})=\frac{\mbox{MAD}(\vec{x})}{0.6745}=\frac{\mbox{Med}\left\{|\vec{x}-\mbox{Med}(\vec{x})|\right\}}{0.6745} \f]
1243
1244
1245 \note This operation implies an internal copy of the data, as well as sorting it!
1246
1247 \note Each value is the specified range is converted to a double using jkqtp_todouble().
1248 Entries in the range that are invalid double (using JKQTPIsOKFloat() )
1249 are ignored when calculating.
1250
1251 \see https://en.wikipedia.org/wiki/Median_absolute_deviation and Ricardo A. Maronna, R. Douglas Martin, Victor J. Yohai: "Robust Statistics: Theory and Methods", Wiley, 2006, ISBN: 978-0-470-01092-1
1252*/
1253template <class InputIt>
1254inline double jkqtpstatNMAD(InputIt first, InputIt last, double* median=nullptr, size_t* Noutput=nullptr) {
1255 return jkqtpstatMAD(first, last, median, Noutput)/0.6745;
1256}
1257
1258
1259
1260
1261#endif // JKQTPSTATBASICS_H_INCLUDED
1262
1263
#define jkqtmath_LIB_EXPORT
Definition jkqtmath_imexport.h:87
#define JKQTP_DOUBLE_NAN
double-value NotANumber
Definition jkqtpmathtools.h:77
constexpr double jkqtp_todouble(const T &d)
converts a boolean to a double, is used to convert boolean to double by JKQTPDatastore
Definition jkqtpmathtools.h:113
T jkqtp_sqr(const T &v)
returns the quare of the value v, i.e. v*v
Definition jkqtpmathtools.h:327
T jkqtp_cube(T x)
cube of a number
Definition jkqtpmathtools.h:357
bool JKQTPIsOKFloat(T v)
check whether the dlotaing point number is OK (i.e. non-inf, non-NAN)
Definition jkqtpmathtools.h:496
double jkqtpstatStdDev(InputIt first, InputIt last, double *averageOut=nullptr, size_t *Noutput=nullptr)
calculates the standard deviation of a given data range first ... last
Definition jkqtpstatbasics.h:515
double jkqtpstatModifiedSum(InputIt first, InputIt last, FF modifierFunctor, size_t *Noutput=nullptr)
calculates the sum of a given data range first ... last of values, modifying each value with a given ...
Definition jkqtpstatbasics.h:320
double jkqtpstatSkewness(InputIt first, InputIt last, double *averageOut=nullptr, size_t *Noutput=nullptr)
calculates the skewness of a given data range first ... last
Definition jkqtpstatbasics.h:615
size_t jkqtpstatFilterGoodFloat(InputIt first, InputIt last, OutputIt output)
filters the given data range first ... last for good floats (using JKQTPIsOKFloat() )
Definition jkqtpstatbasics.h:431
void jkqtpstatCumSum(InputIt first, InputIt last, OutputIt output)
calculates the vector of cummulative (or partial) sums of a given data range first ....
Definition jkqtpstatbasics.h:403
void jkqtpstat5NumberStatistics(InputIt first, InputIt last, double *minimum, double minimumQuantile=0, double *median=nullptr, double *maximum=nullptr, double maximumQuantile=1, double quantile1Spec=0.25, double *quantile1=nullptr, double quantile2Spec=0.75, double *quantile2=nullptr, double *IQR=nullptr, double *IQRSignificance=nullptr, size_t *Noutput=nullptr)
calculates the Five-Number Statistical Summary (minimum, median, maximum and two user-defined quantil...
Definition jkqtpstatbasics.h:1043
double jkqtpstatMedianOfSortedVector(const TVector &data, size_t *Noutput=nullptr)
calculates the median of a given sorted (!) data vector
Definition jkqtpstatbasics.h:800
double jkqtpstatSumSqr(InputIt first, InputIt last, size_t *Noutput=nullptr)
calculates the sum of squares of a given data range first ... last
Definition jkqtpstatbasics.h:377
double jkqtpstatWeightedAverage(InputIt first, InputIt last, InputWeightIt firstWeight, size_t *Noutput=nullptr)
calculates the weighted average of a given data range first ... last
Definition jkqtpstatbasics.h:101
double jkqtpstatMedian(InputIt first, InputIt last, size_t *Noutput=nullptr)
calculates the median of a given data range first ... last
Definition jkqtpstatbasics.h:868
double jkqtpstatAverage(InputIt first, InputIt last, size_t *Noutput=nullptr)
calculates the average of a given data range first ... last
Definition jkqtpstatbasics.h:62
double jkqtpstatQuantile(InputIt first, InputIt last, double quantile, size_t *Noutput=nullptr)
calculates the quantile -th quantile of a given data range first ... last
Definition jkqtpstatbasics.h:1170
double jkqtpstatMedianAndPartialSort(InputIt first, InputIt last)
calculates the median of a given data range first ... last, this version partially sorts the range (i...
Definition jkqtpstatbasics.h:828
void jkqtpstat5NumberStatisticsAndOutliersOfSortedVector(const TVector &data, OutputIt outliersout, double *minimum=nullptr, double minimumQuantile=0, double *median=nullptr, double *maximum=nullptr, double maximumQuantile=1, double *quantile1=nullptr, double quantile1Spec=0.25, double *quantile2=nullptr, double quantile2Spec=0.75, double *IQR=nullptr, double *IQRSignificance=nullptr, size_t *Noutput=nullptr)
calculates the Five-Number Statistical Summary (minimum, median, maximum and two user-defined quantil...
Definition jkqtpstatbasics.h:973
double jkqtpstatMAD(InputIt first, InputIt last, double *median=nullptr, size_t *Noutput=nullptr)
calculates the median absolute deviation about the median (MAD) of a given data range first ....
Definition jkqtpstatbasics.h:1210
double jkqtpstatMoment(InputIt first, InputIt last, int order, size_t *Noutput=nullptr)
calculates the given (non-central) moment of a given data range first ... last
Definition jkqtpstatbasics.h:701
size_t jkqtpstatCount(InputIt first, InputIt last)
calculates the number of valid values in the given data range first ... last
Definition jkqtpstatbasics.h:135
void jkqtpstat5NumberStatisticsOfSortedVector(const TVector &data, double *minimum=nullptr, double minimumQuantile=0, double *median=nullptr, double *maximum=nullptr, double maximumQuantile=1, double *quantile1=nullptr, double quantile1Spec=0.25, double *quantile2=nullptr, double quantile2Spec=0.75, double *IQR=nullptr, double *IQRSignificance=nullptr, size_t *Noutput=nullptr)
calculates the Five-Number Statistical Summary (minimum, median, maximum and two user-defined quantil...
Definition jkqtpstatbasics.h:911
double jkqtpstatWeightedStdDev(InputIt first, InputIt last, InputWeightIt firstWeight, double *averageOut=nullptr, size_t *Noutput=nullptr)
calculates the weighted standard deviation of a given data range first ... last
Definition jkqtpstatbasics.h:587
void jkqtpstatMinMax(InputIt first, InputIt last, double &min, double &max, InputIt *minPos=nullptr, InputIt *maxPos=nullptr, size_t *Noutput=nullptr)
calculates the minimum and maximum values in the given data range first ... last
Definition jkqtpstatbasics.h:168
double jkqtpstatMaximum(InputIt first, InputIt last, InputIt *maxPos=nullptr, size_t *Noutput=nullptr)
calculates the maximum value in the given data range first ... last
Definition jkqtpstatbasics.h:265
double jkqtpstatMinimum(InputIt first, InputIt last, InputIt *minPos=nullptr, size_t *Noutput=nullptr)
calculates the minimum value in the given data range first ... last
Definition jkqtpstatbasics.h:223
double jkqtpstatCorrelationCoefficient(InputIt1 first1, InputIt1 last1, InputIt2 first2, double *averageOut1=nullptr, double *averageOut2=nullptr, size_t *Noutput=nullptr)
calculate empirical (Pearson's) correlation coefficient between two given data ranges first1 ....
Definition jkqtpstatbasics.h:743
void jkqtpstat5NumberStatisticsAndOutliers(InputIt first, InputIt last, OutputIt outliersout, double *minimum=nullptr, double minimumQuantile=0, double *median=nullptr, double *maximum=nullptr, double maximumQuantile=1, double *quantile1=nullptr, double quantile1Spec=0.25, double *quantile2=nullptr, double quantile2Spec=0.75, double *IQR=nullptr, double *IQRSignificance=nullptr, size_t *Noutput=nullptr)
calculates the Five-Number Statistical Summary (minimum, median, maximum and two user-defined quantil...
Definition jkqtpstatbasics.h:1080
double jkqtpstatWeightedVariance(InputIt first, InputIt last, InputWeightIt firstWeight, double *averageOut=nullptr, size_t *Noutput=nullptr)
calculates the weighted variance of a given data range first ... last
Definition jkqtpstatbasics.h:543
double jkqtpstatCentralMoment(InputIt first, InputIt last, int order, double *averageOut=nullptr, size_t *Noutput=nullptr)
calculates the given central moment of a given data range first ... last
Definition jkqtpstatbasics.h:660
double jkqtpstatNMAD(InputIt first, InputIt last, double *median=nullptr, size_t *Noutput=nullptr)
calculates the normalized median absolute deviation about the median (NMAD) of a given data range fir...
Definition jkqtpstatbasics.h:1254
double jkqtpstatSum(InputIt first, InputIt last, size_t *Noutput=nullptr)
calculates the sum of a given data range first ... last
Definition jkqtpstatbasics.h:355
double jkqtpstatVariance(InputIt first, InputIt last, double *averageOut=nullptr, size_t *Noutput=nullptr)
calculates the variance of a given data range first ... last
Definition jkqtpstatbasics.h:473
represents the Five-Number Statistical Summary (minimum, median, maximum and two user-defined quantil...
Definition jkqtpstatbasics.h:1091
double minimumQuantile
specifies a quantile for the return value minimum (default is 0 for the real minimum,...
Definition jkqtpstatbasics.h:1097
double quantile1
first quantile value (specified by quantile1Spec)
Definition jkqtpstatbasics.h:1099
double quantile2
second quantile value (specified by quantile1Spec)
Definition jkqtpstatbasics.h:1105
std::vector< double > outliers
list with the outlier values < minimum and > maximum
Definition jkqtpstatbasics.h:1119
double minimum
minimum value
Definition jkqtpstatbasics.h:1095
double IQRSignificanceEstimate() const
interquartile range, calculated as
double median
median value
Definition jkqtpstatbasics.h:1103
size_t N
number of values used to calculate the summary
Definition jkqtpstatbasics.h:1113
double maximumQuantile
specifies a quantile for the return value maximum (default is 1 for the real maximum,...
Definition jkqtpstatbasics.h:1111
double quantile2Spec
specifies the second quantile (range: 0..1)
Definition jkqtpstatbasics.h:1107
double quantile1Spec
specifies the first quantile (range: 0..1)
Definition jkqtpstatbasics.h:1101
double maximum
maximum value
Definition jkqtpstatbasics.h:1109
double IQR() const
the interquarzile range