R package to efficiently compute estimates for the maximum nestedness of graphs.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



maxnodf calculates the maximum NODF value that can be achieved in a bipartite network with a given number of rows, columns and links.


You can install maxnodf from github with:

install.packages("devtools") # install devtools if needed


maxnodf has one function: maxnodf(). For a given network, maxnodf calculates the maximum nestedness that can be achieved in a network with a given number of rows, columns and links, subject to the constraint that all rows and columns must have at least one link (i.e. row and column totals must always be >= 1). As input, maxnodf() takes either a numeric matrix describing a bipartite network (a bipartite incidence matrix where elements are positive numbers if nodes interact, and 0 otherwise) or a numeric vector of length three of the form c(#Rows, #Columns, #Links).

This allows nestedness values to be normalised as NODF/max(NODF) following Song et al (2017). To control for connectance and network size, Song et al. (2017) suggest an additional normalisation that can be used: (NODF/max(NODF))/(C * log(S)) where C is the network connectance and S is the geometric mean of the number of plants and pollinators in the network.

maxnodf has three algorithms for finding the maximum nestedness of a bipartite network. These can be set using the quality argument. Lower quality settings are faster, but find worse optima. Higher quality settings are slower, but find better optima.

  • quality = 0, uses a greedy algorithm.
  • quality = 1, uses a greedy algorithm plus hillclimbing.
  • quality = 2, uses a simulated annealing algorithm, with the greedy algorithm output as the start point. Best results, but requires the most computation time.


m <- matrix(0,10,10) # initialise an empty network
m[1,] <- 1 # ensure all row species have at least one link
m[,1] <- 1 # ensure all column species have at least one link
m[2:10,2:10] <- sample(0:1, 9 * 9, replace = TRUE) # randomise the rest of the matrix
maxnodf(web = m, quality = 2) # calculate the maximum nestedness


The code is released under the MIT license (see LICENSE file).


Song, C., Rohr, R.P. and Saavedra, S., 2017. Why are some plant–pollinator networks more nested than others?. Journal of Animal Ecology, 86(6), pp.1417-1424.