Sample a number of workers - used when nInd = NULL (see SimParamBee$nWorkers).

This is just an example. You can provide your own functions that satisfy your needs!

nWorkersPoisson(colony, n = 1, average = 100)

nWorkersTruncPoisson(colony, n = 1, average = 100, lowerLimit = 0)

nWorkersColonyPhenotype(
  colony,
  queenTrait = 1,
  workersTrait = NULL,
  checkProduction = FALSE,
  lowerLimit = 0,
  simParamBee = NULL,
  ...
)

Arguments

colony

Colony-class

n

integer, number of samples

average

numeric, average number of workers

lowerLimit

numeric, returned numbers will be above this value

queenTrait

numeric (column position) or character (column name), trait that represents queen's effect on the colony phenotype (defined in SimParamBee - see examples); if 0 then this effect is 0

workersTrait

numeric (column position) or character (column name), trait that represents workers's effect on the colony phenotype (defined in SimParamBee - see examples); if 0 then this effect is 0

checkProduction

logical, does the phenotype depend on the production status of colony; if yes and production is not TRUE, the result is above lowerLimit

simParamBee

SimParamBee, global simulation parameters

...

other arguments of mapCasteToColonyPheno

Value

numeric, number of workers

Details

nWorkersPoisson samples from a Poisson distribution with a given average, which can return a value 0. nDronesTruncPoisson samples from a zero truncated Poisson distribution.

nWorkersColonyPhenotype returns a number (above lowerLimit) as a function of colony phenotype, say queen's fecundity. Colony phenotype is provided by mapCasteToColonyPheno. You need to set up traits influencing the colony phenotype and their parameters (mean and variances) via SimParamBee (see examples).

Functions

  • nWorkersTruncPoisson(): Sample a non-zero number of workers

  • nWorkersColonyPhenotype(): Sample a non-zero number of workers based on colony phenotype, say queen's fecundity

See also

SimParamBee field nWorkers and vignette(topic = "QuantitativeGenetics", package = "SIMplyBee")

Examples

nWorkersPoisson()
#> [1] 120
nWorkersPoisson()
#> [1] 88
n <- nWorkersPoisson(n = 1000)
hist(n, breaks = seq(from = min(n), to = max(n)), xlim = c(0, 200))

table(n)
#> n
#>  70  71  72  74  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91 
#>   1   2   2   5   4   3   3   2   5   8   7   9   7  14  14  19  26  24  34  30 
#>  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 
#>  31  40  27  35  40  21  48  39  32  36  40  26  35  27  34  46  22  28  21  25 
#> 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 130 136 137 
#>  18  13  17  14  11   7   6   8  10   2   7   5   3   1   1   1   1   1   1   1 

nWorkersTruncPoisson()
#> [1] 89
nWorkersTruncPoisson()
#> [1] 99
n <- nWorkersTruncPoisson(n = 1000)
hist(n, breaks = seq(from = min(n), to = max(n)), xlim = c(0, 200))

table(n)
#> n
#>  67  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91 
#>   1   1   1   3   2   1   2   3   7  10   5   7   9  12  22  24  20  28  21  25 
#>  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 
#>  28  34  39  35  36  33  30  38  47  42  37  42  42  32  38  31  29  29  17  19 
#> 112 113 114 115 116 117 118 119 120 121 122 123 127 129 
#>  20  15  14  18   6   9   5   5   6  10   1   3   5   1 

# Example for nWorkersColonyPhenotype()
founderGenomes <- quickHaplo(nInd = 3, nChr = 1, segSites = 100)
SP <- SimParamBee$new(founderGenomes)
SP$nThreads = 1L
average <- 100
h2 <- 0.1
SP$addTraitA(nQtlPerChr = 100, mean = average, var = average * h2)
SP$setVarE(varE = average * (1 - h2))
basePop <- createVirginQueens(founderGenomes)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
drones <- createDrones(x = basePop[1], nInd = 50)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
droneGroups <- pullDroneGroupsFromDCA(drones, n = 2, nDrones = 15)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
colony1 <- createColony(x = basePop[2])
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
colony2 <- createColony(x = basePop[3])
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
colony1 <- cross(colony1, drones = droneGroups[[1]])
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
colony2 <- cross(colony2, drones = droneGroups[[2]])
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
colony1@queen@pheno
#> Error in eval(expr, envir, enclos): object 'colony1' not found
colony2@queen@pheno
#> Error in eval(expr, envir, enclos): object 'colony2' not found
createWorkers(colony1, nInd = nWorkersColonyPhenotype)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
createWorkers(colony2, nInd = nWorkersColonyPhenotype)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found