This function fits a linear model to a given segment of a melatonin profile. It estimates the slope of the best-fit line while enforcing slope constraints and edge boundary conditions if specified.
Usage
fit_linear(
x,
y,
poi,
base_id = NULL,
slope_bounds = NULL,
edge_bounds = NULL,
weight_base = TRUE
)Arguments
- x
Numeric vector of x-coordinates (decimal time).
- y
Numeric vector of y-coordinates (melatonin concentration).
- poi
List containing:
x: The x-coordinate of the Point of Interest (POI).y: The y-coordinate of the POI.
- base_id
Numeric vector. Indicator variable where
1represents base points and0represents ascending points.- slope_bounds
Numeric vector of length 2 specifying lower and upper bounds for the slope. Default is
NULL(no constraints).- edge_bounds
List containing:
left: Numeric vector[min, max]range for left boundary (base segment).right: Numeric vector[min, max]range for right boundary (ascending segment). IfNULL, no edge constraints are applied.
- weight_base
Logical. If
TRUE, applies lower weights to base points in residual computation.
Details
The function applies weights to prioritize ascending points over base points.
Slope constraints ensure that the estimated slope remains within predefined bounds.
If edge constraints are provided, the function ensures that the fitted line does not exceed specified y-limits at the segment edges.