Learn R Programming

sitar (version 1.0.10)

getPeakTrough: Identify peaks and troughs of curve

Description

Given vectors x and y, returns their values at the peak or trough of the curve, where dy/dx = 0.

Usage

getPeakTrough(x, y, peak = TRUE)

Arguments

x

vector.

y

vector.

peak

logical determining whether peak or trough is returned.

Value

A length-2 vector containing the values of x and y at the peak or trough. If no peak/trough is identified NULL is returned invisibly.

Examples

Run this code
# NOT RUN {
## create mean height velocity curve
data(heights)
m1 <- sitar(age, height, id, heights, 4)
x <- getCovariate(m1)
y <- fitted(m1, level=0)
y <- predict(smooth.spline(x, y), x, deriv=1)$y

## and plot it
. <- order(x)
plot(y[.] ~ x[.], type='l', xlab='age', ylab='height')
points(t(getPeakTrough(x, y)), pch=17)
points(t(getPeakTrough(x, y, peak=FALSE)), pch=25)
# }

Run the code above in your browser using DataLab