# load the R mmeta package
library("mmeta")
# load the colorectal dataset
data("colorectal", package = "mmeta")
str(colorectal)
# The function multipletables is called to conduct exact posterior inference of
# the odds ratios This function call takes around 5 mins to run. Please be
# patient.
set.seed(1234)
multiple.OR <- multipletables(data = colorectal, measure = "OR", model = "Sarmanov",
method = "exact")
summary(multiple.OR)
# Construct the forest plot the 95% CI of the overall odds ratio and the 95% CIs
# of the study-specific odds ratios (Figure 1 in the manuscript)
plot(multiple.OR, type = "forest", addline = 1, xlabel=c(0.3,0.5,2,4))
# Overlay the posterior density functions of the study-specific odds ratios for
# some target studies (Figure 2 in the manuscript)
plot(multiple.OR, type = "overlap", select = c(4, 14, 16, 20))
# The posterior density functions of the study-specific odds ratios for some
# target studies are plotted in a side-by-side manner (Figure 3 in the
# manuscript)
plot(multiple.OR, type = "sidebyside", select = c(4, 14, 16, 20), ylim = c(0, 2.7),
xlim = c(0.5, 1.5))
# load the withdrawal dataset
data("withdrawal", package = "mmeta")
str(withdrawal)
# The function multipletables is called to conduct exact posterior inference of
# relative risks
set.seed(1234)
multiple.RR <- multipletables(data = withdrawal, measure = "RR", model = "Sarmanov",
method = "exact")
summary(multiple.RR)
# Construct the forest plot the 95% CI of the overall relative risk and the 95%
# CIs of the study-specific relative risks (Figure 4 in the manuscript)
plot(multiple.RR, type = "forest", addline = 1, mar=c(4, 7, 3, 6), xlabel=c(0.2,0.5,3,6.5))
# Overlay the posterior density functions of the study-specific relative risks
# for some target studies (Figure 5 in the manuscript)
plot(multiple.RR, type = "overlap", select = c(3, 8, 14, 16))
# The posterior density functions of the study-specific relative risks for some
# target studies are plotted in a side-by-side manner (Figure 6 in the
# manuscript)
plot(multiple.RR, type = "sidebyside", select = c(3, 8, 14, 16), ylim = c(0, 1.2),
xlim = c(0.4, 3))
# Evaluate the influence of the study of Loldrup et al (1989) on the inference of
# relative risks by removing it and reanalyzing the dataset
set.seed(1234)
multiple.RR.sens <- multipletables(data = withdrawal[-11, ], measure = "RR", model = "Sarmanov",
method = "exact")
summary(multiple.RR.sens)
# The function multipletables is called to conduct exact posterior inference of
# risk difference using the withdrawal dataset
set.seed(1234)
multiple.RD <- multipletables(data = withdrawal, measure = "RD", model = "Sarmanov")
summary(multiple.RD)
# Evaluate the influence of the study of Loldrup et al (1989) on the inference of
# risk differences by removing it and reanalyzing the dataset
set.seed(1234)
multiple.RD.sens <- multipletables(data = withdrawal[-11, ], measure = "RD", model = "Sarmanov")
summary(multiple.RD.sens)
##########################################
# Single table
##########################################
# The function singletable is called to conduct exact posterior inference of odds
# ratio based on a single 2X2 table using Jeffreys prior distribution
set.seed(1234)
single.OR.Jeffreys <- singletable(a1 = 0.5, b1 = 0.5, a2 = 0.5, b2 = 0.5, y1 = 40,
n1 = 96, y2 = 49, n2 = 109, model = "Independent", measure = "OR", method = "exact")
summary(single.OR.Jeffreys)
# The function singletable is called to conduct exact posterior inference of odds
# ratio based on a single 2X2 table using Laplace prior distribution
set.seed(1234)
single.OR.Laplace <- singletable(a1 = 1, b1 = 1, a2 = 1, b2 = 1, y1 = 40, n1 = 96,
y2 = 49, n2 = 109, model = "Independent", measure = "OR", method = "exact")
summary(single.OR.Laplace)
# The function singletable is called to conduct exact posterior inference of odds
# ratio based on a single 2X2 table using Sarmanov beta prior distribution with
# positive correlation
set.seed(1234)
single.OR.Sar1 <- singletable(a1 = 0.5, b1 = 0.5, a2 = 0.5, b2 = 0.5, rho = 0.5,
y1 = 40, n1 = 96, y2 = 49, n2 = 109, model = "Sarmanov", measure = "OR", method = "exact")
summary(single.OR.Sar1)
# The function singletable is called to conduct exact posterior inference of odds
# ratio based on a single 2X2 table using Sarmanov beta prior distribution with
# nagative correlation
set.seed(1234)
single.OR.Sar2 <- singletable(a1 = 0.5, b1 = 0.5, a2 = 0.5, b2 = 0.5, rho = -0.5,
y1 = 40, n1 = 96, y2 = 49, n2 = 109, model = "Sarmanov", measure = "OR", method = "exact")
summary(single.OR.Sar2)
# Plot the prior and posterior distributions of the odds ratio under four prior
# distributions
par(mfrow = c(2, 2))
plot(single.OR.Jeffreys, type = "overlap", xlim = c(0.5, 2), main = "Jeffreys Prior")
plot(single.OR.Laplace, type = "overlap", xlim = c(0.5, 2), main = "Laplace Prior")
plot(single.OR.Sar1, type = "overlap", xlim = c(0.5, 2),
main = expression(paste("Sarmanov Prior ", rho, " = 0.5")))
plot(single.OR.Sar2, type = "overlap", xlim = c(0.5, 2),
main = expression(paste("Sarmanov Prior ", rho, " = -0.5")))