#' Make random null network for motif
#' @description Make a random null network for a competitive network from nodes and edges
#' @name null_network_make
#' @param n number of nodes
#' @param frac_of_coext probability of coexistence links
#' @return an `igraph` object
#' @examples
#'
#' @export
#' @import igraph
null_network_make <- function(
n = 5,
frac_of_coext = .8
) {
#
nodes <- data.frame(node = 1:n)
edges <- t(combn(n, 2)) %>% as.data.frame() %>% setNames(c("from", "to")) %>%
mutate(interaction = sample(c("coexistence", "exclusion"), choose(n, 2), replace = T,
prob=c(frac_of_coext, 1- frac_of_coext)))
temp_index <- which(sample(c(T, F), choose(n, 2), replace = T))
edges[temp_index, c("from", "to")] <- edges[temp_index, c("to", "from")]
#
net <- network_make(nodes = nodes, edges = edges)
return(net)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.