decimalr2dtable: Generates matrix with same marginal totals for non-negative...

View source: R/decimalr2dtable.R

decimalr2dtableR Documentation

Generates matrix with same marginal totals for non-negative decimal values

Description

Function to generate null model matrices for the cases when the matrix entries are non-negative numbers, possibly non-integers. It maintains marginal totals (as does r2dtable), but "smears" them out over all cells.

Usage

decimalr2dtable(N=10, web, steps=prod(dim(web)))

Arguments

N

Number of desired null model matrices.

web

An interaction matrix.

steps

Number of successive alterations of matrix entries. Defaults to 10 times the number of cells. See details.

Details

This function is a cross between r2dtable and swap.web. Its output are N matrices of the same dimension as the input, and with same marginal totals, but with different allocation of values to the cells. Here is what the algorithm does:

  1. Index a 2 x 2 submatrix by select randomly two rows and two columns.

  2. Draw a random value between 0 and the minimum of the diagonal entries in the submatrix.

  3. Subtract this value from the diagonals and add it to the counter-diagonal entries.

  4. Repeat steps times

The result is a decimal-numbered matrix, typically with values > 0 in each cell.

Indication: This function may be useful in some rare constellations. Imagine you sampled a plant-pollinator network and instead of counting the number of flower visits you recorded the nectar extracted by each pollinator. Then the marginal totals would indicate nectar production (plus confounding nectar attractiveness) and consumption potential for plants and pollinators, respectively. So, given that species differ in nectar production and consumption, what would you expect the network to look like? Enter decimalr2dtable.

If external abundances (even in funny units such as biovolume in ml) are available, this function can easily provide the respective null models. See examples.

Value

A list of N randomised matrices with the same dimensions as the initial web, all probably filled completely.

Note

The output will typically be a fully filled matrix! Computing any index sensitive to matrix filling (such as connectance, degree, nestedness) for such a matrix is non-sensical!

Also, if used as a null model, an implicit assumption is that the values in the original matrix are meaningful as marginal totals. This may often not be the case, for example if entries are rates. Thus, probably this function is of very limited usefulness in the context of network analyses!

Author(s)

Carsten F. Dormann <carsten.dormann@biom.uni-freiburg.de>

See Also

r2dtable, vaznull, shuffle.web and swap.web

Examples

obs <- networklevel(Safariland, index="generality")

nulls <- decimalr2dtable(10, Safariland)
g.dec <- sapply(nulls, networklevel, index="generality")
nullsint <- nullmodel(Safariland, N=10)
g.int <- sapply(nullsint, networklevel, index="generality")
plot(density(g.dec[1,]), xlim=c(1, 3))
lines(density(g.int[1,]), col="red")
abline(v=obs[1], col="green")


## If you want to use external abundances to set up your null model:
set.seed(1)
ext.rows <- runif(9) # imagine these are your external abundances for Safariland
ext.cols <- runif(27)
# standardise to sum = 1:
ext.rows <- ext.rows/sum(ext.rows)
ext.cols <- ext.rows/sum(ext.cols)
web <- tcrossprod(ext.rows, ext.cols) * sum(Safariland) 
# (to get to the same interaction density as original web)
#
# this can now be used as input for decimalr2dtable:
image(decimalr2dtable(N=1, web)[[1]]) # remember: white are high values!

bipartite documentation built on May 29, 2024, 2:23 a.m.