Invert 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=\sqrt{\frac{\Sigma{x^2}-n\bar{x}^2}{n-1}} \qquad \small \Sigma{x^2}=x_1^2+x_2^2+\cdots+x_n^2 \qquad \bar{x}=\frac{\Sigma{x}}{n} \qquad \Sigma{x}=x_1+x_2+\cdots+x_n$$

ds_list_standard_deviation(list, sample)
Returns the standard deviation for values in a list.
COPY/// @func   ds_list_standard_deviation(list, sample)
///
/// @desc   Returns the standard deviation for values in a list.
///         Computes for a sample or entire population (default).
///
/// @param  {list}      list        list data structure
/// @param  {bool}      sample      true for sample, false for population
///
/// @return {real}      standard deviation
///
/// GMLscripts.com/license

function ds_list_standard_deviation(list, sample=false)
{
    var n = ds_list_size(list);
    if (n == 0) return undefined;

    var avg = 0;
    var sum = 0;

    for (var i=0; i<n; i++) avg += ds_list_find_value(list, i);
    avg /= n;

    for (var i=0; i<n; i++) sum += sqr(ds_list_find_value(list, i) - avg);

    return sqrt(sum / (n - real(sample)));
}

Contributors: Quimp

GitHub: View · Commits · Blame · Raw