## Warning: package 'readr' was built under R version 4.1.2
## Warning: package 'ggplot2' was built under R version 4.1.2
## Warning: package 'dplyr' was built under R version 4.1.2
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:gridExtra':
## 
##     combine
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Warning: package 'scales' was built under R version 4.1.2
## 
## Attaching package: 'scales'
## The following object is masked from 'package:readr':
## 
##     col_factor

Setup Working Directory

This code will set your working directory, aka where your files are located. Save all “XXX.spa” files into one folder and adjust the code below to your personal working directory.

setwd("~/Desktop/Desktop - Amaterasu/School/Medical/Research/Anesthesia Elective/BIS Sugamex")

Importing Dataset

You can import either using the import wizard feature underneath the “environment” tab in the upper right corner, or use the following code adjusted to your specific savefile name.

BIS <- read_delim("L07272245.spa", delim = "|", 
                  escape_double = FALSE, col_types = cols(Time = col_datetime(format = "%m/%d/%Y %H:%M:%S")), 
                  trim_ws = TRUE, skip = 1)
BIS[BIS==-3276.8] <- NA

BIS2 <- read_delim("L07290213.spa", delim = "|", 
                  escape_double = FALSE, col_types = cols(Time = col_datetime(format = "%m/%d/%Y %H:%M:%S")), 
                  trim_ws = TRUE, skip = 1)

BIS[BIS==-3276.8] <- NA #These are important to mark NA for analysis; be sure to copy and paste this text and adjust for your new data
BIS[BIS==-327.7] <- NA
BIS2[BIS2==-3276.8] <- NA
BIS2[BIS2==-327.7] <- NA

BISagg <- aggregate(BIS, list(rep(1:(nrow(BIS) %/% 60 + 1), each = 60, len = nrow(BIS))), mean)[-1];

BIS2agg <- aggregate(BIS2, list(rep(1:(nrow(BIS2) %/% 60 + 1), each = 60, len = nrow(BIS2))), mean)[-1];

Create Patient Information Database

Enter new data on patient information here as collected.

Abbreviations

PtDB <- read_csv("BISSugamex Pt Info.csv")

Plotting BIS and marking Sugamex

The important information for this study is the BIS = “DB13U01…12” and SEF = “SEF08…9”, EMG = “EMGLOW01…16”, and SQI = “SQI10…17”. We want to plot BIS against time and mark when we gave Sugammadex (a value recorded in the OR) to see any change in activity around that time. Per protocol, sevoflurane was left at steady concentration and not changed for 5 minutes. Values to manually add: time sugamex given and amount of sugamex admin (mg).

gBIS2<- ggplot(data=BIS2agg, aes(x=as.POSIXct(c(Time)), y=DB13U01...12, group =1,)) + 
  geom_line()+
  geom_point()+
  ggtitle("BIS") +
  theme(plot.title = element_text(hjust = 0.5)) +
  ylab("Bispectral Index") +
  xlab("Time (minutes)") + 
  scale_x_datetime(
    labels=date_format("%M"),
    expand = c(0,0),
    limits = as.POSIXct(c("2023-07-28 22:14:00 UTC", "2023-07-28 22:30:00 UTC"))) +
  geom_segment(x=as.POSIXct(c("2023-07-28 22:18:35 UTC")), y=0, xend=as.POSIXct(c("2023-07-28 22:18:35 UTC")), yend =100) +
  geom_text(x=as.POSIXct(c("2023-07-28 22:25:35 UTC")), y=80, label = "50mg Sugammadex", size=3)

gSEF2<- ggplot(data=BIS2agg, aes(x=Time, y=SEF08...9, group =1,)) + 
  geom_line()+
  geom_point()+
  ggtitle("SEF95") +
  theme(plot.title = element_text(hjust = 0.5)) +  
  ylab("Spectral Edge Frequency (Hz)") +
  xlab("Time (minutes)") + 
  scale_x_datetime(
    labels=date_format("%M"),
    expand = c(0,0),
    limits = as.POSIXct(c("2023-07-28 22:14:00 UTC", "2023-07-28 22:30:00 UTC"))) +
  geom_segment(x=as.POSIXct(c("2023-07-28 22:18:35 UTC")), y=0, xend=as.POSIXct(c("2023-07-28 22:18:35 UTCC")), yend =100) +
  geom_text(x=as.POSIXct(c("2023-07-28 22:25:35 UTC")), y=80, label = "50mg Sugammadex", size=3)

gEMG2<- ggplot(data=BIS2agg, aes(x=Time, y=EMGLOW01...16, group =1,)) + 
  geom_line()+
  geom_point()+
  ggtitle("EMG") +
  theme(plot.title = element_text(hjust = 0.5)) + 
  ylab("Electromyography (dB)") +
  xlab("Time (minutes)") + 
  scale_x_datetime(
    labels=date_format("%M"),
    expand = c(0,0),
    limits = as.POSIXct(c("2023-07-28 22:14:00 UTC", "2023-07-28 22:30:00 UTC"))) +
  geom_segment(x=as.POSIXct(c("2023-07-28 22:18:35 UTC")), y=0, xend=as.POSIXct(c("2023-07-28 22:18:35 UTCC")), yend =100) +
  geom_text(x=as.POSIXct(c("2023-07-28 22:25:35 UTC")), y=80, label = "50mg Sugammadex", size=3)

gSQI2<- ggplot(data=BIS2agg, aes(x=Time, y=SQI10...17, group =1,)) + 
  geom_line()+
  geom_point()+
  ggtitle("SQI") +
  theme(plot.title = element_text(hjust = 0.5)) + 
  ylab("Signal Quality Index") +
  xlab("Time (minutes)") + 
  scale_x_datetime(
    labels=date_format("%M"),
    expand = c(0,0),
    limits = as.POSIXct(c("2023-07-28 22:14:00 UTC", "2023-07-28 22:30:00 UTC"))) +
  geom_segment(x=as.POSIXct(c("2023-07-28 22:18:35 UTC")), y=0, xend=as.POSIXct(c("2023-07-28 22:18:35 UTCC")), yend =100) +
  geom_text(x=as.POSIXct(c("2023-07-28 22:25:35 UTC")), y=80, label = "50mg Sugammadex", size=3)

gBIS2grob <- ggplotGrob(gBIS2)
gSEF2grob <- ggplotGrob(gSEF2)
gEMG2grob <- ggplotGrob(gEMG2)
gSQI2grob <- ggplotGrob(gSQI2)
grid.arrange(gBIS2grob, gSEF2grob, gEMG2grob, gSQI2grob, ncol =2, nrow=2, top=textGrob("L07290213", gp=gpar(fontsize=20,font=8)))

Future Stats

Patient characteristics will be summarized using means with standard deviations, counts, and percentages as appropriate. BIS will be examined using linear effects model with and without EMG as a covariant to examine changes overtime.

#remove_when_prepared_to_run_stats mAge <- mean(PtDB$Age) 
#remove mHt <- mean(PtDB$Ht_m)
#remove mWt <- means(PtDB$Wt_kg)
#remove mBMI <- means(PtDB$BMI)
#remove HTN <- length(grep("HTN", PtDB))
#remove DysL <- length(grep("Dyslipidemia", PtDB))
#remove DM <- length(grep("DM", PtDB))
#remove ICM <- length(grep("ICM", PtDB))
#remove AHTN <- length(grep("Anti-HTN", PtDB))
#remove Statin <- length(grep("Statin", PtDB))
#remove aB <- length(grep("a-Blocker", PtDB))
#remove bB <- length(grep("b-Blocker", PtDB))
#remove aT <- length(grep("Antithrombolytics", PtDB))
#remove aC <- length(grep("Anticoagulants", PtDB))

#Can add other common pathologies/medications seen

#remove Table1 <- data.frame(mAge, mHt, mWt, mBMI, HTN, DysL, DM, ICM, AHTN, Statin, aB, bB, aT, aC)

#remove lmBIS <-lm(BISagg$DB13U01...12 ~ BISagg$Time)
#remove lmBISEMG <-lm(BISagg$DB13U01...12 ~ BISagg$Time + BISagg$EMGLOW01...16)