getSegments | R Documentation |
Given two cutoffs, L and U, this function divides a numerical vector into contiguous parts that are above U, between L and U, and below L.
getSegments(x, f = NULL, cutoff = quantile(abs(x), 0.99),
assumeSorted = FALSE, verbose = FALSE)
x |
A numeric vector. |
f |
A factor used to pre-divide |
cutoff |
a numeric vector of length either 1 or 2. If length is 1, U (see details) will be cutoff and L will be -cutoff. Otherwise it specifies L and U. The function will furthermore always use the minimum of cutoff for L and the maximum for U. |
assumeSorted |
This is a statement that the function may assume
that the vector |
verbose |
Should the function be verbose? |
This function is used to find the indexes of the ‘bumps’ in functions
such as bumphunter
.
x
is a numeric vector, which is converted into three levels
depending on whether x>=U (‘up’), L<x<U (‘zero’) or x<=L
(‘down’), with L and U coming from cutoff
. We assume
that adjacent entries in x
are next to each other in some
sense. Segments, consisting of consecutive indices into x
(ie. values between 1 and length(x)
), are formed such that all
indices in the same segment belong to the same level of f
and
have the same discretized value of x
.
In other words, we can use getSegments
to find runs of x
belonging to the same level of f
and with all of the values of
x either above U, between L and U, or below L.
A list with three components, each a list of indices. Each component
of these lists represents a segment and this segment is represented by a
vector of indices into the original vectors x
and f
.
upIndex: |
a list with each entry an index of contiguous values
in the same segment. These segments have values of |
dnIndex: |
a list with each entry an index of contiguous values
in the same segment. These segments have values of |
zeroIndex: |
a list with each entry an index of contiguous
values in the same segment. These segments have values of |
Rafael A Irizarry and Kasper Daniel Hansen
clusterMaker
x <- 1:100
y <- sin(8*pi*x/100)
chr <- rep(1, length(x))
indexes <- getSegments(y, chr, cutoff=0.8)
plot(x, y, type="n")
for(i in 1:3){
ind <- indexes[[i]]
for(j in seq(along=ind)) {
k <- ind[[j]]
text(x[k], y[k], j, col=i)
}
}
abline(h=c(-0.8,0.8))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.