Simulates a tree sequence object from a model with parameters as specified either by sampling from priors or by a given list of fixed parameter values

simulate_model(
  model,
  parameters,
  sequence_length,
  recombination_rate,
  mutation_rate = 0,
  data = NULL,
  format = c("ts", "files"),
  engine = NULL,
  model_args = NULL,
  engine_args = NULL,
  attempts = 1000
)

Arguments

model

Either a slendr model generating function (in which case engine must be either "msprime" or "slim", i.e. one of the two of slendr's simulation back ends), or a path to a custom user-defined SLiM or msprime script (in which case engine must be "files").

parameters

A list of prior distributions to use for sampling of model parameters

sequence_length

Amount of sequence to simulate using slendr (in base pairs). Ignored when custom simulations scripts are provided.

recombination_rate

Recombination rate to use for the simulation Ignored when custom simulations scripts are provided.

mutation_rate

Mutation rate to use for the simulation Ignored when custom simulations scripts are provided.

engine

Which simulation engine to use? Values "msprime" and "slim" will use one of the built-in slendr simulation back ends. Which engine will be used is determined by the nature of the model. If engine = NULL, then spatial slendr models will by default use the "slim" back end, non-spatial models will use the "msprime" back end, and custom user-defined model scripts will use the "custom" engine. Setting this argument explicitly will change the back ends (where appropriate). Setting this argument for custom simulation script has no effect.

model_args

Optional (non-prior) arguments for the slendr model generating function. Setting this argument for custom simulation script has no effect.

engine_args

Optional arguments for the slendr simulation back end. Setting this argument for custom simulation script has no effect.

attempts

Maximum number of attempts to generate prior values for a valid demographic model (i.e. model which generates an output without error, default is 1000)

random_seed

Random seed to be used for simulation and (potentially) adding of mutations to a simulated tree sequence

Value

Either a tree-sequence object of the class slendr_ts when a slendr model was simulated, or a path to an output file when a custom simulation script was used.

Details

This function is useful to generate a small tree sequence to be used when developing summary statistic functions inference using demografr.