[GRASS-user] Error while using variance in r.series function

Glynn Clements glynn at gclements.plus.com
Thu Feb 24 00:16:34 EST 2011


Monica Buescu wrote:

> I'm using r.series with variance option and I'm getting values that are not
> according to var function in MATLAB or var function in EXCEL.
> 
> For average and count the result is exacly the expected but for variance
> (e.g. bellow is for a pixel
> [     73 116 72 81 75 136 101 112 94 67  ]
> 
> I get 532.011 in EXCEL and in MATLAB
> and in GRASS i get 478.81
> 
> What is happening? Was this already reported?

	sum((x - mean)^2 / n) = 478.81
	sum((x - mean)^2 / (n-1)) = 532.011

r.series returns the actual (population) variance. The figure you're
looking for is the sample variance, which provides an estimation of
the population variance from a sample of the population.

You can calcualate the sample variance using e.g.:

	r.series input=... output=out.pvar,out.count method=variance,count
	r.mapcalc "out.svar = out.pvar * out.count / (out.count - 1)"

As you're not the first person to have asked this, we might want to
add alternate versions of the variance and stddev methods (and
possibly skewness and kurtosis).

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


More information about the grass-user mailing list