Skip to content

pixel-wsie correlation between raster stack and numeric vector?

3 messages · Mike Loranty, Thomas Adams, Robert J. Hijmans

#
Hi All,

Is there a way (e.g. existing function) to calculate correlation
coefficients between a raster stack and a numeric vector? For example,
between gridded vegetation indices and a vector of atmospheric oscillation
indices (e.g. ENSO, NAO, etc...).

Thanks,
Michael Loranty
Assistant Professor
Department of Geography
Colgate University
315.228.6057
mloranty at colgate.edu
http://mikeloranty.wordpress.com/
#
Michael,

I would combine the use of GRASS GIS and R (making use of spgrass7); first,
using the vector point locations:

(0) import raster and vector data into GRASS GIS
(1) use GRASS v.sample (http://grass.osgeo.org/grass70/manuals/v.sample.html)
to sample the raster data at the vector point locations
(2) launch R within the GRASS GIS session, load spgrass7 library
(3) within R (using spgrass7) read the both vector datasets (the original
vector data and new data from using v.sample) from GRASS
(4) do R statistical analyses

All this can be easily scripted for batch processing.

Tom
On Mon, Feb 23, 2015 at 4:14 PM, Mike Loranty <mloranty at colgate.edu> wrote:

            

  
  
#
MIke, I think you can use the 'calc' function for that:

library(raster)
# example data
set.seed(0)
s <- stack(system.file("external/rlogo.grd", package="raster"))
s <- stack(s, s[[1]]*runif(ncell(s)), s[[2]]*runif(ncell(s))/10,
s[[3]]*runif(ncell(s))+10)

# example vector
v <- 1:6

x <- calc(s, fun=function(x) cor(x, v))
plot(x)

Robert
On Mon, Feb 23, 2015 at 1:14 PM, Mike Loranty <mloranty at colgate.edu> wrote: