Description Usage Arguments Details Value Examples
Determine minimum and maximum values from a smoothed curve through x-y points.
1 | zero.cross(x, y, first = FALSE, spar = NULL)
|
x, y |
x- and y-values of the curve to search for extreme values |
first |
if |
spar |
smoothing parameter for |
Multiple x values are collapsed into a single value and the
corresponding y value treated as the mean of multiple values.
The resulting x and y
values are smoothed by smooth.spline() with the smoothing parameter
spar. If spar is NULL, the value will be determined by
the algorithm and returned in model. This is the same code used in
the ribofrag package although neither are exported.
Neither x nor y can have missing values.
The endpoints of the x, y points are included in the search for extreme
values.
The function is called "zero.cross" because the point at which the first
derivative crosses zero is used to determine the extreme. The fit and choice of
spar can be evaluated by plot(x, y); lines(zero.cross(x, y)$model).
A list identifying each extreme value found in the smoothed
curve. The components of the list include x and y for the
x- and y-values, sign which is +1 for a maximum and -1 for a minimum,
and the smoothing model returned by smooth.spline() in model.
1 2 3 4 5 6 7 8 9 10 | set.seed(123)
y_ex <- 100*cumsum(rnorm(250))
x_ex <- seq_along(y_ex)
ans <- zero.cross(x_ex, y_ex, spar = 0.5)
as.data.frame(ans[1:3])
plot(x_ex, y_ex)
lines(ans$model)
abline(v = ans$x, col = ifelse(ans$sign > 0, "black", NA))
print(zero.cross(1:10, 1:10))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.