[GRASS-user] r.covar vs layerStats in R

I am preparing a correlation matrix for 7 raster layers. The results using the r.covar module are different from the R layerStats function. I suspect this is due to handling of null cells. The R function has a parameter to remove NA cells, but the GRASS module, I think, just loops over all cells, including no value.

Can anyone confirm that GRASS does not deal with null cells, and that this would cause the difference in correlation results?

Thanks

···
-- 
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918

On Sun, Nov 18, 2018 at 10:32 PM Micha Silver <tsvibar@gmail.com> wrote:

I am preparing a correlation matrix for 7 raster layers. The results using the r.covar module are different from the R layerStats function. I suspect this is due to handling of null cells. The R function has a parameter to remove NA cells, but the GRASS module, I think, just loops over all cells, including no value.

Can anyone confirm that GRASS does not deal with null cells, and that this would cause the difference in correlation results?

Here how r.covar treats NULL cells:

https://trac.osgeo.org/grass/browser/grass/trunk/raster/r.covar/main.c#L93

Markus

Hi Markus Thanks, I missed those lines when I glanced over the source (not a C programmer). I’ll do some more testing to try to understand why I’m getting different results from R compared to GRASS.

···

On 19/11/2018 12:41, Markus Neteler wrote:

On Sun, Nov 18, 2018 at 10:32 PM Micha Silver [<tsvibar@gmail.com>](mailto:tsvibar@gmail.com) wrote:

I am preparing a correlation matrix for 7 raster layers. The results using the r.covar module are different from the R layerStats function. I suspect this is due to handling of null cells. The R function has a parameter to remove NA cells, but the GRASS module, I think, just loops over all cells, including no value.

Can anyone confirm that GRASS does not deal with null cells, and that this would cause the difference in correlation results?

Here how r.covar treats NULL cells:

[https://trac.osgeo.org/grass/browser/grass/trunk/raster/r.covar/main.c#L93](https://trac.osgeo.org/grass/browser/grass/trunk/raster/r.covar/main.c#L93)
Markus

-- 
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
+972-523-665918

Retested on two small regions, one with some null cells and one with no null cells, using both the GRASS r.covar module and the R layerStats function, and this time results were almost identical. In addition, r.covar outputs “N” the number of cells used, and I saw that in the case of null cells indeed the value of N was smaller. So that answers my previous post :slight_smile:

Now I redo the process on the full rasters to see what caused the different in results.

Regards, Micha

···

On 11/19/18 12:41 PM, Markus Neteler wrote:

On Sun, Nov 18, 2018 at 10:32 PM Micha Silver [<tsvibar@gmail.com>](mailto:tsvibar@gmail.com) wrote:

I am preparing a correlation matrix for 7 raster layers. The results using the r.covar module are different from the R layerStats function. I suspect this is due to handling of null cells. The R function has a parameter to remove NA cells, but the GRASS module, I think, just loops over all cells, including no value.

Can anyone confirm that GRASS does not deal with null cells, and that this would cause the difference in correlation results?

Here how r.covar treats NULL cells:

[https://trac.osgeo.org/grass/browser/grass/trunk/raster/r.covar/main.c#L93](https://trac.osgeo.org/grass/browser/grass/trunk/raster/r.covar/main.c#L93)

Markus

-- 
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918