[GRASS-user] Grass Script- Implementing a Quadratic Mahalanobis Distance

Greetings

I need to implement a Quadratic Mahaloanobis Distance by using GRASS. This is based on medium vector and covariance matrix.
1- As anyone implemented anything similar?
2- If not, Is there any GRASS script that accesses medium vector and Covariance matrix in its processing?

Thanks

PEdro

On Monday 11 of October 2010 19:21:54 Pedro Roma wrote:

Greetings

I need to implement a Quadratic Mahaloanobis Distance by using GRASS. This
is based on medium vector and covariance matrix.
1- As anyone implemented anything similar?
2- If not, Is there any GRASS script that accesses medium vector and
Covariance matrix in its processing?

Thanks
PEdro

Hi Pedro!

Not sure at all but my guess is that it's a (simple) job for grass if you know
the formula. I am not familiar with the term "medium" vector. But there is
"r.covar" to get the covariance (or correlation) matrix based on raster maps.

Nikos

(
Pedro, I kindly ask you to keep the discussion on the list - it's very
interesting (to me at least) and of wider interest (I guess) as a small
challenge for grass. I am sure others can help here.

Also, accept my apologies for re-structuring the mail to make it easy to
follow for other readers.
)

Pedro wrote:

> > I need to implement a Quadratic Mahaloanobis Distance by using GRASS.
> > This is based on medium vector and covariance matrix.

> > 1- As anyone implemented anything similar?
> > 2- If not, Is there any GRASS script that accesses medium vector and
> > Covariance matrix in its processing?

Nikos:

> Not sure at all but my guess is that it's a (simple) job for grass if you
> know the formula. I am not familiar with the term "medium" vector. But
> there is "r.covar" to get the covariance (or correlation) matrix based on
> raster maps.

Pedro:

Medium vector is a vector/array in which each element is the average of
that class in each image
[average in image1; average in image2, ...]

The problem of implemeting this in a script is that it required matrix
calculation. I mean, for each pixel in a class, I will have to multiplicate
byt the covariance matriz and this vector.

I don't have a quick answer on how to do it within grass using r.mapcalc. But
I am convinced that using grass + R is a solution. Also, is the following
matlab (open source?) code of any use?

<http://www.hackchina.com/en/r/129852/mahalanobis.m__html&gt;

I've read on the net efforts trying to link R and matlab. If the latter is
practically doable, then you can even avoid writing the code (again). So, I
imagine something like:

1. import data in grass and prepare/process etc.
2. load data of interest in R
3. calculate the (qudratic) mahalanobis distances of interest (within R with
R code/ with matlab code ?)
4. export results (or even maps) in grass back again

Cheers, Nikos

R has a command to calculate the Mahalanobis distance [1], so I
believe it's just a matter of getting the grass data into R in the
correct way and using the already R built in tools in R.
Unfortunately, this is as far as I can help, not being an expert in R
myself....

Cheers
Daniel

[1] - http://stat.ethz.ch/R-manual/R-devel/library/stats/html/mahalanobis.html

On Fri, Oct 15, 2010 at 8:45 AM, Nikos Alexandris
<nikos.alexandris@felis.uni-freiburg.de> wrote:

(
Pedro, I kindly ask you to keep the discussion on the list - it's very
interesting (to me at least) and of wider interest (I guess) as a small
challenge for grass. I am sure others can help here.

Also, accept my apologies for re-structuring the mail to make it easy to
follow for other readers.
)

Pedro wrote:

> > I need to implement a Quadratic Mahaloanobis Distance by using GRASS.
> > This is based on medium vector and covariance matrix.

> > 1- As anyone implemented anything similar?
> > 2- If not, Is there any GRASS script that accesses medium vector and
> > Covariance matrix in its processing?

Nikos:

> Not sure at all but my guess is that it's a (simple) job for grass if you
> know the formula. I am not familiar with the term "medium" vector. But
> there is "r.covar" to get the covariance (or correlation) matrix based on
> raster maps.

Pedro:

Medium vector is a vector/array in which each element is the average of
that class in each image
[average in image1; average in image2, ...]

The problem of implemeting this in a script is that it required matrix
calculation. I mean, for each pixel in a class, I will have to multiplicate
byt the covariance matriz and this vector.

I don't have a quick answer on how to do it within grass using r.mapcalc. But
I am convinced that using grass + R is a solution. Also, is the following
matlab (open source?) code of any use?

<http://www.hackchina.com/en/r/129852/mahalanobis.m__html&gt;

I've read on the net efforts trying to link R and matlab. If the latter is
practically doable, then you can even avoid writing the code (again). So, I
imagine something like:

1. import data in grass and prepare/process etc.
2. load data of interest in R
3. calculate the (qudratic) mahalanobis distances of interest (within R with
R code/ with matlab code ?)
4. export results (or even maps) in grass back again

Cheers, Nikos
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Daniel Victoria wrote:

R has a command to calculate the Mahalanobis distance [1], so I
believe it's just a matter of getting the grass data into R in the
correct way and using the already R built in tools in R.
Unfortunately, this is as far as I can help, not being an expert in R
myself....

Sorry that I did not take the time to search better within R. So, it seems to
be very easy then using the R function "mahalanobis()". As Daniel notes, it's
just a matter of correctly loading the data in R.

@Pedro: If you have difficulties to get started with R, check the wiki [2].
There are examples. Myself I calculated separability measures this way (grass
raster samples -> R -> separability measures -> exported as csv).

Cheers, Nikos

[1] -
http://stat.ethz.ch/R-manual/R-devel/library/stats/html/mahalanobis.html

[2] <http://grass.osgeo.org/wiki/R_statistics&gt;