simulate: Simulate trait evolution

View source: R/simulate.R

simulateR Documentation

Simulate trait evolution

Description

Simulates the evolution of the ecological trait through time by computing the trait value at the next generation as a function of the selection gradient computed at the present generation.

Usage

simulate(
  xstart,
  ntimes,
  pars,
  init,
  mu = 0.01,
  sigma = 0.1,
  tol = 1e-04,
  dodge = 0.001,
  burnin = 0,
  branch = 1
)

Arguments

xstart

Starting trait value

ntimes

The number of time steps to simulate for

pars

An unevaluated parameter-list (e.g. as returned by get_default_pars)

init

A vector of four starting values for solving of the demographic equilibrium

mu

The mutation rate of the trait (per time step)

sigma

The (standard deviation of) mutational step size upon mutation

tol

The tolerance when assessing if the selection gradient is close enough to zero and an equilibrium has been reached

dodge

How much to displace each morph from the branching point once branching has occurred

burnin

The number of time steps in the burn-in period

branch

Integer indicating whether and how branching occurs (see ?simulate_mono).

Details

This function simulates evolution in three phases: (1) the burn-in phase (where only one habitat and one resource are available), (2) monomorphic evolution (in two habitats and with two resources) and (3) dimorphic evolution once a branching point is reached (if it is ever reached).

At each time step the equilibrium population sizes must be solved numerically, using the values in init as starting points. This is done using find_equilibrium_burnin, find_equilibrium or find_equilibrium_di, depending on the phase we are in. Before branching there are only two population sizes (one for each habitat) and so only the two first values in init are used. After branching, all values are used, the first two corresponding to habitat 1 and 2, respectively, for the first morph (the one with a more negative trait value), and the last two for habitat 1 and 2, respectively, for the second morph.

Parameters mu and sigma modulate the response to selection at each time step (and so the rate of evolution). mu should be interpreted as the probability that the trait mutates in a single time step (mu = 0.01 would be reasonable for a trait encoded by 100 loci and with a 0.0001 mutation rate per locus). sigma is, strictly speaking, the standard deviation of the distribution of mutational effects.

An equilibrium is reached when the selection gradient falls within tol units around zero. If this equilibrium is a branching point (assessed using is_stable) then the dimorphic phase starts and the two morphs are displaced by dodge units before undergoing separate evolutionary trajectories with two different selection gradients (but still influencing each other).

Value

A tibble containing the trait values in the two morphs at each time point (with burn-in time points returned as negative integers).

Note

The trait values of the two morphs are equal before a branching point has been reached.

See Also

simulate_burnin, simulate_mono, simulate_di, is_stable

Examples


pars <- get_default_pars()
simulate(-1, ntimes = 10, pars, init = rep(1000, 4))


rscherrer/speciomx documentation built on March 28, 2023, 8:49 p.m.