edge_gradient: Directional edge covariates from a spatial layer

View source: R/edge_covariates.R

edge_gradientR Documentation

Directional edge covariates from a spatial layer

Description

Builds the antisymmetric per-directed-edge covariate d_{ab} = x_a - x_b used by terradish_directed to drive directional gene flow (e.g. elevation drop, flow accumulation, wind potential). d_{ab} = -d_{ba}, so a positive coefficient makes movement from high to low x faster.

Usage

edge_gradient(x, data)

Arguments

x

A terra::SpatRaster layer (or a numeric vector with one value per active graph cell) giving the potential whose gradient drives direction.

data

A terradish_graph from deme_graph.

Value

A list with edges (an integer matrix of directed edges, columns a, b, 1-based node indices) and d (the matching numeric vector d_{ab} = x_a - x_b).

See Also

terradish_directed

Examples

coords <- as.matrix(expand.grid(x = 0:2, y = 0:2))
g <- deme_graph(coords, neighbours = "lattice")
elevation <- c(10, 20, 30, 25, 15, 5, 8, 18, 28)
edge_gradient(elevation, g)

landgraph documentation built on Sept. 26, 2026, 1:08 a.m.