# GxE practical - Exercise 1 # Selection across environments # # This exercise looks at how the response to selection changes when we # change (1) the genetic relationships between environments and # (2) the weights used to select parents. # # Run this script from the folder containing the supporting R scripts. # Start with four environments and the settings below. After the first # run, change one thing at a time and compare the results. rm(list = ls()) # Install these first if needed: # install.packages("AlphaSimR") # install.packages("FieldSimR") library(AlphaSimR) library(FieldSimR) library(data.table) library(dplyr) library(ggplot2) set.seed(123) # ===================================================================== # 1. Set up the GxE structure - You can set these values youself # ===================================================================== # How many environments are we selecting across? nEnv <- 4 # If you change this, make sure you change index weights in part 3 # If nEnv = 2, specify the variances and correlation directly her Venv1 <- 1 Venv2 <- 1 cor12 <- 0.4 # If nEnv > 2, use FieldSimR to generate the GxE structure. # Try changing rho first. Keep the other parameters fixed for now. rho <- 0.4 # Baseline genetic correlation between environments k <- nEnv # Rank of correlation matrix (cannot exceed nEnv) gamma <- -0.5 # Skewness of genetic correlations # Parameters controlling the genetic variances across environments equal_vars <- TRUE # TRUE: equal variances; FALSE: variable variances alpha <- 1.5 # Gamma distribution shape parameter beta <- 1 # Gamma distribution parameter # Build the GxE matrices using defined parameters source("BuildGeMatrices.R") # Check the GxE structure before moving on. plot_matrix(Ce) summary(Ce[upper.tri(Ce)]) hist(diag(Ge), xlab = "Genetic variance", ylab = "Number of environments", main = "Genetic variances across environments") # ===================================================================== # 2. Create the founding population # ===================================================================== # Load the sim parameters source("GlobalParameters.R") # Create the founding population source("CreateFoundingDHs.R") # Inspect the population FoundingDH # Construct the genetic values of each founder in each environment Founding_env_gv <- FoundingDH@gv[, -1, drop = FALSE] %*% t(covs_tpe) # Check that the realised covariance matrix is close to the target. plot(as.vector(Ge), as.vector(var(Founding_env_gv)), xlab = "Target genetic covariance", ylab = "Realised genetic covariance") abline(0, 1) # ===================================================================== # 3. Run selection with different environment weights # ===================================================================== # One weight per environment. These scenarios assume nEnv = 4. # Weights determine the contribution of each environment to the index. index_scenarios <- list( equal = c(1, 1, 1, 1), env1_focus = c(1, 0, 0, 0), env2_focus = c(0, 1, 0, 0), env3_focus = c(0, 0, 1, 0), env4_focus = c(0, 0, 0, 1) ) stopifnot(all(lengths(index_scenarios) == nEnv)) # Scale each set of weights so they sum to one. index_scenarios <- lapply(index_scenarios, function(w) w / sum(w)) # Run the breeding program using the weights defined above source("RunBreedingProgram.R") # ===================================================================== # 4. Look at the response to selection # ===================================================================== source("PlotGain.R") gain_cycles # Genetic gain over cycles, by environment gain_final # Genetic gain in the final cycle # Challenge question #================================================================================================= # 5. Calculate the expected response to selection using theory (use the formula in the worksheet) #=================================================================================================