-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmakeAA.R
executable file
·40 lines (39 loc) · 1.4 KB
/
makeAA.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#' Creates the additive by additive epistatic genetic relationship matrix
#'
#' Given a pedigree, the matrix of additive by additive genetic relatedness
#' (AA) among all individuals in the pedigree is returned.
#'
#' Missing parents (e.g., base population) should be denoted by either 'NA',
#' '0', or '*'.
#'
#' The function first estimates the A matrix using \code{\link{makeA}}, then it
#' calculates the Hadamard (element-wise) product of the A matrix with itself
#' (A # A).
#'
#' @param pedigree A pedigree where the columns are ordered ID, Dam, Sire
#'
#' @return a \code{list}:
#' \describe{
#' \item{AA }{the AA matrix in sparse matrix form}
#' \item{logDet }{the log determinant of the AA matrix}
#' \item{AAinv }{the inverse of the AA matrix in sparse matrix form}
#' \item{listAAinv }{the three column form of the non-zero elements for the
#' inverse of the AA matrix}
#' }
#' @author \email{matthewwolak@@gmail.com}
#' @seealso \code{\link{makeA}}
#' @examples
#'
#' makeAA(Mrode2)
#'
#' @export
makeAA <- function(pedigree)
{
A <- makeA(pedigree)
AA <- A*A
logDet <- determinant(AA, logarithm = TRUE)$modulus[1]
AAinv <- solve(AA)
AAinv@Dimnames <- list(as.character(pedigree[, 1]), NULL)
listAAinv <- sm2list(AAinv, rownames=pedigree[,1], colnames=c("row", "column", "AAinverse"))
return(list(AA = AA, logDet = logDet, AAinv = AAinv, listAAinv = listAAinv))
}