Code
if(!require("readr", quietly = TRUE)){
install.packages("readr");require("readr")
}2. csv to beats files for RHRV analysis
** 2.1. Load readr package to read/write csv, Excel files.**
if(!require("readr", quietly = TRUE)){
install.packages("readr");require("readr")
}2.1.1. Read the csv file created in the previous part.
*Note: Enter the file number to be processed in FileNo<-xx.
Pre-process data files so that they can be processed by RHRV.
FileNo <- 1
FileName <- paste0("time_HR_", FileNo, ".csv")
data <- read.table(file.path("csv_xls", FileName), header = TRUE, sep = ",", colClasses = c("character", "numeric"))
hr <- data[,2]
rr <- 1/hr
rr = rr*60*10002.1.3. Load the package RHRV.
if(!require("RHRV", quietly = TRUE)){ install.packages("RHRV");require("RHRV") }
library(RHRV)2.1.4. Create a data frame for RHRV analysis.
To compute the HRV time series the BuidNIHR function is used (Build Non Interpolated Heart Reate).
This function constructs both the RR (Equation 2.1) and instantaneous heart rate (HR) series (Equation 2.2) described in Section 2.1*. *Getting started with RHRV version 2.0.
RR{n}=a(t_{n}-t_{n-1})~~~~~~~~~~(2.1)~~~~~~~~~~ HR{n}=\frac{β}{t_{n}-t_{n-1}}~~~~~~~~~~(2.2)
hrv.data <- CreateHRVData()
hrv.data <- SetVerbose(hrv.data, TRUE)
hrv.data$Beat$RR = rr
hrv.data$Beat$niHR = hr
hrv.data$Beat$Time = cumsum(rr)/10002.1.5. Create a data frame for RHRV analysis.
Figure 1: Plot of the episodic information
hrv.data <- FilterNIHR(hrv.data)
PlotNIHR(hrv.data)
hrv.data <- InterpolateNIHR(hrv.data, freqhr = 4)
PlotHR(hrv.data) 2.1.6. Create a data frame for RHRV analysis.
hrv.data <- CreateTimeAnalysis(hrv.data, size = 300, interval = 7.8125)library(tidyverse)
df <- hrv.data$TimeAnalysis %>%
as.data.frame() %>%
slice(1, 2) %>%
select(2:11)# Table 1: Summary of the previous pages
knitr::kable(df[1:10], caption = "Table 1: Summary of the analysis", digits = 3, booktabs = TRUE)| SDNN | SDANN | SDNNIDX | pNN50 | SDSD | rMSSD | IRRR | MADRR | TINN | HRVi |
|---|---|---|---|---|---|---|---|---|---|
| 19.234 | 15.853 | 8.287 | 0 | 1.717 | 1.717 | 21.533 | 0 | 51.92 | 3.323 |