| 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] (ORCID: <https://orcid.org/0000-0002-8563-8884>), Leo Lahti [aut] (ORCID: <https://orcid.org/0000-0001-5537-637X>), Geraldson Muluh [ctb], Akewak Jeba [ctb] (ORCID: <https://orcid.org/0009-0007-1347-7552>) |
| Maintainer: | Yagmur Simsek <[email protected]> |
| License: | Artistic-2.0 | file LICENSE |
| Version: | 1.19.0 |
| Built: | 2026-06-02 06:34:27 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 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.
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 |
|
alpha |
|
stdev |
|
s |
|
d |
|
symmetric |
|
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 |
|
connectance |
|
scale_off_diagonal |
|
mutualism |
|
commensalism |
|
parasitism |
|
amensalism |
|
competition |
|
interactions |
|
symmetric |
|
list_A |
|
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 |
|
mean_production |
|
maintenance |
|
trophic_levels |
|
trophic_preferences |
|
exact |
|
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) )
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))
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 |
|
x0 |
|
resources |
|
resources_dilution |
|
growth_rates |
|
monod_constant |
|
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 |
|
inflow_rate |
outflow_rate |
outflow_rate |
|
volume |
|
... |
additional parameters, see |
an TreeSummarizedExperiment class object
n_species <- 2 n_resources <- 4 tse <- simulateConsumerResource( n_species = n_species, n_resources = n_resources ) ## Not run: # 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 ) ## End(Not run)n_species <- 2 n_resources <- 4 tse <- simulateConsumerResource( n_species = n_species, n_resources = n_resources ) ## Not run: # 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 ) ## End(Not run)
Generate a vector of event times
simulateEventTimes(t_events = NULL, t_duration = NULL, t_end = 1000, ...)simulateEventTimes(t_events = NULL, t_duration = NULL, t_end = 1000, ...)
t_events |
Numeric vector; starting time of the events |
t_duration |
Numeric vector; 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 <- simulateEventTimes( t_events = c(10, 50, 100), t_duration = c(1, 2, 3), t_end = 100, t_store = 100, t_step = 1 )tEvent <- simulateEventTimes( t_events = c(10, 50, 100), t_duration = c(1, 2, 3), t_end = 100, t_store = 100, t_step = 1 )
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 |
|
x0 |
|
growth_rates |
|
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 |
|
M |
|
carrying_capacity |
|
k_events |
|
migration_p |
|
t_skip |
|
t_end |
|
norm |
|
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 |
|
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 |
|
growth_rates |
|
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, assay.type = "counts", time.col = "time", colour.by = "rownames") # 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, assay.type = "counts", time.col = "time", colour.by = "rownames") # 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 |
|
carrying_capacities |
|
error_variance |
|
explosion_bound |
|
t_end |
|
norm |
|
... |
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 |
|
names_species |
Character: names of species. If NULL,
|
carrying_capacity |
|
A |
|
k_events |
|
t_end |
|
metacommunity_probability |
|
death_rates |
|
norm |
|
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 |
|
carrying_capacities |
|
death_rates |
|
x0 |
|
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 |
|
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 )