#setwd("/Users/nielspacheco/Dropbox/Mac/Desktop/labs/Baaj/")
# Creating the dataframe
Endovascular_Y1 <- data.frame(
  Author_year = c(
    "Qi, 2014", "Tsuruta, 2019", "Murphy, 2013", "Cho, 2013", "Ma, 2018", 
    "Lee, 2015", "Durnford, 2017", "Kirsch, 2013", "Su, 2013", "Sasamori, 2015", 
    "Yang, 2022", "Oh, 2021", "Watanabe, 2020", "Takai, 2021", "Koch, 2017", 
    "Koyalmantham, 2020", "Özkan, 2015", "Ronald, 2020", "Vukić, 2021", 
    "Gemmete, 2013", "Bretonnier, 2019", "Boonyakarnkul, 2023", "Lee, 2021", 
    "Gross, 2016"
  ),
  E1 = c(
    12, 172, 64, 28, 10, 28, 22, 61, 40, 31, 9, 34, 13, 50, 20, 5, 5, 7, 7, 29, 40, 64, 56, 28
  ),
  n_endovascular_First = c(
    3, 66, 8, 0, 0, 8, 10, 14, 16, 9, 2, 10, 1, 10, 6, 5, 2, 1, 0, 7, 12, 13, 19, 10
  )
)

# Display the dataframe
print(Endovascular_Y1)
##            Author_year  E1 n_endovascular_First
## 1             Qi, 2014  12                    3
## 2        Tsuruta, 2019 172                   66
## 3         Murphy, 2013  64                    8
## 4            Cho, 2013  28                    0
## 5             Ma, 2018  10                    0
## 6            Lee, 2015  28                    8
## 7       Durnford, 2017  22                   10
## 8         Kirsch, 2013  61                   14
## 9             Su, 2013  40                   16
## 10      Sasamori, 2015  31                    9
## 11          Yang, 2022   9                    2
## 12            Oh, 2021  34                   10
## 13      Watanabe, 2020  13                    1
## 14         Takai, 2021  50                   10
## 15          Koch, 2017  20                    6
## 16  Koyalmantham, 2020   5                    5
## 17         Özkan, 2015   5                    2
## 18        Ronald, 2020   7                    1
## 19         Vukić, 2021   7                    0
## 20       Gemmete, 2013  29                    7
## 21    Bretonnier, 2019  40                   12
## 22 Boonyakarnkul, 2023  64                   13
## 23           Lee, 2021  56                   19
## 24         Gross, 2016  28                   10
# Creating the dataframe
Surgical_Y1 <- data.frame(
  Author_year = c(
    "Qi, 2014", "Murphy, 2013", "Cho, 2013", "Ma, 2018", "Lee, 2015", 
    "Durnford, 2017", "Kirsch, 2013", "Zhang, 2022", "Sasamori, 2015", 
    "Yang, 2022", "Zhang, 2020", "Oh, 2021", "Watanabe, 2020", 
    "Takai, 2021", "Koch, 2017", "Koyalmantham, 2020", "Luo, 2021", 
    "O'Reilly, 2022", "Özkan, 2015", "Ronald, 2020", "Vukić, 2021", 
    "Gemmete, 2013", "Bretonnier, 2019", "Boonyakarnkul, 2023", 
    "Chibbaro, 2015", "Safaee, 2018", "Lee, 2021", "Gross, 2016"
  ),
  S1 = c(
    40, 26, 16, 81, 5, 37, 31, 32, 19, 75, 65, 4, 17, 145, 14, 28, 76, 59, 
    25, 40, 15, 4, 23, 3, 30, 41, 15, 43
  ),
  n_surgical_First = c(
    0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 3, 0, 0, 0, 4, 0, 0, 2, 0, 
    0, 0, 0, 0
  )
)

# Display the dataframe
print(Surgical_Y1)
##            Author_year  S1 n_surgical_First
## 1             Qi, 2014  40                0
## 2         Murphy, 2013  26                5
## 3            Cho, 2013  16                0
## 4             Ma, 2018  81                0
## 5            Lee, 2015   5                0
## 6       Durnford, 2017  37                0
## 7         Kirsch, 2013  31                0
## 8          Zhang, 2022  32                0
## 9       Sasamori, 2015  19                0
## 10          Yang, 2022  75                0
## 11         Zhang, 2020  65                0
## 12            Oh, 2021   4                0
## 13      Watanabe, 2020  17                3
## 14         Takai, 2021 145                0
## 15          Koch, 2017  14                0
## 16  Koyalmantham, 2020  28                3
## 17           Luo, 2021  76                0
## 18      O'Reilly, 2022  59                0
## 19         Özkan, 2015  25                0
## 20        Ronald, 2020  40                4
## 21         Vukić, 2021  15                0
## 22       Gemmete, 2013   4                0
## 23    Bretonnier, 2019  23                2
## 24 Boonyakarnkul, 2023   3                0
## 25      Chibbaro, 2015  30                0
## 26        Safaee, 2018  41                0
## 27           Lee, 2021  15                0
## 28         Gross, 2016  43                0
# Creating the dataframe
Sub_Endo_Surg <- data.frame(
  Author_year = c(
    "Qi, 2014", "Ma, 2018", "Durnford, 2017", "Su, 2013", "Sasamori, 2015", 
    "Yang, 2022", "Zhang, 2020", "Oh, 2021", "Takai, 2021", "Koch, 2017", 
    "Koyalmantham, 2020", "Özkan, 2015", "Gemmete, 2013", "Bretonnier, 2019", 
    "Lee, 2021", 
    "Qi, 2014", "Ma, 2018", "Durnford, 2017", "Su, 2013", "Sasamori, 2015", 
    "Yang, 2022", "Zhang, 2020", "Oh, 2021", "Takai, 2021", "Koch, 2017", 
    "Koyalmantham, 2020", "Özkan, 2015", "Gemmete, 2013", "Bretonnier, 2019", 
    "Lee, 2021"
  ),
  E2 = c(
    5, 1, 10, 13, 9, 1, 3, 8, 8, 6, 1, 2, 7, 6, 17, 
    5, 1, 10, 13, 9, 1, 3, 8, 8, 6, 1, 2, 7, 6, 17
  ),
  partial_occulsion = c(
    0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 1, 
    0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  ),
  subgroup = c(
    rep("Endo-endo", 15),
    rep("Endo-surg", 15)
  )
)

# Display the dataframe
print(Sub_Endo_Surg)
##           Author_year E2 partial_occulsion  subgroup
## 1            Qi, 2014  5                 0 Endo-endo
## 2            Ma, 2018  1                 0 Endo-endo
## 3      Durnford, 2017 10                 0 Endo-endo
## 4            Su, 2013 13                 0 Endo-endo
## 5      Sasamori, 2015  9                 0 Endo-endo
## 6          Yang, 2022  1                 0 Endo-endo
## 7         Zhang, 2020  3                 0 Endo-endo
## 8            Oh, 2021  8                 2 Endo-endo
## 9         Takai, 2021  8                 0 Endo-endo
## 10         Koch, 2017  6                 0 Endo-endo
## 11 Koyalmantham, 2020  1                 0 Endo-endo
## 12        Özkan, 2015  2                 0 Endo-endo
## 13      Gemmete, 2013  7                 0 Endo-endo
## 14   Bretonnier, 2019  6                 1 Endo-endo
## 15          Lee, 2021 17                 1 Endo-endo
## 16           Qi, 2014  5                 0 Endo-surg
## 17           Ma, 2018  1                 0 Endo-surg
## 18     Durnford, 2017 10                 1 Endo-surg
## 19           Su, 2013 13                 0 Endo-surg
## 20     Sasamori, 2015  9                 0 Endo-surg
## 21         Yang, 2022  1                 0 Endo-surg
## 22        Zhang, 2020  3                 0 Endo-surg
## 23           Oh, 2021  8                 0 Endo-surg
## 24        Takai, 2021  8                 0 Endo-surg
## 25         Koch, 2017  6                 0 Endo-surg
## 26 Koyalmantham, 2020  1                 0 Endo-surg
## 27        Özkan, 2015  2                 0 Endo-surg
## 28      Gemmete, 2013  7                 0 Endo-surg
## 29   Bretonnier, 2019  6                 0 Endo-surg
## 30          Lee, 2021 17                 0 Endo-surg
# Creating the dataframe
Sub_Surg_Surg <- data.frame(
  Author_year = c(
    "Zhang, 2020", "Takai, 2021", "Koyalmantham, 2020", "Ronald, 2020", "Bretonnier, 2019", 
    "Zhang, 2020", "Takai, 2021", "Koyalmantham, 2020", "Ronald, 2020", "Bretonnier, 2019"
  ),
  S2 = c(
    3, 8, 3, 1, 3, 
    3, 8, 3, 1, 3
  ),
  partial_occlusion = c(
    0, 0, 0, 0, 0, 
    0, 0, 0, 0, 1
  ),
  subgroup = c(
    rep("Surg-surg", 5), 
    rep("Surg-endo", 5)
  )
)

# Display the dataframe
print(Sub_Surg_Surg)
##           Author_year S2 partial_occlusion  subgroup
## 1         Zhang, 2020  3                 0 Surg-surg
## 2         Takai, 2021  8                 0 Surg-surg
## 3  Koyalmantham, 2020  3                 0 Surg-surg
## 4        Ronald, 2020  1                 0 Surg-surg
## 5    Bretonnier, 2019  3                 0 Surg-surg
## 6         Zhang, 2020  3                 0 Surg-endo
## 7         Takai, 2021  8                 0 Surg-endo
## 8  Koyalmantham, 2020  3                 0 Surg-endo
## 9        Ronald, 2020  1                 0 Surg-endo
## 10   Bretonnier, 2019  3                 1 Surg-endo
# Load the meta package
library(meta)
## Loading required package: metadat
## Loading 'meta' package (version 7.0-0).
## Type 'help(meta)' for a brief overview.
## Readers of 'Meta-Analysis with R (Use R!)' should install
## older version of 'meta' package: https://tinyurl.com/dt4y5drs
# Perform the meta-analysis for the Endovascular_Y1 dataframe
meta_analysis_Endovascular_Y1 <- metaprop(
  event = n_endovascular_First, 
  n = E1, 
  data = Endovascular_Y1,
  sm = "PLO", 
  method.tau = "DL",
  prediction = FALSE, 
  comb.fixed = FALSE,
  comb.random = TRUE, 
  studlab = Author_year
)

# Summary of the meta-analysis
summary(meta_analysis_Endovascular_Y1)
##                     proportion           95%-CI %W(random)
## Qi, 2014                0.2500 [0.0549; 0.5719]        2.7
## Tsuruta, 2019           0.3837 [0.3107; 0.4608]        9.3
## Murphy, 2013            0.1250 [0.0555; 0.2315]        5.5
## Cho, 2013               0.0000 [0.0000; 0.1234]        0.7
## Ma, 2018                0.0000 [0.0000; 0.3085]        0.7
## Lee, 2015               0.2857 [0.1322; 0.4867]        5.0
## Durnford, 2017          0.4545 [0.2439; 0.6779]        4.9
## Kirsch, 2013            0.2295 [0.1315; 0.3550]        6.7
## Su, 2013                0.4000 [0.2486; 0.5667]        6.4
## Sasamori, 2015          0.2903 [0.1422; 0.4804]        5.3
## Yang, 2022              0.2222 [0.0281; 0.6001]        2.0
## Oh, 2021                0.2941 [0.1510; 0.4748]        5.5
## Watanabe, 2020          0.0769 [0.0019; 0.3603]        1.3
## Takai, 2021             0.2000 [0.1003; 0.3372]        5.9
## Koch, 2017              0.3000 [0.1189; 0.5428]        4.2
## Koyalmantham, 2020      1.0000 [0.4782; 1.0000]        0.7
## Özkan, 2015             0.4000 [0.0527; 0.8534]        1.6
## Ronald, 2020            0.1429 [0.0036; 0.5787]        1.2
## Vukić, 2021             0.0000 [0.0000; 0.4096]        0.7
## Gemmete, 2013           0.2414 [0.1030; 0.4354]        4.8
## Bretonnier, 2019        0.3000 [0.1656; 0.4653]        6.0
## Boonyakarnkul, 2023     0.2031 [0.1128; 0.3223]        6.6
## Lee, 2021               0.3393 [0.2181; 0.4781]        7.0
## Gross, 2016             0.3571 [0.1864; 0.5593]        5.3
## 
## Number of studies: k = 24
## Number of observations: o = 835
## Number of events: e = 232
## 
##                      proportion           95%-CI
## Random effects model     0.2751 [0.2283; 0.3274]
## 
## Quantifying heterogeneity:
##  tau^2 = 0.1493 [0.0513; 0.9457]; tau = 0.3864 [0.2266; 0.9725]
##  I^2 = 47.7% [15.8%; 67.5%]; H = 1.38 [1.09; 1.75]
## 
## Test of heterogeneity:
##      Q d.f. p-value
##  43.94   23  0.0053
## 
## Details on meta-analytical method:
## - Inverse variance method
## - DerSimonian-Laird estimator for tau^2
## - Jackson method for confidence interval of tau^2 and tau
## - Logit transformation
## - Clopper-Pearson confidence interval for individual studies
## - Continuity correction of 0.5 in studies with zero cell frequencies
# To visualize the results, you can plot a forest plot
meta::forest(meta_analysis_Endovascular_Y1, layout = "RevMan")

# Load the meta package
library(meta)

# Perform the meta-analysis for the Endovascular_Y1 dataframe
meta_analysis_Surgical_Y1 <- metaprop(
  event = n_surgical_First, 
  n = S1, 
  data = Surgical_Y1,
  sm = "PLO", 
  method.tau = "DL",
  prediction = FALSE, 
  comb.fixed = FALSE,
  comb.random = TRUE, 
  studlab = Author_year
)

# Summary of the meta-analysis
summary(meta_analysis_Endovascular_Y1)
##                     proportion           95%-CI %W(random)
## Qi, 2014                0.2500 [0.0549; 0.5719]        2.7
## Tsuruta, 2019           0.3837 [0.3107; 0.4608]        9.3
## Murphy, 2013            0.1250 [0.0555; 0.2315]        5.5
## Cho, 2013               0.0000 [0.0000; 0.1234]        0.7
## Ma, 2018                0.0000 [0.0000; 0.3085]        0.7
## Lee, 2015               0.2857 [0.1322; 0.4867]        5.0
## Durnford, 2017          0.4545 [0.2439; 0.6779]        4.9
## Kirsch, 2013            0.2295 [0.1315; 0.3550]        6.7
## Su, 2013                0.4000 [0.2486; 0.5667]        6.4
## Sasamori, 2015          0.2903 [0.1422; 0.4804]        5.3
## Yang, 2022              0.2222 [0.0281; 0.6001]        2.0
## Oh, 2021                0.2941 [0.1510; 0.4748]        5.5
## Watanabe, 2020          0.0769 [0.0019; 0.3603]        1.3
## Takai, 2021             0.2000 [0.1003; 0.3372]        5.9
## Koch, 2017              0.3000 [0.1189; 0.5428]        4.2
## Koyalmantham, 2020      1.0000 [0.4782; 1.0000]        0.7
## Özkan, 2015             0.4000 [0.0527; 0.8534]        1.6
## Ronald, 2020            0.1429 [0.0036; 0.5787]        1.2
## Vukić, 2021             0.0000 [0.0000; 0.4096]        0.7
## Gemmete, 2013           0.2414 [0.1030; 0.4354]        4.8
## Bretonnier, 2019        0.3000 [0.1656; 0.4653]        6.0
## Boonyakarnkul, 2023     0.2031 [0.1128; 0.3223]        6.6
## Lee, 2021               0.3393 [0.2181; 0.4781]        7.0
## Gross, 2016             0.3571 [0.1864; 0.5593]        5.3
## 
## Number of studies: k = 24
## Number of observations: o = 835
## Number of events: e = 232
## 
##                      proportion           95%-CI
## Random effects model     0.2751 [0.2283; 0.3274]
## 
## Quantifying heterogeneity:
##  tau^2 = 0.1493 [0.0513; 0.9457]; tau = 0.3864 [0.2266; 0.9725]
##  I^2 = 47.7% [15.8%; 67.5%]; H = 1.38 [1.09; 1.75]
## 
## Test of heterogeneity:
##      Q d.f. p-value
##  43.94   23  0.0053
## 
## Details on meta-analytical method:
## - Inverse variance method
## - DerSimonian-Laird estimator for tau^2
## - Jackson method for confidence interval of tau^2 and tau
## - Logit transformation
## - Clopper-Pearson confidence interval for individual studies
## - Continuity correction of 0.5 in studies with zero cell frequencies
# To visualize the results, you can plot a forest plot
meta::forest(meta_analysis_Surgical_Y1, layout = "RevMan")

# Load the meta package
library(meta)

# Perform the meta-analysis for the Endovascular_Y1 dataframe
meta_analysis_Sub_Endo_Surg <- metaprop(
  event = partial_occulsion, 
  n = E2, 
  data = Sub_Endo_Surg,
  sm = "PLO", 
  method.tau = "DL",
  prediction = FALSE, 
  comb.fixed = FALSE,
  comb.random = TRUE, 
  studlab = Author_year,
  byvar = subgroup
)

# Summary of the meta-analysis
summary(meta_analysis_Sub_Endo_Surg)
##                    proportion           95%-CI %W(random)  subgroup
## Qi, 2014               0.0000 [0.0000; 0.5218]        2.9 Endo-endo
## Ma, 2018               0.0000 [0.0000; 0.9750]        2.4 Endo-endo
## Durnford, 2017         0.0000 [0.0000; 0.3085]        3.0 Endo-endo
## Su, 2013               0.0000 [0.0000; 0.2471]        3.1 Endo-endo
## Sasamori, 2015         0.0000 [0.0000; 0.3363]        3.0 Endo-endo
## Yang, 2022             0.0000 [0.0000; 0.9750]        2.4 Endo-endo
## Zhang, 2020            0.0000 [0.0000; 0.7076]        2.8 Endo-endo
## Oh, 2021               0.2500 [0.0319; 0.6509]        9.6 Endo-endo
## Takai, 2021            0.0000 [0.0000; 0.3694]        3.0 Endo-endo
## Koch, 2017             0.0000 [0.0000; 0.4593]        3.0 Endo-endo
## Koyalmantham, 2020     0.0000 [0.0000; 0.9750]        2.4 Endo-endo
## Özkan, 2015            0.0000 [0.0000; 0.8419]        2.7 Endo-endo
## Gemmete, 2013          0.0000 [0.0000; 0.4096]        3.0 Endo-endo
## Bretonnier, 2019       0.1667 [0.0042; 0.6412]        5.3 Endo-endo
## Lee, 2021              0.0588 [0.0015; 0.2869]        6.0 Endo-endo
## Qi, 2014               0.0000 [0.0000; 0.5218]        2.9 Endo-surg
## Ma, 2018               0.0000 [0.0000; 0.9750]        2.4 Endo-surg
## Durnford, 2017         0.1000 [0.0025; 0.4450]        5.7 Endo-surg
## Su, 2013               0.0000 [0.0000; 0.2471]        3.1 Endo-surg
## Sasamori, 2015         0.0000 [0.0000; 0.3363]        3.0 Endo-surg
## Yang, 2022             0.0000 [0.0000; 0.9750]        2.4 Endo-surg
## Zhang, 2020            0.0000 [0.0000; 0.7076]        2.8 Endo-surg
## Oh, 2021               0.0000 [0.0000; 0.3694]        3.0 Endo-surg
## Takai, 2021            0.0000 [0.0000; 0.3694]        3.0 Endo-surg
## Koch, 2017             0.0000 [0.0000; 0.4593]        3.0 Endo-surg
## Koyalmantham, 2020     0.0000 [0.0000; 0.9750]        2.4 Endo-surg
## Özkan, 2015            0.0000 [0.0000; 0.8419]        2.7 Endo-surg
## Gemmete, 2013          0.0000 [0.0000; 0.4096]        3.0 Endo-surg
## Bretonnier, 2019       0.0000 [0.0000; 0.4593]        3.0 Endo-surg
## Lee, 2021              0.0000 [0.0000; 0.1951]        3.1 Endo-surg
## 
## Number of studies: k = 30
## Number of observations: o = 194
## Number of events: e = 5
## 
##                      proportion           95%-CI
## Random effects model     0.0992 [0.0629; 0.1531]
## 
## Quantifying heterogeneity:
##  tau^2 = 0; tau = 0; I^2 = 0.0% [0.0%; 40.8%]; H = 1.00 [1.00; 1.30]
## 
## Test of heterogeneity:
##     Q d.f. p-value
##  9.44   29  0.9998
## 
## Results for subgroups (random effects model):
##                        k proportion           95%-CI tau^2 tau    Q  I^2
## subgroup = Endo-endo  15     0.1121 [0.0607; 0.1980]     0   0 5.38 0.0%
## subgroup = Endo-surg  15     0.0855 [0.0429; 0.1631]     0   0 3.71 0.0%
## 
## Test for subgroup differences (random effects model):
##                   Q d.f. p-value
## Between groups 0.35    1  0.5537
## 
## Details on meta-analytical method:
## - Inverse variance method
## - DerSimonian-Laird estimator for tau^2
## - Logit transformation
## - Clopper-Pearson confidence interval for individual studies
## - Continuity correction of 0.5 in studies with zero cell frequencies
# To visualize the results, you can plot a forest plot
meta::forest(meta_analysis_Sub_Endo_Surg, layout = "RevMan")

# Load the meta package
library(meta)

# Perform the meta-analysis for the Endovascular_Y1 dataframe
meta_analysis_Sub_Surg_Surg <- metaprop(
  event = partial_occlusion, 
  n = S2, 
  data = Sub_Surg_Surg,
  sm = "PLO", 
  method.tau = "DL",
  prediction = FALSE, 
  comb.fixed = FALSE,
  comb.random = TRUE, 
  studlab = Author_year,
  byvar = subgroup
)

# Summary of the meta-analysis
summary(meta_analysis_Sub_Surg_Surg)
##                    proportion           95%-CI %W(random)  subgroup
## Zhang, 2020            0.0000 [0.0000; 0.7076]        9.6 Surg-surg
## Takai, 2021            0.0000 [0.0000; 0.3694]       10.4 Surg-surg
## Koyalmantham, 2020     0.0000 [0.0000; 0.7076]        9.6 Surg-surg
## Ronald, 2020           0.0000 [0.0000; 0.9750]        8.2 Surg-surg
## Bretonnier, 2019       0.0000 [0.0000; 0.7076]        9.6 Surg-surg
## Zhang, 2020            0.0000 [0.0000; 0.7076]        9.6 Surg-endo
## Takai, 2021            0.0000 [0.0000; 0.3694]       10.4 Surg-endo
## Koyalmantham, 2020     0.0000 [0.0000; 0.7076]        9.6 Surg-endo
## Ronald, 2020           0.0000 [0.0000; 0.9750]        8.2 Surg-endo
## Bretonnier, 2019       0.3333 [0.0084; 0.9057]       14.7 Surg-endo
## 
## Number of studies: k = 10
## Number of observations: o = 36
## Number of events: e = 1
## 
##                      proportion           95%-CI
## Random effects model     0.1410 [0.0615; 0.2916]
## 
## Quantifying heterogeneity:
##  tau^2 = 0; tau = 0; I^2 = 0.0% [0.0%; 62.4%]; H = 1.00 [1.00; 1.63]
## 
## Test of heterogeneity:
##     Q d.f. p-value
##  2.24    9  0.9871
## 
## Results for subgroups (random effects model):
##                        k proportion           95%-CI tau^2 tau    Q  I^2
## subgroup = Surg-surg   5     0.1200 [0.0347; 0.3409]     0   0 0.64 0.0%
## subgroup = Surg-endo   5     0.1626 [0.0518; 0.4084]     0   0 1.46 0.0%
## 
## Test for subgroup differences (random effects model):
##                   Q d.f. p-value
## Between groups 0.14    1  0.7061
## 
## Details on meta-analytical method:
## - Inverse variance method
## - DerSimonian-Laird estimator for tau^2
## - Logit transformation
## - Clopper-Pearson confidence interval for individual studies
## - Continuity correction of 0.5 in studies with zero cell frequencies
# To visualize the results, you can plot a forest plot
meta::forest(meta_analysis_Sub_Surg_Surg, layout = "RevMan")