Description Usage Arguments Value Details Examples
View source: R/make_diet_rand.R
The function make_diet_rand
generates a user-specified number of
random diet compositions.
1 | make_diet_rand(uniq_types, n_diet)
|
uniq_types |
A factor of unique prey-type names. |
n_diet |
The integer number of diet compositions to generate. |
A list containing the following elements:
A numeric matrix of random diet compositions, in column-major format.
An integer error code (0 if no error is detected).
A string contains a brief summary of the execution.
The function make_diet_rand
generates a specified number of random
diet compositions to support simulation-based research of the performance
of QFASA diet estimation procedures. Given a diet composition, predator
fatty acid signatures can be generated using the
function make_pred_sigs
. The diets of such simulated predators
can then be estimated, and the diet estimates can be compared to the
known diet composition to evaluate bias, variance, and perhaps other
properties.
The algorithm starts by generating a uniformly distributed random number between 0 and 1 as the diet proportion for the first prey type. The algorithm then considers each additional prey type in turn, generating a uniform random number between zero and 1 minus the sum of the proportions assigned to the preceding prey types. The diet proportion for the last prey type is 1 minus the sum of the other diet proportions. As a hedge against limitations in the random number generator, the proportions are then randomly ordered among prey types.
It is critical that the prey-type names match those in the prey library. The
easiest way to ensure this happens is to pass the object uniq_types returned
a call to the function prep_sig
as the uniq_types argument.
Alternatively, and more risky, a vector of unique prey names can be created
using the concatenate function and cast as a factor, i.e.,
uniq_types <- as.factor(c("Prey_1", "Prey_2", ..., "Prey_P)).
1 2 3 4 5 6 7 8 | make_diet_rand(uniq_types = as.factor(c("Bearded",
"Beluga",
"Bowhead",
"Ribbon",
"Ringed",
"Spotted",
"Walrus")),
n_diet = 100)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.