Level 3 function that selects colonies from MultiColony object based on colony ID or random selection. Whilst user can provide all three arguments ID, p and n, there is a priority list: ID takes first priority. If no ID is provided, p takes precedence over n.
selectColonies(
multicolony,
ID = NULL,
n = NULL,
p = NULL,
by = NULL,
selectTop = TRUE
)character or numeric, ID of a colony (one or more) to be selected
numeric, number of colonies to select
numeric, percentage of colonies selected (takes precedence
over n)
matrix, matrix of values to select by with names being
colony IDs (can be obtained with calcColonyValue.
If NULL, the colonies are selected at random.
This parameter is used in combination
with n or p to determine the number of selected colonies, and
selectTop to determine whether to select the best or the worst colonies.
logical, selects highest (lowest) values if TRUE (FALSE)
MultiColony-class with selected colonies
founderGenomes <- quickHaplo(nInd = 5, nChr = 1, segSites = 100)
SP <- SimParamBee$new(founderGenomes)
mean <- c(10, 10 / SP$nWorkers)
varA <- c(1, 1 / SP$nWorkers)
corA <- matrix(data = c(
1.0, -0.5,
-0.5, 1.0
), nrow = 2, byrow = TRUE)
varE <- c(3, 3 / SP$nWorkers)
varA / (varA + varE)
#> [1] 0.25 0.25
SP$addTraitADE(nQtlPerChr = 100,
mean = mean,
var = varA, corA = corA,
meanDD = 0.1, varDD = 0.2, corD = corA,
relAA = 0.1, corAA = corA)
SP$setVarE(varE = varE)
basePop <- createVirginQueens(founderGenomes)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
drones <- createDrones(x = basePop[1:4], nInd = 100)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
droneGroups <- pullDroneGroupsFromDCA(drones, n = 10, nDrones = 10)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
apiary <- createMultiColony(basePop[2:5], n = 4)
#> Error in createMultiColony(basePop[2:5], n = 4): object 'basePop' not found
apiary <- cross(apiary, drones = droneGroups[1:4])
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
apiary <- buildUp(apiary)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
getId(apiary)
#> Error in getId(apiary): object 'apiary' not found
getId(selectColonies(apiary, ID = 1))
#> Error in getId(multicolony): object 'apiary' not found
getId(selectColonies(apiary, ID = c("3", "4")))
#> Error in getId(multicolony): object 'apiary' not found
# ... alternative
getId(apiary[1])
#> Error in getId(apiary[1]): object 'apiary' not found
getId(apiary[["4"]])
#> Error in getId(apiary[["4"]]): object 'apiary' not found
# Select a random number of colonies
selectColonies(apiary, n = 3)
#> Error in "MultiColony" %in% class(multicolony): object 'apiary' not found
# Select a percentage of colonies
selectColonies(apiary, p = 0.2)
#> Error in is(x, class2 = "MultiColony"): object 'apiary' not found
# Since selection is random, you would get a different set of colonies with
# each function call
getId(selectColonies(apiary, p = 0.5))
#> Error in is(x, class2 = "MultiColony"): object 'apiary' not found
getId(selectColonies(apiary, p = 0.5))
#> Error in is(x, class2 = "MultiColony"): object 'apiary' not found
# How to select colonies based on colony values?
# Obtain colony phenotype
colonyPheno <- calcColonyPheno(apiary)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
# Select the best colony
selectColonies(apiary, n = 1, by = colonyPheno)
#> Error in "MultiColony" %in% class(multicolony): object 'apiary' not found
# Select the worst 2 colonies
selectColonies(apiary, n = 2, by = colonyPheno, selectTop = FALSE)
#> Error in "MultiColony" %in% class(multicolony): object 'apiary' not found
# Select best colony based on queen's genetic value for trait 1
queenGv <- calcColonyGv(apiary, FUN = mapCasteToColonyGv, workersTrait = NULL)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
selectColonies(apiary, n = 1, by = queenGv)
#> Error in "MultiColony" %in% class(multicolony): object 'apiary' not found