You are not logged in.
Pages: 1
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)); )
/*
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;
/*
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);
/*
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;
/*
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));
/*
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".
/*
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);
/*
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);
/*
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;
/*
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...
/*
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
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
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
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
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
These scripts have been added to the site:
http://www.gmlscripts.com/script/ds_list_cv
http://www.gmlscripts.com/script/ds_list_dispersion
http://www.gmlscripts.com/script/ds_list_geometric_mean
http://www.gmlscripts.com/script/ds_list_max
http://www.gmlscripts.com/script/ds_list_min
http://www.gmlscripts.com/script/ds_lis … _deviation
http://www.gmlscripts.com/script/ds_list_standard_score
http://www.gmlscripts.com/script/ds_list_variance
http://www.gmlscripts.com/script/ds_list_vrm
Thanks!
Abusing forum power since 1986.
Offline
Pages: 1