[GRASS-dev] GRASS 7 r.neighbours average method giving incorrect value

Glynn Clements glynn at gclements.plus.com
Mon Jul 15 08:39:06 PDT 2013


Hamish wrote:

> > For average, median, variance, standard deviation and interspersion,
> > the output should always be floating-point (although I'm not entirely
> > certain about median).
> 
> why not for median? is there any other way to deal with even number of
> values in the list? if value will often be 0.5 then round() isn't ideal..
> It seems better to consistently say "median will output DCELL" than to
> say "depending on the number of input maps, and the number of scattered
> NULLs at each grid cell, sometimes median will save the map as CELL if it
> can".
> 
> or is there some other reason or way to deal with that?

It's a question of definition.

If the number of values is odd, the median will be one of the input
values. If the number of values is even, but the two middle values are
equal, again the median will be one of the input values.

If the number of values is even and the two middle values are
different, then any value between the two is a median, insofar as half
the values will be less than that value while the other half will be
greater. If the two middle values are integers and not adjacent, then
some of the "candidate" medians are also integers.

Taking the arithmetic mean of the two values is one possible approach,
although not necessarily the best one. It's worth considering whether
it really justifies expanding to DCELL for one extra bit (for integer
inputs, the output will always be either an integer or an integer plus
a half).

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list