knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(waveformtools)
library(tidyverse)
library(mgcv)
library(hms)

Fit a GAM to CVP

Find a CVP curve

sample_record2$vital$Intellivue$CVP %>% 
  dygraph_signal()

Find a less noisy period (e.g. 18:42:00 to 18:43:00)

cvp <- sample_record2$vital$Intellivue$CVP %>% 
  filter(between(as_hms(time), as_hms("11:29:00"), as_hms("11:30:00"))) %>% 
  mutate(time_s = seconds_since_start(time))
plot_signal(cvp)

Index cvp to respiratory and cardiac cycle

cvp_indexed <- cvp %>% 
  add_time_since_event(sample_record2$qrs$time, prefix = 'qrs') %>% 
  add_time_since_event(sample_record2$vscapture$insp_start$time, prefix = 'insp')

head(cvp_indexed)

Fit GAM (with bam(): a faster version og gam())

cvp_gam <- bam(
        CVP ~ s(qrs_rel_index, bs = 'cc', k = 50) +
            s(insp_rel_index, bs = 'cc', k = 30) +
            ti(
                qrs_rel_index,
                insp_rel_index,
                bs = c('cc', 'cc'),
                k = c(20, 10)
            ) +
            s(time_s),
        method = 'REML',
        data = cvp_indexed,
        nthreads = 16 # Number of (virtual) cores
    )

Visualise GAM

gratia::draw(cvp_gam)
dygraph_gam(cvp_gam, resid = TRUE)


JohannesNE/waveformtools documentation built on July 1, 2022, 8:48 p.m.