Skip to contents

This function calculates the bounds and width of the "sweet spot" where a given y_values vector crosses a specified reference_value. It uses linear interpolation for precise crossing points.

Usage

sweet_spot_determination(
  x_values,
  y_values,
  reference_value = 0,
  larger_is_better,
  return_NA_at_boundaries = FALSE
)

Arguments

x_values

A numeric vector of x values.

y_values

A numeric vector of y values.

reference_value

A numeric reference value to determine the crossing points.

larger_is_better

Whether larger y_values are better. If FALSE, the sign of the comparison with reference_value is reversed.

return_NA_at_boundaries

If TRUE, a sweet spot bound that falls on the edge of x_values is reported as NA rather than as that edge.

Value

A list containing:

  • sweet_spot_bounds A numeric vector of length 2 with the lower and upper bounds of the sweet spot.

  • sweet_spot_widthA numeric value indicating the width of the sweet spot.