R/theta_t.R

#' Theta_t Function
#'
#' Computes the number of pairwise differences between a group of genomes,
#' normalised over the number of possible pairs.
#'
#'
#' @param  s A single genome matrix consisting of 1s and 0s as per the infinite sites
#' model. Each column represents a different genome. Each row represents a unique
#' polymorphic site within the genome.
#'
#' change this to deal with rows. since discoal does that!!!!!!
#'
#' @return A scalar value of theta_t.
#' @export
#'
#' @examples # The function takes a single argument; namely a matrix of 1's and 0s.
#'
#'   theta_t(s=genome_matrix )

# theta_t  <- function(s){
#   dim_genomes<-dim(s) #grabbing dimensions of genome matrix. Columns are genomes. Rows are the sites.
#   n<-dim_genomes[2] #getting the number of genomes
#   pairwise_diff=vector()
#   pairwise_diff  <- 0
#   for(i in 1:n-1){ # Choose all cols but last
#     for(j in i:n){ # choose remaining cols
#       pairwise_diff  <- pairwise_diff + sum(s[, i] != s[,j])
#     }
#   }
#   return (pairwise_diff/(n*(n-1)/2))
# }

#s=readRDS(file="~/work/MPhil/data/s0.1.rds")

#testing

# set.seed(2019)
# seq  <- matrix(sample(0:1, size = 100, replace = TRUE), nc = 4)
# seq
# x  <- theta_t(seq)
# y  <- sum(as.matrix((dist(t(seq), method = "manhattan"))))/2/choose(4, 2)
# identical(x, y)
deponent-verb/popgen.stats documentation built on Nov. 4, 2019, 10:26 a.m.