simulation: R6 class representing a simulation of the peppered moth...

Description Details Public fields Methods Examples

Description

R6 class representing a simulation of the peppered moth system.

Details

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.

Public fields

world

R6 object of class world. World to simulate.

population

R6 object of class population. Population of moths within the world.

years

Integer. Number of years over which to simulate.

output

Data frame. Output of simulation.

Methods

Public methods


Method new()

Initialize new R6 object of class 'simulation'.

Usage
simulation$new(years = 10000, N = 100, mutation_rate = 0.001, period = 100)
Arguments
years

Integer. Number of years over which to simulate.

N

Integer. Size of population within the world.

mutation_rate

Probability. Probability that moths can change colour in a timestep.

period

period Integer. Number of time steps after which colour of world changes.

Returns

An R6 object of class 'simulation'


Method run()

Run simulation.

Usage
simulation$run(year_to_browse = NULL)
Arguments
year_to_browse

Integer. The year at which the simulation should be paused to explore its content (or NULL, the default, not to interrupt the simulation).

Details

Simulation will run for a number of time steps defined by 'years' attribute.


Method plot()

Plot simulation.

Usage
simulation$plot()

Method clone()

The objects of this class are cloneable with this method.

Usage
simulation$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

 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()

data-zoo-gang/ABMR6 documentation built on Dec. 19, 2021, 8:12 p.m.