Skip to contents

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.

Usage

selectMultiPop(
  x,
  nMulti,
  level = 1,
  trait = 1,
  use = "pheno",
  selectTop = TRUE,
  withinPopFUN = mean,
  withinPopArgs = list(),
  acrossPopFUN = mean,
  acrossPopArgs = list(),
  simParam = NULL,
  ...
)

Arguments

x

a MultiPop-class object

nMulti

the number of population units to select

level

an integer indicating the nesting level at which selection is performed. level=1 selects among direct children, level=2 descends one level into nested MultiPops, 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 at level. The function must work on a vector or matrix of use values as trait(pop@use, ...) - depending on what use is. See selIndex.

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 length nInd(pop) for each population at level. The function must work on each pop at level in x as use(pop, trait, ...) or as trait(pop@use, ...) depending on what trait is.

selectTop

selects highest values if TRUE. Selects lowest values if FALSE.

withinPopFUN

a function used to summarize individual responses within each Pop object. It receives the selection criterion values of one population, with one element per individual. These come as a one-column matrix when trait is a trait number or name, or when use = "rand", and as whatever the function returns when trait is a function, usually a vector. It must return one summary value. Default is mean.

withinPopArgs

a list of additional arguments passed to withinPopFUN

acrossPopFUN

a function used to aggregate population summaries across the immediate children of each MultiPop object. 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 is mean.

acrossPopArgs

a list of additional arguments passed to acrossPopFUN

simParam

an object of SimParam. If NULL, the function uses the object named SP from the global environment.

...

additional arguments passed to the functions supplied to trait or use

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