Selects Pop-class or MultiPop-class
objects at a specified level of a nested MultiPop hierarchy.
Selection is based on response summaries calculated within Pop
objects and recursively aggregated across MultiPop objects.
Arguments
- x
a
MultiPop-classobject- nMulti
the number of population units to select
- level
an integer indicating the nesting level at which selection is performed.
level=1selects among direct children,level=2descends one level into nestedMultiPops, etc.- trait
the trait for selection. Either a number indicating a single trait or a character for a trait name, or a function returning a vector of length
nInd(pop)for each population atlevel. The function must work on a vector or matrix ofusevalues astrait(pop@use, ...)- depending on whatuseis. SeeselIndex.- use
the selection criterion. Either a character (genetic values
"gv", estimated breeding values"ebv", phenotypes"pheno", or random values"rand") or a function returning a vector of lengthnInd(pop)for each population atlevel. The function must work on eachpopatlevelinxasuse(pop, trait, ...)or astrait(pop@use, ...)depending on whattraitis.- selectTop
selects highest values if
TRUE. Selects lowest values ifFALSE.- withinPopFUN
a function used to summarize individual responses within each
Popobject. It receives the selection criterion values of one population, with one element per individual. These come as a one-column matrix whentraitis a trait number or name, or whenuse = "rand", and as whatever the function returns whentraitis a function, usually a vector. It must return one summary value. Default ismean.- withinPopArgs
a list of additional arguments passed to
withinPopFUN- acrossPopFUN
a function used to aggregate population summaries across the immediate children of each
MultiPopobject. It receives a one-column numeric matrix with one row per child, holding the children's summary values, and must return one aggregated value. Default ismean.- acrossPopArgs
a list of additional arguments passed to
acrossPopFUN- simParam
an object of
SimParam. IfNULL, the function uses the object namedSPfrom the global environment.- ...
additional arguments passed to the functions supplied to
traitoruse
Value
A MultiPop-class object containing the selected
nMulti population units at the requested level. Population
units not selected are removed, together with any intermediate
MultiPop objects left empty by their removal.
If nMulti is greater than the number of available candidates, a
warning is issued and x is returned unchanged.
Details
Individual responses are first obtained for every terminal Pop
object using the specified trait and use. These responses are
summarized within each Pop using withinPopFUN. The resulting
summaries are then recursively aggregated with acrossPopFUN until
the requested level is reached.
Population units at the requested level are ranked using their
aggregated values. The highest nMulti units are retained when
selectTop = TRUE, and the lowest nMulti units are retained
when selectTop = FALSE.
Aggregation with acrossPopFUN is unweighted with respect to the
number of individuals in each child population, unless weighting is
explicitly implemented by the user-supplied function.
If a branch ends in a Pop object before the requested level is
reached, that terminal Pop is treated as a candidate at its deepest
available level. If candidates have equal selection values at the selection
boundary, ties are resolved according to their existing order in the
MultiPop hierarchy.
Examples
founderPop = quickHaplo(nInd = 16, nChr = 1, segSites = 50)
SP = SimParam$new(founderPop)
SP$addTraitA(nQtlPerChr = 20)
SP$setVarE(h2 = 0.5)
pop = newPop(founderPop, simParam = SP)
# Create four groups, each divided into two replicates
multiPop = splitPop(
pop,
by = list(
rep(LETTERS[1:4], each = 4),
function(x) {
rep(c("R1", "R2"), length.out = nInd(x))
}
)
)
# Select the two groups with the highest mean phenotypic values
selected = selectMultiPop(
multiPop,
nMulti = 2,
level = 1,
trait = 1,
use = "pheno",
withinPopFUN = mean,
acrossPopFUN = mean,
simParam = SP
)
selected
#> An object of class "MultiPop" with 2 item(s)
#> Level 1:
#> |-- [[1]] "A" - An object of class "MultiPop" with 2 item(s)
#> | | Level 2:
#> | |-- [[1]] "R1" - An object of class "Pop" with 2 individual(s): 1, 3
#> | `-- [[2]] "R2" - An object of class "Pop" with 2 individual(s): 2, 4
#> `-- [[2]] "C" - An object of class "MultiPop" with 2 item(s)
#> | Level 2:
#> |-- [[1]] "R1" - An object of class "Pop" with 2 individual(s): 9, 11
#> `-- [[2]] "R2" - An object of class "Pop" with 2 individual(s): 10, 12
# Select the three replicates with the lowest sum of phenotypic values
selected = selectMultiPop(
multiPop,
nMulti = 3,
level = 2,
trait = 1,
use = "pheno",
selectTop = FALSE,
withinPopFUN = sum,
acrossPopFUN = mean,
simParam = SP
)
selected
#> An object of class "MultiPop" with 2 item(s)
#> Level 1:
#> |-- [[1]] "B" - An object of class "MultiPop" with 1 item(s)
#> | | Level 2:
#> | `-- [[1]] "R1" - An object of class "Pop" with 2 individual(s): 5, 7
#> `-- [[2]] "D" - An object of class "MultiPop" with 2 item(s)
#> | Level 2:
#> |-- [[1]] "R1" - An object of class "Pop" with 2 individual(s): 13, 15
#> `-- [[2]] "R2" - An object of class "Pop" with 2 individual(s): 14, 16