Introduction

This vignette describes and demonstrates how SIMplyBee implements quantitative genetics principles for honeybees. Specifically, it describes three different examples where we simulate:

  1. Honey yield - a single colony trait,

  2. Honey yield and Calmness - two colony traits, and

  3. Colony strength and Honey yield - two colony traits where one trait impacts the other one via the number of workers.

We start by loading SIMplyBee and quickly simulating genomes for some founder honeybees. Specifically, we will simulate genomes for 20 individuals with 16 chromosomes and 1000 segregating sites per chromosome.

library(package = "SIMplyBee")
#> Loading required package: AlphaSimR
#> Loading required package: R6
#> 
#> Attaching package: 'SIMplyBee'
#> The following object is masked from 'package:base':
#> 
#>     split
library(package = "ggplot2")
founderGenomes <- quickHaplo(nInd = 20, nChr = 16, segSites = 1000)

Honey yield

This section shows how to simulate one colony trait, honey yield, that is influenced by the queen and workers as well as the environment. We will achieve this by:

  1. setting base population quantitative genetic parameters,
  2. inspecting individual values in the base population,
  3. inspecting individual values in a colony,
  4. calculating colony value,
  5. calculating multi-colony values, and
  6. selecting on colony values.

Base population quantitative genetic parameters

AlphaSimR, and hence SIMplyBee, simulates each individual with its corresponding genome, and quantitative genetic and phenotypic values. To enable this simulation, we must set base population quantitative genetic parameters for the traits of interest in the global simulation parameters via SimParamBee. We must set:

  1. the number of traits,
  2. the number of quantitative trait loci (QTL) that affect the traits,
  3. the distribution of QTL effects,
  4. trait means, and
  5. trait genetic and environmental variances - if we simulate multiple traits, we must also specify genetic and environmental covariances between the traits.

In honeybees, the majority of traits are influenced by the queen and workers. There are many biological mechanisms for these queen and workers effects. Depending on which caste is the main driver of the trait (the queen or workers), we also talk about direct and indirect effects. For example, for honey yield, workers directly affect honey yield by foraging, while the queen indirectly affects honey yield by stimulating workers via pheromone production. The queen and workers effects for a trait can be genetically and environmentally independent or correlated (usually negatively).

Here, we will simulate two traits to represent the queen and workers effects on honey yield. From this point onward we will use the terms the queen effect and queen trait interchangeably. The same applies to workers effect and workers trait. These two effects (=traits) will give rise to honey yield trait. We will assume that colony honey yield is approximately normally distributed with the mean of 20 kg and variance of 4 \(kg^2\), which implies that most colonies will have honey yield between 14 kg and 26 kg (see hist(rnorm(n = 1000, mean = 20, sd = sqrt(4)))). Traits like honey yield have a complex polygenic genetic architecture, so we will assume that this trait is influenced by 100 QTL per chromosome (with 16 chromosomes, this gives us 1600 QTL in total).

We will first initiate global simulation parameters and set the mean of queen effects to 10 kg with genetic variance of 1 \(kg^2\), while we will set the mean of workers effects to 10 kg with genetic variance of 1 \(kg^2\). The mean and the variance for the worker effect are proportionally scaled by the expected number of workers in a colony. The mean and variance for the queen effect is assumed larger than for the workers effect, because there is one queen and many workers in colony and we assume that workers effects “accumulate”. Deciding how to split the colony mean between queen and workers effects will depend on the individual to colony mapping function, which we will describe in the Colony value sub-section.

# Global simulation parameters
SP <- SimParamBee$new(founderGenomes)

nQtlPerChr <- 100

# Genetic parameters for queen and workers effects - each represented by a trait
mean <- c(10, 10 / SP$nWorkers)
varA <- c(1, 1 / SP$nWorkers)

We next set genetic correlation between the queen and workers effects to -0.5 to reflect the commonly observed antagonistic relationship between these effects. With all the quantitative genetic parameters defined, we now add two additive traits to global simulation parameters and name them queenTrait and workerTrait. These parameters drive the simulation of QTL effects. Read about all the other trait simulation options in AlphaSimR via: vignette(topic = "traits", package="AlphaSimR").

corA <- matrix(data = c( 1.0, -0.5, 
                        -0.5,  1.0), nrow = 2, byrow = TRUE)
SP$addTraitA(nQtlPerChr = nQtlPerChr, mean = mean, var = varA, corA = corA,
             name = c("queenTrait", "workersTrait"))

Finally, we set the environmental variance of the queen and workers effects to 3 \(kg^2\) and we again scale the worker variance by the expected number of workers. Contrary to the negative genetic correlation, we here assume that environmental correlation between the queen and workers effects is slightly positive, 0.3. This is just an example! These parameters should be based on literature or simulation scenarios of interest.

varE <- c(3, 3 / SP$nWorkers)
corE <- matrix(data = c(1.0, 0.3, 
                        0.3, 1.0), nrow = 2, byrow = TRUE)
SP$setVarE(varE = varE, corE = corE)

Individual values in the base population

Now we create a base population of virgin queens. Since we defined two traits, all honeybees in the simulation will have genetic and phenotypic values for both traits. The genetic values are stored in the gv slot of each Pop object, while phenotypic values are stored in the pheno slot.

#>      queenTrait workersTrait
#> [1,]  10.908928  -0.02728018
#> [2,]  10.881251   0.21420518
#> [3,]   9.787639   0.00824872
#> [4,]   9.065346   0.03423439
#> [5,]   7.858275   0.22050245
#> [6,]  12.582846   0.10644155
#>      queenTrait workersTrait
#> [1,]  12.943935   -0.1200754
#> [2,]  11.455150    0.1686372
#> [3,]   9.208746   -0.2128413
#> [4,]   9.210963    0.3401134
#> [5,]  10.382563    0.2211788
#> [6,]  13.455804   -0.1572053

Note that these are virgin queens, yet we obtained queen and workers effect values for them! Is this wrong? No! Virgin queens carry DNA with genes that are differentially expressed in different castes, which would be only showed in their phenotype. Hence, virgin queens have genetic values for the queen and worker effects, but they might never actually express these effects. In this simulation virgin queens also obtained phenotypic values for both of the effects. This is technically incorrect because virgin queens don’t express genes for the worker effect at all, and they also do not express the queen effect, not until they become the queen of a colony. We can treat these phenotypic values for virgin queens as values that we could see if these virgin queens would express these traits. We will show later in the Colony value sub-section how we use these traits from different castes. If existence of these phenotypic values for certain castes is a hindrance, we can always remove them for population or colony objects by modifying the corresponding slots as required.

As with the virgin queens, drones also carry DNA with genes that are expressed in different castes. Therefore, drones will also have the queen and workers effect genetic (and phenotypic values) for honey yield even though they do not contribute to this trait in a colony.

#>      queenTrait workersTrait
#> [1,]  11.980871  -0.18317238
#> [2,]  10.980419  -0.07710109
#> [3,]  10.553260  -0.05370218
#> [4,]  10.960779   0.07432498
#> [5,]   7.864862   0.49695179
#> [6,]   9.593907   0.21352136

Individual values in a colony

We continue by creating a colony from one base population virgin queen, crossing it, and adding some workers.

colony <- createColony(x = basePop[6])
colony <- cross(x = colony, drones = drones)
colony <- addWorkers(x = colony, nInd = 50)
colony
#> An object of class "Colony" 
#> Id: 1 
#> Location: 0 0 
#> Queen: 6 
#> Number of fathers: 15 
#> Number of workers: 50 
#> Number of drones: 0 
#> Number of virgin queens: 0 
#> Has split: FALSE 
#> Has swarmed: FALSE 
#> Has superseded: FALSE 
#> Has collapsed: FALSE 
#> Is productive: FALSE

We can access the genetic and phenotypic values of colony members with functions getGv() and getPheno(), both of which have the caste argument (see more via help(getGv)).

getGv(colony, caste = "queen")
#>   queenTrait workersTrait
#> 6   12.58285    0.1064415
getGv(colony, caste = "workers") |> head(n = 4)
#>    queenTrait workersTrait
#> 36  12.000901   0.11914291
#> 37   9.508123   0.12702733
#> 38  12.522676   0.03779673
#> 39  10.893172   0.15299368

getPheno(colony, caste = "queen")
#>   queenTrait workersTrait
#> 6    13.4558   -0.1572053
getPheno(colony, caste = "workers") |> head(n = 4)
#>    queenTrait workersTrait
#> 36  11.701446   0.11677146
#> 37   7.334154  -0.02617403
#> 38   7.847135  -0.01908843
#> 39  10.104277   0.22667177

For convenience, there are also alias functions for accessing the genetic and phenotypic values of each caste directly.

getQueenGv(colony)
#>   queenTrait workersTrait
#> 6   12.58285    0.1064415
getWorkersGv(colony) |> head(n = 4)
#>    queenTrait workersTrait
#> 36  12.000901   0.11914291
#> 37   9.508123   0.12702733
#> 38  12.522676   0.03779673
#> 39  10.893172   0.15299368

getQueenPheno(colony)
#>   queenTrait workersTrait
#> 6    13.4558   -0.1572053
getWorkersPheno(colony) |> head(n = 4)
#>    queenTrait workersTrait
#> 36  11.701446   0.11677146
#> 37   7.334154  -0.02617403
#> 38   7.847135  -0.01908843
#> 39  10.104277   0.22667177

Some phenotypes, such as honey yield, are only expressed if colony is at full size. This is achieved by the buildUp() colony event function that adds worker and drones and hence turns on the production status of the colony (to TRUE). SIMplyBee includes a function ìsProductive() to check the production status of a colony.

# Check if colony is productive
isProductive(colony)
#> [1] FALSE

# Build-up the colony and check the production status again
colony <- buildUp(colony)
colony
#> An object of class "Colony" 
#> Id: 1 
#> Location: 0 0 
#> Queen: 6 
#> Number of fathers: 15 
#> Number of workers: 100 
#> Number of drones: 100 
#> Number of virgin queens: 0 
#> Has split: FALSE 
#> Has swarmed: FALSE 
#> Has superseded: FALSE 
#> Has collapsed: FALSE 
#> Is productive: TRUE
isProductive(colony)
#> [1] TRUE

For the ease of further demonstration, we now combine workers’ values into a single data.frame.

# Collate genetic and phenotypic values of workers
df <- data.frame(id = colony@workers@id,
                 mother = colony@workers@mother,
                 father = colony@workers@father,
                 gvQueenTrait = colony@workers@gv[, "queenTrait"],
                 gvWorkersTrait = colony@workers@gv[, "workersTrait"],
                 pvQueenTrait =  colony@workers@pheno[, "queenTrait"],
                 pvWorkersTrait = colony@workers@pheno[, "workersTrait"])
head(df)
#>   id mother father gvQueenTrait gvWorkersTrait pvQueenTrait pvWorkersTrait
#> 1 86      6     28    11.261285    -0.02296466    12.073725   -0.171010176
#> 2 87      6     21    12.626985    -0.07310070    16.588980   -0.010569418
#> 3 88      6     35     9.528496     0.22302577     7.740347    0.153982371
#> 4 89      6     27    10.867328    -0.04481330    11.701085    0.009009888
#> 5 90      6     33    10.146731     0.06687296     8.765754   -0.012760596
#> 6 91      6     25     9.906774     0.27649386    10.575597    0.277498894

To visualise correlation between queen and workers effects in workers, we plot these effect values against each other.

# Covariation between queen and workers effect genetic values in workers
p <- ggplot(data = df, aes(x = gvQueenTrait, y = gvWorkersTrait)) +
  xlab("Genetic value for the queen effect") +
  ylab("Genetic value for the workers effect") +
  geom_point() +
  theme_classic()
print(p)

In SIMplyBee, we know genetic values of all individuals, including drones that the queen mated with (=fathers in a colony)!

# Variation in patriline genetic values
getFathersGv(colony)
#>    queenTrait workersTrait
#> 21  11.980871  -0.18317238
#> 22  10.980419  -0.07710109
#> 23  10.553260  -0.05370218
#> 24  10.960779   0.07432498
#> 25   7.864862   0.49695179
#> 26   9.593907   0.21352136
#> 27   8.759040  -0.12461311
#> 28  10.145288  -0.12346939
#> 29   8.828355   0.08429854
#> 30   8.461404   0.13700802
#> 31   8.770852   0.19250610
#> 32  10.193370   0.01583531
#> 33   8.414798   0.21352368
#> 34   6.777782   0.20614739
#> 35   6.751270   0.27859340

Knowing the father of each worker, we inspect variation in the distribution of genetic values of worker by the patriline (workers from a single father drone) for the workers effect.

Colony value

However, in honeybees we usually don’t observe values on individuals, but on a colony. SIMplyBee provides functions for mapping individual values to a colony value. The general function for this is calcColonyValue(), which can combine any value and trait from any caste. There are also aliases calcColonyGv() and calcColonyPheno(). These functions require users to specify the so-called mapping function (via the FUN argument). The mapping function specifies queen and workers traits (potentially also drone traits) and what function we want to apply to each of them before mapping them to the colony value(s). We can also specify whether the colony value(s) depend on the production status. For example, if a colony is not productive, its honey yield would be 0 or unobserved. SIMplyBee provides a general mapping function mapCasteToColonyValue() and aliases mapCasteToColonyGv() and mapCasteToColonyPheno(). These functions have arguments to cater for various situations. By default, they first calculate caste values: leave the queen’s value as it is, sum workers’ values, potentially sum drones’ values, and lastly sum all these caste values together into a colony value. Users can provide their own mapping function(s) too!

We now calculate honey yield for our colony - a single value for the colony.

# Colony phenotype value
calcColonyPheno(colony, queenTrait = "queenTrait", workersTrait = "workersTrait")
#>          [,1]
#> [1,] 21.82211
help(calcColonyPheno)
help(mapCasteToColonyPheno)

These colony values are not stored in a colony, because they change as colony changes due to various events. For example, reducing the number of workers will reduce the colony honey yield.

# Colony phenotype value from a reduced colony
removeWorkers(colony, p = 0.5) |>
  calcColonyPheno(queenTrait = "queenTrait", workersTrait = "workersTrait")
#>         [,1]
#> [1,] 18.5018

Please note that we assumed that the queen contributes half to colony honey yield and workers contribute the other half. This means that removing workers will still give a non-zero honey yield! This shows that we have to design the mapping between individual, caste, and colony values with care!

# Colony phenotype value from a reduced colony
removeWorkers(colony, p = 0.99) |>
  calcColonyPheno(queenTrait = "queenTrait", workersTrait = "workersTrait")
#>          [,1]
#> [1,] 13.65677

Finally, note that SIMplyBee currently does not provide functionality for breeding values, dominance deviations, and epistatic deviations at caste and colony levels, despite the availabiliy of AlphaSimR bv(), dd(), and aa() functions. This is because we have to check or develop theory on how to calculate these values across active colonies and hence we currently advise against the use of AlphaSimR bv(), dd(), and aa() functions with SIMplyBee as the output of these functions could be easily misinterpreted.

MultiColony values

The same functions can be used on a MultiColony class object. Let’s create an apiary.

apiary <- createMultiColony(basePop[7:20])
drones <- createDrones(basePop[1:5], nInd = 100)
droneGroups <- pullDroneGroupsFromDCA(drones, n = nColonies(apiary), nDrones = 15)
apiary <- cross(x = apiary, drones = droneGroups)
apiary <- buildUp(apiary)

We can extract the genetic and phenotypic values from multiple colonies in the same manner as from a single colony, by using get*Gv() and get*Pheno() functions. The output of these function is a named list with values for each colony or a single matrix if we set the collapse argument to TRUE.

getQueenGv(apiary) |> head(n = 4)
#> $`2`
#>   queenTrait workersTrait
#> 7   9.200188    0.1935263
#> 
#> $`3`
#>   queenTrait workersTrait
#> 8   9.407988    0.1371331
#> 
#> $`4`
#>   queenTrait workersTrait
#> 9   10.65553   0.04973425
#> 
#> $`5`
#>    queenTrait workersTrait
#> 10   10.04888   0.01709813
getQueenGv(apiary, collapse = TRUE) |> head(n = 4)
#>    queenTrait workersTrait
#> 7    9.200188   0.19352626
#> 8    9.407988   0.13713306
#> 9   10.655534   0.04973425
#> 10  10.048878   0.01709813

In a similar manner, we can calculate colony value for all the colonies in our apiary, where the row names of the output represent colony IDs.

colonyGv <- calcColonyGv(apiary)
colonyPheno <- calcColonyPheno(apiary)
data.frame(colonyGv, colonyPheno)
#>    colonyGv colonyPheno
#> 2  23.58079    21.18151
#> 3  21.72725    17.06889
#> 4  15.20923    13.50888
#> 5  16.40233    21.87448
#> 6  15.59941    16.63599
#> 7  15.35661    17.70586
#> 8  15.44107    21.01592
#> 9  13.38616    14.40012
#> 10 27.22745    28.05505
#> 11 19.36851    19.97296
#> 12 26.20844    27.47294
#> 13 14.04794    17.16944
#> 14 15.03548    15.23956
#> 15 30.18441    28.65295

Selection on colony values

Since the aim of selection is to select the best individuals or colonies for the reproduction, we could select the best colony in our apiary based on either genetic or phenotypic value for grafting the new generation of virgin queens. We can use the function selectColonies() that takes a matrix of colony values (the output of calcColonyValue() function). The default behavior is to select the colonies with the highest value (argument selectTop set to TRUE), but you can also select the colonies with the lowest values (argument selectTop set to FALSE).

# Select the best colony based on gv
selectColonies(apiary, n = 1, by = colonyGv)
#> An object of class "MultiColony" 
#> Number of colonies: 1 
#> Are empty: 0 
#> Are NULL: 0 
#> Have split: 0 
#> Have swarmed: 0 
#> Have superseded: 0 
#> Have collapsed: 0 
#> Are productive: 0
# Select the best colony based on phenotype
selectColonies(apiary, n = 1, by = colonyPheno)
#> An object of class "MultiColony" 
#> Number of colonies: 1 
#> Are empty: 0 
#> Are NULL: 0 
#> Have split: 0 
#> Have swarmed: 0 
#> Have superseded: 0 
#> Have collapsed: 0 
#> Are productive: 0

The same functionality is implemented in pullColonies() and removeColonies().

Honey yield and Calmness

In this section we expand simulation to two uncorrelated colony traits with queen and workers effects, honey yield and calmness. We follow the same recipe as in the previous section where we simulated only one colony trait.

We first reinitialize the global simulation parameters because we will define new traits. For honey yield we will use the same parameters as before, while for calmness trait we will assume that the trait is scored continuously in such a way that negative values are undesirable and positive values are desirable with zero being population mean. We will further assume the same variances for calmness as for honey yield, and a genetic (and environmental) correlation between the queen and workers effects of -0.4 (and 0.2) for calmness. We assume no genetic or environmental correlation between honey yield and calmness. Beware, this is just an example to show you how to simulate multiple colony traits - we have made up these parameters - please use literature estimates in your simulations!

# Global simulation parameters
SP <- SimParamBee$new(founderGenomes)

nQtlPerChr <- 100

# Quantitative genetic parameters - for two traits, each with the queen and workers effects
meanP <- c(10, 10 / SP$nWorkers, 0, 0)
varA <- c(1, 1 / SP$nWorkers, 1, 1 / SP$nWorkers)
corA <- matrix(data = c( 1.0, -0.5,  0.0,  0.0, 
                        -0.5,  1.0,  0.0,  0.0,
                         0.0,  0.0,  1.0, -0.4, 
                         0.0,  0.0, -0.4,  1.0), nrow = 4, byrow = TRUE)
SP$addTraitA(nQtlPerChr = 100, mean = meanP, var = varA, corA = corA,
             name = c("yieldQueenTrait", "yieldWorkersTrait",
                      "calmQueenTrait", "calmWorkersTrait"))

varE <- c(3, 3 / SP$nWorkers, 3, 3 / SP$nWorkers)
corE <- matrix(data = c(1.0, 0.3, 0.0, 0.0,
                        0.3, 1.0, 0.0, 0.0,
                        0.0, 0.0, 1.0, 0.2,
                        0.0, 0.0, 0.2, 1.0), nrow = 4, byrow = TRUE)
SP$setVarE(varE = varE, corE = corE)

We continue by creating a base population of virgin queens and from them an apiary with 10 full-sized colonies.

basePop <- createVirginQueens(founderGenomes)
drones <- createDrones(x = basePop[1:5], nInd = 100)
apiary <- createMultiColony(basePop[6:20])
droneGroups <- pullDroneGroupsFromDCA(drones, nColonies(apiary), nDrones = 15)
apiary <- cross(x = apiary, drones = droneGroups)
apiary <- buildUp(apiary)
apiary
#> An object of class "MultiColony" 
#> Number of colonies: 15 
#> Are empty: 0 
#> Are NULL: 0 
#> Have split: 0 
#> Have swarmed: 0 
#> Have superseded: 0 
#> Have collapsed: 0 
#> Are productive: 15

We can again inspect the genetic (and phenotypic) values of all individuals in each colony and whole apiary with get*Gv() and get*Pheno() functions. Now, the output contains four traits representing the queen and workers effect for honey yield and calmness. These functions also take an nInd argument to sample a number of individuals along with their values.

getQueenGv(apiary) |> head(n = 4)
#> $`1`
#>   yieldQueenTrait yieldWorkersTrait calmQueenTrait calmWorkersTrait
#> 6        11.82853        -0.0224759     -0.1682083      -0.09075997
#> 
#> $`2`
#>   yieldQueenTrait yieldWorkersTrait calmQueenTrait calmWorkersTrait
#> 7        10.83617          0.141209     0.05132336       0.08916698
#> 
#> $`3`
#>   yieldQueenTrait yieldWorkersTrait calmQueenTrait calmWorkersTrait
#> 8        8.923291          0.198829      0.1627241       0.02703916
#> 
#> $`4`
#>   yieldQueenTrait yieldWorkersTrait calmQueenTrait calmWorkersTrait
#> 9        9.262901         0.2160272       1.303112       -0.1314202
getWorkersPheno(apiary, nInd = 3) |> head(n = 4)
#> $`1`
#>     yieldQueenTrait yieldWorkersTrait calmQueenTrait calmWorkersTrait
#> 521        8.648488       -0.06710429     -0.2099416       0.05586035
#> 522        9.232204        0.17106030      1.8043842       0.33406650
#> 523       10.459903        0.10737787      0.5774723       0.15905454
#> 
#> $`2`
#>     yieldQueenTrait yieldWorkersTrait calmQueenTrait calmWorkersTrait
#> 721        7.043597        0.04169057     -0.6333621      -0.26933430
#> 722       12.677674        0.04930101     -1.0053234      -0.01056375
#> 723       11.460471        0.28036816     -0.4614164       0.04934549
#> 
#> $`3`
#>     yieldQueenTrait yieldWorkersTrait calmQueenTrait calmWorkersTrait
#> 921        8.798280         0.4431042     -1.9818639     -0.003672032
#> 922        8.803095         0.1702675      3.4007082      0.066017394
#> 923        9.906069         0.1797117      0.1451122      0.124170668
#> 
#> $`4`
#>      yieldQueenTrait yieldWorkersTrait calmQueenTrait calmWorkersTrait
#> 1121        9.481855         0.1621409      0.8585575       -0.5669580
#> 1122        4.950670        -0.3477064      0.2903785        0.1156920
#> 1123        6.965683         0.1207894     -0.2717474       -0.1411396

Now, we calculate colony genetic and phenotypic values for all colonies in the apiary. Since we are simulating two traits, honey yield and calmness, we have two ways to calculate corresponding colony values. The first way is to use the default mapCasteToColony*() function in calcColony*() and only define additional arguments as shown here:

colonyValues <- calcColonyPheno(apiary,
                                queenTrait = c("yieldQueenTrait", "calmQueenTrait"),
                                workersTrait = c("yieldWorkersTrait", "calmWorkersTrait"),
                                traitName = c("yield", "calmness"),
                                checkProduction = c(TRUE, FALSE)) |> as.data.frame()
colonyValues
#>        yield    calmness
#> 1  20.914033  -6.5388319
#> 2  23.358794   0.6837650
#> 3  26.964649   4.8189210
#> 4  27.338393  -3.4432502
#> 5  14.606407   0.7338846
#> 6   9.512212   8.2118787
#> 7  28.824018  -6.0453066
#> 8  17.655183   9.2070699
#> 9  22.822100   2.0453784
#> 10 16.063799   3.6468418
#> 11 14.587629   2.7448354
#> 12 14.742038  -6.5325840
#> 13 26.607542   1.3437542
#> 14 32.288726 -16.0739414
#> 15 19.823084   0.8841144

The second way is to create our own mapping function. An equivalent outcome to the above is shown below just to demonstrate use of your own function, but we are simply just reusing mapCasteToColonyPheno() twice;)

myMapCasteToColonyPheno <- function(colony) {
  yield <- mapCasteToColonyPheno(colony,
                                 queenTrait = "yieldQueenTrait",
                                 workersTrait = "yieldWorkersTrait",
                                 traitName = "yield",
                                 checkProduction = TRUE)
  calmness <- mapCasteToColonyPheno(colony,
                                    queenTrait = "calmQueenTrait",
                                    workersTrait = "calmWorkersTrait",
                                    traitName = "calmness",
                                    checkProduction = FALSE)
  return(cbind(yield, calmness))
}
colonyValues <- calcColonyPheno(apiary, FUN = myMapCasteToColonyPheno) |> as.data.frame()
colonyValues
#>        yield    calmness
#> 1  20.914033  -6.5388319
#> 2  23.358794   0.6837650
#> 3  26.964649   4.8189210
#> 4  27.338393  -3.4432502
#> 5  14.606407   0.7338846
#> 6   9.512212   8.2118787
#> 7  28.824018  -6.0453066
#> 8  17.655183   9.2070699
#> 9  22.822100   2.0453784
#> 10 16.063799   3.6468418
#> 11 14.587629   2.7448354
#> 12 14.742038  -6.5325840
#> 13 26.607542   1.3437542
#> 14 32.288726 -16.0739414
#> 15 19.823084   0.8841144

Again, we can now select the best colony based on the best phenotypic value for either yield, calmness, or an index of both. Let’s say that both traits are equally important so we select on a weighted sum of both of them - we will use the AlphaSimR selIndex() function that enables this calculation along with scaling. We will represent the index such that it has a mean of 100 and standard deviation of 10 units.

colonyValues$Index <- selIndex(Y = colonyValues, b = c(0.5, 0.5), scale = TRUE) * 10 + 100
bestColony <- selectColonies(apiary, n = 1, by = colonyValues$Index)
getId(bestColony)
#> [1] 3

We see that we selected colony with ID “3”, but we would be selecting a different colony based on different selection criteria (yield, calmness, or index).

Strength and honey yield

In this section we change simulation to two traits where the phenotype realisation of the first trait affects the phenotype realisation of the second trait. Specifically, we will assume that queen’s fecundity, and hence the number of workers, is under the genetic affect of the queen and her environment. Furthermore, we will assume as before that colony honey yield is due to the queen effect and workers effect. Since the value of the workers effect depends on then number of workers, we obtain correlation between fecundity and honey yield, even if these traits would be uncorrelated on the queen level. We emphasise that this is just an example and the biology of these traits might be different.

We follow the same logic as before and simulate three traits that will contribute to two colony traits, queen’s fecundity, that is colony strength, and honey yield. We assume that fecundity is only due to the queen (and not the workers), hence we simulate only the queen effect for this trait. For honey yield we again assume that both the queen and workers contribute to the colony value. For speed of simulation we only simulate 100 workers per colony on average and split honey yield mean between the queen and workers. We measure fecundity with the number of workers, which is a count variable and for such variables Poisson distribution is a good model. This distribution has just one parameter (lambda) that represents both the mean and variance of the variable. To this end we set phenotypic variance to 100 and split it into 25 for genetic and 65 for environmental variance. As before we warn that these are just exemplary values to demonstrate the code functionality and do not necessarily reflect published values!

# Global simulation parameters
SP <- SimParamBee$new(founderGenomes)

# Quantitative genetic parameters
# - the first trait has only the queen effect
# - the second trait has both the queen and workers effects
nWorkers <- 100
mean <- c(nWorkers, 10, 10 / nWorkers)
varA <- c(25, 1, 1 / nWorkers)
corA <- matrix(data = c(1.0,  0.0,  0.0,
                        0.0,  1.0, -0.5, 
                        0.0, -0.5,  1.0), nrow = 3, byrow = TRUE)
SP$addTraitA(nQtlPerChr = 100, mean = mean, var = varA, corA = corA,
             name = c("fecundityQueenTrait", "yieldQueenTrait", "yieldWorkersTrait"))

varE <- c(75, 3, 3 / nWorkers)
corE <- matrix(data = c(1.0, 0.0, 0.0,
                        0.0, 1.0, 0.3,
                        0.0, 0.3, 1.0), nrow = 3, byrow = TRUE)
SP$setVarE(varE = varE, corE = corE)

We continue by creating an apiary with 10 colonies.

basePop <- createVirginQueens(founderGenomes)
drones <- createDrones(x = basePop[1:5], nInd = 100)
apiary <- createMultiColony(basePop[6:20])
droneGroups <- pullDroneGroupsFromDCA(drones, nColonies(apiary), nDrones = 15)
apiary <- cross(x = apiary, drones = droneGroups)

Let’s explore queen’s genetic and phenotypic values for fecundity and honey yield. The below printouts show quite some variation in fecundity between queens at the genetic, but particularly phenotypic level. This is a small example, so we should not put too much into correlations between these three variables. However, if you restart this simulation many times, you will notice zero correlation on average between fecundityQueenTrait and the other two traits and negative correlation on average between yieldQueenTrait and yieldWorkersTrait. Just like we defined in the global simulation parameters.

#>    fecundityQueenTrait yieldQueenTrait yieldWorkersTrait
#> 6             95.68035        9.669921        0.11893594
#> 7             96.83894       10.558976        0.21783115
#> 8            100.69610       10.089713        0.17045667
#> 9            103.58202       10.696622        0.16453594
#> 10            95.71064        8.363420        0.21176075
#> 11           102.48752        9.524525        0.03156796
#> 12           100.46456        9.346915        0.07719766
#> 13            93.93850       10.608018        0.06993098
#> 14            91.99681        8.342885        0.11704031
#> 15           108.90167        8.324746        0.16701437
#> 16           101.32383       10.735532        0.32395391
#> 17            95.73145       11.495982        0.09262128
#> 18            95.01375       11.106660        0.07780567
#> 19            97.42606       10.818611        0.01834771
#> 20            95.31111        9.179990        0.14137301
#>                     fecundityQueenTrait yieldQueenTrait yieldWorkersTrait
#> fecundityQueenTrait         1.000000000      -0.2608176       0.002623878
#> yieldQueenTrait            -0.260817566       1.0000000       0.692363678
#> yieldWorkersTrait           0.002623878       0.6923637       1.000000000

We next build-up colonies in the apiary. But instead of building them all up to the same fixed number of workers, we build them up according to queen’s fecundity. For that we use the sampling function nWorkersColonyPhenotype(), that samples the number of workers based on phenotypes of colony members, in our case fecundityQueenTrait in queens. Correspondingly, each colony will have a different number of workers. Read more about this function in it’s help page.

apiary <- buildUp(apiary, nWorkers = nWorkersColonyPhenotype,
                  queenTrait = "fecundityQueenTrait")
cbind(nWorkers = nWorkers(apiary), queenPheno)
#>    nWorkers fecundityQueenTrait yieldQueenTrait yieldWorkersTrait
#> 1        95            94.73723        9.479112       -0.06068114
#> 2       113           112.54872       11.302061        0.07516987
#> 3        77            77.23596        7.678633       -0.25152185
#> 4        97            97.45506        8.894370        0.06935865
#> 5       104           103.83075        7.027089       -0.07118176
#> 6        90            90.45883        8.956308        0.10401962
#> 7       102           101.57568        8.866865        0.08258566
#> 8        98            97.89710       11.266423        0.12252859
#> 9        82            82.39998       10.001117        0.03502474
#> 10      116           115.58083        7.925524        0.20982306
#> 11       84            83.51717       13.414509        0.44779798
#> 12      101           100.68054       10.838098        0.05402152
#> 13       83            82.90426       13.786644        0.31331936
#> 14      108           107.89443       10.466731        0.03512150
#> 15       95            95.38857        9.986051       -0.08931975
help(nWorkersColonyPhenotype)

To compute the colony value for honey yield, we again employ the calcColonyPheno() function. Correlating the queen and colony values we will now see a positive correlation because our individual to colony mapping function sums workers effect across all workers and the more workers there are the larger the sum.

#>                        nWorkers fecundityQueenTrait yieldQueenTrait
#> nWorkers             1.00000000         0.999633815      -0.2486969
#> fecundityQueenTrait  0.99963382         1.000000000      -0.2608176
#> yieldQueenTrait     -0.24869689        -0.260817566       1.0000000
#> yieldWorkersTrait    0.01530729         0.002623878       0.6923637
#> yield                0.08801345         0.077254130       0.4099688
#>                     yieldWorkersTrait      yield
#> nWorkers                  0.015307290 0.08801345
#> fecundityQueenTrait       0.002623878 0.07725413
#> yieldQueenTrait           0.692363678 0.40996879
#> yieldWorkersTrait         1.000000000 0.54041704
#> yield                     0.540417041 1.00000000