runSim: Run simulation on population.

View source: R/runSim.R

runSimR Documentation

Run simulation on population.

Description

Run a forward-time simulation on a Population object.

Usage

runSim(
  pop,
  pedigree = NULL,
  generations = 2,
  selection = "random",
  fitness = "phenotypic",
  burnIn = 0,
  truncSire = 1,
  truncDam = 1,
  roundsSire = 1,
  roundsDam = 1,
  litterDist = c(0, 0, 1),
  breedSire = 10,
  mutation = 10^-9,
  recombination = NULL,
  allGenoFileName = NULL
)

Arguments

pop

a valid Population object with all necessary additive and epistatic effects attached

pedigree

an optional data.frame giving the pedigree to follow for selection

generations

an optional integer giving the number of generations to iterate through in the simulation

selection

an optional string specifying random (the default) or linear ranking selection

fitness

an optional string specifying whether selection takes place based on phenotypic value (the default), true genetic value or estimated breeding value

burnIn

an optional integer giving the initial number of generations in which to use random selection without truncation, even when linear ranking selection or truncation is otherwise employed

truncSire

an optional value giving the proportion of the males in the population with the highest phenotypic value to select within

truncDam

an optional value giving the proportion of the females in the population with the highest phenotypic value to select within

roundsSire

an optional integer giving the maximum number of generations for a male to survive; see details below

roundsDam

an optional integer giving the maximum number of generations for a female to survive; see details below

litterDist

an optional vector giving the probability mass function for the litter sizes, starting with a litter of 0

breedSire

an optional integer indicating the maximum number of times that a sire can breed per generation

mutation

an optional value giving the rate of mutation per SNP

recombination

an optional vector giving the probabilities for recombination events between each SNP

allGenoFileName

a string giving a file name, indicating that all genotypes will be outputted to the file during the run

Details

runSim is the forward-time simulation engine of the epinetr package. A Population object with necessary additive and epistatic effects must be supplied; all other arguments are optional, though either pedigree or generations must be supplied.

pedigree should be a data.frame where the first three columns are the ID, sire ID and dam ID respectively. Sire and dam IDs of 0 indicate that the individual is in the first generation; each ID in the first generation should match an ID in the given Population object. The pedigree will be sorted into generations before running, where a 'generation' in this case is defined as the set of individuals whose parents are both from a previous generation. If a pedigree is supplied, all further arguments (which pertain to selection) will be ignored.

generations is the number of generations through which the simulation will iterate. The supplied population represents the first generation: the default value of 2 for this argument thus means that the simulator will simply return the next generation.

selection is a string specifying 'ranking' for linear ranking selection; any other string is interpreted as 'random' for random selection.

Linear ranking selection mimics natural selection: if the individuals in a population of size n are each given a rank r based on descending order of phenotypic value (i.e. the individual with the highest phenotypic value is given the rank r1 = 1 while the individual with the lowest phenotypic value is given the rank rn = n), the probability of an individual i being selected for mating is given by:

P(i is selected) = 2(n - ri + 1) / n(n + 1)

Selection occurs by the population first being split into male and female sub-populations. Next, if the round is outside any initial burn-in period, each sub-population is truncated to a proportion of its original size per the values of truncSire and truncDam, respectively.

When linear ranking selection is used, females are exhaustively sampled, without replacement, for each mating pair using their linear ranking probabilities, as given above; males are sampled for each mating pair using their linear ranking probabilities but with replacement, where they are each only replaced a maximum number of times as specified by breedSire. Random selection occurs in the same manner, but all probabilities are uniform. During any initial burnIn period, random selection is enforced.

fitness specifies how fitness is determined for the purposes of selection: 'phenotypic' (the default) selects based on the phenotype while 'TGV' selects by ignoring environmental noise; 'EBV' selects based on estimated breeding values using estimated SNP effects.

Each mating pair produces a number of full-sibling offspring by sampling once from the litter-size probability mass function given by litterDist (with the default guaranteeing two full-sibling offspring per mating pair). The PMF is specified via a vector giving the probabilities for each litter size, starting with a litter size of 0. For example, c(0.2, 0.0, 0.1, 0.4, 0.3) gives a 20% chance of a litter size of 0, a 10% chance of litter size of 2, a 40% chance of a litter size of 3, a 30% chance of a litter size of 4 and a 0% chance of a litter size of 1 or greater than 4.

Half-siblings occur when sires can mate more than once per round (as given by breedSire) or when sires or dams survive beyond one round (as given by roundsSire and roundsDam, respectively). It is important to note that roundsSire and roundsDam, which specify the maximum number of generations for males and females to survive, respectively, will be ignored in the case where an insufficient number of offspring are produced to replace the individuals who have nonetheless survived the maximum number of rounds: in this case, younger individuals will be preserved in order to meet the population size.

recombination is a vector of recombination rates between SNPs. The length of this vector should be equal to the number of SNPs in the population's map minus the number of chromosomes. The order of the chromosomes is as per the map.

allGenoFileName is the name of a file in which the phased genotype for every individual will be stored. The output is serialised and can be read using loadGeno. If the allGenoFileName argument is not given, no genotypes will be written to file.

Value

A new Population object is returned.

Author(s)

Dion Detterer, Paul Kwan, Cedric Gondro

See Also

Population, addEffects, attachEpiNet, print.Population, plot.Population, loadGeno

Examples


# Create population
pop <- Population(
  popSize = 200, map = map100snp, QTL = 20,
  alleleFrequencies = runif(100),
  broadH2 = 0.9, narrowh2 = 0.6, traitVar = 40
)

# Attach additive effects using a normal distribution
pop <- addEffects(pop)

# Attach epistatic effects
pop <- attachEpiNet(pop)

# Run simulation for 150 generations
pop <- runSim(pop, generations = 150)

# Display results
pop

# Plot results
plot(pop)


epinetr documentation built on March 18, 2022, 7:01 p.m.