R/getKrn.R

Defines functions getK.rn

Documented in getK.rn

#'@title  Environmental kernels for genomic prediction
#'
#'
#' @description Builds empirical environmental kernels for genomic prediction
#' @author Germano Martins F Costa Neto <germano.cneto@usp.br>
#' @param .Kc Kernel of environmental covariates (see envK function)
#' @param .Kg Kernel of environmental covariates
#' @param .Y data.frame Phenotypic data with three columns. The first column is a factor for environments, the second column is a factor identifying genotypes, and the third column contains the trait of interest
#' @param .X Marker matrix with individuals in rows and markers in columns. Missing markers are not allowed.
#' @param .type Kernel to be created internally. Methods currently implemented are the Reaction Norm (RN) and Random Covariate (RC).
#' @param .intrandom if TRUE, kernel related to random intercept of genotype is included.
#' @references Jarquín, D. et al (2014). A reaction norm model for genomic selection using high-dimensional genomic and environmental data. Theoretical and Applied Genetics, 127(3), 595–607. https://doi.org/10.1007/s00122-013-2243-1
#' @references Bandeira e Souza, M et al. (2017). Genomic-Enabled Prediction in Maize Using Kernel Models with Genotype × Environment Interaction. G3, 7(June), g3.117.042341. https://doi.org/10.1534/g3.117.042341
#' @references Granato, I. et al.  (2018). BGGE : A New Package for Genomic-Enabled Prediction Incorporating Genotype x Environment Interaction Models, 8(September), 3039–3047. https://doi.org/10.1534/g3.118.200435
#' @importFrom BGGE getK
#' @importFrom utils install.packages
#' @seealso envK

getK.rn = function(.Kc=NULL,
                   .Kg=NULL,
                   .Y=NULL,
                   .X = NULL,
                   .type= NULL,
                   .intrandom = NULL){

  .L = list(.Kc, .Kg, .Y)
  if(any(is.null(.L))){stop("Kc, Kg or Y is missing")}
  if(is.null(.type)){.type = "RN"}
  if(is.null(.intrandom)){.intrandom  = FALSE}
  if (!require(BGGE)) {install.packages("BGGE")}

  k.list  <- list(G = .Kg, O = .Kg)

  if(.type == "RN"){

    cat("Empirical kernel for random effects of environment and interaction GxE (reaction norm)\n")
    K <- getK(Y = .Y, X = .X, setKernel = k.list, model = "MDs",intercept.random = .intrandom)
    K <- list(G= K$G_G, W = K$G_O, GW = K$GE_O)
    K$W$Kernel  <- .Kc
    K$GW$Kernel <- K$G$Kernel * K$W$Kernel # haddamard product

    }
  if(!.type == "RN"){

    cat("Empirical kernel for random environment effects\n")
    K <- getK(Y = .Y, X = .X ,setKernel = k.list, model = "MDs",intercept.random = .intrandom)
    K <- list(G= K$G_G, W = K$G_O, GE = K$GE_G)
    K$W$Kernel  <- .Kc

    }
  return(K)
}
gcostaneto/envirotype documentation built on Feb. 19, 2020, 10:36 p.m.