#

3. Optimum Contribution Selection

#### Robin Wellmann

#### 2017-12-15

The aim of optimum contribution selection (OCS) is to find the optimum number of offspring for each breeding animal and to determine if a young animal (a selection candidate) should be selected for breeding or not. This is done in an optimal way, i.e. in a way that ensures that genetic gain is achieved, and that genetic diversity and genetic originality of the population are maintained or recovered. It can be based either on pedigree data or on marker data, whereby the latter approach is recommended. It requires that data is available from a sample of the population which includes the selection candidates.

OCS can be done for populations with overlapping and non-overlapping generations. For OCS with overlapping generations, the percentage which each age class represents in the population must be defined, and the data set should contain individuals from all age classes with non-zero contribution.

Even if the frequency of use of breeding animals is not regulated by the breeding organization, running the optimization still provides valuable information for a breeder, as the animals with highest optimum contributions are most valuable for a breeding program.

This vignette is organized as follows:

- Example Data Set
- Introductory Example: Traditional OCS
- Defining the Objective of a Breeding Program
- Marker-based OCS
  - Maximize Genetic Gain
  - Minimize Inbreeding
  - Recover the Native Genetic Background
  - Increase Diversity Between Breeds
- Pedigree-based OCS
  - Maximize Genetic Gain
  - Minimize Inbreeding
  - Recover the Native Genetic Background

## Example Data Set

All evaluations using marker data are demonstrated at the example of cattle data included in the package. This multi-breed data has already been described in the companion vignette for basic marker-based evaluations.

Data frame `Cattle` includes simulated phenotypic information and has columns `Indiv` (individual IDs), `Born` (years of birth), `Breed` (breed names), `BV` (breeding values), `Sex` (sexes), and `herd` (herds).

    library("optiSel")
    data(Cattle)
    head(Cattle)

    ##           Indiv Born  Breed         BV    Sex herd
    ## Angler1 Angler1 1991 Angler -1.0706066   male <NA>
    ## Angler2 Angler2 1994 Angler -0.3362574 female    2
    ## Angler3 Angler3 1986 Angler -2.0735649 female    1
    ## Angler4 Angler4 1987 Angler  1.5968307   male <NA>
    ## Angler5 Angler5 1994 Angler  1.0023969   male <NA>
    ## Angler6 Angler6 1998 Angler -0.2426676   male <NA>

The data frame contains information on the 4 breeds Angler, Fleckvieh, Holstein, Rotbunt. The “Angler” is an endangered German cattle breed, which had been upgraded with Red Holstein (also called “Rotbunt”). The Rotbunt cattle are a subpopulation of the “Holstein” breed. The “Fleckvieh” or Simmental breed is unrelated to the Angler. The Angler cattle are the selection candidates.

This small example data set contains only genotypes from the first parts of the first two chromosomes. Vector `GTfiles` defined below contains the names of the genotype files. There is one file for each chromosome. Data frame `map` contains the marker map and has columns `Name` (marker name), `Chr` (chromosome number), `Position`, `Mb` (position in Mega base pairs), and `cM` (position in centiMorgan):

    data(map)
    dir     <- system.file("extdata", package="optiSel")
    GTfiles <- file.path(dir, paste("Chr", unique(map$Chr), ".phased", sep=""))
    head(map)

    ##                                    Name Chr Position cM       Mb
    ## ARS-BFGL-NGS-16466   ARS-BFGL-NGS-16466   1   267940  0 0.267940
    ## ARS-BFGL-NGS-98142   ARS-BFGL-NGS-98142   1   471078  0 0.471078
    ## ARS-BFGL-NGS-114208 ARS-BFGL-NGS-114208   1   533815  0 0.533815
    ## ARS-BFGL-NGS-65067   ARS-BFGL-NGS-65067   1   883895  0 0.883895
    ## ARS-BFGL-BAC-32722   ARS-BFGL-BAC-32722   1   929617  0 0.929617
    ## ARS-BFGL-BAC-34682   ARS-BFGL-BAC-34682   1   950841  0 0.950841

## Introductory Example: Traditional OCS

As an introductory example consider traditional OCS with marker based kinship matrices. All alternative approaches involve the same steps, so it is recommended to read this section even if you want to minimize inbreeding instead of maximizing genetic gain. The following steps are involved:

For populations with overlapping generations you need to define the percentage which each age class represents in the population. One possibility is to assume that the percentage represented by a class is proportional to the percentage of offspring that is not yet born. Moreover, males and females (excluding newborn individuals) should be equally represented. These percentages can be estimated with function agecont from pedigree data. Since pedigree data is not available for this data set, the percentages are entered by hand:

    cont  <- data.frame(
      age   = c(   1,    2,    3,    4,    5,    6,    7,   8,    9,    10),
      male  = c(0.14, 0.14, 0.09, 0.04, 0.03, 0.03, 0.02, 0.02, 0.01, 0.01),
      female= c(0.08, 0.08, 0.07, 0.06, 0.05, 0.04, 0.03, 0.02, 0.02, 0.02))

One age class spans one year and the individuals born in the current year are in age class 1. Note that in this example young male classes have higher percentages than young female classes because males were used for breeding at an earlier age. The generation interval in years is approximately

    L <- 1/(4*cont$male[1]) + 1/(4*cont$female[1])
    L

    ## [1] 4.910714

Define a data frame containing the phenotypes of a sample from the population which includes the selection candidates. Make sure that there is one column for each trait that should be improved. Logical column `isCandidate` is appended indicating the individuals available as selection candidates.

    phen <- Cattle[Cattle$Breed=="Angler",]
    phen$isCandidate <- phen$Born<=2013

Compute the kinships that are to be managed. Below, the kinship is named `sKin`, which is a shorthand for segment based kinship.

    sKin <- segIBD(GTfiles, map)

    ## Using  skip = 2
    ## Using cskip = 2
    ## Reading chromosome 1 ...M=400
    ## Reading chromosome 2 ...M=400

Create variable `cand` with function candes, containing all information required to describe the selection candidates, which are the phenptypes and the kinships. The current values of the parameters in the population and the available objective functions and constraints for OCS are shown. Generations are defined to be non-overlapping if argument `cont` is omitted.

    cand  <- candes(phen=phen, sKin=sKin, cont=cont)

    ## Column 'Sire' was missing. It is set to NA.
    ## Column 'Dam' was missing. It is set to NA.
    ## The population is evaluated at time 2014
    ##
    ##  Mean values of the parameters are:   Value
    ##  for trait   'BV'   in Angler:       -0.0530
    ##  for kinship 'sKin' in Angler:        0.0550
    ##
    ##  Available objective functions and constraints:
    ##  for trait   'BV'   in Angler: min.BV, max.BV, lb.BV, eq.BV, ub.BV
    ##  for kinship 'sKin' in Angler: min.sKin, ub.sKin
    ##
    ##  ub  lb uniform

For numeric columns in data frame `phen` the possibility is provided to define an upper bound (prefix `ub`), a lower bound (prefix `lb`), an equality constraint (prefix `eq`), or to minimize (prefix `min`) or to maximize (prefix `max`) the weighted sum of the values, whereby the weights are the contributions of the selection candidates. If the column contains breeding values, then this is the expected mean breeding value in the offspring.

For each kinship and native kinship included in the call of function candes, the possibility is provided to define an upper bound for the expected mean value of the kinship in the offspring (prefix `ub`), or to minimize the value (prefix `min`).

Constraints `ub` and `lb` allow to define upper bounds and lower bounds for the contributions of the selection candidates. Constraint `uniform` allows to assume that individuals belonging to specified groups have equal contributions.

Now choose the parameters you want to restrict and the parameters you want to optimize. For traditional OCs the objective is to maximize genetic gain with method `max.BV`, and to restrict the mean kinship in the offspring by defining constraint `ub.sKin`.

The upper bound for the mean kinship in the offspring should depend on the current mean kinship in the population, which is included in component `mean` of `cand`.

    cand$mean

    ##           BV       sKin
    ## 1 -0.0529632 0.05497215

In general, if an upper bound for a kinship \(K\) should be defined, it is recommended to derive the threshold value from the desired effective size \(N_e\) of the population by the formula \[ub.K=\overline{K}+(1-\overline{K})\Delta F,\] where \(\overline{K}\) is the current mean kinship in the population, which has been estimated above, \(\Delta F=\frac{1}{2 N_eL}\), and \(L\) is the generation interval. The critical effective size, i. e. the size below which the fitness of the population steadily decreases, depends on the population and is usually between 50 and 100. But there seems to be a consensus that 50-100 is a long-term viable effective size. To be on the safe side, an effective size of \(N_e=100\) should be envisaged (T H E Meuwissen 2009).

A list containing the constraints is defined below.

    Ne <- 100

    con <- list(
      uniform = "female",
      ub.sKin = cand$mean$sKin + (1-cand$mean$sKin)*(1/(2*Ne*L))
    )

The component named `ub.sKin` defines the upper bound for the mean kinship `sKin` in the population in the next year. Component `uniform = "female"` states that all females from a particular age cohort should have equal contributions, so only the contributions of male selection candidates will be optimized. Upper and lower bounds for the contributions of selection candidates could be defined with `lb` and `ub` (see the help page of function opticont).

Now the optimum contributions of the selection candidates can be calculated:

    Offspring <- opticont("max.BV", cand, con, trace=FALSE)

    ##
    ## Using solver 'cccp2' with parameters:
    ##          Value
    ## trace        0
    ## abstol   1e-05
    ## feastol  1e-05
    ## stepadj    0.9
    ## maxiters   100
    ## reltol   1e-06
    ## beta       0.5
    ##
    ##             valid solver  status
    ##              TRUE  cccp2 optimal
    ##
    ##    Variable                  Value      Bound    OK?
    ##    --------------------------------------------------
    ##    BV                 Angler 0.2594 max        :
    ##    --------------------------------------------------
    ##    lower bounds              all x  >=  lb     : TRUE
    ##    upper bounds              all x  <=  ub     : TRUE
    ##    breed contribution Angler 1      ==  1      : TRUE
    ##    sex contrib. diff. Angler 0      ==  0      : TRUE
    ##    BV                 Angler 0.2594            :
    ##    sKin               Angler 0.0559 <=  0.0559 : TRUE
    ##    --------------------------------------------------

The report above states that the solution is considered optimal by the solver and that all constraints are fulfilled since valid=TRUE. This information can also be obtained as

    Offspring$info

    ##   valid solver  status
    ## 1  TRUE  cccp2 optimal

The value of the objective function can be accessed as

    Offspring$obj.fun

    ##        BV
    ## 0.2594244

and the expected average values of the kinshps and traits in the offspring are

    Offspring$mean

    ##          BV       sKin
    ## 1 0.2594244 0.05593452

The results are OK. If they are not, then try to use another solver. The solver can be specified in parameter `solver` of function opticont. Available solvers are `"alabama"`, `"cccp"`, `"cccp2"`, `"csdp"`, and `"slsqp"`. By default the solver is chosen automatically. Alternatively, the same solver may be used but with different tuning parameters. The available paramters are displayed if the function opticont is called (as shown above).

The optimum contributions of the selection candidates are in component `parent`:

    Candidate <- Offspring$parent[,  c("Indiv", "Sex", "oc", "herd")]
    head(Candidate[Candidate$Sex=="male" & Candidate$oc>0.001,])

    ##               Indiv  Sex         oc herd
    ## Angler147 Angler147 male 0.28480012 <NA>
    ## Angler166 Angler166 male 0.13096065 <NA>
    ## Angler171 Angler171 male 0.08411906 <NA>

In general, since the number of females with offspring is large, we expect that about \(\frac{N_e}{4L}\approx 5\) new males are selected each year. In the first year of OCS with overlapping generation often only very few individuals are selected for breeding. This changes in subsequent years and can be avoided by imposing upper bounds for the optimum contributions.

The numbers of offspring can be obtained from the optimum contributions and the size `N` of the offspring population with function noffspring. These values are rounded up or down to whole numbers.

    Candidate$n <- noffspring(Candidate, N=20)$nOff
    head(Candidate[Candidate$Sex=="male" & Candidate$oc>0.001,])

    ##               Indiv  Sex         oc herd  n
    ## Angler147 Angler147 male 0.28480012 <NA> 11
    ## Angler166 Angler166 male 0.13096065 <NA>  6
    ## Angler171 Angler171 male 0.08411906 <NA>  3

Males and females can be allocated for mating with function matings such that all breeding animals have the desired number of matings. In the example below the mean marker-based inbreeding coefficient in the offspring is minimized.

    Mating <- matings(Candidate, Kin=sKin)

    ## Optimal branch and bound solution found

    head(Mating)

    ##         Sire       Dam n
    ## 2  Angler166  Angler66 1
    ## 4  Angler147  Angler76 1
    ## 7  Angler147 Angler106 1
    ## 11 Angler166 Angler109 1
    ## 13 Angler147 Angler110 1
    ## 18 Angler171 Angler113 1

The mean inbreeding in the offspring (which is equal to the mean kinship of the parents) is:

    attributes(Mating)$objval

    ## [1] 0.02286156

## Defining the Objective of a Breeding Program

The objective of a breeding program depends on several factors. These are the intended use of the breed, the presence of historic bottlenecks, and the importance being placed on the maintenance of genetic originality. In most livestock breeds the focus is on increasing the economic merit, so the objective of the breeding program is to maximize genetic gain. In contrast, companion animals often suffer from historic bottlenecks due to an overuse of popular sires. Hence, in these breeds the objective is to minimize inbreeding. In endangered breeds, which get subsidies for conservation, the focus may be on increasing their conservation values by recovering the native genetic background or by increasing the genetic distance to other breeds.

However, these are conflicting objectives: For maximizing genetic gain, the animals with highest breeding values would be used for breeding, which may create a new bottleneck and contribute to inbreeding depression. Maximizing genetic gain would also favor the use of animals with high genetic contributions from commercial breeds because these animals often have the highest breeding values. But this would reduce the genetic originality of the breed. Minimizing inbreeding in the offspring favors the use of animals with high contributions from other breeds because they have low kinship with the population and it may require the use of outcross animals with breeding values below average.

Thus, focussing on only one aspect automatically worsens the other ones. This can be avoided by imposing constraints on the aspects that are not optimized.

In general, best practice is genotying all selection candidates to enable marker based evaluations. A breeding program based on marker information is more efficient than a breeding program based only on pedigree information, provided that the animals are genotyped for a sufficient number of markers. For several species, however, genotyping is still too expensive, so the breeding programs rely only on pedigree information.

Depending on what the objective of the breeding program is, you may continue reading at the appropriate section:

- Marker-based OCS
  - Maximize Genetic Gain
  - Minimize Inbreeding
  - Recover the Native Genetic Background
  - Increase Diversity Between Breeds
- Pedigree-based OCS
  - Maximize Genetic Gain
  - Minimize Inbreeding]
  - Recover the Native Genetic Background

## Marker-based OCS

The required genotype file format, the marker map, the parameters `minSNP`, `minL`, `unitL`, `unitP`, and `ubFreq`, which are used for estimating the segment based kinship, the kinships at native haplotype segments, and the breed composition, have been described in the companion vignette for basic marker-based evaluations.

The breed composition of individuals can be estimated with function segBreedComp. Since native contributions `NC` of the Angler cattle should be considered, they are computed and added as an additional column to data frame `Cattle`.

    wdir  <- file.path(tempdir(), "HaplotypeEval")
    wfile <- haplofreq(GTfiles, Cattle, map, thisBreed="Angler", minL=1.0, w.dir=wdir)
    Comp  <- segBreedComp(wfile$match, map)
    Cattle[rownames(Comp), "NC"] <- Comp$native

    head(Cattle[,-1])

    ##         Born  Breed         BV    Sex herd        NC
    ## Angler1 1991 Angler -1.0706066   male <NA> 0.5805690
    ## Angler2 1994 Angler -0.3362574 female    2 0.5687157
    ## Angler3 1986 Angler -2.0735649 female    1 0.7418098
    ## Angler4 1987 Angler  1.5968307   male <NA> 0.4045441
    ## Angler5 1994 Angler  1.0023969   male <NA> 0.2239983
    ## Angler6 1998 Angler -0.2426676   male <NA> 0.2458519

A matrix containing the segment based kinship between all pairs of individuals can be computed with function segIBD, whereas the kinships at native haplotype segments can be calculated from the results of function segIBDatN. Both kinships are computed below. These kinships and the phenotypes of the selection candidates are combined into a single R-object with function candes. This function computes also the current values of the parameters in the population and displays the available objective functions and constraints. Below, the kinship at native haplotype segments is named `sKinatN`:

    phen    <- Cattle[Cattle$Breed=="Angler",]
    phen$isCandidate <- phen$Born<=2013

    sKin    <- segIBD(GTfiles, map, minL=1.0)
    sKinatN <- segIBDatN(GTfiles, Cattle, map, thisBreed="Angler", minL=1.0)

    cand  <- candes(phen=phen, sKin=sKin, sKinatN=sKinatN, cont=cont)

    ## Column 'Sire' was missing. It is set to NA.
    ## Column 'Dam' was missing. It is set to NA.
    ## The population is evaluated at time 2014
    ##
    ##  Mean values of the parameters are:   Value
    ##  for trait     'BV'      in Angler:  -0.0530
    ##  for trait     'NC'      in Angler:   0.4091
    ##  for kinship   'sKin'    in Angler:   0.0550
    ##  for nat. kin. 'sKinatN' in Angler:   0.0765
    ##
    ##  Available objective functions and constraints:
    ##  for trait     'BV'      in Angler: min.BV, max.BV, lb.BV, eq.BV, ub.BV
    ##  for trait     'NC'      in Angler: min.NC, max.NC, lb.NC, eq.NC, ub.NC
    ##  for kinship   'sKin'    in Angler: min.sKin, ub.sKin
    ##  for nat. kin. 'sKinatN' in Angler: min.sKinatN, ub.sKinatN
    ##
    ##  ub  lb uniform

Compared to the introductory example the possibility to restrict or to maximize native contributions became available because column `NC` was added to data frame `Cattle`. Additionally, the possibility to minimize or to restrict the kinship at native segments `sKinatN` became available since this kinship was used as an argument to function candes. The current mean values in the population are

    cand$mean

    ##           BV        NC       sKin    sKinatN
    ## 1 -0.0529632 0.4090566 0.05497215 0.07654763

Function opticont can now be used to perform the optimization.

Depending on what the objective of the breeding program is, you may continue reading at the appropriate section:

- Maximize Genetic Gain
- Minimize Inbreeding
- Recover the Native Genetic Background
- Increase Diversity Between Breeds

### Maximize Genetic Gain

First we create a list of constraints:

    con <- list(
      uniform = "female",
      ub.sKin = cand$mean$sKin + (1-cand$mean$sKin)*(1/(2*Ne*L))
      )

Again, equal contributions are assumed for the females and only the contributions of males are to be optimized. The upper bound for the mean segment based kinship was derived from the effective population size as explained above. Now the optimum contributions of the selection candidates can be calculated:

    Offspring   <- opticont("max.BV", cand, con, trace=FALSE)

    Offspring$info

    ##   valid solver  status
    ## 1  TRUE  cccp2 optimal

The expected values of the parameters in the next generation are

    Offspring$mean

    ##          BV        NC       sKin    sKinatN
    ## 1 0.2594244 0.4015824 0.05593452 0.07955012

The results are the same as in the introductory example (as expected). This approach may be apppropriate for a population without introgression, but for populations with historic introgression, the kinship at native alleles should be restricted as well in accordance with the desired effective size, and the native contributions should be restricted in order not to decrease. Otherwise the genetic originality of the breed may get lost in the long term.

    con <- list(
      uniform    ="female",
      ub.sKin    = cand$mean$sKin    + (1-cand$mean$sKin)*(1/(2*Ne*L)),
      ub.sKinatN = cand$mean$sKinatN + (1-cand$mean$sKinatN)*(1/(2*Ne*L)),
      lb.NC      = cand$mean$NC
      )

    Offspring2 <- opticont("max.BV", cand, con)

For comparison, the summaries of both scenarios are combined into a single data frame:

    rbind(Ref=cand$mean, maxBV=Offspring$mean, maxBV2=Offspring2$mean)

    ##                BV        NC       sKin    sKinatN
    ## Ref    -0.0529632 0.4090566 0.05497215 0.07654763
    ## maxBV   0.2594244 0.4015824 0.05593452 0.07955012
    ## maxBV2  0.2370521 0.4090577 0.05529105 0.07748867

Since native contributions and breeding values are negatively correlated, the genetic gain decreases slightly when native contributions are constrained not to decrease.

### Minimize Inbreeding

Minimizing inbreeding means to minimize the average kinship of the population in order to enable breeders to avoid inbreeding. This is the appropriate approach e.g. for companion animals suffering from a historic bottleneck. It can be done with or without accounting for breeding values. In the example below no breeding values are considered since accurate breeding values are not available for most of these breeds.

First we create a list of constraints:

    con  <- list(uniform="female")

Again, equal contributions are assumed for the females and only the contributions of males are to be optimized. The segment based kinship is not constrained in this example because it should be minimized.

    Offspring   <- opticont("min.sKin", cand, con)

    rbind(cand$mean, Offspring$mean)

    ##           BV        NC       sKin    sKinatN
    ## 1 -0.0529632 0.4090566 0.05497215 0.07654763
    ## 2 -0.1413072 0.4320944 0.04867808 0.06362482

Minimizing kinship without constraining the mean breeding value decreases the mean breeding value in the offspring slightly because the individuals with high breeding values are related. For this breed, it also increases the native contribution because the individuals from other breeds that were used for upgrading were related.

While in livestock breeds the native contributions should be restricted in order to maintain the genetic originality of the breeds, in several companion breeds the opposite is true. Several companion breeds have high inbreeding coefficients and descend from only very few (e.g. 3) founders (Wellmann and Pfeiffer 2009), and purging seems to be not feasible. Hence, a sufficient genetic diversity of the population cannot be achieved in the population even if marker data is used to minimize inbreeding. For these breeds it may be appropriate to use unrelated individuals from a variety of other breeds in order to increase the genetic diversity. However, only a small contribution from other breeds is needed, so the native contributions should be restricted also for these breeds in order to preserve their genetic originality. Hence, the difference between a breed with high diversity and a breed with low diversity suffering from inbreeding depression is, that the optimum value for the native contribution is smaller than 1 for the latter.

For such a breed it is advisable to allow the use of unrelated individuals from other breeds but to restrict the admissible mean contribution from other breeds in the population. The mean kinship at native alleles should be restricted as well to require only a small amount of introgression:

    con <- list(
      uniform    = "female",
      lb.NC      = cand$mean$NC + 0.04,
      ub.sKinatN = cand$mean$sKinatN + (1-cand$mean$sKinatN)*(1/(2*Ne*L))
    )
    Offspring2     <- opticont("min.sKin", cand, con)

For comparison, the estimates for both scenarios are combined into a single data frame:

    rbind(Ref=cand$mean, minKin=Offspring$mean, minKin2=Offspring2$mean)

    ##                 BV        NC       sKin    sKinatN
    ## Ref     -0.0529632 0.4090566 0.05497215 0.07654763
    ## minKin  -0.1413072 0.4320944 0.04867808 0.06362482
    ## minKin2 -0.1855352 0.4490567 0.05088076 0.07244558

Of course, for a companion breed, the lower bound for the native contribution should be much higher.

### Recover the Native Genetic Background

For endangered breeds the priority of a breeding program could be to recover the original genetic background by maximizing native contributions. However, since the individuals with highest native contributions are related, this may considerably increase the inbreeding coefficients if the diversity at native alleles is not preserved. Hence, constraints are defined below not only for the segment based kinship but also for the kinship at native segments in accordance with the desired effective size:

    con <- list(
      uniform    = "female",
      ub.sKin    = cand$mean$sKin    + (1-cand$mean$sKin   )*(1/(2*Ne*L)),
      ub.sKinatN = cand$mean$sKinatN + (1-cand$mean$sKinatN)*(1/(2*Ne*L))
    )
    Offspring <- opticont("max.NC", cand, con)

    Offspring$info

    ##   valid solver  status
    ## 1  TRUE  cccp2 optimal

    Offspring$mean

    ##           BV        NC       sKin    sKinatN
    ## 1 -0.1496039 0.4507294 0.05229563 0.07750082

For this breed, maximizing native contributions results in negative genetic gain because native contributions and breeding values are negatively correlated. This can be avoided by adding an additional constraint for the breeding values:

    con <- list(
      uniform    = "female",
      ub.sKin    = cand$mean$sKin    + (1-cand$mean$sKin   )*(1/(2*Ne*L)),
      ub.sKinatN = cand$mean$sKinatN + (1-cand$mean$sKinatN)*(1/(2*Ne*L)),
      lb.BV      = cand$mean$BV
    )

    Offspring2  <- opticont("max.NC", cand, con)

For comparison, the estimated parameters of both scenarios are combined into a single data frame:

    rbind(Ref=cand$mean, maxNC=Offspring$mean, maxNC2=Offspring2$mean)

    ##                BV        NC       sKin    sKinatN
    ## Ref    -0.0529632 0.4090566 0.05497215 0.07654763
    ## maxNC  -0.1496039 0.4507294 0.05229563 0.07750082
    ## maxNC2 -0.0529570 0.4487906 0.05219637 0.07748910

### Increase Diversity Between Breeds

While removing introgressed genetic material from the population is one possibility to increase the conservation value of an endangered breed, an alternative approach is to increase the genetic distance between the endangered breed and commercial breeds. In this case we do not care about whether alleles are native or not. We just want to accumulate haplotype segments which are rare in commercial breeds. This can be done with a core set approach.

In the core set approach, a hypothetical population is considered, consisting of individuals from various breeds. This population is called the core set. The contributions of each breed to the core set are such that the genetic diversity of the core set is maximized.

In the following example the parameter to be minimized is the mean kinship of individuals from the core set in the next generation. Constraint `uniform` defined below states that the contributions of the male selection candidates from the breed of interest are to be optimized, whereas individuals from all other breeds have uniform contributions.

Since the average kinship in a multi-breed population should be managed, argument `phen` of function cand contains individuals from all genotyped breeds. This was not the case in the above examples, where argument `phen` contained only the selection candidates.

    Cattle$isCandidate <- Cattle$Born<=2013
    cand <- candes(phen=Cattle, sKin=sKin, sKinatN.Angler=sKinatN, bc="sKin", cont=cont)

    ## Column 'Sire' was missing. It is set to NA.
    ## Column 'Dam' was missing. It is set to NA.
    ## The population is evaluated at time 2014
    ##
    ##  Mean values of the parameters are:              Value
    ##  for trait     'NC'             in Angler    :   0.4091
    ##  for trait     'BV'             across breeds:  -0.0684
    ##  for trait     'BV.Angler'      in Angler    :  -0.0530
    ##  for trait     'BV.Holstein'    in Holstein  :   0.0130
    ##  for trait     'BV.Fleckvieh'   in Fleckvieh :  -0.1136
    ##  for trait     'BV.Rotbunt'     in Rotbunt   :   0.0886
    ##  for kinship   'sKin'           across breeds:   0.0350
    ##  for nat. kin. 'sKinatN.Angler' in Angler    :   0.0765
    ##  for kinship   'sKin.Angler'    in Angler    :   0.0550
    ##  for kinship   'sKin.Holstein'  in Holstein  :   0.1071
    ##  for kinship   'sKin.Fleckvieh' in Fleckvieh :   0.0684
    ##  for kinship   'sKin.Rotbunt'   in Rotbunt   :   0.1070
    ##
    ##  Available objective functions and constraints:
    ##  for trait     'NC'             in Angler    : min.NC, max.NC, lb.NC, eq.NC, ub.NC
    ##  for trait     'BV'             across breeds: min.BV, max.BV, lb.BV, eq.BV, ub.BV
    ##  for trait     'BV.Angler'      in Angler    : min.BV.Angler, max.BV.Angler, lb.BV.Angler, eq.BV.Angler, ub.BV.Angler
    ##  for trait     'BV.Holstein'    in Holstein  : min.BV.Holstein, max.BV.Holstein, lb.BV.Holstein, eq.BV.Holstein, ub.BV.Holstein
    ##  for trait     'BV.Fleckvieh'   in Fleckvieh : min.BV.Fleckvieh, max.BV.Fleckvieh, lb.BV.Fleckvieh, eq.BV.Fleckvieh, ub.BV.Fleckvieh
    ##  for trait     'BV.Rotbunt'     in Rotbunt   : min.BV.Rotbunt, max.BV.Rotbunt, lb.BV.Rotbunt, eq.BV.Rotbunt, ub.BV.Rotbunt
    ##  for kinship   'sKin'           across breeds: min.sKin, ub.sKin
    ##  for nat. kin. 'sKinatN.Angler' in Angler    : min.sKinatN.Angler, ub.sKinatN.Angler
    ##  for kinship   'sKin.Angler'    in Angler    : min.sKin.Angler, ub.sKin.Angler
    ##  for kinship   'sKin.Holstein'  in Holstein  : min.sKin.Holstein, ub.sKin.Holstein
    ##  for kinship   'sKin.Fleckvieh' in Fleckvieh : min.sKin.Fleckvieh, ub.sKin.Fleckvieh
    ##  for kinship   'sKin.Rotbunt'   in Rotbunt   : min.sKin.Rotbunt, ub.sKin.Rotbunt
    ##
    ##  ub  lb uniform

    mKin <- cand$mean$sKinatN.Angler
    con  <- list(
      uniform = c("Angler.female", "Fleckvieh", "Holstein", "Rotbunt"),
      ub.sKinatN.Angler = mKin + (1-mKin)*(1/(2*Ne*L))
      )

The upper bound for the mean native kinship was derived from the effective population size as explained above. Now the optimum contributions of the selection candidates can be calculated:

    Offspring <- opticont("min.sKin", cand, con, trace=FALSE)

    ##
    ## Using solver 'cccp' with parameters:
    ##          Value
    ## trace        0
    ## abstol   1e-05
    ## feastol  1e-05
    ## stepadj    0.9
    ## maxiters   100
    ## reltol   1e-06
    ## beta       0.5
    ##
    ## A square matrix was approximated by a positive
    ##   definite matrix with relative distance 6e-04.
    ##             valid solver  status
    ##              TRUE   cccp optimal
    ##
    ##    Variable                         Value      Bound    OK?
    ##    ---------------------------------------------------------
    ##    sKin               across breeds 0.0332 min        :
    ##    ---------------------------------------------------------
    ##    lower bounds                     all x  >=  lb     : TRUE
    ##    upper bounds                     all x  <=  ub     : TRUE
    ##    breed contribution Angler        0.4791 ==  0.4791 : TRUE
    ##    breed contribution Holstein      0.0443 ==  0.0443 : TRUE
    ##    breed contribution Fleckvieh     0.4243 ==  0.4243 : TRUE
    ##    breed contribution Rotbunt       0.0523 ==  0.0523 : TRUE
    ##    sex contrib. diff. Angler        0      ==  0      : TRUE
    ##    sex contrib. diff. Holstein      0      ==  0      : TRUE
    ##    sex contrib. diff. Fleckvieh     0      ==  0      : TRUE
    ##    sex contrib. diff. Rotbunt       0      ==  0      : TRUE
    ##    NC                 Angler        0.4333            :
    ##    BV                 across breeds -0.1166            :
    ##    BV                 Angler        -0.1453            :
    ##    BV                 Holstein      0.029             :
    ##    BV                 Fleckvieh     -0.1244            :
    ##    BV                 Rotbunt       0.0861            :
    ##    sKin               across breeds 0.0332            :
    ##    sKin               Angler        0.0487            :
    ##    sKin               Holstein      0.1075            :
    ##    sKin               Fleckvieh     0.0687            :
    ##    sKin               Rotbunt       0.1078            :
    ##    sKinatN            Angler        0.0637 <=  0.0775 : TRUE
    ##    ---------------------------------------------------------

    Offspring$info

    ##   valid solver  status
    ## 1  TRUE   cccp optimal

    Offspring$mean

    ##          NC         BV BV.Angler BV.Holstein BV.Fleckvieh BV.Rotbunt
    ## 1 0.4333183 -0.1165935 -0.145326  0.02899812    -0.124364 0.08612751
    ##         sKin sKin.Angler sKin.Holstein sKin.Fleckvieh sKin.Rotbunt
    ## 1 0.03315834  0.04872121     0.1074871     0.06871999    0.1077745
    ##   sKinatN.Angler
    ## 1     0.06368671

Since the contributions of the selection candidates minimize the mean kinship `sKin` in the core set, they maximize the genetic diversity of the core set. This is achieved by increasing the gentic diversity within the breed or by increasing the genetic distance between the breed of interest and the other breeds. The optimum contributions are standardized so that their sum is equal to one within each breed:

    head(Offspring$parent[Offspring$parent$oc>0.02,c("Breed","lb","oc","ub")])

    ##           Breed lb         oc ub
    ## Angler8  Angler  0 0.02383260 NA
    ## Angler14 Angler  0 0.13923596 NA
    ## Angler16 Angler  0 0.07641662 NA
    ## Angler25 Angler  0 0.05764641 NA
    ## Angler30 Angler  0 0.02743479 NA
    ## Angler53 Angler  0 0.07552095 NA

## Pedigree-based OCS

All evaluations using pedigree data are demonstrated at the example of the Hinterwald cattle. A pedigree is contained in the package. The pedigree and the functions dealing with pedigree data have already been described in the companion vignette for basic pedigree-based evaluations.

The pedigree completeness is an important factor to get reliable results. If an animal has many missing ancestors, then it would falsely considered to be unrelated to other animals, so it will falsely obtain high optimum contributions. There are several approaches to overcome this problem:

- Calculate the pedigree completeness for all selection candidates and exclude individuals with a small number of equivalent complete generations from the evaluations. The number of equivalent complete generations can be computed with function summary.

- Classify the breed of founders born after some fixed date as `unknown`, and restrict the genetic contribution from these founders in the offspring. The breed names of the founders can be classified by using appropriate values for parameters `lastNative` and `thisBreed` in function prePed.

- Classify the breed of founders born after some fixed date as `unknown`, so that these founders are considered non-native, and restrict or minimize the kinship at native alleles which is less affected by incomplete pedigrees than the classical pedigree-based kinship.

Of course, all 3 approaches can be followed simultaneously. First, we prepare the pedigree and classify the breed of founders born after 1970 to be `unknown`:

    data("PedigWithErrors")
    Pedig <- prePed(PedigWithErrors, thisBreed="Hinterwaelder", lastNative=1970)

    tail(Pedig[,-1])

    ##                             Sire             Dam    Sex         Breed Born
    ## 276000813677673  276000813368988 276000812749878 female Hinterwaelder 2007
    ## 276000812771580  276000812771544 276000891438774 female Hinterwaelder 2006
    ## 276000892197676  276000812771544 276000811287686 female Hinterwaelder 2006
    ## 276000813517568  276000813121706 276000812905334 female Hinterwaelder 2007
    ## 276000813752879  276000811903592 276000812803634 female Hinterwaelder 2007
    ## 276000891978029 S276000891978029 276000891978027 female Hinterwaelder 2008
    ##                   I        BV Offspring
    ## 276000813677673 1.5 0.6354795     FALSE
    ## 276000812771580 3.5 1.2294519     FALSE
    ## 276000892197676 4.5 0.5375719     FALSE
    ## 276000813517568 2.0 0.6818203     FALSE
    ## 276000813752879 4.0 0.7640241     FALSE
    ## 276000891978029 2.0 1.3397333     FALSE

The breed composition of individuals can be estimated with function pedBreedComp. Since the native contribution should be considered in some scenarios, they are added as additional column `NC` to the pedigree.

    cont     <- pedBreedComp(Pedig, thisBreed="Hinterwaelder")
    Pedig$NC <- cont$native
    tail(cont[, 2:5])

    ##                     native   unknown      unbek0  Fleckvieh
    ## 276000813677673 0.48454285 0.2441406 0.029510498 0.09605408
    ## 276000812771580 0.31429291 0.5390625 0.020900726 0.06287766
    ## 276000892197676 0.37435150 0.4394531 0.023830414 0.06507492
    ## 276000813517568 0.50592804 0.1152344 0.032798767 0.08444214
    ## 276000813752879 0.58937836 0.1464844 0.035198212 0.10577011
    ## 276000891978029 0.08495712 0.8837891 0.004339218 0.01391411

Below, the Hinterwald cattle born between 1980 and 1990 with at least 4 complete equivalent generations in the pedigree are selected to describe the population and the individuals being at least 1 year old are chosen as selection candidates. The aim is computing optimum contributions of the selection candidates to the birth cohort 1991. Data frame `phen` is defined below, which contains the individual IDs in Colmumn 1 (`Indiv`), sexes in Column 2 (`Sex`), breed names (`Breed`), years of birth (`Born`), breeding values (`BV`), and the native contributions (`NC`) of the individuals. Finally, the logical column `isCandidate` indicating the selection candidates is appended.

    use   <- Pedig$Born %in% (1980:1990) & Pedig$Breed=="Hinterwaelder"
    use   <- use & summary(Pedig)$equiGen>=4
    phen  <- Pedig[use, c("Indiv", "Sex", "Breed", "Born", "BV", "NC")]
    phen$isCandidate <- phen$Born<=1991

Since cattle have overlapping generations, the percentage which each age class represents in the population must be defined. One possibility is to assume that the percentage represented by a class is proportional to the percentage of offspring that is not yet born. Moreover, males and females (excluding newborn individuals) should be equally represented. Percentages fulfilling these assumptions can obtained with function agecont:

    cont     <- agecont(Pedig, phen$Indiv)
    head(cont)

    ##   age       male     female
    ## 1   1 0.16547917 0.07255799
    ## 2   2 0.16500502 0.07255799
    ## 3   3 0.12162008 0.06704857
    ## 4   4 0.05500167 0.05675740
    ## 5   5 0.01849194 0.04740178
    ## 6   6 0.01090550 0.03804617

The generation interval is approximately

    L <- 1/(4*cont$male[1]) + 1/(4*cont$female[1])
    L

    ## [1] 4.956284

The breeding values were simulated such that breeding values and native contributions are negatively correlated. This mimics historic introgression from a high-yielding commercial breed.

A matrix containing the pedigree based kinship between all pairs of individuals can be computed with function pedIBD. It is half the additive relationship matrix. The pedigree based kinship at native alleles can be calculated from the results of function pedIBDatN.

The data fame containing phenotypes and the kinships are combined below into a single R-object with function candes. This function also estimates the current values of the parameters in the population and displays the available objective functions and constraints. Below, the pedigree based kinship is named `pKin`, and the kinship at native alleles is named `pKinatN`:

    pKin    <- pedIBD(Pedig, keep.only=phen$Indiv)
    pKinatN <- pedIBDatN(Pedig, thisBreed="Hinterwaelder", keep.only=phen$Indiv)

    cand <- candes(phen=phen, pKin=pKin, pKinatN=pKinatN, cont=cont)

    ## Column 'Sire' was missing. It is set to NA.
    ## Column 'Dam' was missing. It is set to NA.
    ## The population is evaluated at time 1990
    ##
    ##  Mean values of the parameters are:          Value
    ##  for trait     'BV'      in Hinterwaelder:  -0.6212
    ##  for trait     'NC'      in Hinterwaelder:   0.6236
    ##  for kinship   'pKin'    in Hinterwaelder:   0.0253
    ##  for nat. kin. 'pKinatN' in Hinterwaelder:   0.0451
    ##
    ##  Available objective functions and constraints:
    ##  for trait     'BV'      in Hinterwaelder: min.BV, max.BV, lb.BV, eq.BV, ub.BV
    ##  for trait     'NC'      in Hinterwaelder: min.NC, max.NC, lb.NC, eq.NC, ub.NC
    ##  for kinship   'pKin'    in Hinterwaelder: min.pKin, ub.pKin
    ##  for nat. kin. 'pKinatN' in Hinterwaelder: min.pKinatN, ub.pKinatN
    ##
    ##  ub  lb uniform

Compared to the introductory example the possibility to restrict or to maximize native contributions becomes available because column `NC` is now included in data frame `phen`. Additionally, there is the possibility to minimize or to restrict the kinship at native alleles `pKinatN` and the pedigree based kinship `pKin`.

For defining appropriate threshold values for the constraints, the current mean kinships, the mean native contribution, and the mean breeding value in the population need to be known. The values can be obtained as

    cand$mean

    ##           BV        NC       pKin    pKinatN
    ## 1 -0.6212472 0.6235631 0.02528665 0.04505241

Depending on what the objective of the breeding program is, you may continue reading at the appropriate section:

- Maximize Genetic Gain
- Minimize Inbreeding
- Recover the Native Genetic Background

### Maximize Genetic Gain

This is the traditional approach proposed by T. H. E. Meuwissen (1997). First we create a list of constraints:

    con <- list(
      uniform = "female",
      ub.pKin = cand$mean$pKin + (1-cand$mean$pKin)*(1/(2*Ne*L))
    )

Here, equal numbers of offspring are assumed for the females and only the contributions of males are to be optimized. The upper bound for the mean pedigree based kinship was derived from the effective population size as explained above. Now the optimum contributions of the selection candidates can be calculated:

    Offspring <- opticont("max.BV", cand, con)

    rbind(cand$mean, Offspring$mean)

    ##           BV        NC       pKin    pKinatN
    ## 1 -0.6212472 0.6235631 0.02528665 0.04505241
    ## 2 -0.5378618 0.6152668 0.02627022 0.04704803

This approach may be apppropriate for a population without introgression and complete pedigrees, but for populations with historic introgression, the kinship at native alleles should be restricted as well in accordance with the desired effective size, and the native contributions should be restricted in order not to decrease. Otherwise the genetic originality of the breed may get lost in the long term.

    con <- list(
      uniform    = "female",
      ub.pKin    = cand$mean$pKin    + (1-cand$mean$pKin)*(1/(2*Ne*L)),
      ub.pKinatN = cand$mean$pKinatN + (1-cand$mean$pKinatN)*(1/(2*Ne*L)),
      lb.NC      = cand$mean$NC
    )
    Offspring2     <- opticont("max.BV", cand, con)

For comparison, the parameters of both scenarios are combined into a single data frame with `rbind`:

    rbind(Ref=cand$mean, maxBV=Offspring$mean, maxBV2=Offspring2$mean)

    ##                BV        NC       pKin    pKinatN
    ## Ref    -0.6212472 0.6235631 0.02528665 0.04505241
    ## maxBV  -0.5378618 0.6152668 0.02627022 0.04704803
    ## maxBV2 -0.5487270 0.6235636 0.02588799 0.04601804

Thus, genetic gain in Method 2 is only slightly below the genetic gain in Method 1, but the native contributions do not decrease and the kinship at native alleles increases at a lower rate.

### Minimize Inbreeding

Minimizing inbreeding means to minimize the average kinship of the population in order to enable breeders to avoid inbreeding. This is the appropriate approach e.g. for companion animals suffering from a historic bottleneck. It can be done with or without accounting for breeding values. In the example below no breeding values are considered since accurate breeding values are not available for most of these breeds.

First we create a list of constraints:

    con  <- list(uniform="female")

Again, equal numbers of offspring are assumed for all females and only the contributions of males are to be optimized. The pedigree based kinship is not constrained in this example because it should be minimized.

    Offspring <- opticont("min.pKin", cand, con)

    rbind(cand$mean, Offspring$mean)

    ##           BV        NC       pKin    pKinatN
    ## 1 -0.6212472 0.6235631 0.02528665 0.04505241
    ## 2 -0.6740305 0.6293595 0.02193709 0.03875837

The approach shown above has the disadvantage that kinships between individuals are less reliable if ancestors are missing in the pedigree. The alternative approach, shown below, is to minimize the kinship at native alleles and to restrict pedigree based kinship.

While in livestock breeds the native contributions should be preserved in order to maintain the genetic originality of the breeds, in several companion breeds the opposite is true. Several companion breeds have high inbreeding coefficients and descend from only very few (e.g. 3) founders. Hence, a sufficient genetic diversity cannot be achieved in the population. For these breeds it may be appropriate to use unrelated individuals from a variety of other breeds in order to increase the genetic diversity. However, only a small contribution from other breeds is needed, so the native contributions should be restricted also for these breeds in order to preserve their genetic originality. The difference between a breed with high diversity and a breed with low diversity suffering from inbreeding depression is, that the optimum value for the native contribution is smaller than 1 for the latter. For such a breed it is advisable to allow the use of individuals from other breeds but to restrict the admissible mean contribution from other breeds.

In summary, the alternative approach is to minimize the kinship at native alleles and to restrict pedigree based kinship and native contributions:

    con  <- list(
      uniform = "female",
      lb.NC   = 1.02*cand$mean$NC,
      ub.pKin = cand$mean$pKin + (1-cand$mean$pKin)*(1/(2*Ne*L))
    )

    Offspring2  <- opticont("min.pKinatN", cand, con)

For comparison, the parameter estimates are combined into a single data frame:

    rbind(Ref=cand$mean, minKin=Offspring$mean, minKin2=Offspring2$mean)

    ##                 BV        NC       pKin    pKinatN
    ## Ref     -0.6212472 0.6235631 0.02528665 0.04505241
    ## minKin  -0.6740305 0.6293595 0.02193709 0.03875837
    ## minKin2 -0.6813351 0.6360344 0.02212155 0.03851295

The pedigree based kinship is slightly higher in the second approach, but the kinship at native alleles is lower. Since pedigree based kinships are less reliable due to missing ancestors in the pedigree, the second approach is recommended. However, the use of pedigree data has the disadvantage that only the expected kinships can be minimized. The expected kinships deviate from the realized kinships due to mendelian segregation. Hence, for breeds with serious inbreeding problems it is recommended to genotype the selection candidates and to perform marker-based optimum contribution selection.

### Recover the Native Genetic Background

For endangered breeds the priority of a breeding program could be to recover the original genetic background by maximizing native contributions. However, since the individuals with highest native contributions are related, this may considerably increase the inbreeding coefficients if the diversity at native alleles is not preserved. Hence, constraints are defined below not only for the pedigree based kinship, but also for the kinship at native alleles in accordance with the desired effective size:

    con <- list(
      uniform    = "female",
      ub.pKin    = cand$mean$pKin    + (1-cand$mean$pKin   )*(1/(2*Ne*L)),
      ub.pKinatN = cand$mean$pKinatN + (1-cand$mean$pKinatN)*(1/(2*Ne*L))
    )
    Offspring <- opticont("max.NC", cand, con)

    Offspring$mean

    ##           BV        NC       pKin    pKinatN
    ## 1 -0.6947239 0.6534619 0.02627134 0.04576731

For some breeds, native contributions and breeding values are negatively correlated, so maximizing native contributions results in negative genetic. This can be avoided by adding an additional constraint for the breeding values:

    con <- list(
      uniform    = "female",
      ub.pKin    = cand$mean$pKin    + (1-cand$mean$pKin   )*(1/(2*Ne*L)),
      ub.pKinatN = cand$mean$pKinatN + (1-cand$mean$pKinatN)*(1/(2*Ne*L)),
      lb.BV      = cand$mean$BV
    )
    Offspring2 <- opticont("max.NC", cand, con)

For comparison, the estimates for both scenarios are combined into a single data frame:

    rbind(Ref=cand$mean, maxNC=Offspring$mean, maxNC2=Offspring2$mean)

    ##                BV        NC       pKin    pKinatN
    ## Ref    -0.6212472 0.6235631 0.02528665 0.04505241
    ## maxNC  -0.6947239 0.6534619 0.02627134 0.04576731
    ## maxNC2 -0.6212445 0.6477829 0.02627221 0.04589208

## References

Meuwissen, T H E. 2009. “Genetic Management of Small Populations: A Review.” Acta Agriculturae Scand Section A 59: 71–79.

Meuwissen, T. H. E. 1997. “Maximising the Response of Selection with a Predefined Rate of Inbreeding.” J. Animal Sci 75: 934–40.

Wellmann, R., and I. Pfeiffer. 2009. “Pedigree Analysis for Conservation of Genetic Diversity and Purging.” Genetical Research (Camb) 91 (34).