This function overlays the estimated DLMO fit lines (base and ascending phase) onto a melatonin profile plot.
The fit can be either linear or parabolic, depending on the dlmoFit results.
Arguments
- plot
A ggplot object. The base plot of the melatonin profile.
- profile_data
A dataframe containing melatonin concentration data, with required columns:
datetime(POSIXct) – Time of measurement.melatonin(numeric) – Melatonin concentration levels.base(binary) – Indicator column for base segment points.ascending(binary) – Indicator column for ascending segment points.
- dlmoFit
A list containing the estimated DLMO inflection point and fit parameters, including:
inflection_point$x(decimal hours) – The estimated x-coordinate of the inflection point.inflection_point$y(numeric) – The estimated y-coordinate of the inflection point.base_params(numeric) – Slope of the linear base fit.ascending_params(list) – Either a single slope (for linear) or coefficientsa, b, c(for parabolic).
Details
The base fit is always linear and is drawn from the start of the base segment to the inflection point.
The ascending fit can be either linear or parabolic:
Linear fit: A simple straight line extending from the inflection point to the last ascending point.
Parabolic fit: A nonlinear curve extending from the inflection point to the last ascending point.
Uses
posixct_to_decimal()anddecimal_to_posixct()to convert between time formats.
Examples
if (FALSE) { # \dontrun{
plot <- ggplot2::ggplot(profile_data, ggplot2::aes(x = datetime, y = melatonin)) +
ggplot2::geom_point()
dlmoFit <- list(inflection_point = list(x = 20.5, y = 3.2),
base_params = 0.1,
ascending_params = list(a = -0.03, b = 2.1, c = 0.5))
plot_fit(plot, profile_data, dlmoFit)
} # }