create_multilayer_network: Create Multilayer Network

View source: R/create_multilayer_network.R

create_multilayer_networkR Documentation

Create Multilayer Network

Description

This function creates a multilayer network from multiple matrices / link lists.

Usage

create_multilayer_network(
  list_of_layers,
  bipartite,
  directed,
  interlayer_links = NULL,
  layer_attributes = NULL,
  state_node_attributes = NULL,
  physical_node_attributes = NULL
)

Arguments

list_of_layers

List of matrices or list of link lists (format from to weight; see description). These are the intralayer links.

bipartite

Is the network bipartite? Must be provided (no default value).

directed

Is the network directed? Must be provided (no default value).

interlayer_links

Interlayer extended edge list of the format layer_from node_from layer_to node_to weight. Default is NULL, assuming no interlayer links.

layer_attributes

Optional. A data frame with layer attributes. The first column must be called layer_id, and it must have unique values (one row per layer). Layer name column, if exists must be called layer_name, and its values must be unique. The order of the rows and layer_id should be the same as in list_of_layers. No column is allowed to be named name.

state_node_attributes

Optional. Additional information on physical nodes in layers. Must contain columns layer_name and node_name.

physical_node_attributes

Optional. Additional information on physical nodes. Must contain column node_name.

Details

Input of list_of_layers is handled by the function create_monolayer_network; see it's description for details on input. If using matrices as input, they should contain row and column names. If link lists are provided as input column names should be from to weight.

When using link lists, it is possible to include link attributes. In that case the headers of all the link lists and, if included, the interlayer links, must be the same (after the weight), even if some attributes are included in only some layers (see detailed example in the code accompanying the package). Missing link attributes can be set to NA.

If interlayer links are provided, then layer_attributes must also be provided. Specify layer and nodes by UNIQUE names (not IDs). Layer names should correspond to those provided in layer_attributes.

Attributes of state nodes can be provided with state_node_attributes. If provided, then columns layer_name and node_name must be included.

For compatibility with function load_emln the output contains description and references. The value of any missing data frames in the multilayer object will be set to NULL.

See multiple example in the code accompanying the package

Value

A multilayer object (see ?multilayer).

See Also

multilayer, create_monolayer_network

Examples

library(tibble)
pond_1 <- matrix(c(0,1,1,0,0,1,0,0,0), byrow = TRUE,
nrow = 3, ncol = 3, dimnames = list(c('pelican','fish','crab'),
c('pelican','fish','crab')))
pond_2 <- matrix(c(0,1,0,0,0,1,0,0,0), byrow = TRUE,
nrow = 3, ncol = 3, dimnames = list(c('pelican','fish','crab'),
c('pelican','fish','crab')))
pond_3 <- matrix(c(0,1,1,0,0,1,0,0,0), byrow = TRUE,
nrow = 3, ncol = 3, dimnames = list(c('pelican','fish','tadpole'),
c('pelican','fish','tadpole')))

layer_attrib <- tibble(layer_id=1:3,
                       layer_name=c('pond_1','pond_2','pond_3'),
                       location=c('valley','mid-elevation','uphill'))

# Create the ELL tibble with interlayer links.
interlayer <- tibble(layer_from=c('pond_1','pond_1','pond_1'),
                     node_from=c('pelican','crab','pelican'),
                     layer_to=c('pond_2','pond_2','pond_3'),
                    node_to=c('pelican','crab','pelican'),
                     weight=1)

# This is a directed network so the links should go both ways,
# even though they are symmetric.
interlayer_2 <- interlayer[,c(3,4,1,2,5)]
names(interlayer_2) <- names(interlayer)
interlayer <- rbind(interlayer, interlayer_2)

multilayer <- create_multilayer_network(list_of_layers =
list(pond_1, pond_2, pond_3), layer_attributes = layer_attrib,
interlayer_links = interlayer, bipartite = FALSE, directed = TRUE)


emln documentation built on May 6, 2026, 1:06 a.m.