landgraph landgraph hex sticker

Shared, dependency-light functions for landscape-genetic network methods: a lightweight graph, genetic covariance/distance from data, and antisymmetric directional edge-covariate builders. It provides the common elements beneath terradish (symmetric resistance). No compiled code.

Installation

install.packages("landgraph")

# development version
# install.packages("remotes")
# remotes::install_github("wpeterman/landgraph")
install.packages("landgraph", repos = c('https://wpeterman.r-universe.dev', 'https://cloud.r-project.org'))

What it provides

Example

library(landgraph)

coords <- as.matrix(expand.grid(x = 0:4, y = 0:4))
g <- deme_graph(coords, neighbours = "lattice")   # 25 demes, rook adjacency

# derived-allele counts Y (demes x loci), 40 chromosomes per deme
set.seed(1)
Y <- matrix(rbinom(25 * 50, size = 40, prob = 0.4), nrow = 25)
S <- cov_from_biallelic(Y, N = 40)                # count-standardized scale
S_freq <- S / 40                                  # frequency scale for terradish

# directional covariates for a downstream directed model
elev <- g$vertex_coordinates[, 1]
d_grad <- edge_gradient(elev, g)                  # gradient of a scalar potential
wind_field <- function(xy) cbind(-(xy[, 2] - 2), xy[, 1] - 2)  # rotation about (2, 2)
d_curl <- edge_flow(wind_field, g)                # a rotational flow field

Relationship to other packages

landgraph holds only the shared inputs. terradish estimates symmetric conductance (resistance distance) from the covariance and distance matrices built by cov_from_*() and dist_from_*(), and it builds its own fitting graphs with terradish::conductance_surface(). edge_gradient() builds the antisymmetric covariate d_ab = x_a - x_b for directional gene-flow models; it is positive from high to low x. edge_flow() serves the same directional models. terradish does not fit directional models.