Implemented simulateIndividuals
This commit is contained in:
parent
e645d00fca
commit
2e8ad9a89d
5 changed files with 60 additions and 25 deletions
25
R/admix1.R
25
R/admix1.R
|
|
@ -453,29 +453,4 @@ admix1 <- function(tietue) {
|
|||
# simuloidut = randdir(counts(1:noalle(j),j,i) , noalle(j));
|
||||
# allfreqs(1:noalle(j),j,i) = simuloidut;
|
||||
# end
|
||||
# end
|
||||
|
||||
# %--------------------------------------------------------------------------
|
||||
|
||||
|
||||
# function refData = simulateIndividuals(n,rowsFromInd,allfreqs,pop, missing_level)
|
||||
# % simulate n individuals from population pop, such that approximately
|
||||
# % proportion "missing_level" of the alleles are present.
|
||||
|
||||
# nloci = size(allfreqs,2);
|
||||
|
||||
# refData = zeros(n*rowsFromInd,nloci);
|
||||
# counter = 1; % which row will be generated next.
|
||||
|
||||
# for ind = 1:n
|
||||
# for loc = 1:nloci
|
||||
# for k=0:rowsFromInd-1
|
||||
# if rand<missing_level
|
||||
# refData(counter+k,loc) = simuloiAlleeli(allfreqs,pop,loc);
|
||||
# else
|
||||
# refData(counter+k,loc) = -999;
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# counter = counter+rowsFromInd;
|
||||
# end
|
||||
27
R/simulateIndividuals.R
Normal file
27
R/simulateIndividuals.R
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#' @title Simulate individuals
|
||||
#' @description simulate n individuals from population pop, such that
|
||||
#' proportion "missing_level" of the alleles are present.
|
||||
#' @export
|
||||
|
||||
simulateIndividuals <- function(n, rowsFromInd, allfreqs, pop, missing_level) {
|
||||
nloci <- size(allfreqs, 2)
|
||||
|
||||
refData <- zeros(n * rowsFromInd, nloci)
|
||||
counter <- 1 # which row will be generated next.
|
||||
|
||||
for (ind in 1:n) {
|
||||
for (loc in 1:nloci) {
|
||||
for (k in 0:(rowsFromInd - 1)) {
|
||||
if (runif(1) < missing_level) {
|
||||
refData[counter + k, loc] <- simuloiAlleeli(
|
||||
allfreqs, pop, loc
|
||||
)
|
||||
} else {
|
||||
refData[counter + k, loc] <- -999
|
||||
}
|
||||
}
|
||||
}
|
||||
counter <- counter + rowsFromInd
|
||||
}
|
||||
return(refData)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue