--- title: "Reproducibility" output: rmarkdown::html_document: toc: true toc_depth: 3 toc_float: true number_sections: true vignette: > %\VignetteIndexEntry{reproducibility} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, warning = FALSE, eval=FALSE ) ``` ```{r warning=FALSE, message=FALSE} library(RaCE.NMA) library(ggplot2) library(dplyr) library(cowplot) library(gridExtra) library(reshape2) ``` In this vignette, we provide code to reproduce the analyses presented in the paper associated with this R package. Specifically, we reproduce two simulation studies (Sections 3.1 and 3.2) and a case study (Section 4). We assume knowledge of the associated R package functions; please refer to the "Tutorial" and "Reference" pages for more information. No figures are produced; see paper. ## Reproduction of Simulation Study 1 (Section 3.1) The following code reproduces Figure 1. ```{r fig.asp=0.35} s <- 0.1 g1a<-ggplot()+scale_x_continuous(limits=c(-3*s,1+3*s))+ stat_function(fun = dnorm, args = list(mean = 0, sd =s))+ stat_function(fun = dnorm, args = list(mean = 1, sd =s))+ theme_bw()+labs(x=" ",y="Density",subtitle=expression(hat(sigma)~"=0.1"))+ theme(panel.grid.minor = element_blank(),panel.grid.major.y = element_blank()) s <- 0.3 g1b<-ggplot()+scale_x_continuous(limits=c(-3*s,1+3*s))+ stat_function(fun = dnorm, args = list(mean = 0, sd =s))+ stat_function(fun = dnorm, args = list(mean = 1, sd =s))+ theme_bw()+labs(x="Posterior Intervention Effects",y=NULL,subtitle=expression(hat(sigma)~"=0.3"))+ theme(panel.grid.minor = element_blank(),panel.grid.major.y = element_blank()) s <- 0.5 g1c<-ggplot()+scale_x_continuous(limits=c(-3*s,1+3*s))+ stat_function(fun = dnorm, args = list(mean = 0, sd =s))+ stat_function(fun = dnorm, args = list(mean = 1, sd =s))+ theme_bw()+labs(x=" ",y=NULL,subtitle=expression(hat(sigma)~"=0.5"))+ theme(panel.grid.minor = element_blank(),panel.grid.major.y = element_blank()) grid.arrange(g1a,g1b,g1c,nrow=1) ``` The following code reproduces Figure 2: First, we perform a simulation study. Second, we create the figure. ```{r cache=TRUE} ## Perform simulation study set.seed(1) results <- matrix(NA,nrow=0,ncol=6) for(iter in 1:20){ for(J in c(6,12,18)){ for(K in c(J/3,2*J/3,J)){ for(s in c(0.1,0.3,0.5)){ if(K==J){ mu_hat <- 1:K }else{ mu_hat <- sample(1:K,J,replace=T) while(length(unique(mu_hat))0.4,"white","black")) g4b<-ggplot(melt(race_ranks_probs), aes(x=Var1,y=factor(Var2,levels=paste0("mu",1:J), labels=paste0(1:J)),fill=value))+ geom_tile() + theme_minimal() + scale_y_discrete(limits=rev) + scale_x_continuous(breaks=1:4,limits=c(.5,4.5)) + scale_fill_gradient(low="white",high="black",limits=c(0,1)) + labs(x="Rank",y="Treatment",fill="Probability")+ theme(panel.grid = element_blank(),legend.position = "bottom")+ geom_text(aes(x=Var1,y=factor(Var2,levels=paste0("mu",1:J),labels=paste0(1:J)), label=round(value,2)), color=ifelse(melt(race_ranks_probs)$value>0.4,"white","black")) plot_grid(plot_grid(g4a+theme(legend.position = "none"), g4b+theme(legend.position = "none"), labels = c('A', 'B'), label_size = 12), get_plot_component(g4a, 'guide-box-bottom', return_all = TRUE), nrow=2,rel_heights = c(.9,.1) ) ``` ## Reproduction of Case Study (Section 4) We first load the posteriors from Wang et al. (2022) and calculate the mean and covariances of the relative treatment effects. ```{r} data("wang_posterior") # loads posterior of non-baseline treatments # define assumed mean and variance for baseline treatment (R-CHOP) mu_hat_baseline <- 0 var_baseline <- min(apply(wang_posterior,2,var))/10 # calculate summary statistics, mu_hat and cov, for all treatments mu_hat <- c( mu_hat_baseline, apply(wang_posterior,2,mean) ) cov <- cbind( c(var_baseline, rep(0, 10) ), rbind(0, cov(wang_posterior)) ) # store treatment names treatments <- c("R-CHOP", names(wang_posterior)) ``` The following code chunk reproduces Figure 5. ```{r fig.asp = 0.4, warning=FALSE} forestplot_muhat(data=wang_posterior,names=treatments[-1]) ``` Next, we fit the RaCE model to estimated relative treatment effects from Wang et al. (2022). ```{r} mcmc <- mcmc_raceNMA(mu_hat = mu_hat, cov = cov, mu0 = mean(mu_hat), sigma0 = sqrt(10*var(mu_hat)), iter = 50000, nu_iter = 5, chains = 4, seed = 1, verbose = FALSE) ``` The following code chunk reproduces Figure 6, Figure 7, and Table 2: First, we calculate the values underpinning each graphic. Then, we create each in turn. ```{r fig.asp=0.45} # Figure 6 g9a <- clusterplot_ranks(data=cbind(0,wang_posterior), names=treatments,label_ranks=1)+ theme(legend.position = "bottom") g9b <- clusterplot_ranks(mcmc=mcmc,names=treatments,label_ranks = 1) plot_grid(plot_grid(g9a+theme(legend.position = "none"), g9b+theme(legend.position = "none"), labels = c('A', 'B'), label_size = 12), get_plot_component(g9a, 'guide-box-bottom', return_all = TRUE), nrow=2,rel_heights = c(.9,.1)) # Figure 7 g10a <- cumulativeprobplot_ranks(data=cbind(0,wang_posterior),names=treatments)+ theme(legend.position = "bottom") + guides(color = guide_legend(nrow = 2)) g10b <- cumulativeprobplot_ranks(mcmc=mcmc,names=treatments) plot_grid(plot_grid(g10a+theme(legend.position = "none"), g10b+theme(legend.position = "none"), labels = c('A', 'B'), label_size = 12), get_plot_component(g10a, 'guide-box-bottom', return_all = TRUE), nrow=2,rel_heights = c(.85,.15) ) # Table 2 res_WANG <- calculate_SUCRA_MNBT(data = cbind(0,wang_posterior), level = 0.50, names = treatments) res_RaCENMA <- calculate_SUCRA_MNBT(mcmc = mcmc, level = 0.50, names = treatments) table2 <- left_join(res_WANG,res_RaCENMA,by="Treatment")[,c(1,2,4,3,5)] names(table2) <- c("Treatment","SUCRA (Wang)","SUCRA (RaCE)","MNBT (Wang)","MNBT (RaCE)") print(table2) ``` The following code chunk reproduces the Figures 8--10 (Appendix B). ```{r fig.asp=0.4} traceplot_K(mcmc)+ scale_x_continuous(breaks=seq(125000,250000,by=25000), labels=paste0(seq(125,250,by=25),"k")) traceplot_mu(mcmc,names=treatments)+ scale_x_continuous(breaks=seq(125000,250000,by=25000), labels=paste0(seq(125,250,by=25),"k")) forestplot_muhat(mcmc=mcmc,names=treatments) ```