If error at this stage be sure your RMarkdown is up-to-date and that all installed packages are up to date. Did not include install packages code (install.packages(‘package_of_interest’)), you should be able to add what you don’t have.
library(readr)
library(ggplot2)
library(gridExtra)
library(grid)
library(rmarkdown)
library(dplyr)
library(scales)
library(tidyverse)
library(data.table)
library(patchwork)
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)
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)
The data needs to be transformed for analysis. Each paragraph of text needs to be reproduced for your new imported data set (aka. copy paste paragraph and change BIS to your new name (BIS3, BIS4, etc)). Need to also record if patient moved or not, which will be important for data analysis
BIS[BIS==-3276.8] <- NA
BIS[BIS==-327.7] <- NA
BISagg <- aggregate(BIS, list(rep(1:(nrow(BIS) %/% 60 + 1), each = 60, len = nrow(BIS))), mean)[-1];
BISagg$Movement <- 'No Movement'
BISagg$ID <- 'L07272245'
BISagg<- BISagg %>%
mutate(Time = ymd_hms(Time),
dif = Time - ymd_hms('2023-07-28 00:03:13'), #Suggamadex injection time
rank = dense_rank(dif) - row_number()[dif== 0])
IDRows <- BISagg$rank >= -10 & BISagg$rank <= 5
BISagg <- BISagg[IDRows, ]
BISagg <- BISagg[, c(59, 57, 56, 1:55)]
BIS2[BIS2==-3276.8] <- NA
BIS2[BIS2==-327.7] <- NA
BIS2agg <- aggregate(BIS2, list(rep(1:(nrow(BIS2) %/% 60 + 1), each = 60, len = nrow(BIS2))), mean)[-1];
BIS2agg$Movement <- 'Movement'
BIS2agg$ID <- 'L07290213'
BIS2agg<- BIS2agg %>%
mutate(Time = ymd_hms(Time),
dif = Time - ymd_hms('2023-07-29 03:18:36'), #Suggamadex injection time
rank = dense_rank(dif) - row_number()[dif== 0])
IDRows2 <- BIS2agg$rank >= -10 & BIS2agg$rank <= 5
BIS2agg <- BIS2agg[IDRows2, ]
BIS2agg <- BIS2agg[, c(59, 57, 56, 1:55)]
Enter new data on patient information here as collected.
Abbreviations
PtDB <- read_csv("BISSugamex Pt Info.csv")
Patient characteristics will be summarized using means with standard deviations, counts, and percentages as appropriate. Suggamadex dose should be examined for differences between movement groups and BIS. BIS, SEF, EMG, and SPI 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
#remove lmBIS <-lm(BISav$DB13U01...12 ~ BISagg$Time)
#remove lmBISEMG <-lm(BISav$DB13U01...12 ~ BISagg$Time + BISagg$EMGLOW01...16)
#remove lmSEF <-lm(BISav$SEF08...9 ~ BISagg$Time)
#remove lmBISSEF <-lm(BISav$SEF08...9 ~ BISagg$Time + BISagg$EMGLOW01...16)
#remove lmEMG <-lm(BISav$EMGLOW01...16 ~ BISagg$Time)
#remove lm <-lm(BISav$DB13U01...12 ~ BISagg$Time)
#remove lmBISEMG <-lm(BISav$DB13U01...12 ~ BISagg$Time + BISagg$EMGLOW01...16)
The important information for this study is the BIS = “DB13U01…12” and SEF = “SEF08…9”, EMG = “EMGLOW01…16”, and SQI = “SQI10…17” and movement. We want to plot BIS, SEF, EMG, and SQI against time and mark when we gave Sugammadex (a value recorded in the OR) to see any change in activity around that time. We also want to make two separate graph sets for patients that moved and patients that did not for 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).
gBIS<- ggplot(data=BISav, aes(x=rank, y=DB13U01...12, group = factor(Movement, level=c('Movement', 'No Movement')), colour= Movement)) +
geom_line()+
geom_point()+
ggtitle("BIS") +
theme(plot.title = element_text(hjust = 0.5)) +
ylab("Bispectral Index") +
xlab("Time (minutes)") +
geom_segment(x=0, y=0, xend=0, yend =100, color= 'black') +
geom_text(x=-5, y=70, label = "Sugammadex Admin", size=3, color = 'black')
gSEF<- ggplot(data=BISav, aes(x=rank, y=SEF08...9, group = factor(Movement, level=c('Movement', 'No Movement')), colour= Movement)) +
geom_line()+
geom_point()+
ggtitle("SEF95") +
theme(plot.title = element_text(hjust = 0.5), legend.position = "none") +
ylab("Spectral Edge Frequency") +
xlab("Time (minutes)") +
geom_segment(x=0, y=0, xend=0, yend =100, color= 'black') +
geom_text(x=-5, y=23, label = "Sugammadex Admin", size=3, color = 'black')
gEMG<- ggplot(data=BISav, aes(x=rank, y=EMGLOW01...16, group = factor(Movement, level=c('Movement', 'No Movement')), colour= Movement)) +
geom_line()+
geom_point()+
ggtitle("EMG") +
theme(plot.title = element_text(hjust = 0.5), legend.position = "none") +
ylab("Electromyography (dB)") +
xlab("Time (minutes)") +
geom_segment(x=0, y=0, xend=0, yend =100, color= 'black') +
geom_text(x=-5, y=43, label = "Sugammadex Admin", size=3, color = 'black')
gSQI<- ggplot(data=BISav, aes(x=rank, y=SQI10...17, group = factor(Movement, level=c('Movement', 'No Movement')), colour= Movement)) +
geom_line()+
geom_point()+
ggtitle("SQI") +
theme(plot.title = element_text(hjust = 0.5), legend.position = "none") +
ylab("Signal Quality Index") +
xlab("Time (minutes)") +
geom_segment(x=0, y=0, xend=0, yend =100, color= 'black') +
geom_text(x=-5, y=83, label = "Sugammadex Admin", size=3, color = 'black')
gBISgrob <- ggplotGrob(gBIS)
gSEFgrob <- ggplotGrob(gSEF)
gEMGgrob <- ggplotGrob(gEMG)
gSQIgrob <- ggplotGrob(gSQI)
gBIS + gSEF + gEMG + gSQI +
plot_layout(ncol = 2, nrow = 2, guides = "collect")
# stat_summary(fun.data = mean_se, geom = "errorbar", width = 0.2)
This represents a solid example of one patient overtime in case you want supplementary visualization
gBIS2<- ggplot(data=BIS2agg, aes(x=rank, 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)") +
geom_segment(x=0, y=0, xend=0, yend =100) +
geom_text(x=0, y=80, label = "50mg Sugammadex", size=3)
gSEF2<- ggplot(data=BIS2agg, aes(x=rank, y=SEF08...9, group =1,)) +
geom_line()+
geom_point()+
ggtitle("SEF95") +
theme(plot.title = element_text(hjust = 0.5)) +
ylab("Spectral Edge Frequency") +
xlab("Time (minutes)") +
geom_segment(x=0, y=0, xend=0, yend =100) +
geom_text(x=0, y=80, label = "50mg Sugammadex", size=3)
gEMG2<- ggplot(data=BIS2agg, aes(x=rank, 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)") +
geom_segment(x=0, y=0, xend=0, yend =100) +
geom_text(x=0, y=80, label = "50mg Sugammadex", size=3)
gSQI2<- ggplot(data=BIS2agg, aes(x=rank, 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)") +
geom_segment(x=0, y=0, xend=0, yend =100) +
geom_text(x=0, 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)))