Added poistaLiianPienet
This commit is contained in:
parent
7bb6d3224b
commit
eff04b3124
4 changed files with 82 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ export(etsiParas)
|
||||||
export(laskeMuutokset4)
|
export(laskeMuutokset4)
|
||||||
export(learn_simple_partition)
|
export(learn_simple_partition)
|
||||||
export(ownNum2Str)
|
export(ownNum2Str)
|
||||||
|
export(poistaLiianPienet)
|
||||||
export(proportion2str)
|
export(proportion2str)
|
||||||
export(rand)
|
export(rand)
|
||||||
export(randdir)
|
export(randdir)
|
||||||
|
|
|
||||||
49
R/poistaLiianPienet.R
Normal file
49
R/poistaLiianPienet.R
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
#' @title Remove too small
|
||||||
|
#' @description Muokkaa tulokset muotoon, jossa outlier yksilöt on poistettu.
|
||||||
|
#' Tarkalleen ottaen poistaa ne populaatiot, joissa on vähemmän kuin
|
||||||
|
#' 'alaraja':n verran yksilöit?
|
||||||
|
#' @param npops npops
|
||||||
|
#' @param rowsFromInd rowsFromInd
|
||||||
|
#' @param alaraja alaraja
|
||||||
|
#' @export
|
||||||
|
poistaLiianPienet <- function (npops, rowsFromInd, alaraja,
|
||||||
|
PARTITION = matrix(NA, 0, 0), COUNTS = matrix(NA, 0, 0),
|
||||||
|
SUMCOUNTS = NA) {
|
||||||
|
|
||||||
|
popSize <- zeros(1,npops)
|
||||||
|
if (npops > 0) {
|
||||||
|
for (i in 1:npops) {
|
||||||
|
popSize[i] <- length(which(PARTITION == i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
miniPops <- which(popSize < alaraja)
|
||||||
|
|
||||||
|
if (length(miniPops) == 0) {
|
||||||
|
return(npops)
|
||||||
|
}
|
||||||
|
|
||||||
|
outliers <- matrix(NA, 0, 0)
|
||||||
|
for (pop in miniPops) {
|
||||||
|
inds <- which(PARTITION == pop)
|
||||||
|
cat('Removed individuals: ')
|
||||||
|
cat(as.character(inds))
|
||||||
|
outliers = matrix(c(outliers, inds), ncol=1)
|
||||||
|
}
|
||||||
|
|
||||||
|
ninds <- length(PARTITION)
|
||||||
|
PARTITION[outliers] <- 0
|
||||||
|
korit <- unique(PARTITION(which(PARTITION > 0)))
|
||||||
|
for (n in 1:length(korit)) {
|
||||||
|
kori <- korit[n]
|
||||||
|
yksilot <- which(PARTITION == kori)
|
||||||
|
PARTITION[yksilot] == n
|
||||||
|
}
|
||||||
|
|
||||||
|
# TODO: add COUNTS, SUMCOUNTS and PARTITION to return or use <<-
|
||||||
|
COUNTS[, , miniPops] <- NA
|
||||||
|
SUMCOUNTS[miniPops, ] <- NA
|
||||||
|
|
||||||
|
npops <- npops - length(miniPops)
|
||||||
|
|
||||||
|
return(npops)
|
||||||
|
}
|
||||||
27
man/poistaLiianPienet.Rd
Normal file
27
man/poistaLiianPienet.Rd
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/poistaLiianPienet.R
|
||||||
|
\name{poistaLiianPienet}
|
||||||
|
\alias{poistaLiianPienet}
|
||||||
|
\title{Remove too small}
|
||||||
|
\usage{
|
||||||
|
poistaLiianPienet(
|
||||||
|
npops,
|
||||||
|
rowsFromInd,
|
||||||
|
alaraja,
|
||||||
|
PARTITION = matrix(NA, 0, 0),
|
||||||
|
COUNTS = matrix(NA, 0, 0),
|
||||||
|
SUMCOUNTS = NA
|
||||||
|
)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{npops}{npops}
|
||||||
|
|
||||||
|
\item{rowsFromInd}{rowsFromInd}
|
||||||
|
|
||||||
|
\item{alaraja}{alaraja}
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Muokkaa tulokset muotoon, jossa outlier yksilöt on poistettu.
|
||||||
|
Tarkalleen ottaen poistaa ne populaatiot, joissa on vähemmän kuin
|
||||||
|
'alaraja':n verran yksilöit?
|
||||||
|
}
|
||||||
|
|
@ -228,3 +228,8 @@ test_that("simulateAllFreqs works as expected", {
|
||||||
test_that("computeAllFreqs2 works as expected", {
|
test_that("computeAllFreqs2 works as expected", {
|
||||||
expect_equivalent(computeAllFreqs2(10), matrix(NA, 0, 0))
|
expect_equivalent(computeAllFreqs2(10), matrix(NA, 0, 0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test_that("poistaLiianPienet works as expected", {
|
||||||
|
expect_equal(poistaLiianPienet(100, matrix(1:4, 2), 0), 100)
|
||||||
|
expect_equal(poistaLiianPienet(100, matrix(1:4, 2), -5), 100)
|
||||||
|
})
|
||||||
Loading…
Add table
Reference in a new issue