rspatial / terra

R package for spatial data handling https://rspatial.github.io/terra/reference/terra-package.html
GNU General Public License v3.0
539 stars 89 forks source link

Extracting p-values after LayerCor performing #1328

Closed RafP2021 closed 1 year ago

RafP2021 commented 1 year ago

Hi everybody. I was wondering if there exist a command, subsequent to "layerCor", through which terra can calculate the p-values of the Pearson correlation tests performed onto a stacked raster file. I am not finding information about this. Thank you for any clue

rhijmans commented 1 year ago

Please see the instructions:

Here you can report bugs or ask for new features. Stack Overflow is a better place for "how-to" questions.

I have not directly implemented this because I do not think that p-values are meaningful in this context (are you testing a hypothesis with a small sample size?) but you can do this:

library(terra)
b <- rast(system.file("ex/logo.tif", package="terra"))   
layerCor(b, \(x, y) cor.test(x,y)$p.value )