Invert GMLscripts.com

dl_list_pop_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.

$$\sigma{x}=\sqrt{\frac{\Sigma{x^2}-n\bar{x}^2}{n}} \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_pop_standard_deviation(list)
Returns the population standard deviation for values in a list.
COPY/// @func   ds_list_pop_standard_deviation(list)
///
/// @desc   Returns the population standard deviation for values in a list.
///
/// @param  {list}      list        list data structure
///
/// @return {real}      population standard deviation
///
/// GMLscripts.com/license

function ds_list_pop_standard_deviation(list)
{
    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);
}

Contributors: xot

GitHub: View · Commits · Blame · Raw