knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

AlphaSimR is a package with many useful functions to simulate plant and animal breeding schemes. But it is not very easy to implement. AlfSimHlpR defines functions that provide structure for a breeding scheme

Using AlfSimHlpR

# Make sure you have the right packages installed
neededPackages <- c("AlphaSimR", "dplyr", "tidyr", "plotrix", "lme4", "sommer", "optiSel")
for (p in neededPackages) if (!require(p, character.only=T)) install.packages(p)
suppressMessages(library(AlphaSimHlpR))

Define simulation settings

Define the genetic architecture of the population and other breeding scheme parameters in a list bsp.

bsp <- specifyPopulation(ctrlFileName="../inst/PopulationCtrlFile_Small.txt")
bsp <- specifyPipeline(bsp, ctrlFileName="../inst/ControlFile_Small.txt")
bsp <- specifyCosts(bsp, ctrlFileName="../inst/CostsCtrlFile_Small.txt")
print(bsp)

nReplications <- 3
bsp$nCyclesToRun <- 6

Run a simple breeding scheme for r bsp$nCyclesToRun cycles

Replicate a very simple breeding program r nReplications times.

replicRecords <- lapply(1:nReplications, runBreedingScheme, nCycles=bsp$nCyclesToRun, initializeFunc=initFuncADChk, productPipeline=prodPipeFncChk, populationImprovement=popImprov1Cyc, bsp)

Calculate the means of the breeding programs

And plot them out

plotData <- plotRecords(replicRecords)
meanMeans <- tapply(plotData$genValMean, list(plotData$year, plotData$stage), mean)
meanMeans <- meanMeans[,c("F1", bsp$stageNames)]
stdErrMeans <- tapply(plotData$genValMean, list(plotData$year, plotData$stage), std.error)
stdErrMeans <- stdErrMeans[,c("F1", bsp$stageNames)]
print(meanMeans)
print(stdErrMeans)


jeanlucj/AlfSimHlpR documentation built on Nov. 7, 2021, 5:10 p.m.