zero.cross: Determine Extreme Values

Description Usage Arguments Details Value Examples

View source: R/zero.cross.R

Description

Determine minimum and maximum values from a smoothed curve through x-y points.

Usage

1
zero.cross(x, y, first = FALSE, spar = NULL)

Arguments

x, y

x- and y-values of the curve to search for extreme values

first

if TRUE, return only the first extreme value

spar

smoothing parameter for smooth.spline between 0 and 1

Details

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).

Value

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.

Examples

 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))

ornelles/flowExtra documentation built on March 1, 2020, 9:33 a.m.