Added code and tests for simuloiAlleeli
This commit is contained in:
parent
0bc86d8005
commit
309519dd08
5 changed files with 43 additions and 9 deletions
10
R/admix1.R
10
R/admix1.R
|
|
@ -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
17
R/simuloiAlleeli.R
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue