Aggregates a vector of edge weights using various methods. Compatible with igraph's edge.attr.comb parameter.
Arguments
- w
Numeric vector of finite edge weights.
NAand zero weights are excluded before aggregation, so every method (including"density","min","max","prod","geomean") operates on the non-zero, non-NAsubset.- method
Single aggregation method: "sum", "mean", "median", "max", "min", "prod", "density", or "geomean". Because zeros are stripped first,
"density"(sum(w) / n_possible) and"mean"(sum(w) / number of non-zero edges) return the same value whenever the block is fully dense – i.e. when the count of non-zero edges equalsn_possible. They diverge only when zero/NAedges are present (then"density"divides by the largern_possible,"mean"by the smaller non-zero count).- n_possible
Optional single finite numeric number of possible edges for density calculation. When omitted,
"density"falls back tosum(w) / length(w)on the non-zero subset (equivalent to"mean"); supplyn_possible(e.g. the block sizen_i * n_j) for a true edge density.
Examples
w <- c(0.5, 0.8, 0.3, 0.9)
net_aggregate_weights(w, "sum") # 2.5
#> [1] 2.5
net_aggregate_weights(w, "mean") # 0.625
#> [1] 0.625
net_aggregate_weights(w, "max") # 0.9
#> [1] 0.9
net_aggregate_weights(w, "density", n_possible = 9) # 2.5 / 9
#> [1] 0.2777778