Last updated: 2021-08-27

Checks: 7 0

Knit directory: BreedingSchemeOpt/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20210422) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 9d369ee. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/images/.DS_Store
    Ignored:    data/.DS_Store

Untracked files:
    Untracked:  data/baselineScheme.gsheet
    Untracked:  data/siErrorVarEst_byTrialType_directApproach_2021Aug25.rds
    Untracked:  output/benchmark_sim.rds
    Untracked:  output/benchmark_sims5.rds
    Untracked:  output/burnIn_test.rds
    Untracked:  output/postBurnIn_test.rds
    Untracked:  output/test_burnIn_sim.rds

Unstaged changes:
    Modified:   data/README.md

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/AlphaSimHlpR_firstSteps.Rmd) and HTML (docs/AlphaSimHlpR_firstSteps.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
html 92bd15b wolfemd 2021-04-22 Build site.
html 1d503b6 wolfemd 2021-04-22 Build site.
html fe3048a wolfemd 2021-04-22 Build site.
Rmd 9df9d9b wolfemd 2021-04-22 Publish the initial files for the Breeding Scheme Optimization Group project

Preamble: Install AlphaSimHlpR

R packages we will need. Install them if necessary.

install.packages(c("tidyverse","AlphaSimR","devtools"))

Install AlphaSimHlpR

devtools::install_github("jeanlucj/AlphaSimHlpR", ref = 'master', 
                         dependencies = T, force = T) # force = T to ensure I get a fresh install

When prompted “Which would you like to update?” choose “1: All”.

library(AlphaSimHlpR)
# Get `Error: package ‘optiSel’ could not be loaded`??
install.packages("optiSel",dependencies = T)
library(AlphaSimHlpR)
# still error
library(optiSel)
# Error: package or namespace 
# load failed for ‘optiSel’: .on
# Load failed in loadNamespace() for 'rgl', 
# details: call:         rgl.init(initValue, onlyNULL) 
# error: OpenGL is not available in this build

Following is specific to my macOS install state

Google search of error leads to: https://stackoverflow.com/questions/9878693/error-in-loading-rgl-package-with-mac-os-x

Suggestion Solution: install XQuartz

brew install xquartz
library(AlphaSimHlpR)

Finally I get a clean load!

browseVignettes("AlphaSimHlpR")

The vignettes don’t show up… but their Rmd’s are in the GitHub Repo. Best guess: need to be added to the namespace or knit and the package master needs to be freshly built.

I downloaded the Rmd’s from GitHub here.

Basic AlphaSimHlpR tutorial

New R session. Follow the AlphaSimHlpR vignette.

I also had to download the inst folder and it’s example “control file” contents from GitHub here

# 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)
Loading required package: AlphaSimR
Loading required package: R6
Loading required package: dplyr

Attaching package: 'dplyr'
The following object is masked from 'package:AlphaSimR':

    mutate
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
Loading required package: tidyr
Loading required package: plotrix
Loading required package: lme4
Loading required package: Matrix

Attaching package: 'Matrix'
The following objects are masked from 'package:tidyr':

    expand, pack, unpack
Loading required package: sommer
Loading required package: MASS

Attaching package: 'MASS'
The following object is masked from 'package:dplyr':

    select
Loading required package: lattice
Loading required package: crayon
Loading required package: optiSel
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="data/inst/PopulationCtrlFile_Small.txt")
bsp <- specifyPipeline(bsp, ctrlFileName="data/inst/ControlFile_Small.txt")
bsp <- specifyCosts(bsp, ctrlFileName="data/inst/CostsCtrlFile_Small.txt")
nReplications <- 3
bsp$nCyclesToRun <- 6

print(bsp)
$nChr
[1] 3

$effPopSize
[1] 100

$quickHaplo
[1] TRUE

$segSites
[1] 400

$nQTL
[1] 40

$nSNP
[1] 100

$genVar
[1] 40

$gxeVar
numeric(0)

$gxyVar
[1] 15

$gxlVar
[1] 10

$gxyxlVar
[1] 5

$meanDD
[1] 0.8

$varDD
[1] 0.01

$relAA
[1] 0.5

$nStages
[1] 3

$stageNames
[1] "SDN" "CET" "PYT"

$stageToGenotype
[1] "CET"

$trainingPopCycles
 F1 SDN CET PYT 
  0   3   3   2 

$nParents
[1] 15

$nCrosses
[1] 30

$nProgeny
[1] 10

$usePolycrossNursery
[1] FALSE

$nSeeds
[1] 300

$useOptContrib
[1] FALSE

$nCandOptCont
[1] 200

$targetEffPopSize
[1] 20

$nEntries
SDN CET PYT 
200  75  20 

$nReps
SDN CET PYT 
  1   1   2 

$nLocs
SDN CET PYT 
  1   2   2 

$nClonesToNCRP
[1] 3

$nChks
SDN CET PYT 
  5   4   2 

$entryToChkRatio
SDN CET PYT 
 50  25  20 

$errVars
SDN CET PYT 
200 100  70 

$phenoF1toStage1
[1] TRUE

$errVarPreStage1
[1] 500

$useCurrentPhenoTrain
[1] FALSE

$nCyclesToKeepRecords
[1] 4

$nCyclesToRun
[1] 6

$selCritPipeAdv
function(records, candidates, bsp, SP){
  phenoDF <- framePhenoRec(records, bsp)
  # Candidates don't have phenotypes so return random vector
  if (!any(candidates %in% phenoDF$id)){
    crit <- runif(length(candidates))
  } else{
    crit <- iidPhenoEval(phenoDF)
    crit <- crit[candidates]
  }
  names(crit) <- candidates
  return(crit)
}
<bytecode: 0x7fae9fe59a40>
<environment: namespace:AlphaSimHlpR>

$selCritPopImprov
function(records, candidates, bsp, SP){
  phenoDF <- framePhenoRec(records, bsp)
  # Candidates don't have phenotypes so return random vector
  if (!any(candidates %in% phenoDF$id)){
    crit <- runif(length(candidates))
  } else{
    crit <- iidPhenoEval(phenoDF)
    crit <- crit[candidates]
  }
  names(crit) <- candidates
  return(crit)
}
<bytecode: 0x7fae9fe59a40>
<environment: namespace:AlphaSimHlpR>

$analyzeInbreeding
[1] 0

$chkReps
SDN CET PYT 
  1   1   1 

$checks
NULL

$plotCosts
SDN CET PYT 
  1   8  14 

$perLocationCost
[1] 1000

$crossingCost
[1] 0.2

$qcGenoCost
[1] 1.5

$wholeGenomeCost
[1] 10

$develCosts
[1] 60

$genotypingCosts
  CET 
862.5 

$trialCosts
     [,1]
[1,] 2645

$locationCosts
[1] 2000

$totalCosts
       [,1]
[1,] 5567.5

Replicate simple scheme

Run a simple breeding scheme for 6 cycles

Replicate a very simple breeding program 3 times.

replicRecords <- lapply(1:nReplications, runBreedingScheme, 
                        nCycles=bsp$nCyclesToRun, 
                        initializeFunc=initFuncADChk, 
                        productPipeline=prodPipeFncChk, 
                        populationImprovement=popImprov1Cyc, bsp)
****** 1 
[1] "initFuncADChk deprecated. Please use initializeScheme"
1  [1] "prodPipeFncChk deprecated. Please use productPipeline"
2  [1] "prodPipeFncChk deprecated. Please use productPipeline"
3  [1] "prodPipeFncChk deprecated. Please use productPipeline"
4  [1] "prodPipeFncChk deprecated. Please use productPipeline"
5  [1] "prodPipeFncChk deprecated. Please use productPipeline"
6  [1] "prodPipeFncChk deprecated. Please use productPipeline"

****** 2 
[1] "initFuncADChk deprecated. Please use initializeScheme"
1  [1] "prodPipeFncChk deprecated. Please use productPipeline"
2  [1] "prodPipeFncChk deprecated. Please use productPipeline"
3  [1] "prodPipeFncChk deprecated. Please use productPipeline"
4  [1] "prodPipeFncChk deprecated. Please use productPipeline"
5  [1] "prodPipeFncChk deprecated. Please use productPipeline"
6  [1] "prodPipeFncChk deprecated. Please use productPipeline"

****** 3 
[1] "initFuncADChk deprecated. Please use initializeScheme"
1  [1] "prodPipeFncChk deprecated. Please use productPipeline"
2  [1] "prodPipeFncChk deprecated. Please use productPipeline"
3  [1] "prodPipeFncChk deprecated. Please use productPipeline"
4  [1] "prodPipeFncChk deprecated. Please use productPipeline"
5  [1] "prodPipeFncChk deprecated. Please use productPipeline"
6  [1] "prodPipeFncChk deprecated. Please use productPipeline"

Calculate means and plot results

Calculate the means of the breeding programs and plot them out

plotData <- plotRecords(replicRecords)

Version Author Date
fe3048a wolfemd 2021-04-22

Version Author Date
fe3048a wolfemd 2021-04-22

Version Author Date
fe3048a wolfemd 2021-04-22

Version Author Date
fe3048a wolfemd 2021-04-22
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)
         F1       SDN       CET       PYT
0  4.788684  3.384214  3.435910  5.784658
1  6.776836  5.591508  5.605060  6.483341
2  7.695134  7.481067  7.393820  9.799798
3  9.214746  8.525191  9.620269 10.129217
4  9.482519 10.021769 10.581698 12.783492
5 11.339604 10.248401 11.430718 14.049004
6 11.932867 11.979959 12.009061 13.983051
print(stdErrMeans)
         F1       SDN       CET       PYT
0 0.1294490 0.3511957 0.4192225 0.5054042
1 0.6598288 0.1100316 0.3948318 0.4281404
2 0.5907782 0.5954389 0.3311990 0.4274365
3 0.4103964 0.5907788 0.7397421 0.4224925
4 0.3596464 0.5870375 0.8675606 0.7937926
5 0.8101920 0.5019150 0.7412440 0.7320315
6 0.3171822 0.6888787 0.3588681 0.2304982

Next step

Run a simple example simulation of the effect of reducing error with new tools.


sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] AlphaSimHlpR_0.2.1 optiSel_2.0.5      sommer_4.1.4       crayon_1.4.1      
 [5] lattice_0.20-44    MASS_7.3-54        lme4_1.1-27.1      Matrix_1.3-4      
 [9] plotrix_3.8-1      tidyr_1.1.3        dplyr_1.0.7        AlphaSimR_1.0.3   
[13] R6_2.5.0           workflowr_1.6.2   

loaded via a namespace (and not attached):
 [1] magic_1.5-9          sass_0.4.0           foreach_1.5.1       
 [4] jsonlite_1.7.2       splines_4.1.0        ECOSolveR_0.5.4     
 [7] cccp_0.2-7           bslib_0.2.5.1        assertthat_0.2.1    
[10] highr_0.9            yaml_2.2.1           numDeriv_2016.8-1.1 
[13] pillar_1.6.2         glue_1.4.2           quadprog_1.5-8      
[16] alabama_2015.3-1     optiSolve_0.1.2      digest_0.6.27       
[19] promises_1.2.0.1     minqa_1.2.4          htmltools_0.5.1.1   
[22] httpuv_1.6.1         plyr_1.8.6           pkgconfig_2.0.3     
[25] purrr_0.3.4          whisker_0.4          later_1.2.0         
[28] git2r_0.28.0         shapes_1.2.6         tibble_3.1.3        
[31] generics_0.1.0       ellipsis_0.3.2       pedigree_1.4        
[34] cachem_1.0.5         magrittr_2.0.1       memoise_2.0.0       
[37] evaluate_0.14        kinship2_1.8.5       fs_1.5.0            
[40] fansi_0.5.0          doParallel_1.0.16    nlme_3.1-152        
[43] tools_4.1.0          data.table_1.14.0    HaploSim_1.8.4      
[46] minpack.lm_1.2-1     lifecycle_1.0.0      pspline_1.0-18      
[49] stringr_1.4.0        compiler_4.1.0       pkgdown_1.6.1       
[52] jquerylib_0.1.4      rlang_0.4.11         grid_4.1.0          
[55] nloptr_1.2.2.2       iterators_1.0.13     htmlwidgets_1.5.3   
[58] crosstalk_1.1.1      rmarkdown_2.10       boot_1.3-28         
[61] nadiv_2.17.1         codetools_0.2-18     abind_1.4-5         
[64] DBI_1.1.1            reshape2_1.4.4       knitr_1.33          
[67] fastmap_1.1.0        utf8_1.2.2           rprojroot_2.0.2     
[70] stringi_1.7.3        parallel_4.1.0       Rcpp_1.0.7          
[73] vctrs_0.3.8          rgl_0.107.10         scatterplot3d_0.3-41
[76] tidyselect_1.1.1     xfun_0.25