This function implements the robust algorithm for heart rate variability (HRV) time series artefact correction described in Lipponen & Tarvainen (2019). It detects and classifies artefacts such as extra, missed, misaligned, and ectopic beats in RR interval time series data.

classify_hrv_artefacts_lipponen(
  data,
  alpha = 5.2,
  c1 = 0.13,
  c2 = 0.17,
  qd_window = 91
)

Arguments

data

A dplyr::tibble with at least one column:

  • time: A numeric vector representing RR intervals (time since the last beat) in seconds.

alpha

A numeric value representing the scaling factor for threshold calculation. Defaults to 5.2 as suggested in the paper.

c1

Constant for ectopic beat detection boundary. Defaults to 0.13.

c2

Constant for ectopic beat detection boundary. Defaults to 0.17.

qd_window

Window size for quartile deviation calculation. Defaults to 91.

Value

A dplyr::tibble with the following columns:

  • time: The original RR intervals (in seconds).

  • classification: A character vector indicating the classification of each RR interval. (Same possible values as before)

Details

The algorithm uses time-varying thresholds based on the distribution of successive RR-interval differences (dRRs) and differences between individual RR intervals and a median RR interval (mRRs). It implements a decision algorithm (see Figure 1 in the paper) to classify beats into different artefact types. Missing beats are handled specially: a new row is inserted into the tibble, with the time value representing the estimated time of the missed beat (half of the "long" interval), and the classification set to "missed". This insertion ensures that subsequent calculations depending on the number of beats can be performed correctly. Long, short and ectopic beat are not corrected in this function. The original time series including all kind of original beats is returned.

References

Jukka A. Lipponen & Mika P. Tarvainen (2019) A robust algorithm for heart rate variability time series artefact correction using novel beat classification, Journal of Medical Engineering & Technology, 43:3, 173-181, DOI: 10.1080/03091902.2019.1640306

See also

stats::quantile() for quartile calculations, zoo::rollapply() for rolling window calculations.

Examples

library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
library(zoo)
#> 
#> Attaching package: ‘zoo’
#> The following objects are masked from ‘package:base’:
#> 
#>     as.Date, as.Date.numeric

# Create some sample data with a few artefacts
set.seed(123)
rr_data <- tibble(time = cumsum(rnorm(100, mean = 0.8, sd = 0.1)))
rr_data$time[50] <- rr_data$time[50] + 1.0 # Missed beat
rr_data$time[70] <- rr_data$time[70] - 0.4 # Extra beat

# Detect and classify the artefacts
rr_data_classified <- classify_hrv_artefacts_lipponen(rr_data)

# Print the rows with artefacts
print(rr_data_classified %>% filter(classification != "normal"))
#> # A tibble: 2 × 2
#>    time classification
#>   <dbl> <chr>         
#> 1  41.2 long          
#> 2  41.0 short