In this vignette, we demonstrate how to compute the multidimensional Rao’s Index using rasterdiv for multiple numerical matrices, represented as spatially autocorrelated SpatRaster objects.
We now calculate the multidimensional Rao’s Index using varying window sizes and alpha values.
mRao <- paRao(x=list(r, r1), window=c(3, 5), alpha=c(1, Inf), na.tolerance=1, method="multidimension", simplify=3)
The output is a nested list of SpatRaster which we can transform in a stack of SpatRaster and plotted together with the input layers, as follows:
# Create a list of all the rasters to plot
rasters_to_plot <- c(r, r1, mRao[[1]]$alpha.1, mRao[[2]]$alpha.Inf)
names(rasters_to_plot) <- c("Raster1", "Raster2", "Rao_Index_Window_3", "Rao_Index_Window_5")
# Use lapply to create a list of levelplots
plots_list <- lapply(rasters_to_plot, function(rst) {
levelplot(as.matrix(rst, wide=TRUE), margin=FALSE,
col.regions=magma(100),
main=list(label=names(rst),
cex=1.5))
})
# Arrange the plots in a grid
do.call(gridExtra::grid.arrange, c(plots_list, ncol = 2))
Now, we demonstrate how to compute the multidimensional Rao’s Index for a time series of rasters accounting for phenology, and compare it with Rao’s Index on the same time series without a distance metrics that account for phenology.
# Calculate Phenological Rao's Index using TWDTW
RaoPhen <- paRao(x = raster_ts,
window = 5,
alpha = 2,
na.tolerance = 0,
time_vector = dates,
method = "multidimension",
dist_m = "twdtw",
np = 7, progBar = FALSE)
# Calculate Rao's Index using Euclidean distance
RaoEuc <- paRao(x = raster_ts,
window = 5,
alpha = 2,
na.tolerance = 0,
method = "multidimension",
dist_m = "euclidean",
np = 7, progBar = FALSE)
The key takeaway is that by accounting for seasonality in our index time series, we can reduce artifact hotspots in Rao’s index. These hotspots often arise from transitions between areas with high spatial variability and those with low spatial variability, which are not due to plant phenology but to buildings or other human-made objects. This effect is illustrated by the square area in the centre of the plot below.
# Visualization
raster_ts_plot <- levelplot(mean(raster_ts), margin = FALSE,
col.regions = viridis(100),
main = list(label = "Average index",
cex = 1.5))
RaoP_plot <- levelplot(RaoPhen[[1]][[1]], margin = FALSE,
col.regions = viridis(100),
main = list(label = "Phenological Rao",
cex = 1.5))
Rao_plot <- levelplot(RaoEuc[[1]][[1]], margin = FALSE,
col.regions = viridis(100),
main = list(label = "Rao",
cex = 1.5))
do.call(gridExtra::grid.arrange, c(list(raster_ts_plot, Rao_plot, RaoP_plot), ncol = 3))