R/make_k.R

#' Kinship matrix function for complete data using the estimated variance across all loci
#'
#' This function makes a kinship matrix using the cov function. It standardizes by the estimated genic variance across all loci, not each locus individually
#' @param myG matrix where the rows are individuals/populations and the columns are loci and the values are the allele frequency (not the # of copies present in an individual!!!).
#' @export


make_k <- function (myG) 
{
  scaleFactor = sqrt(mean(colMeans(myG) * (1 - colMeans(myG))))
    myM = dim(myG)[1]
    myT = matrix(data = -1/myM, nrow = myM - 1, ncol = myM)
    diag(myT) = (myM - 1)/myM
    myGstand = (myT %*% myG)/scaleFactor
    myK = cov(t(myGstand))
    return(myK)
}
emjosephs/quaint documentation built on June 10, 2025, 2:03 a.m.