You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

ds_list_variance

Wikipedia:

In probability theory and statistics, variance measures how far a set of numbers is spread out. A variance of zero indicates that all the values are identical. Variance is always non-negative: a small variance indicates that the data points tend to be very close to the mean (expected value) and hence to each other, while a high variance indicates that the data points are very spread out around the mean and from each other.

Population Variance

In general, the population variance of a finite population of size \(N\) with values \(x_i\) is given by

\( \sigma^2 = \frac 1N \sum_{i=1}^N \left(x_i - \mu \right)^2 \)

where

\( \mu = \frac 1N \sum_{i=1}^N x_i \)

is the population mean.

ds_list_variance(id[,sample])
Returns the variance of the values in a given list.
COPY/// ds_list_variance(id[,sample])
//
//  Returns the variance of the values in a given list.
//
//      id          list data structure, real
//      sample      true if the list is made up of a sample, bool
//
/// GMLscripts.com/license
{
    var n, avg, sum, i;
    n = ds_list_size(argument0);
    avg = 0;
    sum = 0;

    for (i=0; i<n; i+=1) avg += ds_list_find_value(argument0, i);
    avg /= n;
    for (i=0; i<n; i+=1) sum += sqr(ds_list_find_value(argument0, i) - avg);

    return sum/(n - argument1);
}

Contributors: Quimp

GitHub: View · Commits · Blame · Raw