This function validates RR intervals based on minimum and maximum physiologically plausible values. Intervals outside the specified range are marked as invalid.

rr_validate_physiological(
  rr_segment,
  is_valid = rep(TRUE, length(rr_segment)),
  min_rr = 272,
  max_rr = 2000
)

Arguments

rr_segment

A numeric vector of RR intervals (in milliseconds).

is_valid

A logical vector indicating which intervals are valid initially. Defaults to all TRUE.

min_rr

The minimum acceptable RR interval (in milliseconds). Defaults to 272 ms (corresponding to a maximum heart rate of ~220 bpm).

max_rr

The maximum acceptable RR interval (in milliseconds). Defaults to 2000 ms (corresponding to a minimum heart rate of 30 bpm).

Value

A list containing two elements:

is_valid

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.

cleaned_rr

A numeric vector containing only the valid RR intervals.

Examples

# 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)
#>