0

I have 4 rasters and I calculated the correlation matrix with this code; but I need to know the p-value and I haven't been able to do it. Can you help me?

a<-stack(FS2,FP2,W2,P)

jnk=layerStats(a, 'pearson', na.rm=T)
corr_matrix=jnk$'pearson correlation coefficient'
gawi
  • 2,843
  • 4
  • 29
  • 44

1 Answers1

1

You can use the corLocal function in the raster package:

library(raster)
b <- stack(system.file("external/rlogo.grd", package="raster"))
b <- aggregate(b, 2, mean)

#flip one layer so values differ:
set.seed(0)
b[[2]] <- flip(b[[2]], 'y') + runif(ncell(b))
b[[1]] <- b[[1]] + runif(ncell(b))
plot(b)

#run correlation
x <- corLocal(b[[1]], b[[2]], test=TRUE )

#view pearson correlation and p-value
plot(x)
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
Tim Assal
  • 677
  • 6
  • 15