findBestNpvs {ramwas}R Documentation

Quickly Find N Smallest P-values in a Long Vector

Description

Finding top, say, 100 p-values out of millions can be slow. This function does it much faster than the usual application of order(pv)[1:N].

Usage

findBestNpvs(pv, n)

Arguments

pv

Vector of p-values.

n

Number of best p-values to select.

Details

The function is a faster analog of sort(order(pv)[1:N])

Value

Return a vector of positions of the smallest N p-values in pv.

Author(s)

Andrey A Shabalin andrey.shabalin@gmail.com

See Also

See order.

Examples

pv = runif(1000)^10
n = 100

# Faster version
topSites1 = findBestNpvs(pv, n)

# Slow alternative
topSites2 = sort(order(pv)[1:n])

# The results must match
stopifnot(all( topSites1 == topSites2 ))

[Package ramwas version 1.18.0 Index]