Skip to contents

Computes mean phenotype values for individual Pop-class objects in a MultiPop-class object. Means are then recursively aggregated upward through the nested MultiPop structure by taking the mean of child-population means at each level. Aggregation is intentionally unweighted across child populations.

Usage

meanPPop(x, level = 0)

Arguments

x

A Pop-class or MultiPop-class object.

level

Integer scalar \(\ge 0\) indicating the requested aggregation level (see Details).

Value

If x is a Pop-class object, or if level=0, a numeric vector of mean phenotype values for each trait.

If x is a MultiPop-class object and level>0, a numeric matrix of (possibly aggregated) mean phenotype values for each trait. The origin of each row is described by the "source" attribute.

Details

The level argument controls the nesting level in a MultiPop structure at which mean aggregation stops:
- When level>0, the function returns a numeric matrix with one row per Pop or MultiPop unit at the requested level. The returned matrix includes a "source" attribute with columns level1, level2, etc., indicating the origin of each row, and values indicating the name or index of the population at each nesting level.
- When level=0, the function returns a numeric vector giving the overall mean-of-means across all branches for each trait.

Examples

founderPop = quickHaplo(nInd = 16, nChr = 1, segSites = 10)
SP = SimParam$new(founderPop)
SP$addTraitA(10)
SP$setVarE(h2 = 0.5)
pop = newPop(founderPop, simParam = SP)

mp = splitPop(
  pop,
  by = list(
    sample(rep(LETTERS[1:2], length.out = pop@nInd)),
    function(x) sample(letters[5:6], length(x), replace = TRUE)
  )
)

meanPPop(mp, level = 1)
#>           Trait1
#> [1,] -0.08406984
#> [2,] -0.24739734
#> attr(,"source")
#>   level1
#> 1      A
#> 2      B
meanPPop(mp, level = 0)
#>     Trait1 
#> -0.1657336