Hi!
I am new with Rstudio and I need to work with it to carry out a Mann-Kendall test.
I have a total of 620 images in a directory (folder) and I would like to get the p-value through the Mann-Kendall test.
library(sp)
library(raster)
library(Kendall)
myfolder <- 'Z:\\ArcGIS_project\\R\\IMAGES'
r_path <- file.path(myfolder, grep("STACK_KENDALL.TIF$",
list.files(file.path(myfolder),
all.files = F),
ignore.case = TRUE, value = TRUE))
mystack <- raster:stack(r_path)
#raster::layerStats(mystack, 'pearson')
fun_kendall <- function(x){ return(unlist(MannKendall(x)))}
kendall_result <- calc(mystack,fun_kendall)
writeRaster(kendall_result$tau, filename = "Z:\\ArcGIS_project\\R\\IMAGES\\STACK_tau.tif", format="GTiff", overwrite=TRUE)
writeRaster(kendall_result$sl, filename = "Z:\\ArcGIS_project\\R\\IMAGES\\STACK_p-value.tif", format="GTiff", overwrite=TRUE)
I got an error "Error in x[[1]] : subscript out of bounds" when I try to stack the raster (mystack <- raster:stack(r_path)).
Am I doing well? Does anyone know which is the issue?
Thank you so much,