R/rr_processing.R
rr_validate_physiological.RdThis function validates RR intervals based on minimum and maximum physiologically plausible values. Intervals outside the specified range are marked as invalid.
A numeric vector of RR intervals (in milliseconds).
A logical vector indicating which intervals are valid initially. Defaults to all TRUE.
The minimum acceptable RR interval (in milliseconds). Defaults to 272 ms (corresponding to a maximum heart rate of ~220 bpm).
The maximum acceptable RR interval (in milliseconds). Defaults to 2000 ms (corresponding to a minimum heart rate of 30 bpm).
A list containing two elements:
A logical vector of the same length as rr_segment, where
TRUE indicates a valid RR interval and FALSE indicates an invalid
interval after applying the physiological limits.
A numeric vector containing only the valid RR intervals.
# Example with some values outside the default range
rr_data <- c(250, 500, 1000, 1800, 2500)
result <- rr_validate_physiological(rr_data)
print(result)
#> $is_valid
#> [1] FALSE TRUE TRUE TRUE FALSE
#>
#> $cleaned_rr
#> [1] 500 1000 1800
#>
# Example with pre-existing invalid values and a custom range
rr_data2 <- c(250, 500, 1000, 1800, 2500)
is_valid_initial <- c(TRUE, FALSE, TRUE, TRUE, FALSE)
result2 <- rr_validate_physiological(rr_data2,
is_valid = is_valid_initial,
min_rr = 400,
max_rr = 1500
)
print(result2)
#> $is_valid
#> [1] FALSE FALSE TRUE FALSE FALSE
#>
#> $cleaned_rr
#> [1] 1000
#>
# Example with empty input
result_empty <- rr_validate_physiological(numeric(0))
print(result_empty)
#> $is_valid
#> logical(0)
#>
#> $cleaned_rr
#> numeric(0)
#>