Skip to contents

This function identifies the inflection point in a melatonin profile by performing a grid search over a region of interest (ROI). It first conducts a coarse search over a large grid and, if fine_flag = TRUE, refines the search using a fine-grid search.

Usage

seek_inflection(
  data,
  threshold = threshold,
  roi,
  step_x = 0.1,
  step_y = 0.2,
  step_size_small = 0.01,
  fit_type = "linear",
  fine_flag = fine_flag
)

Arguments

data

A tibble containing melatonin profile data.

threshold

Numeric. The threshold value for the fit constraint.

roi

A list defining the region of interest (ROI) for the search:

  • x: A numeric vector of two values representing the min and max x-coordinates.

  • y: A numeric vector of two values representing the min and max y-coordinates.

step_x

Numeric. The step size for x-coordinates in the coarse grid (default = 0.1).

step_y

Numeric. The step size for y-coordinates in the coarse grid (default = 0.2).

step_size_small

Numeric. The step size for fine grid refinement (default = 0.01).

fit_type

Character. Type of fit used in fit():

  • "linear" (default): Uses a linear model.

  • "parabolic": Uses a parabolic model for the ascending segment.

fine_flag

Logical. If TRUE, performs an additional fine-grid search (default = fine_flag).

Value

A list containing:

  • inflection_point: The estimated inflection point (x, y).

  • base_params: Parameters of the base segment fit.

  • ascending_params: Parameters of the ascending segment fit.

  • grid_big: The coarse grid used in the first search.

  • res_big: The residuals corresponding to grid_big.

  • grid_small: The fine grid used in the second search (if fine_flag = TRUE).

  • res_small: The residuals corresponding to grid_small (if fine_flag = TRUE).

Details

  • The coarse grid search is performed over the ROI.

  • If fine_flag = TRUE, the best 10% of coarse-grid points are used to refine the search.

  • The inflection point is selected as the point that minimizes the residual error from fit().

See also

make_grid, reduce_grid, fit