简体   繁体   中英

Correlation and p-value of raster

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'

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM