美文网首页R - tips
grm2asreml grm转Asreml-R V4

grm2asreml grm转Asreml-R V4

作者: 董八七 | 来源:发表于2020-03-03 16:51 被阅读0次

a wrapper of the write.relationshipMatrix function from the synbreed package. still asreml requires attr(G_a,"rowNames")<-as.character(df$Os_id_x);attr(G_a,"colNames")<-as.character(df$Os_id_x);attr(G_a,"INVERSE")<-TRUE. therefore i add them together.

#' A function used to convert a genomic relationship matrix to matrix format allowed in Asreml-R V4
#'
#' @param x A genomic relationship matrix
#' @param digits 
#'
#' @return
#' @export
#'
#' @examples
grm2asreml=function(x, digits = 10){
  rMinv <- ginv(x)
  rMinv <- round(rMinv, digits)
  res <- data.frame(Row = rep(1:nrow(rMinv), nrow(rMinv)), 
                    Column = rep(1:nrow(rMinv), each = nrow(rMinv)), coeff = as.numeric(rMinv), 
                    lower = as.logical(lower.tri(rMinv, diag = TRUE)))
  res <- res[res$lower == TRUE, c("Row", "Column", "coeff")]
  res <- res[order(res$Row, res$Column), ]
  res <- res[res$coeff != 0, ]
  attr(res,"colNames")=attr(res, "rowNames") <- rownames(x)
  attr(res,"INVERSE")<-TRUE
  rm(rMinv, x)
  return(res)
}

相关文章

网友评论

    本文标题:grm2asreml grm转Asreml-R V4

    本文链接:https://www.haomeiwen.com/subject/dfbhlhtx.html