Added code and tests for simuloiAlleeli

This commit is contained in:
Waldir Leoncio 2020-01-30 14:57:11 +01:00
parent 0bc86d8005
commit 309519dd08
5 changed files with 43 additions and 9 deletions

View file

@ -478,12 +478,4 @@ admix1 <- function(tietue) {
# end
# end
# counter = counter+rowsFromInd;
# end
# function all = simuloiAlleeli(allfreqs,pop,loc)
# % Simuloi populaation pop lokukseen loc alleelin.
# freqs = allfreqs(:,loc,pop);
# cumsumma = cumsum(freqs);
# arvo = rand;
# isommat = find(cumsumma>arvo);
# all = min(isommat);
# end

17
R/simuloiAlleeli.R Normal file
View file

@ -0,0 +1,17 @@
#' @title simuloiAlleeli
#' @description Simuloi populaation pop lokukseen loc alleelin.
#' @note This function is (only?) called by `simulateIndividuals()`. Therefore, exporting it is probably unnecessary.
#' @export
simuloiAlleeli <- function(allfreqs, pop, loc) {
if (length(dim(allfreqs)) == 3) { # distinguish between arrays and matrices
freqs <- allfreqs[, loc, pop]
} else {
freqs <- allfreqs[, loc]
}
cumsumma <- cumsum(freqs)
arvo <- runif(1)
isommat <- which(cumsumma > arvo)
all <- min(isommat)
return(all)
}