Title: | Networks Characterising the Physical Configurations of Animal Habitats |
---|---|
Description: | Functions for generating and visualising networks for characterising the physical attributes and spatial organisations of habitat components (i.e. habitat physical configurations). The network generating algorithm first determines the X and Y coordinates of N nodes within a rectangle with a side length of L and an area of A. Then it computes the pair-wise Euclidean distance Dij between node i and j, and then a complete network with 1/Dij as link weights is constructed. Then, the algorithm removes links from the complete network with the probability as shown in the function ahn_prob(). Such link removals can make the network disconnected whereas a connected network is wanted. In such cases, the algorithm rewires one network component to its spatially nearest neighbouring component and repeat doing this until the network is connected again. Finally, it outputs an undirected network (weighted or unweighted, connected or disconnected). This package came with a manuscript on modelling the physical configurations of animal habitats using networks (in preparation). |
Authors: | Peng He [aut, cre] , Damien R. Farine [ths] |
Maintainer: | Peng He <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2024-12-18 06:28:52 UTC |
Source: | CRAN |
Generate undirected networks (weighted or unweighted, connected or disconnected) characterising the physical attributes and spatial organizations (or distributions) of habitat components (i.e. habitat configurations).
ahn_gen(N, L, mu, lamda, Connected = TRUE, Weighted = TRUE, eta = 1, A = 25, X = NULL, Y = NULL, U = NULL, V = NULL)
ahn_gen(N, L, mu, lamda, Connected = TRUE, Weighted = TRUE, eta = 1, A = 25, X = NULL, Y = NULL, U = NULL, V = NULL)
N |
The number of nodes |
L |
A side length of the rectangle landscape within which nodes are anchored |
mu |
the critical |
lamda |
the steepness of the link removing probability curve |
Connected |
|
Weighted |
|
eta |
mediates the weight, i.e. |
A |
The area of the rectangle landscape within which the network is defined |
X |
A vector of |
Y |
A vector of |
U |
A vector with |
V |
A vector with |
Return an animal habitat network (an igraph
object)
# generate a connected and weighted network ahn_gen(N = 10, L = 5, mu = 1, lamda = 5) N <- 10 x <- runif(N, 0, 5) ql <- sample(LETTERS, N, replace = TRUE) qn <- sample(1:20, N, replace = TRUE) # specify the X coordinates, node attributes U and V for a connected and unweighted network ahn_gen(N, L = 5, mu = 1, lamda = 5, Weighted = FALSE, X = x, U = ql, V = qn) # specify the Y coordinates, node attributes U and V for a weighted network, no matter if the # network will be connected or not ahn_gen(N, L = 5, mu = 1, lamda = 5, Weighted = TRUE, Connected = FALSE, Y = x, U = ql, V = qn)
# generate a connected and weighted network ahn_gen(N = 10, L = 5, mu = 1, lamda = 5) N <- 10 x <- runif(N, 0, 5) ql <- sample(LETTERS, N, replace = TRUE) qn <- sample(1:20, N, replace = TRUE) # specify the X coordinates, node attributes U and V for a connected and unweighted network ahn_gen(N, L = 5, mu = 1, lamda = 5, Weighted = FALSE, X = x, U = ql, V = qn) # specify the Y coordinates, node attributes U and V for a weighted network, no matter if the # network will be connected or not ahn_gen(N, L = 5, mu = 1, lamda = 5, Weighted = TRUE, Connected = FALSE, Y = x, U = ql, V = qn)
Visualise networks generated by the function ahn_gen
.
ahn_plot(ahn, NodeLabels = unname(V(ahn)), NodeColors = unname(V(ahn)), NodeSizes = rep(3, length(V(ahn))))
ahn_plot(ahn, NodeLabels = unname(V(ahn)), NodeColors = unname(V(ahn)), NodeSizes = rep(3, length(V(ahn))))
ahn |
Networks returned by |
NodeLabels |
The labels of nodes in |
NodeColors |
The colors of nodes in |
NodeSizes |
The sizes of nodes in |
Return a plot of the network
# generate a weighted and connected network and plot it by default N <- 10 x <- runif(N, 0, 5) ahn <- ahn_gen(N, L = 5, mu = 1, lamda = 5, X = x) ahn_plot(ahn) # plot the network with specified colors, labels and sizes for nodes ahn_plot( ahn, NodeColors = sample(4, N, replace = TRUE), NodeLabels = letters[1:N], NodeSizes = seq(1, 5, length.out = N))
# generate a weighted and connected network and plot it by default N <- 10 x <- runif(N, 0, 5) ahn <- ahn_gen(N, L = 5, mu = 1, lamda = 5, X = x) ahn_plot(ahn) # plot the network with specified colors, labels and sizes for nodes ahn_plot( ahn, NodeColors = sample(4, N, replace = TRUE), NodeLabels = letters[1:N], NodeSizes = seq(1, 5, length.out = N))
Plot the probability curve P(Dij, mu, lamda)
for removing links from the initial complete network
ahn_prob(Dij = seq(0.05, 10, length.out = 30), mu = c(0.1, 2, 5, 10), lamda = c(1e-04, 0.15, 0.35, 0.75, 1.25, 5, 30))
ahn_prob(Dij = seq(0.05, 10, length.out = 30), mu = c(0.1, 2, 5, 10), lamda = c(1e-04, 0.15, 0.35, 0.75, 1.25, 5, 30))
Dij |
A vector of Euclidean distances between node |
mu |
The concave-to-convex transition point of the probability curves |
lamda |
The steepness of the probability curves |
Return a plot with probability curves
# plot the probabilities for removing network links between node i and j with # Euclidean distances Dij dis <- seq(.05, 10, length.out = 20) m <- c(.1, 2, 5, 10) l <- c(.0001, .15, .35, .75, 1.25, 5, 30) ahn_prob(dis, m, l)
# plot the probabilities for removing network links between node i and j with # Euclidean distances Dij dis <- seq(.05, 10, length.out = 20) m <- c(.1, 2, 5, 10) l <- c(.0001, .15, .35, .75, 1.25, 5, 30) ahn_prob(dis, m, l)