I have six raster datasets with matching resolution and extent.
I want to analyze the relation between those rasters by calculating pairwise Spearman's correlation coefﬁcients for all combinations of two raster layers.
The aim is to output a correlation matrix that shows the coefficient for each of the combinations of bands.
I tried this https://www.rdocumentation.org/packages/raster/versions/2.9-23/topics/layerStats, it worked, but not for spearman.
myfolder<- "G:/name/name_2/test" r_path <- file.path(myfolder, grep(".tif$", list.files(file.path(myfolder), all.files = F), ignore.case = TRUE, value = TRUE)) mystack <- raster::stack(r_path) #https://www.researchgate.net/post/How_do_I_make_a_raster_correlation_map_using_different_raster_response_ecosystem_service_value_and_explanatory_temperature_NDVI_raster_data raster::layerStats(mystack, 'pearson', na.rm=T)
I found the function corLocal (Spearman correlation between two rasters in R), but it performed a spearman correlation between two raster datasets and I need a correlation matrix for six raster datasets.
temp = list.files(pattern="*.tif$") #source https://stackoverflow.com/questions/52746936/how-to-efficiently-import-multiple-raster-tif-files-into-r raster1<-temp[] raster2<-temp[] corLocal(raster1, raster2, method="spearman") Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘corLocal’ for signature ‘"character", "character"’
Are there any suggestions?