pulses_above_threshold {LightLogR} | R Documentation |
Pulses above threshold
Description
This function clusters the light data into continuous clusters (pulses) of light above/below a given threshold. Clustering may be fine-tuned by setting the minimum length of the clusters and by allowing brief interruptions to be included in a single cluster, with a specified maximum length of interruption episodes and proportion of total amount of interruptions to light above threshold.
Usage
pulses_above_threshold(
Light.vector,
Time.vector,
comparison = c("above", "below"),
threshold,
min.length = "8 mins",
max.interrupt = "2 mins",
prop.interrupt = 0.25,
epoch = "dominant.epoch",
return.indices = FALSE,
na.rm = FALSE,
as.df = FALSE
)
Arguments
Light.vector |
Numeric vector containing the light data. Missing values will
be considered as |
Time.vector |
Vector containing the time data. Can be POSIXct, hms, duration, or difftime. |
comparison |
String specifying whether the time above or below threshold
should be calculated. Can be either |
threshold |
Single numeric value or two numeric values specifying the threshold light level(s) to compare with. If a vector with two values is provided, the timing corresponding to light levels between the two thresholds will be calculated. |
min.length |
The minimum length of a pulse. Can be either a
duration or a string. If it is a string, it needs to be a valid
duration string, e.g., |
max.interrupt |
Maximum length of each episode of interruptions. Can be either a
duration or a string. If it is a string, it needs to be a valid
duration string, e.g., |
prop.interrupt |
Numeric value between |
epoch |
The epoch at which the data was sampled. Can be either a
duration or a string. If it is a string, it needs to be
either |
return.indices |
Logical. Should the cluster indices be returned? Only works if
|
na.rm |
Logical. Should missing values be removed for the calculation of
pulse metrics? Defaults to |
as.df |
Logical. Should a data frame be returned? If |
Details
The timeseries is assumed to be regular. Missing values in the light data will be replaced by 0.
Value
List or data frame with calculated values.
References
Wilson, J., Reid, K. J., Braun, R. I., Abbott, S. M., & Zee, P. C. (2018). Habitual light exposure relative to circadian timing in delayed sleep-wake phase disorder. Sleep, 41(11). doi:10.1093/sleep/zsy166
See Also
Other metrics:
bright_dark_period()
,
centroidLE()
,
disparity_index()
,
duration_above_threshold()
,
exponential_moving_average()
,
frequency_crossing_threshold()
,
interdaily_stability()
,
intradaily_variability()
,
midpointCE()
,
nvRC()
,
nvRD()
,
nvRD_cumulative_response()
,
period_above_threshold()
,
threshold_for_duration()
,
timing_above_threshold()
Examples
# Sample data
data = sample.data.environment %>%
dplyr::filter(Id == "Participant") %>%
filter_Datetime(length = lubridate::days(1)) %>%
dplyr::mutate(
Time = hms::as_hms(Datetime),
)
# Time vector as datetime
data %>%
dplyr::reframe(pulses_above_threshold(MEDI, Datetime, threshold = 250, as.df = TRUE))
# Time vector as hms time
data %>%
dplyr::reframe(pulses_above_threshold(MEDI, Time, threshold = 250, as.df = TRUE))
# Pulses below threshold
data %>%
dplyr::reframe(pulses_above_threshold(MEDI, Datetime, "below", threshold = 250, as.df = TRUE))
# Pulses within threshold range
data %>%
dplyr::reframe(pulses_above_threshold(MEDI, Datetime, threshold = c(250,1000), as.df = TRUE))