R/reduceNetwork.R

Defines functions .reduceNetwork

# .reduceNetwork extract a subnetwork by relative or absolute thresholding

.reduceNetwork <- function(network, N = 0, Threshold = 0) {
  network <- as.array(network)
  if ((N > 0) && (Threshold > 0)) {
    warning("both N and Threshold set, N takes precedence")
  }

  up <- upper.tri(network)
  thresh <- Threshold
  if (N > 0) {
    thresh <- sort(network[up], decreasing = TRUE)[N]
  }
  subnet <- network * (network >= thresh)

  nodelist <- which(rowSums(subnet) > 0)
  subnet <- subnet[nodelist, nodelist]

  return(list(network = subnet, nodelist = nodelist))
}
ANTsX/ANTsR documentation built on March 29, 2025, 6:24 p.m.