Simulates phenotypic data across arbitrary pedigrees. phen_sim
simulate direct, maternal and paternal genetic and environmental effects for an arbitrary number of traits with arbitrary patterns of missing data.
Usage
phen_sim(
pedigree,
traits = 1,
randomA = NULL,
randomE = NULL,
parentalA = NULL,
parentalE = NULL,
sampled = NULL,
records = NULL,
returnAllEffects = FALSE,
verbose = TRUE
)
Arguments
- pedigree
A pedigree
- traits
The number of traits for which data should be simulated.
- randomA
An additive genetic covariance matrix, with dimensions a multiple of traits - see details
- randomE
An additive environmental covariance matrix, with dimensions a multiple of traits - see details
- parentalA
A vector indicating which effects in
randomA
(if any) to treat as parental effects- parentalE
A vector indicating which effects in
randomE
(if any) to treat as parental effects- sampled
A vector indicating which individuals are sampled
- records
A single value, array of matrix specifying data record availability - see details
- returnAllEffects
If
TRUE
then all individual breeding values and environmental effects are returned- verbose
If
TRUE
provide a progress bar and messages, Default: TRUE
Value
- phenotypes
A dataframe containing phenotypes for all individuals specified to have records.
- allEffects
(optional) A dataframe with all direct and indirect genetic and environmental effects.
Details
randomA
and randomE
are square matrices with dimension equal to the sum of the number direct and indirect effects. This must be a multiple of the number of traits, i.e. if an indirect effect is to be simulated for only one of multiple traits, those traits with no indirect effect should be included with (co)variances of zero.
parentalA
and parentalE
are optional vectors of characters indicating which trait positions in randomA
and randomE
are to be treated as indirect effects, and which effects to treat as maternal or paternal. Valid values are 'd', 'm', and 'p', for direct, maternal indirect and paternal indirect effects, respectively.
records
can be specified either (1) as a single value to be applied to all individuals and traits, (2) as a vector the same length as the number of traits, representing trait-specific rates to be applied uniformly to all individuals, or (3) as data frames with rows for each individual and columns for each trait. In the third option, observed patterns of data availability can be simulated by supplying 0s and 1s for missing and available individual genotypes, respectively.
Examples
## make up a pedigree
id <- c("a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9")
dam <- c(NA, NA, NA, "a1", "a1", "a1", "a4", "a4", "a4")
sire <- c(NA, NA, NA, "a2", "a2", "a2", "a5", "a6", "a6")
pedigree <- as.data.frame(cbind(id, sire, dam))
traits <- 2
## no correlations
randomA <- diag(4)
randomE <- diag(4)
parentalA <- c("d", "d", "m", "m")
parentalE <- c("d", "d", "m", "m")
## generate phenoypic data based on this architecture
phen_sim(
pedigree = pedigree, traits = 2, randomA = randomA, randomE = randomE,
parentalA = parentalA, parentalE = parentalE
)
#> Simulating breeding values and environmental effects...
#> done.
#> Calculating phenotypes...
#> done.
#> $phenotypes
#> id trait_1 trait_2
#> a1 a1 0.635630356 2.5303279
#> a2 a2 0.573565965 1.6102071
#> a3 a3 -0.821761510 -1.1875030
#> a4 a4 -0.008898436 2.3850244
#> a5 a5 1.896592223 3.3994600
#> a6 a6 2.581344532 0.8592014
#> a7 a7 2.887748532 1.9672431
#> a8 a8 2.682974192 0.9062174
#> a9 a9 1.474571866 2.2015559
#>
## let's do it again but see how the phenotypes were composed
phen_sim(
pedigree = pedigree, traits = 2, randomA = randomA, randomE = randomE,
parentalA = parentalA, parentalE = parentalE, returnAllEffects = TRUE
)
#> Simulating breeding values and environmental effects...
#> done.
#> Calculating phenotypes...
#> done.
#> $phenotypes
#> id trait_1 trait_2
#> a1 a1 -0.4099814 -0.2708281
#> a2 a2 -0.8987986 4.0180170
#> a3 a3 -2.0619251 0.4699000
#> a4 a4 0.5101248 1.7330805
#> a5 a5 3.1419989 2.2318840
#> a6 a6 -2.0368235 0.8033704
#> a7 a7 -0.1579793 0.1603304
#> a8 a8 -0.9392673 -1.7291288
#> a9 a9 -3.5522131 0.5295370
#>
#> $allEffects
#> id sire dam a_tr1 a_tr2 bv_m_tr1 bv_m_tr2 e_tr1
#> a1 a1 <NA> <NA> 1.4974139 -0.3028269 -1.3768313 0.8831702 0.11062832
#> a2 a2 <NA> <NA> 0.6714203 1.2300224 1.6454679 -0.1829260 -0.05961225
#> a3 a3 <NA> <NA> -1.3792578 1.2506006 -1.8762368 -0.3687876 -0.57938809
#> a4 a4 a2 a1 -0.4212235 0.7023495 -0.9790743 0.2113033 0.73325992
#> a5 a5 a2 a1 1.7314623 1.2263090 1.1616050 -0.8189242 1.21244833
#> a6 a6 a2 a1 -0.8685181 0.6505350 0.8587998 -0.1159925 -1.36639361
#> a7 a7 a5 a4 0.3819610 0.7928566 0.2472483 -1.3510993 0.69450905
#> a8 a8 a6 a4 -0.1324367 -1.0047145 -0.1063885 -0.2844761 0.42761881
#> a9 a9 a6 a4 -0.8432258 1.0829131 -0.2055727 0.2137410 -1.47453793
#> e_tr2 e_m_tr1 e_m_tr2 P_bv_m_tr1 P_bv_m_tr2 P_e_m_tr1
#> a1 0.2742022 1.5749196 0.56776783 -0.9014624 0.5380665 -1.1165613
#> a2 -0.1495877 0.2661688 0.52840324 0.5204204 0.1868176 -2.0310270
#> a3 0.9421994 -0.7063614 -1.27540210 -0.8440720 -0.4520918 0.7407928
#> a4 -0.4202071 -0.2553751 -0.36923822 -1.3768313 0.8831702 1.5749196
#> a5 -0.4453630 1.1386675 0.19052348 -1.3768313 0.8831702 1.5749196
#> a6 -1.2981026 -2.1370983 -0.09620553 -1.3768313 0.8831702 1.5749196
#> a7 -0.4745912 1.7631306 2.02584606 -0.9790743 0.2113033 -0.2553751
#> a8 -0.5664793 -0.8338353 0.39825915 -0.9790743 0.2113033 -0.2553751
#> a9 -0.3954412 -0.1307025 -1.99949395 -0.9790743 0.2113033 -0.2553751
#> P_e_m_tr2 Phen_tr1 Phen_tr2
#> a1 -0.7802699 -0.4099814 -0.2708281
#> a2 2.7507648 -0.8987986 4.0180170
#> a3 -1.2708082 -2.0619251 0.4699000
#> a4 0.5677678 0.5101248 1.7330805
#> a5 0.5677678 3.1419989 2.2318840
#> a6 0.5677678 -2.0368235 0.8033704
#> a7 -0.3692382 -0.1579793 0.1603304
#> a8 -0.3692382 -0.9392673 -1.7291288
#> a9 -0.3692382 -3.5522131 0.5295370
#>