Last data update: 2014.03.03
|
R: Finds extreme points in the empirical density estimated from...
findPeaksAndValleys | R Documentation |
Finds extreme points in the empirical density estimated from data
Description
Finds extreme points in the empirical density estimated from data.
Usage
## 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
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)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(aroma.light)
aroma.light v3.2.0 (2016-01-06) successfully loaded. See ?aroma.light for help.
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/aroma.light/findPeaksAndValleys.Rd_%03d_medium.png", width=480, height=480)
> ### Name: findPeaksAndValleys
> ### Title: Finds extreme points in the empirical density estimated from
> ### data
> ### Aliases: findPeaksAndValleys findPeaksAndValleys.density
> ### findPeaksAndValleys.numeric
> ### Keywords: methods internal
>
> ### ** Examples
>
> 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)
type x density
1 peak -0.1334831 0.392287
> 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)
type x density
1 peak -0.08501183 0.12317918
2 valley 1.99788931 0.04586722
3 peak 3.97835269 0.12463149
4 valley 5.95881607 0.04457639
5 peak 7.93927946 0.12506953
> 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)
type x density
1 peak -0.01396756 3.427949e-01
2 valley 1.97896545 1.227938e-06
3 peak 3.97189847 3.422092e-01
4 valley 5.98626087 1.178856e-06
5 peak 7.97919389 3.426187e-01
> plot(d, lwd=2, main="c(x1b,x2b,x3b)")
> abline(v=fit$x)
>
>
>
>
>
> dev.off()
null device
1
>
|
|