Description Details Public fields Methods Examples
R6 class representing a simulation of the peppered moth system.
Used to generate a world with N peppered moth individuals that can be either black or white. Method 'run()' can be used to simulate the evolution of the moth colour over time as the colour of the world changes.
worldR6 object of class world. World to simulate.
populationR6 object of class population. Population of moths within the world.
yearsInteger. Number of years over which to simulate.
outputData frame. Output of simulation.
new()Initialize new R6 object of class 'simulation'.
simulation$new(years = 10000, N = 100, mutation_rate = 0.001, period = 100)
yearsInteger. Number of years over which to simulate.
NInteger. Size of population within the world.
mutation_rateProbability. Probability that moths can change colour in a timestep.
periodperiod Integer. Number of time steps after which colour of world changes.
An R6 object of class 'simulation'
run()Run simulation.
simulation$run(year_to_browse = NULL)
year_to_browseInteger. The year at which the simulation should be paused to explore its content (or NULL, the default, not to interrupt the simulation).
Simulation will run for a number of time steps defined by 'years' attribute.
plot()Plot simulation.
simulation$plot()
clone()The objects of this class are cloneable with this method.
simulation$clone(deep = FALSE)
deepWhether to make a deep clone.
1 2 3 4 5 6 7 8 9 10 11 12 13 | #Normal example where moths change colour with world
set.seed(123)
simu <- simulation$new(years = 200, N = 500, mutation_rate = 1e-2, period = 10)
simu$output
simu$run()
simu$plot()
#Example with low mutation rate that leads to fixation
set.seed(681210)
simu <- simulation$new(years = 200, N = 500, mutation_rate = 1e-4, period = 10)
simu$output
simu$run()
simu$plot()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.