find_optimal_resolution: Find Optimal Resolution for Louvain Clustering

View source: R/utils.R

find_optimal_resolutionR Documentation

Find Optimal Resolution for Louvain Clustering

Description

This function iterates over a range of resolution values to find the optimal resolution for Louvain clustering, balancing the number of clusters and modularity. It aims to identify a resolution that results in a reasonable number of clusters while maintaining a high modularity score.

Usage

find_optimal_resolution(
  graph,
  start_resolution = 0.1,
  end_resolution = 10,
  resolution_increment = 0.1,
  min_modularity = 0.3,
  target_clusters_range = c(3, 6)
)

Arguments

graph

An igraph object representing the graph to be clustered.

start_resolution

Numeric. The starting resolution for the Louvain algorithm. Default is 0.1.

end_resolution

Numeric. The maximum resolution to test. Default is 10.

resolution_increment

Numeric. The increment to adjust the resolution at each step. Default is 0.1.

min_modularity

Numeric. The minimum acceptable modularity for valid clusterings. Default is 0.3.

target_clusters_range

Numeric vector of length 2. Specifies the acceptable range for the number of clusters (inclusive). Default is c(3, 6).

Details

The function performs Louvain clustering at different resolutions, starting from start_resolution and ending at end_resolution, incrementing by resolution_increment at each step. At each resolution, the function calculates the number of clusters and modularity. The results are filtered to select those where modularity exceeds min_modularity and the number of clusters falls within the specified range target_clusters_range. The optimal resolution is chosen based on the most frequent number of clusters and the median resolution that satisfies these criteria.

Value

A list containing:

selected

A list with the optimal resolution, best modularity, and number of clusters.

frequent_clusters_results

A data frame containing results for resolutions that yielded the most frequent number of clusters.

all_results

A data frame with the resolution, number of clusters, and modularity for all tested resolutions.


immunaut documentation built on April 12, 2025, 1:22 a.m.