Skip to content

Commit

Permalink
random nw generation function and updates to github documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
marioangst committed Feb 10, 2020
1 parent 98c5380 commit b6715ab
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 13 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
47 changes: 46 additions & 1 deletion R/generate_baseline_ml_graph.R
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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")))
9 changes: 5 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,7 +77,7 @@ cld_viz$plot

<img src="man/figures/cld_example.svg">

### 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:

Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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

Expand Down Expand Up @@ -80,7 +83,7 @@ cld_viz$plot

<img src="man/figures/cld_example.svg">

### 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
Expand Down

0 comments on commit b6715ab

Please sign in to comment.