Set the topology in a network model.
set_topo(nm, ..., from = NULL, to = NULL)
A networkModel
object (output from
new_networkModel
).
One or more strings describing the links defining the network topology. Optionally, links can be given as a data frame. See the examples for more details about acceptable input formats.
Optional, string containing the column name for sources if links are provided as a data frame.
Optional, string containing the column name for destinations if links are provided as a data frame.
A networkModel
object.
# A single string can describe several links in one go.
m <- new_networkModel() %>%
set_topo("NH4, NO3 -> epi -> pseph, tricor")
#> Using default distribution family for proportions ("gamma_cv").
#> (eta is the coefficient of variation of gamma distributions.)
#> Using default distribution family for sizes ("normal_cv").
#> (zeta is the coefficient of variation of normal distributions.)
m
#> # A tibble: 1 × 4
#> topology initial observations parameters
#> <list> <list> <list> <list>
#> 1 <topology [5 × 5]> <NULL> <NULL> <tibble [11 × 2]>
topo(m)
#> <5 comps>
#> NH4 NO3 epi pseph tricor
#> NH4 0 0 0 0 0
#> NO3 0 0 0 0 0
#> epi 1 1 0 0 0
#> pseph 0 0 1 0 0
#> tricor 0 0 1 0 0
# Several strings can be given as distinct arguments.
m2 <- new_networkModel() %>%
set_topo("NH4, NO3 -> epi -> pseph, tricor",
"NH4 -> FBOM, CBOM", "CBOM <- NO3")
#> Using default distribution family for proportions ("gamma_cv").
#> (eta is the coefficient of variation of gamma distributions.)
#> Using default distribution family for sizes ("normal_cv").
#> (zeta is the coefficient of variation of normal distributions.)
m2
#> # A tibble: 1 × 4
#> topology initial observations parameters
#> <list> <list> <list> <list>
#> 1 <topology [7 × 7]> <NULL> <NULL> <tibble [16 × 2]>
topo(m2)
#> <7 comps>
#> CBOM FBOM NH4 NO3 epi pseph tricor
#> CBOM 0 0 1 1 0 0 0
#> FBOM 0 0 1 0 0 0 0
#> NH4 0 0 0 0 0 0 0
#> NO3 0 0 0 0 0 0 0
#> epi 0 0 1 1 0 0 0
#> pseph 0 0 0 0 1 0 0
#> tricor 0 0 0 0 1 0 0
# Multiple strings can be also be combined into a single argument with `c()`.
links <- c("NH4, NO3 -> epi -> pseph, tricor", "NH4 -> FBOM, CBOM",
"CBOM <- NO3")
m3 <- new_networkModel() %>%
set_topo(links)
#> Using default distribution family for proportions ("gamma_cv").
#> (eta is the coefficient of variation of gamma distributions.)
#> Using default distribution family for sizes ("normal_cv").
#> (zeta is the coefficient of variation of normal distributions.)
m3
#> # A tibble: 1 × 4
#> topology initial observations parameters
#> <list> <list> <list> <list>
#> 1 <topology [7 × 7]> <NULL> <NULL> <tibble [16 × 2]>
topo(m3)
#> <7 comps>
#> CBOM FBOM NH4 NO3 epi pseph tricor
#> CBOM 0 0 1 1 0 0 0
#> FBOM 0 0 1 0 0 0 0
#> NH4 0 0 0 0 0 0 0
#> NO3 0 0 0 0 0 0 0
#> epi 0 0 1 1 0 0 0
#> pseph 0 0 0 0 1 0 0
#> tricor 0 0 0 0 1 0 0
# A data frame can be used to specify the links.
links <- data.frame(source = c("NH4", "NO3", "epi"),
consumer = c("epi", "epi", "petro"))
links
#> source consumer
#> 1 NH4 epi
#> 2 NO3 epi
#> 3 epi petro
m4 <- new_networkModel() %>%
set_topo(links, from = "source", to = "consumer")
#> Using default distribution family for proportions ("gamma_cv").
#> (eta is the coefficient of variation of gamma distributions.)
#> Using default distribution family for sizes ("normal_cv").
#> (zeta is the coefficient of variation of normal distributions.)
m4
#> # A tibble: 1 × 4
#> topology initial observations parameters
#> <list> <list> <list> <list>
#> 1 <topology [4 × 4]> <NULL> <NULL> <tibble [9 × 2]>
m4$topology[[1]]
#> <4 comps>
#> NH4 NO3 epi petro
#> NH4 0 0 0 0
#> NO3 0 0 0 0
#> epi 1 1 0 0
#> petro 0 0 1 0