findPeaksAndValleys: Finds extreme points in the empirical density estimated from...

Description Usage Arguments Value Author(s) See Also Examples

Description

Finds extreme points in the empirical density estimated from data.

Usage

1
2
3
4
## S3 method for class 'density'
findPeaksAndValleys(x, tol=0, ...)
## S3 method for class 'numeric'
findPeaksAndValleys(x, ..., tol=0, na.rm=TRUE)

Arguments

x

A numeric vector containing data points or a density object.

...

Arguments passed to density. Ignored if x is a density object.

tol

A non-negative numeric threshold specifying the minimum density at the extreme point in order to accept it.

na.rm

If TRUE, missing values are dropped, otherwise not.

Value

Returns a data.frame (of class 'PeaksAndValleys') containing of "peaks" and "valleys" filtered by tol.

Author(s)

Henrik Bengtsson

See Also

This function is used by callNaiveGenotypes().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
layout(matrix(1:3, ncol=1))
par(mar=c(2,4,4,1)+0.1)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# A unimodal distribution
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x1 <- rnorm(n=10000, mean=0, sd=1)
x <- x1
fit <- findPeaksAndValleys(x)
print(fit)
plot(density(x), lwd=2, main="x1")
abline(v=fit$x)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# A trimodal distribution
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x2 <- rnorm(n=10000, mean=4, sd=1)
x3 <- rnorm(n=10000, mean=8, sd=1)
x <- c(x1,x2,x3)
fit <- findPeaksAndValleys(x)
print(fit)
plot(density(x), lwd=2, main="c(x1,x2,x3)")
abline(v=fit$x)


# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# A trimodal distribution with clear separation
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x1b <- rnorm(n=10000, mean=0, sd=0.1)
x2b <- rnorm(n=10000, mean=4, sd=0.1)
x3b <- rnorm(n=10000, mean=8, sd=0.1)
x <- c(x1b,x2b,x3b)

# Illustrating explicit usage of density()
d <- density(x)
fit <- findPeaksAndValleys(d, tol=0)
print(fit)
plot(d, lwd=2, main="c(x1b,x2b,x3b)")
abline(v=fit$x)

HenrikBengtsson/aroma.light-BioC_release documentation built on May 7, 2019, 1:55 a.m.