R/graph2effdist.r

Defines functions graph2effdist

Documented in graph2effdist

#' Calculate effective distances between nodes of a graph
#'
#' This function accepts an igraph object generated by package \code{\link{igraph}} and calcuates the effective distances.
#'
#' @param g An igraph object.
#' @param edge.attribute An attribute from the graph, e.g. weight.
#' @return A square matrix with effective distances between nodes.
#' @examples
#' # generates object 'units_effdist':
#' graph2effdist(units_igraph, edge.attribute = "weight")
#' @export graph2effdist

graph2effdist <- function(g, edge.attribute = NULL) {
  A <- igraph::as_adjacency_matrix(g, attr = edge.attribute, sparse = FALSE)
  p = A/rowSums(A)
  eff <- NetOrigin::eff_dist(p)
  return(eff)
}
joheli/yea13 documentation built on Sept. 18, 2020, 11:21 p.m.