# compute_graph_modul: Compute modules from a graph by maximising modularity In graph4lg: Build Graphs for Landscape Genetics Analysis

 compute_graph_modul R Documentation

## Compute modules from a graph by maximising modularity

### Description

The function computes modules from a graph by maximising modularity.

### Usage

```compute_graph_modul(
graph,
algo = "fast_greedy",
node_inter = NULL,
nb_modul = NULL
)
```

### Arguments

 `graph` An object of class `igraph`. Its nodes must have names. `algo` A character string indicating the algorithm used to create the modules with igraph. If `algo = 'fast_greedy'` (default), function `cluster_fast_greedy` from igraph is used (Clauset et al., 2004). If `algo = 'walktrap'`, function `cluster_walktrap` from igraph is used (Pons et Latapy, 2006) with 4 steps (default options). If `algo = 'louvain'`, function `cluster_louvain` from igraph is used (Blondel et al., 2008). In that case, the number of modules created in each graph is imposed. If `algo = 'optimal'`, function `cluster_optimal` from igraph is used (Brandes et al., 2008) (can be very long). In that case, the number of modules created in each graph is imposed. `node_inter` (optional, default = NULL) A character string indicating whether the links of the graph are weighted by distances or by similarity indices. It is only used to compute the modularity index. It can be: 'distance': Link weights correspond to distances. Nodes that are close to each other will more likely be in the same module. 'similarity': Link weights correspond to similarity indices. Nodes that are similar to each other will more likely be in the same module. Inverse link weights are then used to compute the modularity index. `nb_modul` (optional , default = NULL) A numeric or integer value indicating the number of modules in the graph. When this number is not specified, the optimal value is retained.

### Value

A `data.frame` with the node names and the corresponding module ID.

P. Savary

### Examples

```data("data_tuto")
mat_gen <- data_tuto[]
graph <- gen_graph_thr(mat_w = mat_gen, mat_thr = mat_gen,
thr = 0.8)
res_mod <- compute_graph_modul(graph = graph,
algo = "fast_greedy",
node_inter = "distance")
```

graph4lg documentation built on Feb. 16, 2023, 5:43 p.m.