# [GRASS-user] Using r.quantile result with r.recode

Glynn Clements glynn at gclements.plus.com
Mon Apr 15 06:59:30 PDT 2013

```Pedro Venâncio wrote:

> I have a doubt about using the r.quantile output with r.recode.
>
> r.quantile returns the upper limit value corresponding to each
> class, right?

r.quantile calculates quantile values. If you use the -r flag, each
value is used as the upper limit for one range and the lower limit of
the next. The map's total range sets the lower limit of the first
range and the upper limit of the last range.

If the number of values is an exact multiple of the number of
divisions (e.g. 4 for quantiles, 10 for deciles, etc), the quantile
will be one of the input values, otherwise it will be linearly

It's possible that there should be a -1 in the calculation; currently,
if you calculate the deciles of the 100 distinct values 0-99
inclusive, the results will be 10,20,...,90, so the ranges will be
0-10,10-20,...,90-99.

> But r.recode uses r.quantile result as closed interval in the lower
> value and open interval in the upper value.

r.recode does whatever the Rast_fpreclass_* functions do. Which is to
scan the rules from highest to lowest and stop on the first match. So
for a value which is on the boundary between ranges, the upper range
will be chosen.

> But this is not correct. According to quantiles method, the reclassification should be as follows:
>
> ]2.000000:6.000000] -> 1
> ]6.000000:8.000000] -> 2
> ]8.000000:12.000000] -> 3
> ]12.000000:20.000000] -> 4
> ]20.000000:872.727295] -> 5
>
> or am I wrong?

I think that if the number of values is an exact multiple of the
number of divisions, r.quantile+r.recode should result in each range
having exactly the same number of values.

But I'm not sure whether it's r.quantile, r.recode or both which
need to be fixed.

 More precisely, the Rast_fpreclass_* functions.

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