Check Consistency of Base Segment in Melatonin Profile
Source:R/check_base_profile_consistency.R
dot-check_base_profile_consistency.RdThis function checks for consistency issues in the base segment of a melatonin profile. It evaluates the following conditions:
Presence of NA values in the base segment.
Descents in melatonin concentration across the threshold of 2.3 ng/mL within the base segment.
Large slope differences (greater than half the threshold value) in the base segment.
Arguments
- profile_data
A tibble containing melatonin profile data with the following columns:
datetime(POSIXct): Timestamp for each data point.melatonin(numeric): Melatonin concentrations.time(numeric): Time in hours or another unit (optional, not used in this function).slope(numeric): Slope of melatonin concentration between consecutive time points.base(integer): Indicator for base segment (1 for base, 0 otherwise).
Value
A tibble containing the original profile data with three additional logical columns:
warning_na: TRUE if an NA value is present in the base segment.warning_threshold_descend: TRUE if there is a descent across the threshold within the base segment.warning_large_diff: TRUE if a slope exceeds half the threshold value within the base segment.
Details
The function prints warnings for any detected inconsistencies and returns a tibble containing the full profile with additional columns to indicate where inconsistencies occurred.
Examples
if (FALSE) { # \dontrun{
# Example profile data
profile_data <- tibble::tibble(
datetime = seq.POSIXt(from = as.POSIXct("2024-11-23 00:00:00"),
by = "hour", length.out = 10),
melatonin = c(2.5, 2.2, 2.1, 2.3, 2.8, 2.9, 3.0, 2.7, 2.4, NA),
time = seq(0, 9, 1),
slope = c(-0.3, -0.1, 0.2, 0.5, 0.1, 0.1, -0.3, -0.3, NA, NA),
base = c(1, 1, 1, 1, 1, 0, 0, 0, 0, 0)
)
# Check for inconsistencies in the base segment
dlmoR:::.check_base_profile_consistency(profile_data)
} # }