PredationMatrixToLinks {cheddar} | R Documentation |
Predation matrix to trophic links
Description
A function that converts a predation matrix to a
data.frame
with the columns ‘resource’ and ‘consumer’.
Usage
PredationMatrixToLinks(pm, link.property=NULL)
Arguments
pm |
a |
link.property |
either |
Details
Returns a data.frame
of trophic links contained within
pm
. Non-zero and non-NA
values indicate a trophic link between
a resource (row) and consumer (column). pm
should have both row names
and column names. The returned data.frame
will contain the columns
‘resource’ and ‘consumer’. If pm
contains quantitative information
such as diet fractions or number of observations then you can set
link.property
to the name of the quantity and the returned
data.frame
will include a column with that name, that contains link
strength values extracted from pm
.
If you have existing food-web data in predation-matrix form then this function can help to import your data in to Cheddar.
Value
A data.frame
Author(s)
Lawrence Hudson
See Also
Community
,
PredationMatrix
,
TLPS
Examples
data(TL84)
links <- PredationMatrixToLinks(PredationMatrix(TL84))
identical(links, TLPS(TL84)) # TRUE
# Create a Cheddar community from an existing square predation matrix
node <- c('Leaf', 'Caterpillar', 'Bluetit')
pm <- matrix( c(0, 1, 0,
0, 0, 1,
0, 0, 0),
ncol=3, byrow=TRUE, dimnames=list(node, node))
community1 <- Community(nodes=data.frame(node=node),
trophic.links=PredationMatrixToLinks(pm),
properties=list(title='Test community'))
TLPS(community1)
# The same set of trophic links could be represented by a non-square predation
# matrix
pm <- matrix( c(1, 0,
0, 1),
ncol=2, byrow=TRUE,
dimnames=list(node[1:2], node[2:3]))
community2 <- Community(nodes=data.frame(node=node),
trophic.links=PredationMatrixToLinks(pm),
properties=list(title='Test community'))
TLPS(community2)
all.equal(community1, community2) # TRUE
# Extract quantitative information
node <- c('Leaf 1', 'Leaf 2', 'Caterpillar 1', 'Caterpillar 2')
pm <- matrix( c(0, 0, 0.4, 0.8,
0, 0, 0.6, 0.2,
0, 0, 0, 0,
0, 0, 0, 0),
ncol=4, byrow=TRUE, dimnames=list(node, node))
# A data.frame that has a column called diet.fraction
PredationMatrixToLinks(pm, link.property='diet.fraction')