Processing math: 100%
GMLscripts.com

ds_list_standard_deviation

Wikipedia:

In statistics, the standard deviation (SD) (represented by the Greek letter sigma, σ) is a measure that is used to quantify the amount of variation or dispersion of a set of data values. A low standard deviation indicates that the data points tend to be very close to the mean (also called the expected value) of the set, while a high standard deviation indicates that the data points are spread out over a wider range of values.

sx=Σx2nˉx2n1Σx2=x21+x22++x2nˉx=ΣxnΣx=x1+x2++xn

ds_list_standard_deviation(list, sample)
Returns the standard deviation for values in a list.
COPY
  1. /// @func ds_list_standard_deviation(list, sample)
  2. ///
  3. /// @desc Returns the standard deviation for values in a list.
  4. /// Computes for a sample or entire population (default).
  5. ///
  6. /// @param {list} list list data structure
  7. /// @param {bool} sample true for sample, false for population
  8. ///
  9. /// @return {real} standard deviation
  10. ///
  11. /// GMLscripts.com/license
  12.  
  13. function ds_list_standard_deviation(list, sample=false)
  14. {
  15. var n = ds_list_size(list);
  16. if (n == 0) return undefined;
  17.  
  18. var avg = 0;
  19. var sum = 0;
  20.  
  21. for (var i=0; i<n; i++) avg += ds_list_find_value(list, i);
  22. avg /= n;
  23.  
  24. for (var i=0; i<n; i++) sum += sqr(ds_list_find_value(list, i) - avg);
  25.  
  26. return sqrt(sum / (n - real(sample)));
  27. }

Contributors: Quimp

GitHub: View · Commits · Blame · Raw