Code
::p_load(ape,
pacman
GoodmanKruskal,
DT,
dtplyr,
ggokabeito,
ggcorrplot,
here,
knitr,
tidyverse,
patchwork,
metafor,
miWQS,
multcomp,
orchaRd,
parallel,
RColorBrewer)
# function for calculating effect size (lnRR) - the same as function.R
<- function(dt) {
effect_lnRR # replace 0 in "C_mean", "T_sd", "C_sd", "C_proportion" with each minimum values
# if proportion too extreme value, replace minimum value (only "T_proportion")
<- dt %>%
dt mutate(
C_mean = ifelse(C_mean == 0, 0.04, C_mean),
T_sd = ifelse(T_sd == 0, 0.01, T_sd),
C_sd = ifelse(C_sd == 0, 0.05, C_sd),
C_proportion = ifelse(C_proportion == 0, 0.01, C_proportion),
T_proportion = ifelse(T_proportion < 0.01, 0.01, T_proportion),
T_proportion = ifelse(T_proportion == 1, 0.9, T_proportion)
)
# copy dataset for adding effect size and its variation (lnRR /lnRR_var) column
<- dt %>%
dt1 mutate(
lnRR = NA,
lnRR_var = NA
)
for (i in seq_len(nrow(dt1))) {
<- dt1$Tn[i]
Tn <- dt1$Cn[i]
Cn <- dt1$T_mean[i]
T_mean <- dt1$C_mean[i]
C_mean <- dt1$T_proportion[i]
T_proportion <- dt1$C_proportion[i]
C_proportion <- dt1$T_sd[i]
T_sd <- dt1$C_sd[i]
C_sd <- dt1$Response[i]
Response <- dt1$Measure[i]
Measure <- dt1$Study_design[i]
Study_design <- dt1$Direction[i]
Direction
# continuous data - using escalc() (metafor package)
if (Response == "continuous" & Study_design == "independent") {
<- escalc(
effect measure = "ROM",
n1i = Tn, n2i = Cn,
m1i = T_mean, m2 = C_mean,
sd1i = T_sd, sd2i = C_sd,
var.names = c("lnRR", "lnRR_var")
)
$lnRR[i] <- effect$lnRR
dt1$lnRR_var[i] <- effect$lnRR_var
dt1else if (Response == "continuous" & Study_design == "dependent") {
}
<- escalc(
effect measure = "ROMC",
ni = (Tn + Cn) / 2,
m1i = T_mean, m2 = C_mean,
sd1i = T_sd, sd2i = C_sd,
ri = 0.5,
var.names = c("lnRR", "lnRR_var")
)
$lnRR[i] <- effect$lnRR
dt1$lnRR_var[i] <- effect$lnRR_var
dt1
}
# proportion data (no sd values)
else if (Response == "proportion1" & Study_design == "independent") {
<- replace(
T_proportion == "Decrease",
T_proportion, Direction 1 - T_proportion[Direction == "Decrease"])
(
)<- replace(
C_proportion == "Decrease",
C_proportion, Direction 1 - C_proportion[Direction == "Decrease"])
(
)
# transform proportion value
<- function(proportion) {
asin_trans <- asin(sqrt(proportion))
trans
trans
}
<- asin_trans(T_proportion)
T_proportion <- asin_trans(C_proportion)
C_proportion
# calculate lnRR and lnRR variance
<- log(T_proportion / C_proportion)
lnRR_pro1 <- (1 / sqrt(8))^2 * (1 / (T_proportion^2 * Tn) +
lnRR_var_pro1 1 / (C_proportion^2 * Cn))
$lnRR[i] <- lnRR_pro1
dt1$lnRR_var[i] <- lnRR_var_pro1
dt1
else if (Response == "proportion1" & Study_design == "dependent") {
}
<- replace(
T_proportion == "Decrease",
T_proportion, Direction 1 - T_proportion[Direction == "Decrease"])
(
)<- replace(
C_proportion == "Decrease",
C_proportion, Direction 1 - C_proportion[Direction == "Decrease"])
(
)
# transform proportion value
<- function(proportion) {
asin_trans <- asin(sqrt(proportion))
trans
trans
}
<- asin_trans(T_proportion)
T_proportion <- asin_trans(C_proportion)
C_proportion
# calculate lnRR and lnRR variance
<- log(T_proportion / C_proportion)
lnRR_pro1 <- (1 / sqrt(8))^2 * (1 / (T_proportion^2 * Tn) +
lnRR_var_pro1 1 / (C_proportion^2 * Cn)) -
2 * 0.5 * sqrt((1 / sqrt(8))^2 * (1 / (T_proportion^2 * Tn))) *
sqrt((1 / sqrt(8))^2 * (1 / (C_proportion^2 * Cn)))
$lnRR[i] <- lnRR_pro1
dt1$lnRR_var[i] <- lnRR_var_pro1
dt1
}
# proportion data (exist sd values)
else if (Response == "proportion2" & Study_design == "independent") {
<- replace(
T_proportion == "Decrease",
T_proportion, Direction 1 - T_proportion[Direction == "Decrease"])
(
)<- replace(
C_proportion == "Decrease",
C_proportion, Direction 1 - C_proportion[Direction == "Decrease"])
(
)
# transform proportion mean value
<- function(proportion) {
asin_trans <- asin(sqrt(proportion))
trans
trans
}
<- sqrt(T_sd^2 / (4 * (T_proportion) * (1 - (T_proportion))))
T_SD <- sqrt(C_sd^2 / (4 * (C_proportion) * (1 - (C_proportion))))
C_SD
<- asin_trans(T_proportion)
T_proportion <- asin_trans(C_proportion)
C_proportion
# calculate lnRR and lnRR variance
<- log(T_proportion / C_proportion)
lnRR_pro2 <- (T_SD)^2 * (1 / (T_proportion^2 * Tn)) +
lnRR_var_pro2 ^2 * (1 / (C_proportion^2 * Cn))
(C_SD)
$lnRR[i] <- lnRR_pro2
dt1$lnRR_var[i] <- lnRR_var_pro2
dt1
else if (Response == "proportion2" & Study_design == "dependent") {
}
<- replace(
T_proportion == "Decrease",
T_proportion, Direction 1 - T_proportion[Direction == "Decrease"])
(
)<- replace(
C_proportion == "Decrease",
C_proportion, Direction 1 - C_proportion[Direction == "Decrease"])
(
)
# transform proportion mean value
<- function(proportion) {
asin_trans <- asin(sqrt(proportion))
trans
trans
}
<- sqrt(T_sd^2 / (4 * (T_proportion) * (1 - (T_proportion))))
T_SD <- sqrt(C_sd^2 / (4 * (C_proportion) * (1 - (C_proportion))))
C_SD
<- asin_trans(T_proportion)
T_proportion <- asin_trans(C_proportion)
C_proportion
# calculate lnRR and lnRR variance
<- log(T_proportion / C_proportion)
lnRR_pro2 <- (T_SD)^2 * (1 / (T_proportion^2 * Tn)) +
lnRR_var_pro2 ^2 * (1 / (C_proportion^2 * Cn)) -
(C_SD)2 * 0.5 * sqrt((T_SD)^2 * (1 / (T_proportion^2 * Tn))) *
sqrt((C_SD)^2 * (1 / (C_proportion^2 * Cn)))
$lnRR[i] <- lnRR_pro2
dt1$lnRR_var[i] <- lnRR_var_pro2
dt1
}
}
return(dt1)
}
# setting tables
options(DT.options = list(dom = "Blfrtip",
scrollX = TRUE,
pageLength = 5,
columnDefs = list(list(targets = '_all',
className = 'dt-center')),
buttons = c('copy', 'csv', 'excel', 'pdf')))