Title: | Microbiome Data Simulation |
---|---|
Description: | Microbiome time series simulation with generalized Lotka-Volterra model, Self-Organized Instability (SOI), and other models. Hubbell's Neutral model is used to determine the abundance matrix. The resulting abundance matrix is applied to (Tree)SummarizedExperiment objects. |
Authors: | Yagmur Simsek [cre, aut], Karoline Faust [aut], Yu Gao [aut], Emma Gheysen [aut], Daniel Rios Garza [aut], Tuomas Borman [aut] , Leo Lahti [aut] |
Maintainer: | Yagmur Simsek <[email protected]> |
License: | Artistic-2.0 | file LICENSE |
Version: | 1.13.0 |
Built: | 2024-10-30 08:50:56 UTC |
Source: | https://github.com/bioc/miaSim |
A helper function to be used in combination with .getInteractions()
.applyInterType(I, pair, interType)
.applyInterType(I, pair, interType)
I |
Matrix: defining the interaction between each pair of species |
pair |
Numeric: a vector with a length of 2, indicating the 2 focusing species in the process of applying the interaction types |
interType |
Character: one of 'mutualism', 'commensalism', 'parasitism', 'amensalism', or 'competition'. Defining the interaction type |
A matrix of interaction types with one pair changed
generate matrix A from the comparisons between simulations with one absent species and a simulation with complete species (leave-one-out)
.estimateAFromSimulations( simulations, simulations2, n_instances = 1, t_end = NULL, scale_off_diagonal = 0.1, diagonal = -0.5, connectance = 0.2 )
.estimateAFromSimulations( simulations, simulations2, n_instances = 1, t_end = NULL, scale_off_diagonal = 0.1, diagonal = -0.5, connectance = 0.2 )
simulations |
A list of simulation(s) with complete species |
simulations2 |
A list of simulation(s), each with one absent species |
n_instances |
Integer: number of instances to generate
(default: |
t_end |
Numeric: end time of the simulation. If not identical with t_end
in params_list, then it will overwrite t_end in each simulation
(default: |
scale_off_diagonal |
Numeric: scale of the off-diagonal elements
compared to the diagonal. Same to the parameter in function |
diagonal |
Values defining the strength of self-interactions. Input can
be a number (will be applied to all species) or a vector of length n_species.
Positive self-interaction values lead to exponential growth. Same to the
parameter in function |
connectance |
Numeric frequency of inter-species interactions.
i.e. proportion of non-zero off-diagonal terms. Should be in the interval
0 <= connectance <= 1. Same to the parameter in function |
a matrix A with dimensions (n_species x n_species) where n_species equals to the number of elements in simulations2
generate a vector of times when events is happening
.eventTimes(t_events = NULL, t_duration = NULL, t_end = 1000, ...)
.eventTimes(t_events = NULL, t_duration = NULL, t_end = 1000, ...)
t_events , t_duration
|
Numeric: vector of starting time and duration of the events |
t_end |
Numeric: end time of the simulation |
... |
: additional parameters to pass to simulationTimes, including t_start, t_step, and t_store. |
A vector of time points in the simulation
tEvent <- .eventTimes( t_events = c(10, 50, 100), t_duration = c(1, 2, 3), t_end = 100, t_store = 100, t_step = 1 )
tEvent <- .eventTimes( t_events = c(10, 50, 100), t_duration = c(1, 2, 3), t_end = 100, t_store = 100, t_step = 1 )
Generate interactions according to five types of interactions and their weights
.getInteractions(n_species, weights, connectance)
.getInteractions(n_species, weights, connectance)
n_species |
Integer: defining the dimension of matrix of interaction |
weights |
Numeric: defining the weights of mutualism, commensalism, parasitism, amensalism, and competition in all interspecies interactions. |
connectance |
Numeric: defining the density of the interaction network. Ranging from 0 to 1 |
A matrix of interactions with all interactions changed according to the weights and connectance.
check whether a number is a positive integer
.isPosInt(x, tol = .Machine$double.eps^0.5)
.isPosInt(x, tol = .Machine$double.eps^0.5)
x |
Numeric number to test |
tol |
Numeric tolerance of detection |
A logical value: whether the number is a positive integer.
Generate dirichlet random deviates
.rdirichlet(n, alpha)
.rdirichlet(n, alpha)
n |
Number of random vectors to generate. |
alpha |
Vector containing shape parameters. |
a vector containing the Dirichlet density
dirichletExample <- .rdirichlet(1, c(1, 2, 3))
dirichletExample <- .rdirichlet(1, c(1, 2, 3))
If the list contains m elements, then lengths of each element must be m, too.
This function is intended to generate a list of x0 (the initial community)
with one missing species, to prepare the parameter simulations_compare in
estimateAFromSimulations
.
.replaceByZero(input_list)
.replaceByZero(input_list)
input_list |
A list containing m elements, and lengths of each element must be m, too. |
A list of same dimension as input_list, but with 0 at specific positions in the elements of the list.
N is the an Interspecific Interaction matrix with values drawn from a normal distribution H the interaction strength heterogeneity drawn from a power-law distribution with the parameter alpha, and G the adjacency matrix of with out-degree that reflects the heterogeneity of the powerlaw. A scaling factor s may be used to constrain the values of the interaction matrix to be within a desired range. Diagonal elements of A are defined by the parameter d.
powerlawA(n_species, alpha = 3, stdev = 1, s = 0.1, d = -1, symmetric = FALSE)
powerlawA(n_species, alpha = 3, stdev = 1, s = 0.1, d = -1, symmetric = FALSE)
n_species |
integer number of species |
alpha |
numeric power-law distribution parameter. Should be > 1.
(default: |
stdev |
numeric standard deviation parameter of the normal
distribution with mean 0 from which the elements of the nominal interspecific
interaction matrix N are drawn. (default: |
s |
numeric scaling parameter with which the final global
interaction matrix A is multiplied. (default: |
d |
numeric diagonal values, indicating self-interactions (use
negative values for stability). (default: |
symmetric |
logical scalar returning a symmetric interaction matrix
(default: |
The interaction matrix A with dimensions (n_species x n_species)
Gibson TE, Bashan A, Cao HT, Weiss ST, Liu YY (2016) On the Origins and Control of Community Types in the Human Microbiome. PLOS Computational Biology 12(2): e1004688. https://doi.org/10.1371/journal.pcbi.1004688
# Low interaction heterogeneity A_low <- powerlawA(n_species = 10, alpha = 3) # Strong interaction heterogeneity A_strong <- powerlawA(n_species = 10, alpha = 1.01)
# Low interaction heterogeneity A_low <- powerlawA(n_species = 10, alpha = 3) # Strong interaction heterogeneity A_strong <- powerlawA(n_species = 10, alpha = 1.01)
Generates a random interaction matrix for Generalized Lotka-Volterra (GLV) model.
randomA( n_species, names_species = NULL, diagonal = -0.5, connectance = 0.2, scale_off_diagonal = 0.1, mutualism = 1, commensalism = 1, parasitism = 1, amensalism = 1, competition = 1, interactions = NULL, symmetric = FALSE, list_A = NULL )
randomA( n_species, names_species = NULL, diagonal = -0.5, connectance = 0.2, scale_off_diagonal = 0.1, mutualism = 1, commensalism = 1, parasitism = 1, amensalism = 1, competition = 1, interactions = NULL, symmetric = FALSE, list_A = NULL )
n_species |
Integer: number of species |
names_species |
Character: names of species. If NULL,
|
diagonal |
Values defining the strength of self-interactions. Input can
be a number (will be applied to all species) or a vector of length n_species.
Positive self-interaction values lead to exponential growth.
(default: |
connectance |
Numeric frequency of inter-species interactions.
i.e. proportion of non-zero off-diagonal terms.
Should be in the interval 0 <= connectance <= 1.
(default: |
scale_off_diagonal |
Numeric: scale of the off-diagonal elements
compared to the diagonal.
(default: |
mutualism |
Numeric: relative proportion of interactions terms
consistent with mutualism (positive <-> positive)
(default: |
commensalism |
Numeric: relative proportion of interactions terms
consistent with commensalism (positive <-> neutral)
(default: |
parasitism |
Numeric: relative proportion of interactions terms
consistent with parasitism (positive <-> negative)
(default: |
amensalism |
Numeric: relative proportion of interactions terms
consistent with amensalism (neutral <-> negative)
(default: |
competition |
Numeric: relative proportion of interactions terms
consistent with competition (negative <-> negative)
(default: |
interactions |
Numeric: values of the n_species^2 pairwise interaction
strengths. Diagonal terms will be replaced by the 'diagonal' parameter
If NULL, interactions are drawn from
|
symmetric |
Logical: whether the strength of mutualistic and competitive
interactions are symmetric. This is implemented by overwrite a half of the
matrix, so the proportions of interactions might deviate from expectations.
(default: |
list_A |
List: a list of matrices generated by randomA. Used to support
different groups of interactions. If NULL (by default), no group is
considered. Otherwise the given list of matrices will overwrite values around
the diagonal.
(default: |
randomA
returns a matrix A with dimensions (n_species x n_species)
dense_A <- randomA( n_species = 10, scale_off_diagonal = 1, diagonal = -1.0, connectance = 0.9 ) sparse_A <- randomA( n_species = 10, diagonal = -1.0, connectance = 0.09 ) user_interactions <- rbeta(n = 10^2, .5, .5) user_A <- randomA(n_species = 10, interactions = user_interactions) competitive_A <- randomA( n_species = 10, mutualism = 0, commensalism = 0, parasitism = 0, amensalism = 0, competition = 1, connectance = 1, scale_off_diagonal = 1 ) parasitism_A <- randomA( n_species = 10, mutualism = 0, commensalism = 0, parasitism = 1, amensalism = 0, competition = 0, connectance = 1, scale_off_diagonal = 1, symmetric = TRUE ) list_A <- list(dense_A, sparse_A, competitive_A, parasitism_A) groupA <- randomA(n_species = 40, list_A = list_A)
dense_A <- randomA( n_species = 10, scale_off_diagonal = 1, diagonal = -1.0, connectance = 0.9 ) sparse_A <- randomA( n_species = 10, diagonal = -1.0, connectance = 0.09 ) user_interactions <- rbeta(n = 10^2, .5, .5) user_A <- randomA(n_species = 10, interactions = user_interactions) competitive_A <- randomA( n_species = 10, mutualism = 0, commensalism = 0, parasitism = 0, amensalism = 0, competition = 1, connectance = 1, scale_off_diagonal = 1 ) parasitism_A <- randomA( n_species = 10, mutualism = 0, commensalism = 0, parasitism = 1, amensalism = 0, competition = 0, connectance = 1, scale_off_diagonal = 1, symmetric = TRUE ) list_A <- list(dense_A, sparse_A, competitive_A, parasitism_A) groupA <- randomA(n_species = 40, list_A = list_A)
Generate random efficiency matrix for consumer resource model from Dirichlet distribution, where positive efficiencies indicate the consumption of resources, whilst negatives indicate that the species would produce the resource.
randomE( n_species, n_resources, names_species = NULL, names_resources = NULL, mean_consumption = n_resources/4, mean_production = n_resources/6, maintenance = 0.5, trophic_levels = NULL, trophic_preferences = NULL, exact = FALSE )
randomE( n_species, n_resources, names_species = NULL, names_resources = NULL, mean_consumption = n_resources/4, mean_production = n_resources/6, maintenance = 0.5, trophic_levels = NULL, trophic_preferences = NULL, exact = FALSE )
n_species |
Integer: number of species |
n_resources |
Integer: number of resources |
names_species |
Character: names of species. If NULL,
|
names_resources |
Character: names of resources. If NULL,
|
mean_consumption |
Numeric: mean number of resources consumed by each
species drawn from a poisson distribution
(default: |
mean_production |
Numeric: mean number of resources produced by each
species drawn from a poisson distribution
(default: |
maintenance |
Numeric: proportion of resources that cannot be converted
into products
between 0~1 the proportion of resources used
to maintain the living of microorganisms. 0 means all the resources will be
used for the reproduction of microorganisms, and 1 means all the resources
would be used to maintain the living of organisms and no resources would be
left for their growth(reproduction).
(default: |
trophic_levels |
Integer: number of species in microbial trophic levels.
If NULL, by default, microbial trophic levels would not be considered.
(default: |
trophic_preferences |
List: preferred resources and productions of each trophic level. Positive values indicate the consumption of resources, whilst negatives indicate that the species would produce the resource. |
exact |
Logical: whether to set the number of consumption/production to
be exact as mean_consumption/mean_production or to set them using a Poisson
distribution.
(default: |
randomE
returns a matrix E with dimensions (n_species x n_resources),
and each row represents a species.
# example with minimum parameters ExampleEfficiencyMatrix <- randomE(n_species = 5, n_resources = 12) # examples with specific parameters ExampleEfficiencyMatrix <- randomE( n_species = 3, n_resources = 6, names_species = letters[1:3], names_resources = paste0("res", LETTERS[1:6]), mean_consumption = 3, mean_production = 1 ) ExampleEfficiencyMatrix <- randomE( n_species = 3, n_resources = 6, maintenance = 0.4 ) ExampleEfficiencyMatrix <- randomE( n_species = 3, n_resources = 6, mean_consumption = 3, mean_production = 1, maintenance = 0.4 ) # examples with microbial trophic levels ExampleEfficiencyMatrix <- randomE( n_species = 10, n_resources = 15, trophic_levels = c(6, 3, 1), trophic_preferences = list( c(rep(1, 5), rep(-1, 5), rep(0, 5)), c(rep(0, 5), rep(1, 5), rep(-1, 5)), c(rep(0, 10), rep(1, 5)) ) ) ExampleEfficiencyMatrix <- randomE( n_species = 10, n_resources = 15, trophic_levels = c(6, 3, 1), trophic_preferences = list(c(rep(1, 5), rep(-1, 5), rep(0, 5)), NULL, NULL) ) ExampleEfficiencyMatrix <- randomE( n_species = 10, n_resources = 15, trophic_levels = c(6, 3, 1) )
# example with minimum parameters ExampleEfficiencyMatrix <- randomE(n_species = 5, n_resources = 12) # examples with specific parameters ExampleEfficiencyMatrix <- randomE( n_species = 3, n_resources = 6, names_species = letters[1:3], names_resources = paste0("res", LETTERS[1:6]), mean_consumption = 3, mean_production = 1 ) ExampleEfficiencyMatrix <- randomE( n_species = 3, n_resources = 6, maintenance = 0.4 ) ExampleEfficiencyMatrix <- randomE( n_species = 3, n_resources = 6, mean_consumption = 3, mean_production = 1, maintenance = 0.4 ) # examples with microbial trophic levels ExampleEfficiencyMatrix <- randomE( n_species = 10, n_resources = 15, trophic_levels = c(6, 3, 1), trophic_preferences = list( c(rep(1, 5), rep(-1, 5), rep(0, 5)), c(rep(0, 5), rep(1, 5), rep(-1, 5)), c(rep(0, 10), rep(1, 5)) ) ) ExampleEfficiencyMatrix <- randomE( n_species = 10, n_resources = 15, trophic_levels = c(6, 3, 1), trophic_preferences = list(c(rep(1, 5), rep(-1, 5), rep(0, 5)), NULL, NULL) ) ExampleEfficiencyMatrix <- randomE( n_species = 10, n_resources = 15, trophic_levels = c(6, 3, 1) )
Simulates time series with the consumer-resource model.
simulateConsumerResource( n_species, n_resources, names_species = NULL, names_resources = NULL, E = NULL, x0 = NULL, resources = NULL, resources_dilution = NULL, growth_rates = NULL, monod_constant = NULL, sigma_drift = 0.001, sigma_epoch = 0.1, sigma_external = 0.3, sigma_migration = 0.01, epoch_p = 0.001, t_external_events = NULL, t_external_durations = NULL, stochastic = FALSE, migration_p = 0.01, metacommunity_probability = NULL, error_variance = 0, norm = FALSE, t_end = 1000, trophic_priority = NULL, inflow_rate = 0, outflow_rate = 0, volume = 1000, ... )
simulateConsumerResource( n_species, n_resources, names_species = NULL, names_resources = NULL, E = NULL, x0 = NULL, resources = NULL, resources_dilution = NULL, growth_rates = NULL, monod_constant = NULL, sigma_drift = 0.001, sigma_epoch = 0.1, sigma_external = 0.3, sigma_migration = 0.01, epoch_p = 0.001, t_external_events = NULL, t_external_durations = NULL, stochastic = FALSE, migration_p = 0.01, metacommunity_probability = NULL, error_variance = 0, norm = FALSE, t_end = 1000, trophic_priority = NULL, inflow_rate = 0, outflow_rate = 0, volume = 1000, ... )
n_species |
Integer: number of species |
n_resources |
Integer: number of resources |
names_species |
Character: names of species. If NULL,
|
names_resources |
Character: names of resources. If NULL,
|
E |
matrix: matrix of efficiency. A matrix defining the efficiency of
resource-to-biomass conversion (positive values) and the relative conversion
of metabolic by-products (negative values). If NULL,
|
x0 |
Numeric: initial abundances of simulated species. If NULL,
|
resources |
Numeric: initial concentrations of resources. If NULL,
|
resources_dilution |
Numeric: concentrations of resources in the
continuous inflow (applicable when inflow_rate > 0). If NULL,
|
growth_rates |
Numeric: vector of maximum growth rates(mu) of species.
If NULL, |
monod_constant |
matrix: the constant of additive monod growth of
n_species consuming n_resources. If NULL,
|
sigma_drift |
Numeric: standard deviation of a normally distributed
noise applied in each time step (t_step)
(default: |
sigma_epoch |
Numeric: standard deviation of a normally distributed
noise applied to random periods of the community composition with frequency
defined by the epoch_p parameter
(default: |
sigma_external |
Numeric: standard deviation of a normally distributed
noise applied to user-defined external events/disturbances
(default: |
sigma_migration |
Numeric: standard deviation of a normally distributed
variable that defines the intensity of migration at each time step (t_step)
(default: |
epoch_p |
Numeric: the probability/frequency of random periodic
changes introduced to the community composition
(default: |
t_external_events |
Numeric: the starting time points of defined
external events that introduce random changes to the community composition
(default: |
t_external_durations |
Numeric: respective duration of the external
events that are defined in the 't_external_events' (times) and
sigma_external (std).
(default: |
stochastic |
Logical: whether to introduce noise in the simulation.
If False, sigma_drift, sigma_epoch, and sigma_external are ignored.
(default: |
migration_p |
Numeric: the probability/frequency of migration from a
metacommunity.
(default: |
metacommunity_probability |
Numeric: Normalized probability distribution
of the likelihood that species from the metacommunity can enter the community
during the simulation. If NULL, |
error_variance |
Numeric: the variance of measurement error.
By default it equals to 0, indicating that the result won't contain any
measurement error. This value should be non-negative.
(default: |
norm |
Logical: whether the time series should be returned with
the abundances as proportions ( |
t_end |
Numeric: the end time of the simulationTimes, defining the
modeled time length of the community.
(default: |
trophic_priority |
Matrix: a matrix defining the orders of resources to
be consumed by each species. If NULL, by default, this feature won't be
turned on, and species will consume all resources simultaneously to grow.
The dimension should be identical to matrix E.
(default: |
inflow_rate , outflow_rate
|
Numeric: the inflow and outflow rate of a culture process. By default, inflow_rate and outflow_rate are 0, indicating a batch culture process. By setting them equally larger than 0, we can simulate a continuous culture(e.g. chemostat). |
volume |
Numeric: the volume of the continuous cultivation. This
parameter is important for simulations where inflow_rate or outflow_rate are
not 0.
(default: |
... |
additional parameters, see |
an TreeSummarizedExperiment class object
n_species <- 2 n_resources <- 4 tse <- simulateConsumerResource( n_species = n_species, n_resources = n_resources ) # example with user-defined values (names_species, names_resources, E, x0, # resources, growth_rates, error_variance, t_end, t_step) ExampleE <- randomE( n_species = n_species, n_resources = n_resources, mean_consumption = 3, mean_production = 1, maintenance = 0.4 ) ExampleResources <- rep(100, n_resources) tse1 <- simulateConsumerResource( n_species = n_species, n_resources = n_resources, names_species = letters[seq_len(n_species)], names_resources = paste0("res", LETTERS[seq_len(n_resources)]), E = ExampleE, x0 = rep(0.001, n_species), resources = ExampleResources, growth_rates = runif(n_species), error_variance = 0.01, t_end = 5000, t_step = 1 ) # example with trophic levels n_species <- 10 n_resources <- 15 ExampleEfficiencyMatrix <- randomE( n_species = 10, n_resources = 15, trophic_levels = c(6, 3, 1), trophic_preferences = list( c(rep(1, 5), rep(-1, 5), rep(0, 5)), c(rep(0, 5), rep(1, 5), rep(-1, 5)), c(rep(0, 10), rep(1, 5)) ) ) ExampleResources <- c(rep(500, 5), rep(200, 5), rep(50, 5)) tse2 <- simulateConsumerResource( n_species = n_species, n_resources = n_resources, names_species = letters[1:n_species], names_resources = paste0( "res", LETTERS[1:n_resources] ), E = ExampleEfficiencyMatrix, x0 = rep(0.001, n_species), resources = ExampleResources, growth_rates = rep(1, n_species), # error_variance = 0.001, t_end = 5000, t_step = 1 ) # example with trophic priority n_species <- 4 n_resources <- 6 ExampleE <- randomE( n_species = n_species, n_resources = n_resources, mean_consumption = n_resources, mean_production = 0 ) ExampleTrophicPriority <- t(apply( matrix(sample(n_species * n_resources), nrow = n_species ), 1, order )) # make sure that for non-consumables resources for each species, # the priority is 0 (smaller than any given priority) ExampleTrophicPriority <- (ExampleE > 0) * ExampleTrophicPriority tse3 <- simulateConsumerResource( n_species = n_species, n_resources = n_resources, E = ExampleE, trophic_priority = ExampleTrophicPriority, t_end = 2000 )
n_species <- 2 n_resources <- 4 tse <- simulateConsumerResource( n_species = n_species, n_resources = n_resources ) # example with user-defined values (names_species, names_resources, E, x0, # resources, growth_rates, error_variance, t_end, t_step) ExampleE <- randomE( n_species = n_species, n_resources = n_resources, mean_consumption = 3, mean_production = 1, maintenance = 0.4 ) ExampleResources <- rep(100, n_resources) tse1 <- simulateConsumerResource( n_species = n_species, n_resources = n_resources, names_species = letters[seq_len(n_species)], names_resources = paste0("res", LETTERS[seq_len(n_resources)]), E = ExampleE, x0 = rep(0.001, n_species), resources = ExampleResources, growth_rates = runif(n_species), error_variance = 0.01, t_end = 5000, t_step = 1 ) # example with trophic levels n_species <- 10 n_resources <- 15 ExampleEfficiencyMatrix <- randomE( n_species = 10, n_resources = 15, trophic_levels = c(6, 3, 1), trophic_preferences = list( c(rep(1, 5), rep(-1, 5), rep(0, 5)), c(rep(0, 5), rep(1, 5), rep(-1, 5)), c(rep(0, 10), rep(1, 5)) ) ) ExampleResources <- c(rep(500, 5), rep(200, 5), rep(50, 5)) tse2 <- simulateConsumerResource( n_species = n_species, n_resources = n_resources, names_species = letters[1:n_species], names_resources = paste0( "res", LETTERS[1:n_resources] ), E = ExampleEfficiencyMatrix, x0 = rep(0.001, n_species), resources = ExampleResources, growth_rates = rep(1, n_species), # error_variance = 0.001, t_end = 5000, t_step = 1 ) # example with trophic priority n_species <- 4 n_resources <- 6 ExampleE <- randomE( n_species = n_species, n_resources = n_resources, mean_consumption = n_resources, mean_production = 0 ) ExampleTrophicPriority <- t(apply( matrix(sample(n_species * n_resources), nrow = n_species ), 1, order )) # make sure that for non-consumables resources for each species, # the priority is 0 (smaller than any given priority) ExampleTrophicPriority <- (ExampleE > 0) * ExampleTrophicPriority tse3 <- simulateConsumerResource( n_species = n_species, n_resources = n_resources, E = ExampleE, trophic_priority = ExampleTrophicPriority, t_end = 2000 )
Simulates time series with the generalized Lotka-Volterra model.
simulateGLV( n_species, names_species = NULL, A = NULL, x0 = NULL, growth_rates = NULL, sigma_drift = 0.001, sigma_epoch = 0.1, sigma_external = 0.3, sigma_migration = 0.01, epoch_p = 0.001, t_external_events = NULL, t_external_durations = NULL, stochastic = TRUE, migration_p = 0.01, metacommunity_probability = NULL, error_variance = 0, norm = FALSE, t_end = 1000, ... )
simulateGLV( n_species, names_species = NULL, A = NULL, x0 = NULL, growth_rates = NULL, sigma_drift = 0.001, sigma_epoch = 0.1, sigma_external = 0.3, sigma_migration = 0.01, epoch_p = 0.001, t_external_events = NULL, t_external_durations = NULL, stochastic = TRUE, migration_p = 0.01, metacommunity_probability = NULL, error_variance = 0, norm = FALSE, t_end = 1000, ... )
n_species |
Integer: number of species |
names_species |
Character: names of species. If NULL,
|
A |
matrix: interaction matrix defining the positive and negative
interactions between n_species. If NULL, |
x0 |
Numeric: initial abundances of simulated species. If NULL,
|
growth_rates |
Numeric: growth rates of simulated species. If NULL,
|
sigma_drift |
Numeric: standard deviation of a normally distributed
noise applied in each time step (t_step)
(default: |
sigma_epoch |
Numeric: standard deviation of a normally distributed
noise applied to random periods of the community composition with frequency
defined by the epoch_p parameter
(default: |
sigma_external |
Numeric: standard deviation of a normally distributed
noise applied to user-defined external events/disturbances
(default: |
sigma_migration |
Numeric: standard deviation of a normally distributed
variable that defines the intensity of migration at each time step (t_step)
(default: |
epoch_p |
Numeric: the probability/frequency of random periodic
changes introduced to the community composition
(default: |
t_external_events |
Numeric: the starting time points of defined
external events that introduce random changes to the community composition
(default: |
t_external_durations |
Numeric: respective duration of the external
events that are defined in the 't_external_events' (times) and
sigma_external (std).
(default: |
stochastic |
Logical: whether to introduce noise in the simulation.
If False, sigma_drift, sigma_epoch, and sigma_external are ignored.
(default: |
migration_p |
Numeric: the probability/frequency of migration from a
metacommunity.
(default: |
metacommunity_probability |
Numeric: Normalized probability distribution
of the likelihood that species from the metacommunity can enter the community
during the simulation. If NULL, |
error_variance |
Numeric: the variance of measurement error.
By default it equals to 0, indicating that the result won't contain any
measurement error. This value should be non-negative.
(default: |
norm |
Logical: whether the time series should be returned with
the abundances as proportions ( |
t_end |
Numeric: the end time of the simulationTimes, defining the
modeled time length of the community.
(default: |
... |
additional parameters, see |
Simulates a community time series using the generalized Lotka-Volterra model, defined as dx/dt = x(b+Ax), where x is the vector of species abundances, diag(x) is a diagonal matrix with the diagonal values set to x. A is the interaction matrix and b is the vector of growth rates.
simulateGLV
returns a TreeSummarizedExperiment class object
# generate a random interaction matrix ExampleA <- randomA(n_species = 4, diagonal = -1) # run the model with default values (only stochastic migration considered) tse <- simulateGLV(n_species = 4, A = ExampleA) # run the model with two external disturbances at time points 240 and 480 # with durations equal to 1 (10 time steps when t_step by default is 0.1). ExampleGLV <- simulateGLV( n_species = 4, A = ExampleA, t_external_events = c(0, 240, 480), t_external_durations = c(0, 1, 1) ) # run the model with no perturbation nor migration set.seed(42) tse1 <- simulateGLV( n_species = 4, A = ExampleA, stochastic = FALSE, sigma_migration = 0 ) # run the model with no perturbation nor migration but with measurement error set.seed(42) tse2 <- simulateGLV( n_species = 4, A = ExampleA, stochastic = FALSE, error_variance = 0.001, sigma_migration = 0 )
# generate a random interaction matrix ExampleA <- randomA(n_species = 4, diagonal = -1) # run the model with default values (only stochastic migration considered) tse <- simulateGLV(n_species = 4, A = ExampleA) # run the model with two external disturbances at time points 240 and 480 # with durations equal to 1 (10 time steps when t_step by default is 0.1). ExampleGLV <- simulateGLV( n_species = 4, A = ExampleA, t_external_events = c(0, 240, 480), t_external_durations = c(0, 1, 1) ) # run the model with no perturbation nor migration set.seed(42) tse1 <- simulateGLV( n_species = 4, A = ExampleA, stochastic = FALSE, sigma_migration = 0 ) # run the model with no perturbation nor migration but with measurement error set.seed(42) tse2 <- simulateGLV( n_species = 4, A = ExampleA, stochastic = FALSE, error_variance = 0.001, sigma_migration = 0 )
Neutral species abundances simulation according to the Hubbell model.
simulateHubbell( n_species, M, carrying_capacity = 1000, k_events = 10, migration_p = 0.02, t_skip = 0, t_end, norm = FALSE )
simulateHubbell( n_species, M, carrying_capacity = 1000, k_events = 10, migration_p = 0.02, t_skip = 0, t_end, norm = FALSE )
n_species |
integer amount of different species initially in the local community |
M |
integer amount of different species in the metacommunity, including those of the local community |
carrying_capacity |
integer value of fixed amount of individuals in the local community
(default: |
k_events |
integer value of fixed amount of deaths of local community
individuals in each generation (default: |
migration_p |
numeric immigration rate: the probability that a death in the local
community is replaced by a migrant of the metacommunity rather than by
the birth of a local community member (default: |
t_skip |
integer number of generations that should not be included
in the outputted species abundance matrix. (default: |
t_end |
integer number of simulations to be simulated |
norm |
logical scalar choosing whether the time series should be
returned with the abundances as proportions ( |
simulateHubbell
returns a TreeSummarizedExperiment class
object
Rosindell, James et al. "The unified neutral theory of biodiversity and biogeography at age ten." Trends in ecology & evolution vol. 26,7 (2011).
tse <- simulateHubbell( n_species = 8, M = 10, carrying_capacity = 1000, k_events = 50, migration_p = 0.02, t_end = 100 )
tse <- simulateHubbell( n_species = 8, M = 10, carrying_capacity = 1000, k_events = 50, migration_p = 0.02, t_end = 100 )
Neutral species abundances simulation according to the Hubbell model. This model shows that losses in society can be replaced either by the birth of individuals or by immigration depending on their probabilities. The specific time between the events of birth or migration is calculated and time effect is considered to determine the next event.
simulateHubbellRates( n_species = NULL, x0 = NULL, names_species = NULL, migration_p = 0.01, metacommunity_probability = NULL, k_events = 1, growth_rates = NULL, error_variance = 0, norm = FALSE, t_end = 1000, ... )
simulateHubbellRates( n_species = NULL, x0 = NULL, names_species = NULL, migration_p = 0.01, metacommunity_probability = NULL, k_events = 1, growth_rates = NULL, error_variance = 0, norm = FALSE, t_end = 1000, ... )
n_species |
Integer: number of species |
x0 |
Numeric: initial species composition. If NULL,
|
names_species |
Character: names of species. If NULL,
|
migration_p |
Numeric: the probability/frequency of migration from a
metacommunity.
(default: |
metacommunity_probability |
Numeric: Normalized probability distribution
of the likelihood that species from the metacommunity can enter the community
during the simulation. If NULL, |
k_events |
Integer: number of events to simulate before updating the
sampling distributions.
(default: |
growth_rates |
Numeric: maximum growth rates(mu) of species.
If NULL, |
error_variance |
Numeric: the variance of measurement error.
By default it equals to 0, indicating that the result won't contain any
measurement error. This value should be non-negative.
(default: |
norm |
Logical: whether the time series should be returned with
the abundances as proportions ( |
t_end |
Numeric: the end time of the simulationTimes, defining the
modeled time length of the community.
(default: |
... |
additional parameters, see |
simulateHubbellRates
returns a TreeSummarizedExperiment class
object
Rosindell, James et al. "The unified neutral theory of biodiversity and biogeography at age ten." Trends in ecology & evolution vol. 26,7 (2011).
set.seed(42) tse <- simulateHubbellRates(n_species = 5) miaViz::plotSeries(tse, x = "time") # no migration, all stochastic birth and death set.seed(42) tse1 <- simulateHubbellRates(n_species = 5, migration_p = 0) # all migration, no stochastic birth and death set.seed(42) tse2 <- simulateHubbellRates( n_species = 5, migration_p = 1, metacommunity_probability = c(0.1, 0.15, 0.2, 0.25, 0.3), t_end = 20, t_store = 200 ) # all migration, no stochastic birth and death, but with measurement errors set.seed(42) tse3 <- simulateHubbellRates( n_species = 5, migration_p = 1, metacommunity_probability = c(0.1, 0.15, 0.2, 0.25, 0.3), t_end = 20, t_store = 200, error_variance = 100 ) # model with specified inputs set.seed(42) tse4 <- simulateHubbellRates( n_species = 5, migration_p = 0.1, metacommunity_probability = c(0.1, 0.15, 0.2, 0.25, 0.3), t_end = 200, t_store = 1000, k_events = 5, growth_rates = c(1.1, 1.05, 1, 0.95, 0.9) )
set.seed(42) tse <- simulateHubbellRates(n_species = 5) miaViz::plotSeries(tse, x = "time") # no migration, all stochastic birth and death set.seed(42) tse1 <- simulateHubbellRates(n_species = 5, migration_p = 0) # all migration, no stochastic birth and death set.seed(42) tse2 <- simulateHubbellRates( n_species = 5, migration_p = 1, metacommunity_probability = c(0.1, 0.15, 0.2, 0.25, 0.3), t_end = 20, t_store = 200 ) # all migration, no stochastic birth and death, but with measurement errors set.seed(42) tse3 <- simulateHubbellRates( n_species = 5, migration_p = 1, metacommunity_probability = c(0.1, 0.15, 0.2, 0.25, 0.3), t_end = 20, t_store = 200, error_variance = 100 ) # model with specified inputs set.seed(42) tse4 <- simulateHubbellRates( n_species = 5, migration_p = 0.1, metacommunity_probability = c(0.1, 0.15, 0.2, 0.25, 0.3), t_end = 200, t_store = 1000, k_events = 5, growth_rates = c(1.1, 1.05, 1, 0.95, 0.9) )
The Ricker model is a discrete version of the generalized Lotka-Volterra model and is implemented here as proposed by Fisher and Mehta in PLoS ONE 2014.
simulateRicker( n_species, A, names_species = NULL, x0 = runif(n_species), carrying_capacities = runif(n_species), error_variance = 0.05, explosion_bound = 10^8, t_end = 1000, norm = FALSE, ... )
simulateRicker( n_species, A, names_species = NULL, x0 = runif(n_species), carrying_capacities = runif(n_species), error_variance = 0.05, explosion_bound = 10^8, t_end = 1000, norm = FALSE, ... )
n_species |
Integer: number of species |
A |
interaction matrix |
names_species |
Character: names of species. If NULL,
|
x0 |
Numeric: initial abundances of simulated species. If NULL,
|
carrying_capacities |
numeric carrying capacities. If NULL,
|
error_variance |
Numeric: the variance of measurement error.
By default it equals to 0, indicating that the result won't contain any
measurement error. This value should be non-negative.
(default: |
explosion_bound |
numeric value of boundary for explosion
(default: |
t_end |
integer number of simulations to be simulated |
norm |
logical scalar returning normalised abundances (proportions
in each generation) (default: |
... |
additional parameters, see |
simulateRicker
returns a TreeSummarizedExperiment class object
Fisher & Mehta (2014). Identifying Keystone Species in the Human Gut Microbiome from Metagenomic Timeseries using Sparse Linear Regression. PLoS One 9:e102451
A <- powerlawA(10, alpha = 1.01) tse <- simulateRicker(n_species = 10, A, t_end = 100)
A <- powerlawA(10, alpha = 1.01) tse <- simulateRicker(n_species = 10, A, t_end = 100)
Generate time-series with The Self-Organised Instability (SOI) model. Implements a K-leap method for accelerating stochastic simulation.
simulateSOI( n_species, x0 = NULL, names_species = NULL, carrying_capacity = 1000, A = NULL, k_events = 5, t_end = 1000, metacommunity_probability = runif(n_species, min = 0.1, max = 0.8), death_rates = runif(n_species, min = 0.01, max = 0.08), norm = FALSE )
simulateSOI( n_species, x0 = NULL, names_species = NULL, carrying_capacity = 1000, A = NULL, k_events = 5, t_end = 1000, metacommunity_probability = runif(n_species, min = 0.1, max = 0.8), death_rates = runif(n_species, min = 0.01, max = 0.08), norm = FALSE )
n_species |
Integer: number of species |
x0 |
a vector of initial community abundances
If (default: |
names_species |
Character: names of species. If NULL,
|
carrying_capacity |
integer community size, number of available sites (individuals) |
A |
matrix: interaction matrix defining the positive and negative
interactions between n_species. If NULL, |
k_events |
integer number of transition events that are allowed to take
place during one leap. (default: |
t_end |
Numeric: the end time of the simulation, defining the
modeled time length of the community.
(default: |
metacommunity_probability |
Numeric: Normalized probability distribution
of the likelihood that species from the metacommunity can enter the community
during the simulation. By default, |
death_rates |
Numeric: death rates of each species. By default,
|
norm |
logical scalar indicating whether the time series should be
returned with the abundances as proportions ( |
simulateSOI
returns a TreeSummarizedExperiment class object
# Generate interaction matrix A <- miaSim::powerlawA(10, alpha = 1.2) # Simulate data from the SOI model tse <- simulateSOI( n_species = 10, carrying_capacity = 1000, A = A, k_events = 5, x0 = NULL, t_end = 150, norm = TRUE )
# Generate interaction matrix A <- miaSim::powerlawA(10, alpha = 1.2) # Simulate data from the SOI model tse <- simulateSOI( n_species = 10, carrying_capacity = 1000, A = A, k_events = 5, x0 = NULL, t_end = 150, norm = TRUE )
Simulates time series with the (stochastic) logistic model
simulateStochasticLogistic( n_species, names_species = NULL, growth_rates = NULL, carrying_capacities = NULL, death_rates = NULL, x0 = NULL, sigma_drift = 0.001, sigma_epoch = 0.1, sigma_external = 0.3, sigma_migration = 0.01, epoch_p = 0.001, t_external_events = NULL, t_external_durations = NULL, migration_p = 0.01, metacommunity_probability = NULL, stochastic = TRUE, error_variance = 0, norm = FALSE, t_end = 1000, ... )
simulateStochasticLogistic( n_species, names_species = NULL, growth_rates = NULL, carrying_capacities = NULL, death_rates = NULL, x0 = NULL, sigma_drift = 0.001, sigma_epoch = 0.1, sigma_external = 0.3, sigma_migration = 0.01, epoch_p = 0.001, t_external_events = NULL, t_external_durations = NULL, migration_p = 0.01, metacommunity_probability = NULL, stochastic = TRUE, error_variance = 0, norm = FALSE, t_end = 1000, ... )
n_species |
Integer: number of species |
names_species |
Character: names of species. If NULL,
|
growth_rates |
Numeric: growth rates of simulated species. If NULL,
|
carrying_capacities |
Numeric: The max population of species supported
in the community. If NULL,
|
death_rates |
Numeric: death rates of each species. If NULL,
|
x0 |
Numeric: initial abundances of simulated species. If NULL,
|
sigma_drift |
Numeric: standard deviation of a normally distributed
noise applied in each time step (t_step)
(default: |
sigma_epoch |
Numeric: standard deviation of a normally distributed
noise applied to random periods of the community composition with frequency
defined by the epoch_p parameter
(default: |
sigma_external |
Numeric: standard deviation of a normally distributed
noise applied to user-defined external events/disturbances
(default: |
sigma_migration |
Numeric: standard deviation of a normally distributed
variable that defines the intensity of migration at each time step (t_step)
(default: |
epoch_p |
Numeric: the probability/frequency of random periodic
changes introduced to the community composition
(default: |
t_external_events |
Numeric: the starting time points of defined
external events that introduce random changes to the community composition
(default: |
t_external_durations |
Numeric: respective duration of the external
events that are defined in the 't_external_events' (times) and
sigma_external (std).
(default: |
migration_p |
Numeric: the probability/frequency of migration from a
metacommunity.
(default: |
metacommunity_probability |
Numeric: Normalized probability distribution
of the likelihood that species from the metacommunity can enter the community
during the simulation. If NULL, |
stochastic |
Logical: whether to introduce noise in the simulation.
If False, sigma_drift, sigma_epoch, and sigma_external are ignored.
(default: |
error_variance |
Numeric: the variance of measurement error.
By default it equals to 0, indicating that the result won't contain any
measurement error. This value should be non-negative.
(default: |
norm |
Logical: whether the time series should be returned with
the abundances as proportions ( |
t_end |
Numeric: the end time of the simulationTimes, defining the
modeled time length of the community.
(default: |
... |
additional parameters, see |
The change rate of the species was defined as
dx/dt = b*x*(1-(x/k))*rN - dr*x
, where
b is the vector of growth rates,
x is the vector of initial species abundances,
k is the vector of maximum carrying capacities,
rN is a random number ranged from 0 to 1 which changes in each time step,
dr is the vector of constant death rates.
Also, the vectors of initial dead species abundances can be set.
The number of species will be set to 0 if the dead species abundances
surpass the alive species abundances.
simulateStochasticLogistic
returns a TreeSummarizedExperiment
class object
# Example of logistic model without stochasticity, death rates, or external # disturbances set.seed(42) tse <- simulateStochasticLogistic( n_species = 5, stochastic = FALSE, death_rates = rep(0, 5) ) # Adding a death rate set.seed(42) tse1 <- simulateStochasticLogistic( n_species = 5, stochastic = FALSE, death_rates = rep(0.01, 5) ) # Example of stochastic logistic model with measurement error set.seed(42) tse2 <- simulateStochasticLogistic( n_species = 5, error_variance = 1000 ) # example with all the initial parameters defined by the user set.seed(42) tse3 <- simulateStochasticLogistic( n_species = 2, names_species = c("species1", "species2"), growth_rates = c(0.2, 0.1), carrying_capacities = c(1000, 2000), death_rates = c(0.001, 0.0015), x0 = c(3, 0.1), sigma_drift = 0.001, sigma_epoch = 0.3, sigma_external = 0.5, sigma_migration = 0.002, epoch_p = 0.001, t_external_events = c(100, 200, 300), t_external_durations = c(0.1, 0.2, 0.3), migration_p = 0.01, metacommunity_probability = miaSim::.rdirichlet(1, alpha = rep(1, 2)), stochastic = TRUE, error_variance = 0, norm = FALSE, # TRUE, t_end = 400, t_start = 0, t_step = 0.01, t_store = 1500 )
# Example of logistic model without stochasticity, death rates, or external # disturbances set.seed(42) tse <- simulateStochasticLogistic( n_species = 5, stochastic = FALSE, death_rates = rep(0, 5) ) # Adding a death rate set.seed(42) tse1 <- simulateStochasticLogistic( n_species = 5, stochastic = FALSE, death_rates = rep(0.01, 5) ) # Example of stochastic logistic model with measurement error set.seed(42) tse2 <- simulateStochasticLogistic( n_species = 5, error_variance = 1000 ) # example with all the initial parameters defined by the user set.seed(42) tse3 <- simulateStochasticLogistic( n_species = 2, names_species = c("species1", "species2"), growth_rates = c(0.2, 0.1), carrying_capacities = c(1000, 2000), death_rates = c(0.001, 0.0015), x0 = c(3, 0.1), sigma_drift = 0.001, sigma_epoch = 0.3, sigma_external = 0.5, sigma_migration = 0.002, epoch_p = 0.001, t_external_events = c(100, 200, 300), t_external_durations = c(0.1, 0.2, 0.3), migration_p = 0.01, metacommunity_probability = miaSim::.rdirichlet(1, alpha = rep(1, 2)), stochastic = TRUE, error_variance = 0, norm = FALSE, # TRUE, t_end = 400, t_start = 0, t_step = 0.01, t_store = 1500 )