threshold_for_duration {LightLogR} | R Documentation |
Find threshold for given duration
Description
This function finds the threshold for which light levels are above/below for
a given duration. This function can be considered as the inverse of
duration_above_threshold
.
Usage
threshold_for_duration(
Light.vector,
Time.vector,
duration,
comparison = c("above", "below"),
epoch = "dominant.epoch",
na.rm = FALSE,
as.df = FALSE
)
Arguments
Light.vector |
Numeric vector containing the light data. |
Time.vector |
Vector containing the time data. Can be POSIXct, hms, duration, or difftime. |
duration |
The duration for which the threshold should be found. Can be either a
duration or a string. If it is a string, it needs to be a valid
duration string, e.g., |
comparison |
String specifying whether light levels above or below the threshold
should be considered. Can be either |
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 |
na.rm |
Logical. Should missing values (NA) be removed for the calculation?
Defaults to |
as.df |
Logical. Should a data frame with be returned? If |
Value
Single numeric value or single column data frame.
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()
,
pulses_above_threshold()
,
timing_above_threshold()
Examples
N <- 60
# Dataset with 30 min < 250lx and 30min > 250lx
dataset1 <-
tibble::tibble(
Id = rep("A", N),
Datetime = lubridate::as_datetime(0) + lubridate::minutes(1:N),
MEDI = sample(c(sample(1:249, N / 2, replace = TRUE),
sample(250:1000, N / 2, replace = TRUE))),
)
dataset1 %>%
dplyr::reframe("Threshold above which for 30 mins" =
threshold_for_duration(MEDI, Datetime, duration = "30 mins"))
dataset1 %>%
dplyr::reframe("Threshold below which for 30 mins" =
threshold_for_duration(MEDI, Datetime, duration = "30 mins",
comparison = "below"))
dataset1 %>%
dplyr::reframe(threshold_for_duration(MEDI, Datetime, duration = "30 mins",
as.df = TRUE))