File: R_functions_Kimmoun_et_al_final.R

Comment:   function to calculate proporiton of studies within each time period for continuous variables that were transformed in a cutoff   x  character string of the variable  name  character string of the name that will appear in the table  time  character string of the time period variable  method  either "chisq" or "fisher" depending on the type of the test wanted 
Category: Statistical Test
Code:
CAT<-function(x, name, time, method) { tabtot <- table(DATA[,x]) sumtot <- sum(tabtot) tabtime <- table(DATA[,x], DATA[,time]) sumtime <- apply(tabtime, 2, sum) proptot <- tabtot[2]/sum(tabtot) CItot <- exactci(tabtot[2], sum(tabtot), conf.level = 0.95) proptime <- tabtime[2,]/sumtime CItime <- map2(tabtime[2,], sumtime, function(x, y){exactci(x, y, conf.level = 0.95)}) propCItime <- map2(proptime, CItime, function(x,y){paste0(round(x*100,0)," (", round(y[["conf.int"]][1]*100,0),"-", round(y[["conf.int"]][2]*100,0),")")}) if(method == "fisher"){ p <- fisher.test(tabtime) } else if(method == "chisq"){ p<-chisq.test(tabtime) } N_propCItime <- NULL for(i in 1:length(propCItime)){ N_propCItime <- c(N_propCItime, c(sumtime[i], propCItime[[i]])) } res=c(name, sumtot, paste0(round(proptot*100,0)," (",round(CItot$conf.int[1]*100,0),"-", round(CItot$conf.int[2]*100,0),")"), N_propCItime, round(p$p.value[1],4)) return(res) }

Comment: function to calculate overall effect size for death or readmission rates (output has results + model to do model checks)   var  character string of the variable to calculate the effect size for
Category: Statistical Modeling
Code:
rate_ES <- function(var){ dat <- na.omit(DATA[,c("number_follow_up", var)]) colnames(dat)<-c("Ni","Ei") dat_es <- escalc( xi= Ei, ni =Ni, data = dat, measure = "PLO", to="if0all")

Comment:   function to get weighted logistic regression with continuous X variable and proportion Y variable and ggplot showing the predicted relationship   x  X variable as character  y  Y variable as character  Xpred  vector of X values to get predictions for  labX  X label as character  labY  Y label as character  limY  axis limits for Y axis, vector of 2 values  title  plot title as character  ypos  y relative position of text with OR and pvalue 
Category: Visualization
Code:
wtlogis_plot <- function(NB, x, y, Xpred, labX, labY, limY, title, ypos, unit){ dat <- data.frame(count=as.integer(DATA[,y]), Ntot=DATA[,NB], t=DATA[,x]) %>% mutate(prop = count/Ntot, perc = prop*100, wt = log(Ntot), t_div = t/10) dat <- na.omit(dat)

Comment: model with time divided by 10 to get OR for 10yr increment
Category: Statistical Modeling
Code:
timediv_mod <- glm(prop ~ t_div, family = "binomial", weights = wt, data = dat) ORdiv <- tidy(timediv_mod, conf.int = TRUE) %>% mutate(OR_CI = paste0(round(exp(estimate),2), " (", round(exp(conf.low),2),"-", round(exp(conf.high),2), ")"))

Comment:   function to get weighted linear regression with continuous X variable and continuous Y variable and ggplot showing the predicted relationship   x  X variable as character  y  Y variable as character  Xpred  vector of X values to get predictions for  labX  X label as character  labY  Y label as character  limY  axis limits for Y axis, vector of 2 values  title  plot title as character  ypos  y relative position of text with OR and pvalue 
Category: Statistical Modeling
Code:
wtlin_plot <- function(NB, x, y, Xpred, labX, labY, limY, title, ypos, unit){ dat <- data.frame(y=as.integer(DATA[,y]), Ntot=DATA[,NB], t=DATA[,x]) %>% mutate(wt = log(Ntot), t_div = t/10) dat <- na.omit(dat)

Comment: function to get OR and CI from the model with 10 year increment   obj  model with x variable divided by 10  p  pvalue from the LRT
Category: Statistical Modeling
Code:
OR_div <- function(obj, p){ OR_CI <- paste0(round(exp(obj$beta[2]),2), " (", round(exp(obj$ci.lb[2]),2),"-", round(exp(obj$ci.ub[2]),2), ")") pval_clean <- ifelse(p[["pval"]] < 0.001, "p<0.001", paste0("p=",round(p[["pval"]],3))) OR_p <- c(OR_CI, p, pval_clean) return(OR_p) }

Comment:   function to get metaregression model with continuous X variable and proportion Y variable and ggplot showing the predicted relationship   x  X variable as character  y  Y variable as character  Xpred  vector of X values to get predictions for  labX  X label as character  labY  Y label as character  limY  axis limits for Y axis, vector of 2 values  title  plot title as character  ypos  y relative position of text with OR and pvalue 
Category: Visualization
Code:
MA_prop_plot <- function(NB, x, y, Xpred, labX, labY, limY, title, ypos){ prop_dat <- na.omit(DATA[,c(NB, y, x)]) colnames(prop_dat)<-c("Ni","Ei","X") prop_dat$prop <- (prop_dat$Ei/prop_dat$Ni) * 100 prop_dat$X_div <- prop_dat$X/10 es_prop_dat <- escalc( xi= Ei, ni =Ni, data = prop_dat, measure = "PLO", to="if0all")

Comment: function to get OR for subgroup variables with 2 categories   x  character string for the x variable  y  character string for the y variable  group  chracter string for the group variable  newref  character string for the level of the group variable that is not the reference level
Category: Data Variable
Code:
OR_group_fun <- function(x, y, group, newref){ OR_data <- data.frame(Group = rep(NA,2), N = rep(NA,2), OR = rep(NA,2), lowCI = rep(NA,2), upCI = rep(NA,2), p = rep(NA,2), I2 = rep(NA,2)) group_dat <- na.omit(DATA[,c("number_follow_up", y, x, group)]) colnames(group_dat)<-c("Ni","Ei","X","group") group_dat$X_div <- group_dat$X/10 OR_data$Group <- levels(group_dat$group) OR_data$N <- as.integer(table(group_dat$group)) es_group_dat <- escalc( xi= Ei, ni =Ni, data = group_dat, measure = "PLO", to="if0all") inter_mod1 <- rma(yi=yi,mods = ~ X_div * group, vi=vi, data=es_group_dat, method = "REML") inter_mod2 <- rma(yi=yi,mods = ~ X_div * I(relevel(group, newref)) , vi=vi, data=es_group_dat, method = "REML")

Comment:   function to get metaregression model with continuous X1 and X2 variables and 2 group variables and proportion Y variable and ggplot showing the predicted relationship with x1 for a median value of x2   x1  X1 variable as character  x2  X2 variable as character  group1  group1 variable (2level factor) as character  group2  group2 variable (2level factor) as character  y  Y variable as character  x1pred  vector of values for which to predict x1  x2val  median value of X2 for which to get predictions  labX  X label as character  labY  Y label as character  limY  axis limits for Y axis, vector of 2 values  title  plot title as character  ypos  y relative for text of OR and pvalue 
Category: Statistical Modeling
Code:
MA_prop_plot_adj <- function(NB, x1, x2, group1, group2, y, x1pred, x2val, labX, labY, limY, title, ypos){ prop_dat <- na.omit(DATA[,c(NB, y, x1, x2, group1, group2)]) colnames(prop_dat)<-c("Ni","Ei","X1", "X2", "group1", "group2") prop_dat$prop <- (prop_dat$Ei/prop_dat$Ni) * 100 prop_dat$X1_div <- prop_dat$X1/10 es_prop_dat <- escalc( xi= Ei, ni =Ni, data = prop_dat, measure = "PLO", to="if0all")