This function simulates a geneology where the last generation has population_size
individuals.
sample_geneology(
population_size,
generations,
generations_full = 1L,
generations_return = 3L,
enable_gamma_variance_extension = FALSE,
gamma_parameter_shape = 5,
gamma_parameter_scale = 1/5,
progress = TRUE,
verbose_result = FALSE
)
The size of the population.
The number of generations to simulate:
-1 for simulate to 1 founder
else simulate this number of generations.
Number of full generations to be simulated.
How many generations to return (pointers to) individuals for.
Enable symmetric Dirichlet (and disable standard Wright-Fisher).
Parameter related to symmetric Dirichlet distribution for each man's probability to be father. Refer to details.
Parameter realted to symmetric Dirichlet distribution for each man's probability to be father. Refer to details.
Show progress.
Verbose result.
A malan_simulation / list with the following entries:
population
. An external pointer to the population.
generations
. Generations actually simulated, mostly useful when parameter generations = -1
.
founders
. Number of founders after the simulated generations
.
growth_type
. Growth type model.
sdo_type
. Standard deviation in a man's number of male offspring. StandardWF or GammaVariation depending on enable_gamma_variance_extension
.
end_generation_individuals
. Pointers to individuals in end generation.
individuals_generations
. Pointers to individuals in last generations_return
generation (if generations_return = 3
, then individuals in the last three generations are returned).
If verbose_result
is true, then these additional components are also returned:
individual_pids
. A matrix with pid (person id) for each individual.
father_pids
. A matrix with pid (person id) for each individual's father.
father_indices
. A matrix with indices for fathers.
By the backwards simulating process of the Wright-Fisher model,
individuals with no descendants in the end population are not simulated.
If for some reason additional full generations should be simulated,
the number can be specified via the generations_full
parameter.
This can for example be useful if one wants to simulate the
final 3 generations although some of these may not get (male) children.
Let \(\alpha\) be the parameter of a symmetric Dirichlet distribution specifying each man's probability to be the father of an arbitrary male in the next generation. When \(\alpha = 5\), a man's relative probability to be the father has 95\ constant 1 under the standard Wright-Fisher model and the standard deviation in the number of male offspring per man is 1.10 (standard Wright-Fisher = 1).
This symmetric Dirichlet distribution is implemented by drawing
father (unscaled) probabilities from a Gamma distribution with
parameters gamma_parameter_shape
and gamma_parameter_scale
that are then normalised to sum to 1.
To obtain a symmetric Dirichlet distribution with parameter \(\alpha\),
the following must be used:
\(`gamma_parameter_shape` = \alpha\)
and
\(`gamma_parameter_scale` = 1/\alpha\).
sim <- sample_geneology(100, 10)
str(sim, 1)
#> List of 7
#> $ population :Classes 'malan_population', 'externalptr' <externalptr>
#> $ generations : num 10
#> $ founders : int 18
#> $ growth_type : chr "ConstantPopulationSize"
#> $ sdo_type : chr "StandardWF"
#> $ end_generation_individuals:List of 100
#> $ individuals_generations :List of 208
#> - attr(*, "class")= chr [1:2] "malan_simulation" "list"
sim$population
#> Population with 395 individuals
peds <- build_pedigrees(sim$population)
peds
#> List of 18 pedigrees (of size 36, 36, 35, 34, 27, 26, ...)