Process Generations for Pedigree Simulation
Source:R/simulatePedigree_within.R
buildWithinGenerations.RdThis function iterates through generations in a pedigree simulation, assigning IDs, creating data frames, determining sexes, and managing pairing within each generation.
Usage
buildWithinGenerations(
beta = FALSE,
sizeGens,
marR,
sexR,
Ngen,
verbose = FALSE,
personID = "ID",
momID = "momID",
dadID = "dadID",
code_male = "M",
code_female = "F",
fam_shift = 1L
)Arguments
- beta
logical or character. Controls which algorithm version to use:
FALSE,"base", or"original"(default): Use the original algorithm. Slower but ensures exact reproducibility with set.seed().TRUEor"optimized": Use the optimized algorithm with 4-5x speedup. Produces statistically equivalent results but not identical to base version due to different random number consumption. Recommended for large simulations where speed matters more than exact reproducibility.
Note: Both versions are mathematically correct and produce valid pedigrees with the same statistical properties (sex ratios, mating rates, etc.). The optimized version uses vectorized operations instead of loops, making it much faster for large pedigrees.
- sizeGens
A numeric vector containing the sizes of each generation within the pedigree.
- marR
Mating rate. A numeric value ranging from 0 to 1 which determines the proportion of mated (fertilized) couples in the pedigree within each generation. For instance, marR = 0.5 suggests 50 percent of the offspring in a specific generation will be mated and have their offspring.
- sexR
Sex ratio of offspring. A numeric value ranging from 0 to 1 that determines the proportion of males in all offspring in this pedigree. For instance, 0.4 means 40 percent of the offspring will be male.
- Ngen
Number of generations. An integer >= 2 that determines how many generations the simulated pedigree will have. The first generation is always a fertilized couple. The last generation has no mated individuals.
- verbose
logical If TRUE, message progress through stages of algorithm
- personID
character. Name of the column in ped for the person ID variable
- momID
character. Name of the column in ped for the mother ID variable
- dadID
character. Name of the column in ped for the father ID variable
- code_male
The value to use for males. Default is "M"
- code_female
The value to use for females. Default is "F"
- fam_shift
An integer to shift the person ID. Default is 1L. This is useful when simulating multiple pedigrees to avoid ID conflicts.