# GMLscripts.com

Discuss and collaborate on GML scripts

You are not logged in.

## #1 2007-11-18 22:56:20

Quimp
Member
Registered: 2007-10-09
Posts: 15

### ds_list extensions

I wrote a few scripts to extend the list data structure functions. I avoided relying on other scripts, so it may be a bit redundant (ex.: standard_deviation = sqrt(ds_list_variance(list)); )

Expand/*
ds_list_mean(list)

Arguments:
list (real) - List data structure

Returns: (real)
the arithmetic mean of the list's values
*/

var n, avg, i;
n = ds_list_size(argument0);
avg = 0;

for (i=0; i<n; i+=1)
{
avg += ds_list_find_value(argument0, i);
}

return avg/n;
Expand/*
ds_list_variance(list[, sample])

Arguments:
list (real) - List data structure
sample (optional, bool) - TRUE if the list is made up of a sample

Returns: (real)
the variance of the given list
*/

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);
Expand/*
ds_list_vrm(list[, sample])

Arguments:
list (real) - List data structure
sample (optional, bool) - TRUE if the list is made up of a sample

Returns: (real)
the variance-to-mean ratio (V.R.M.) of the given list
*/

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)/avg;
Expand/*
ds_list_stand_deviation(list[, sample])

Arguments:
list (real) - List data structure
sample (optional, bool) - TRUE if the list is made up of a sample

Returns: (real)
the standard deviation of the given list
*/

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 sqrt(sum/(n - argument1));
Expand/*
ds_list_cv(list[, sample])

Arguments:
list (real) - List data structure
sample (optional, bool) - TRUE if the list is made up of a sample

Returns: (real)
the coefficient of deviation (C.V.) of the given list
*/

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 sqrt(sum/(n - argument1))/avg;

I'm not sure about this one. How do you call it in English? In French it's called the "Cote Z".

Expand/*
ds_list_z_cote(list, pos)

Arguments:
list (real) - List data structure
pos (real) - The position in the list

Returns: (real)
the z cote of the value at position pos in the given list
*/

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 (ds_list_find_value(argument0, argument1) - avg)/sqrt(sum/n);
Expand/*
ds_list_dispersion(list)

Arguments:
list (real) - List data structure

Returns: (real)
the dispersion of the given list
*/

var n, maxv, minv, i, val;
n = ds_list_size(argument0);
maxv = ds_list_find_value(argument0, 0);
minv = maxv;

for (i=1; i<n; i+=1)
{
val = ds_list_find_value(argument0, i);

if (val > maxv)
maxv = val;
else if (val < minv)
minv = val;
}

return (maxv - minv);
Expand/*
ds_list_max(list)

Arguments:
list (real) - List data structure

Returns: (real)
the maximum value of the given list
*/

var n, maxv, i, val;
n = ds_list_size(argument0);
maxv = ds_list_find_value(argument0, 0);

for (i=1; i<n; i+=1)
{
val = ds_list_find_value(argument0, i);

if (val > maxv)
maxv = val;
}

return maxv;
Expand/*
ds_list_min(list)

Arguments:
list (real) - List data structure

Returns: (real)
the minimum value of the given list
*/

var n, minv, i, val;
n = ds_list_size(argument0);
minv = ds_list_find_value(argument0, 0);

for (i=1; i<n; i+=1)
{
val = ds_list_find_value(argument0, i);

if (val < minv)
minv = val;
}

return minv;

And somewhat lost in the bunch is...

Expand/*
ds_list_geometric_mean(list)

Arguments:
list (real) - List data structure

Returns: (real)
the geometric mean of the list's values
*/

var n, geo, i;
n = ds_list_size(argument0);
geo = 1;

for (i=0; i<n; i+=1)
{
geo *= ds_list_find_value(argument0, i);
}

return power(geo, 1/n);

I also wrote one for the Harmonic Mean but somehow I lost it. If you think it could be useful, it will take only a few seconds to write.

Edit: Oh boy! I totally forgot to adapt the scripts to your style. I'm not even sure the header is correct either. I may do it later, but not today.

Cheers!
Quimp

Last edited by Quimp (2007-11-18 22:58:12)

Offline

## #2 2007-11-19 14:32:36

xot
Registered: 2007-08-18
Posts: 1,240

### Re: ds_list extensions

Thanks for the submissions, Quimp. Several scripts like these were actually added to the site during the last update (October 28, 2007), but a few others are new. I think someone else may have already submitted the ds_list_min/max functions. I'm on vacation right now, so I can't evaluate these scripts, but I will as soon as I am able.

Abusing forum power since 1986.

Offline

## #3 2007-11-19 20:00:46

Quimp
Member
Registered: 2007-10-09
Posts: 15

### Re: ds_list extensions

It was not my intention to resubmit some of the scripts, I missed this update. (I see that you added visuals to some scripts, that's brilliant). I like the fact that some of my scripts use an optional argument for sample populations rather than having separated scripts though.

Last edited by Quimp (2007-11-19 20:04:03)

Offline

## #4 2007-11-22 15:35:49

xot
Registered: 2007-08-18
Posts: 1,240

### Re: ds_list extensions

I like the fact that some of my scripts use an optional argument for sample populations rather than having separated scripts though.

I like that feature as well. I don't really know enough about statistics to know what to call that option. I will probably replace the two scripts with one as you suggest.

Abusing forum power since 1986.

Offline

## #5 2007-11-23 13:41:28

Yourself
Member
Registered: 2007-10-09
Posts: 48

### Re: ds_list extensions

The population standard deviation is used to estimate the standard deviation of a large population given a random sample of that population.

The other kind is where you're given the entire population.

Offline

xot