Learn R Programming

bipartite (version 2.16)

decimalr2dtable: 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.

Value

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

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.

See Also

r2dtable, vaznull, shuffle.web and swap.web

Examples

Run this code
# NOT RUN {
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!
# }

Run the code above in your browser using DataLab