# \donttest{
library(sf)
library(terra)
data(ralu.site)
xvars <- rast(system.file("extdata/covariates.tif", package="GeNetIt"))
( dist.graph <- knn.graph(ralu.site, row.names = ralu.site$SiteName,
max.dist = 1500) )
skew <- function(x, na.rm = TRUE) {
if (na.rm) x <- x[!is.na(x)]
sum( (x - mean(x)) ^ 3) / ( length(x) * sd(x) ^ 3 )
}
# Moments on continuous raster data
system.time( {
stats <- graph.statistics(dist.graph, r = xvars[[-6]],
stats = c("min", "median", "max", "var", "skew"))
} )
# Proportional function on nominal raster data
p <- function(x) { length(x[x < 52]) / length(x) }
system.time( {
nstats <- graph.statistics(dist.graph, r = xvars[[6]],
stats = "p")
} )
# Based on 500m buffer distance around line(s)
system.time( {
stats <- graph.statistics(dist.graph, r = xvars[[-6]],
stats = c("min", "median", "max", "var", "skew"),
buffer = 500)
} )
# }
Run the code above in your browser using DataLab