diff --git a/NAMESPACE b/NAMESPACE index 31c1576..74309f8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,8 @@ export(aggregate_cld) export(count_motifs) +export(generate_random_ml_adjmat) +export(generate_random_ml_net) export(get_entry_from_mapping) export(get_shortest_inv_distance) export(get_weighted_sum_of_paths) diff --git a/R/generate_baseline_ml_graph.R b/R/generate_baseline_ml_graph.R index 74d30a9..a8e3a88 100644 --- a/R/generate_baseline_ml_graph.R +++ b/R/generate_baseline_ml_graph.R @@ -1,5 +1,15 @@ -generate_random_ml_graph <- function(n_social_nodes, +#' Generate a random multi-level adjacency matrix +#' +#' @param n_social_nodes the number of social nodes in the network +#' @param n_non_social_nodes the number of "non-social" nodes in the network +#' @param density density of total network, defaults to random +#' +#' @return labeled adjacency matrix +#' @export +#' +#' @examples +generate_random_ml_adjmat <- function(n_social_nodes, n_non_social_nodes, density = NULL){ load_python_sma() @@ -11,3 +21,38 @@ generate_random_ml_graph <- function(n_social_nodes, adj_mat <- reticulate::py_to_r(adj_mat) adj_mat } + +#' Generate a random multi-level network (statnet network object) +#' +#' @param n_social_nodes the number of social nodes in the network +#' @param n_non_social_nodes the number of "non-social" nodes in the network +#' @param density density of total network, defaults to random +#' @param to_py should the object be returned as a sma compatible python object +#' +#' @return either a statnet network object with an attribute "sesType" specifying node type or an equivalent python compatible object +#' @export +#' +#' @examples +generate_random_ml_net <- function(n_social_nodes, + n_non_social_nodes, + density = NULL, + to_py = FALSE){ + adjmat <- generate_random_ml_adjmat(n_social_nodes = n_social_nodes, + n_non_social_nodes = n_non_social_nodes, + density = density) + net <- network::network(adjmat) + network::set.vertex.attribute(net, "sesType", ifelse(grepl(pattern = "non-social", + x = network::get.vertex.attribute(net, + "vertex.names")), + 1,0)) + if(to_py == TRUE){ + pynet <- toPyGraph(net,typeAttr = "sesType") + return(pynet) + } + else{ + return(net) + } +} + +# first idea for baseline distribution, incredibly slow +# hist(unlist(lapply(netlist[1:500], integrateR::count_motifs, "sesType", 3, "II.A", "social"))) diff --git a/README.Rmd b/README.Rmd index 18c9f7e..59fadb7 100644 --- a/README.Rmd +++ b/README.Rmd @@ -32,16 +32,17 @@ knitr::opts_chunk$set( This package provides tools to analyze and visualize multi-level networks in general, and so-called integrated networks specifically. -Multi-level networks combine multiple networks in one, e.g. social-ecological networks. +Multi-level networks combine multiple networks in one representation, e.g. social-ecological networks. Integrated networks are specific networks combining causal loop diagrams (CLDs) and social networks. The package has three main areas: Visualization, Aggregation and Analysis. - Visualization: The package visualizes CLDs and two-level networks. - - Aggregation: The package implements ways to aggregate CLDs to use as inputs in multi-level networks by way of finding common causes of parts of a CLD. + - Aggregation: The package implements ways to aggregate CLDs by creating a network between a subset of nodes in a CLD based on how these nodes are related via other parts (common causes) of the network. - - Analysis: The package is in many parts a R wrapper for the excellent [sesmotifanalyser](https://gitlab.com/t.seppelt/sesmotifanalyser) Python framework written by Tim Seppelt to count multi-level network motifs, compare them to a baseline and much more. It further identifies and visualizes functional gaps in integrated networks and virtuous and vicious cycles in CLDs. + - Analysis: The package is in many parts a R wrapper for the excellent [sesmotifanalyser](https://gitlab.com/t.seppelt/sesmotifanalyser) Python framework written by Tim Seppelt to count multi-level network motifs, compare them to a baseline and much more. Only small part of sesmotifanalyser are yet wrapped, so consult the python framework for full functionality. + IntegrateR further identifies and visualizes functional gaps in integrated networks and virtuous and vicious cycles in CLDs. ## Installation @@ -76,7 +77,7 @@ cld_viz$plot -### Visualize a multi-level network. +### Visualize a multi-level network Visualizations exist for two-level networks at the moment. The following uses DiagrammeR and is based on a network model gathered in a Swiss wetland. Actors are red, activities in wetlands governance are blue. Relations between activities are based on causal interdependence: diff --git a/README.md b/README.md index e21d674..c737d47 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ integrateR This package provides tools to analyze and visualize multi-level networks in general, and so-called integrated networks specifically. -Multi-level networks combine multiple networks in one, +Multi-level networks combine multiple networks in one representation, e.g. social-ecological networks. Integrated networks are specific networks combining causal loop diagrams (CLDs) and social networks. @@ -35,16 +35,19 @@ Analysis. - Visualization: The package visualizes CLDs and two-level networks. - - Aggregation: The package implements ways to aggregate CLDs to use as - inputs in multi-level networks by way of finding common causes of - parts of a CLD. + - Aggregation: The package implements ways to aggregate CLDs by + creating a network between a subset of nodes in a CLD based on how + these nodes are related via other parts (common causes) of the + network. - Analysis: The package is in many parts a R wrapper for the excellent [sesmotifanalyser](https://gitlab.com/t.seppelt/sesmotifanalyser) Python framework written by Tim Seppelt to count multi-level network - motifs, compare them to a baseline and much more. It further - identifies and visualizes functional gaps in integrated networks and - virtuous and vicious cycles in CLDs. + motifs, compare them to a baseline and much more. Only small part of + sesmotifanalyser are yet wrapped, so consult the python framework + for full functionality. IntegrateR further identifies and visualizes + functional gaps in integrated networks and virtuous and vicious + cycles in CLDs. ## Installation @@ -80,7 +83,7 @@ cld_viz$plot -### Visualize a multi-level network. +### Visualize a multi-level network Visualizations exist for two-level networks at the moment. The following uses DiagrammeR and is based on a network model gathered in a Swiss