library(metafor)
#
{# Revised Analyses ----
  {#Group 1: Medial Distal FL by Volume -----
    med_distal_df_fl_vol <- read.csv("C:/Users/Thanasis/OneDrive - stc02/Ongoing projects/Bogdanis/R2/13_mediaLdistal_combined_fl_by_volume_R1.csv")
    names(med_distal_df_fl_vol)
    {# The Models ----
      med_distal_df_fl_vol1 <- escalc(measure="SMD", 
                                      m1i=mex, sd1i=sdex, n1i=nex,
                                      m2i=mcn, sd2i=sdcn, n2i=ncn, data=med_distal_df_fl_vol)
      # Non-random
      # Non-random
      x0   <- rma(yi, vi, data=med_distal_df_fl_vol1); x0; x0$I2
      {# Random model all ----
        x1  <- rma.mv(yi, vi, random= ~       1 | study1, data=med_distal_df_fl_vol1); x1
        x11 <- rma.mv(yi, vi, random = ~ sample | study1, data=med_distal_df_fl_vol1); x11
        
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x11$vi)
          X <- model.matrix(x11)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1$sigma2) / (sum(x1$sigma2) + (x1$k-x1$p)/sum(diag(P)))
        }  
        W <- diag(1/x1$vi)
        X <- model.matrix(x1)
        P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
        100 * sum(x1$sigma2) / (sum(x1$sigma2) + (x1$k-x1$p)/sum(diag(P)))
        #
        W <- diag(1/x11$vi)
        X <- model.matrix(x11)
        P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
        100 * sum(x11$sigma2) / (sum(x11$sigma2) + (X11$k-x11$p)/sum(diag(P)))
      }
      {# Random model < 5400  ----
        x1a   <- rma.mv(yi, vi, subset=var_5400 ==0, random= ~     1 | study1, data=med_distal_df_fl_vol1); x1a
        x11a  <- rma.mv(yi, vi, subset=var_5400 ==0, random= ~ sample|study1, data=med_distal_df_fl_vol1); x11a
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1a$vi)
          X <- model.matrix(x1a)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1a$sigma2) / (sum(x1a$sigma2) + (x1a$k-x1a$p)/sum(diag(P)))
        }  
      }
      {# Random model > 5400  ----
        x1b   <- rma.mv(yi, vi, subset=var_5400==1, random= ~      1 | study1, data=med_distal_df_fl_vol1); x1b
        x11b  <- rma.mv(yi, vi, subset=var_5400==1, random= ~ sample | study1, data=med_distal_df_fl_vol1); x11b
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1b$vi)
          X <- model.matrix(x1b)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1b$sigma2) / (sum(x1b$sigma2) + (x1b$k-x1b$p)/sum(diag(P)))
        }  
      }
      {# Compare the two groups ----
        names(df_fl_vol1)
        res10 <- rma.mv(yi, vi, random=~ sample|study1, data=med_distal_df_fl_vol1, subset=var_5400=="0"); res10
        res20 <- rma.mv(yi, vi, random=~ sample|study1, data=med_distal_df_fl_vol1, subset=var_5400=="1"); res20
        
        dat.comp1 <- data.frame(estimate = c(coef(res10), coef(res20)), stderror = c(res10$se, res20$se),
                                meta = c("0","1"), tau2 = round(c(res10$tau2, res20$tau2),3))
        dat.comp1
        rma(estimate, sei=stderror, mods = ~ meta, method="FE", data=dat.comp1, digits=3)
        with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))
        2*pnorm((with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))), lower.tail = T)
      }
    }
  }
  {#Group 2: Medial Distal FL by Intensity -----
    med_distal_df_fl_int <- read.csv("C:/Users/Thanasis/OneDrive - stc02/Ongoing projects/Bogdanis/R2/13_mediaLdistal_combined_fl_by_intensity_R1.csv")
    names(med_distal_df_fl_int)
    {# The Models ----
      med_distal_df_fl_int1 <- escalc(measure="SMD", 
                                      m1i=mex, sd1i=sdex, n1i=nex,
                                      m2i=mcn, sd2i=sdcn, n2i=ncn, data=med_distal_df_fl_int)
      # Non-random
      x0   <- rma(yi, vi, data=med_distal_df_fl_int1); x0; x0$I2
      {# Random model all ----
        x1   <- rma.mv(yi, vi, random= ~1       | study1, data=med_distal_df_fl_int1); x1
        x11  <- rma.mv(yi, vi, random= ~ sample | study1, data=med_distal_df_fl_int1); x11
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1$vi)
          X <- model.matrix(x1)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1$sigma2) / (sum(x1$sigma2) + (x1$k-x1$p)/sum(diag(P)))
        }  
      }
      {# Random model Low Intenstiy  ----
        x1a   <- rma.mv(yi, vi, subset=var_HIGH.LOW.INTENSITY ==0, random= ~      1 | study1, data=med_distal_df_fl_int1); x1a
        x11a  <- rma.mv(yi, vi, subset=var_HIGH.LOW.INTENSITY ==0, random= ~ sample | study1, data=med_distal_df_fl_int1); x11a
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1a$vi)
          X <- model.matrix(x1a)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1a$sigma2) / (sum(x1a$sigma2) + (x1a$k-x1a$p)/sum(diag(P)))
        }  
      }
      {# Random model High intensity  ----
        x1b   <- rma.mv(yi, vi, subset=var_HIGH.LOW.INTENSITY==1, random= ~      1 | study1, data=med_distal_df_fl_int1); x1b
        x11b  <- rma.mv(yi, vi, subset=var_HIGH.LOW.INTENSITY==1, random= ~ sample | study1, data=med_distal_df_fl_int1); x1b
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1b$vi)
          X <- model.matrix(x1b)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1b$sigma2) / (sum(x1b$sigma2) + (x1b$k-x1b$p)/sum(diag(P)))
        }  
      }
      {# Compare the two groups ----
        names(med_distal_df_fl_int1)
        res10 <- rma.mv(yi, vi, random=~ sample |study1, data=med_distal_df_fl_int1, subset=var_HIGH.LOW.INTENSITY=="0"); res10
        res20 <- rma.mv(yi, vi, random=~ sample |study1, data=med_distal_df_fl_int1, subset=var_HIGH.LOW.INTENSITY=="1"); res20
        
        dat.comp1 <- data.frame(estimate = c(coef(res10), coef(res20)), stderror = c(res10$se, res20$se),
                                meta = c("0","1"), tau2 = round(c(res10$tau2, res20$tau2),3))
        dat.comp1
        rma(estimate, sei=stderror, mods = ~ meta, method="FE", data=dat.comp1, digits=3)
        with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))
        2*pnorm((with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))), lower.tail = T)
      }
    }
  }
  {#Group 3: Medial Distal FL by Extensibility -----
    med_distal_df_fl_ext <- read.csv("C:/Users/Thanasis/OneDrive - stc02/Ongoing projects/Bogdanis/R2/13_mediaLdistal_combined_fl_by_extensibility_R1.csv")
    names(med_distal_df_fl_ext)
    {# The Models ----
      med_distal_df_fl_ext1 <- escalc(measure="SMD", 
                                      m1i=mex, sd1i=sdex, n1i=nex,
                                      m2i=mcn, sd2i=sdcn, n2i=ncn, data=med_distal_df_fl_ext)
      # Non-random
      x0   <- rma(yi, vi, data=med_distal_df_fl_ext1); x0; x0$I2
      {# Random model all ----
        x1   <- rma.mv(yi, vi, random= ~      1 | study1, data=med_distal_df_fl_ext1); x1
        x11  <- rma.mv(yi, vi, random= ~ sample | study1, data=med_distal_df_fl_ext1); x1
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1$vi)
          X <- model.matrix(x1)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1$sigma2) / (sum(x1$sigma2) + (x1$k-x1$p)/sum(diag(P)))
        }  
      }
    }
  }
  {#Group 4: Medial Distal Pennation by Volume -----
    med_distal_df_pen_vol <- read.csv("C:/Users/Thanasis/OneDrive - stc02/Ongoing projects/Bogdanis/R2/13_mediaLdistal_combined_pennation_by_volume_R1.csv")
    names(med_distal_df_pen_vol); nrow(med_distal_df_pen_vol)
    {# The Models ----
      med_distal_df_pen_vol1 <- escalc(measure="SMD", 
                                       m1i=mex, sd1i=sdex, n1i=nex,
                                       m2i=mcn, sd2i=sdcn, n2i=ncn, data=med_distal_df_pen_vol)
      # Non-random
      x0   <- rma(yi, vi, data=med_distal_df_pen_vol1); x0; x0$I2
      {# Random model all ----
        x1   <- rma.mv(yi, vi, random= ~      1 | study1, data=med_distal_df_pen_vol1); x1
        x11  <- rma.mv(yi, vi, random= ~ sample | study1, data=med_distal_df_pen_vol1); x1
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1$vi)
          X <- model.matrix(x1)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1$sigma2) / (sum(x1$sigma2) + (x1$k-x1$p)/sum(diag(P)))
        }  
      }
      {# Random model < 5400  ----
        x1a  <- rma.mv(yi, vi, subset=var_5400 ==0, random= ~      1 | study1, data=med_distal_df_pen_vol1); x1a
        x1a  <- rma.mv(yi, vi, subset=var_5400 ==0, random= ~ sample | study1, data=med_distal_df_pen_vol1); x1a
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1a$vi)
          X <- model.matrix(x1a)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1a$sigma2) / (sum(x1a$sigma2) + (x1a$k-x1a$p)/sum(diag(P)))
        }  
      }
      {# Random model > 5400  ----
        x1b  <- rma.mv(yi, vi, subset=var_5400==1, random= ~1        | study1, data=med_distal_df_pen_vol1); x1b
        x11b  <- rma.mv(yi, vi, subset=var_5400==1, random= ~ sample | study1, data=med_distal_df_pen_vol1); x1b
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1b$vi)
          X <- model.matrix(x1b)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1b$sigma2) / (sum(x1b$sigma2) + (x1b$k-x1b$p)/sum(diag(P)))
        }  
      }
      {# Compare the two groups ----
        names(med_distal_df_fl_int1)
        res10 <- rma.mv(yi, vi, random=~ sample |study1, data=med_distal_df_pen_vol1, subset=var_5400=="0"); res10
        res20 <- rma.mv(yi, vi, random=~ sample |study1, data=med_distal_df_pen_vol1, subset=var_5400=="1"); res20
        
        dat.comp1 <- data.frame(estimate = c(coef(res10), coef(res20)), stderror = c(res10$se, res20$se),
                                meta = c("0","1"), tau2 = round(c(res10$tau2, res20$tau2),3))
        dat.comp1
        rma(estimate, sei=stderror, mods = ~ meta, method="FE", data=dat.comp1, digits=3)
        with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))
        2*pnorm((with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))), lower.tail = F)
      }
    }
  }
  {#Group 5: Medial Distal Pennation by Intensity -----
    med_distal_df_pen_int <- read.csv("C:/Users/Thanasis/OneDrive - stc02/Ongoing projects/Bogdanis/R2/13_mediaLdistal_combined_pennation_by_intensity_R1.csv")
    names(med_distal_df_pen_int)
    {# The Models ----
      med_distal_df_pen_int1 <- escalc(measure="SMD", 
                                       m1i=mex, sd1i=sdex, n1i=nex,
                                       m2i=mcn, sd2i=sdcn, n2i=ncn, data=med_distal_df_pen_int)
      # Non-random
      x0   <- rma(yi, vi, data=med_distal_df_pen_int1); x0; x0$I2
      {# Random model all ----
        x1   <- rma.mv(yi, vi, random= ~1       | study1, data=med_distal_df_pen_int1); x1
        x11  <- rma.mv(yi, vi, random= ~ sample | study1, data=med_distal_df_pen_int1); x1
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1$vi)
          X <- model.matrix(x1)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1$sigma2) / (sum(x1$sigma2) + (x1$k-x1$p)/sum(diag(P)))
        }  
      }
      {# Random model Low intensity  ----
        x1a   <- rma.mv(yi, vi, subset=var_HIGH_LOW.INTENSITY ==0, random= ~      1 | study1, data=med_distal_df_pen_int1); x1a
        x11a  <- rma.mv(yi, vi, subset=var_HIGH_LOW.INTENSITY ==0, random= ~ sample | study1, data=med_distal_df_pen_int1); x1a
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1a$vi)
          X <- model.matrix(x1a)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1a$sigma2) / (sum(x1a$sigma2) + (x1a$k-x1a$p)/sum(diag(P)))
        }  
      }
      {# Random model High intensity  ----
        x1b   <- rma.mv(yi, vi, subset=var_HIGH_LOW.INTENSITY==1, random= ~      1 | study1, data=med_distal_df_pen_int1); x1b
        x11b  <- rma.mv(yi, vi, subset=var_HIGH_LOW.INTENSITY==1, random= ~ sample | study1, data=med_distal_df_pen_int1); x1b
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1b$vi)
          X <- model.matrix(x1b)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1b$sigma2) / (sum(x1b$sigma2) + (x1b$k-x1b$p)/sum(diag(P)))
        }  
      }
      {# Compare the two groups ----
        names(med_distal_df_fl_int1)
        res10 <- rma.mv(yi, vi, random=~ sample |study1, data=med_distal_df_pen_int1, subset=var_HIGH_LOW.INTENSITY=="0"); res10
        res20 <- rma.mv(yi, vi, random=~ sample |study1, data=med_distal_df_pen_int1, subset=var_HIGH_LOW.INTENSITY=="1"); res20
        
        dat.comp1 <- data.frame(estimate = c(coef(res10), coef(res20)), stderror = c(res10$se, res20$se),
                                meta = c("0","1"), tau2 = round(c(res10$tau2, res20$tau2),3))
        dat.comp1
        rma(estimate, sei=stderror, mods = ~ meta, method="FE", data=dat.comp1, digits=3)
        with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))
        2*pnorm((with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))), lower.tail = t)
      }
    }
  }
  {#Group 6: Medial Distal Thickness by Volume -----
    med_distal_df_thick_vol <- read.csv("C:/Users/Thanasis/OneDrive - stc02/Ongoing projects/Bogdanis/R2/13_mediaLdistal_combined_thick_by_volume_R1.csv")
    names(med_distal_df_thick_vol)
    {# The Models ----
      med_distal_df_thick_vol1 <- escalc(measure="SMD", 
                                         m1i=mex, sd1i=sdex, n1i=nex,
                                         m2i=mcn, sd2i=sdcn, n2i=ncn, data=med_distal_df_thick_vol)
      # Non-random
      x0   <- rma(yi, vi, data=med_distal_df_thick_vol1); x0; x0$I2
      {# Random model all ----
        x1   <- rma.mv(yi, vi, random= ~1       | study1, data=med_distal_df_thick_vol1); x1
        x11  <- rma.mv(yi, vi, random= ~ sample | study1, data=med_distal_df_thick_vol1); x1
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1$vi)
          X <- model.matrix(x1)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1$sigma2) / (sum(x1$sigma2) + (x1$k-x1$p)/sum(diag(P)))
        }  
      }
      {# Random model < 5400  ----
        x1a   <- rma.mv(yi, vi, subset=var_5400 ==0, random= ~1       | study1, data=med_distal_df_thick_vol1); x1a
        x11a  <- rma.mv(yi, vi, subset=var_5400 ==0, random= ~ sample | study1, data=med_distal_df_thick_vol1); x1a
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1a$vi)
          X <- model.matrix(x1a)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1a$sigma2) / (sum(x1a$sigma2) + (x1a$k-x1a$p)/sum(diag(P)))
        }  
      }
      {# Random model > 5400  ----
        x1b   <- rma.mv(yi, vi, subset=var_5400==1, random= ~      1 | study1, data=med_distal_df_thick_vol1); x1b
        x11b  <- rma.mv(yi, vi, subset=var_5400==1, random= ~ sample | study1, data=med_distal_df_thick_vol1); x1b
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1b$vi)
          X <- model.matrix(x1b)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1b$sigma2) / (sum(x1b$sigma2) + (x1b$k-x1b$p)/sum(diag(P)))
        }  
      }
      {# Compare the two groups ----
        names(med_distal_df_fl_int1)
        res10 <- rma.mv(yi, vi, random=~ sample |study1, data=med_distal_df_thick_vol1, subset=var_5400=="0"); res10
        res20 <- rma.mv(yi, vi, random=~ sample |study1, data=med_distal_df_thick_vol1, subset=var_5400=="1"); res20
        
        dat.comp1 <- data.frame(estimate = c(coef(res10), coef(res20)), stderror = c(res10$se, res20$se),
                                meta = c("0","1"), tau2 = round(c(res10$tau2, res20$tau2),3))
        dat.comp1
        rma(estimate, sei=stderror, mods = ~ meta, method="FE", data=dat.comp1, digits=3)
        with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))
        2*pnorm((with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))), lower.tail = F)
      }
    }
  }
  {#Group 7: Medial Distal Thickness by intensity -----
    med_distal_df_thick_int <- read.csv("C:/Users/Thanasis/OneDrive - stc02/Ongoing projects/Bogdanis/R2/13_mediaLdistal_combined_thick_by_intensity_R1.csv")
    names(med_distal_df_thick_int)
    {# The Models ----
      med_distal_df_thick_int1 <- escalc(measure="SMD", 
                                         m1i=mex, sd1i=sdex, n1i=nex,
                                         m2i=mcn, sd2i=sdcn, n2i=ncn, data=med_distal_df_thick_int)
      # Non-random
      x0   <- rma(yi, vi, data=med_distal_df_thick_int1); x0; x0$I2
      {# Random model all ----
        x1   <- rma.mv(yi, vi, random= ~1 | study1, data=med_distal_df_thick_int1); x1
        x11  <- rma.mv(yi, vi, random= ~ sample | study1, data=med_distal_df_thick_int1); x1
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1$vi)
          X <- model.matrix(x1)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1$sigma2) / (sum(x1$sigma2) + (x1$k-x1$p)/sum(diag(P)))
        }  
      }
      {# Random model Low intensity  ----
        x1a   <- rma.mv(yi, vi, subset=var_HIGH_LOW.INTENSITY ==0, random= ~      1 | study1, data=med_distal_df_thick_int1); x1a
        x11a  <- rma.mv(yi, vi, subset=var_HIGH_LOW.INTENSITY ==0, random= ~ sample | study1, data=med_distal_df_thick_int1); x1a
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1a$vi)
          X <- model.matrix(x1a)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1a$sigma2) / (sum(x1a$sigma2) + (x1a$k-x1a$p)/sum(diag(P)))
        }  
      }
      {# Random model High intensity  ----
        x1b   <- rma.mv(yi, vi, subset=var_HIGH_LOW.INTENSITY==1, random= ~      1 | study1, data=med_distal_df_thick_int1); x1b
        x11b  <- rma.mv(yi, vi, subset=var_HIGH_LOW.INTENSITY==1, random= ~ sample | study1, data=med_distal_df_thick_int1); x1b
        #
        {# Get the I^2 for the above model ----
          W <- diag(1/x1b$vi)
          X <- model.matrix(x1b)
          P <- W - W %*% X %*% solve(t(X) %*% W %*% X) %*% t(X) %*% W
          100 * sum(x1b$sigma2) / (sum(x1b$sigma2) + (x1b$k-x1b$p)/sum(diag(P)))
        }  
      }
      {# Compare the two groups ----
        names(med_distal_df_thick_int1)
        res10 <- rma.mv(yi, vi, random=~ sample |study1, data=med_distal_df_thick_int1, subset=var_HIGH_LOW.INTENSITY=="0"); res10
        res20 <- rma.mv(yi, vi, random=~ sample |study1, data=med_distal_df_thick_int1, subset=var_HIGH_LOW.INTENSITY=="1"); res20
        
        dat.comp1 <- data.frame(estimate = c(coef(res10), coef(res20)), stderror = c(res10$se, res20$se),
                                meta = c("0","1"), tau2 = round(c(res10$tau2, res20$tau2),3))
        dat.comp1
        rma(estimate, sei=stderror, mods = ~ meta, method="FE", data=dat.comp1, digits=3)
        with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))
        2*pnorm((with(dat.comp1, round(c(zval = (estimate[1] - estimate[2])/sqrt(stderror[1]^2 + stderror[2]^2)), 3))), lower.tail = T)
      }
    }
  }
  
}
{# Plots ----
  par(mar=c(0,0,0,0)) # setting 0-inch margins (sequence is bottom, left, top, right)
  windowsFonts(NSimSun=windowsFont("NSimSun")); par(family="NSimSun") #same as above
  #
  {# The plot for Figure 01 ----
    tiff("Donti_Bogdanis_Fig_01.tiff", width = 9.27, height = 12.69, units = 'in', res = 300) #you run this first, then the graph
    forest(x1, slab=paste(med_distal_df_fl_vol$Authors),
           xlim=c(-5,5), efac=.7, annosym = c(" [", ", ", "]"), 
           ylim=c(0, 42),
           alim=c(-1.5, 2.4), 
           at=(c(-1.5, -1.00, -0.50, 0, 0.50, 1.00, 1.50)),  
           order= -order(med_distal_df_fl_vol$var_5400),
           rows=c(4:22, 27:37),
           xlab="", mlab="", psize=1.)
    #addpoly(res2all,  row=-1, lty="solid", col="black", cex = 1.0, annotate = F, mlab="")
    text(c(-4.5, 0, 3.5, 4.4), 41, 
         c( "Study", "Standardized Mean \nDifference (SMD)", 
            "SMD", 
            "95%-CI"), 
         cex = 1.0)      
    abline(h=c(26.5, 3), lwd=c(1,1), lty="dotted" )
    text(c(-5), c(23, 38), c(expression(bold("Studies with > 5400 s")),
                             expression(bold("Studies with < 5400 s"))), pos=c(4,4), cex = 1.0)
    addpoly(x1a,  row=26, lty="twodash", col="white", cex = 1, mlab="" )
    addpoly(x1b,  row=2, lty="twodash", col="white", cex = 1, mlab="" )
    text(c(-5, 2.7, 3.0), 26, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    text(c(-5, 2.7, 3.0), 2, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    dev.off()
  }
  {# The plot for Figure 02  ----
    tiff("Donti_Bogdanis_Fig_02.tiff", width = 9.27, height = 12.69, units = 'in', res = 300) #you run this first, then the graph
    forest(x1, slab=paste(med_distal_df_fl_int$Authors),
           xlim=c(-5,5), efac=.7, annosym = c(" [", ", ", "]"), 
           ylim=c(0, 42),
           alim=c(-1.5, 2.4), 
           at=(c(-1.5, -1.00, -0.50, 0, 0.50, 1.00, 1.50)),  
           order= -order(med_distal_df_fl_int$var_HIGH.LOW.INTENSITY),
           rows=c(4:23, 28:37),
           xlab="", mlab="", psize=1.)
    #addpoly(res2all,  row=-1, lty="solid", col="black", cex = 1.0, annotate = F, mlab="")
    text(c(-4.5, 0, 3.5, 4.4), 41, 
         c( "Study", "Standardized Mean \nDifference (SMD)", 
            "SMD", 
            "95%-CI"), 
         cex = 1.0)      
    abline(h=c(26.5, 3), lwd=c(1,1), lty="dotted" )
    text(c(-5), c(24, 38), c(expression(bold("Studies with High Intensity")),
                             expression(bold("Studies with Low Intensity"))), pos=c(4,4), cex = 1.0)
    addpoly(x1a,  row=26, lty="twodash", col="white", cex = 1, mlab="" )
    addpoly(x1b,  row=2, lty="twodash", col="white", cex = 1, mlab="" )
    text(c(-5, 2.7, 3.0), 26, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    text(c(-5, 2.7, 3.0), 2, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    dev.off()
  }
  {# The plot for Figure 03 ----
    tiff("Donti_Bogdanis_Fig_03.tiff", width = 9.27, height = 12.69, units = 'in', res = 300) #you run this first, then the graph
    forest(x1, slab=paste(med_distal_df_fl_ext$Authors),
           xlim=c(-5,5), efac=.7, annosym = c(" [", ", ", "]"), 
           ylim=c(0, 15),
           alim=c(-1.5, 2.4), 
           at=(c(-1.5, -1.00, -0.50, 0, 0.50, 1.00, 1.50)),  
           order= -order(med_distal_df_fl_ext$Authors),
           rows=c(4:12),
           xlab="", mlab="", psize=1.)
    addpoly(x1,  row=2, lty="solid", col="black", cex = 1.0, annotate = T, mlab="")
    text(c(-4.5, 0, 3.5, 4.4), 14, 
         c( "Study", "Standardized Mean \nDifference (SMD)", 
            "SMD", 
            "95%-CI"), 
         cex = 1.0)      
    abline(h=c(3), lwd=c(1,1), lty="dotted" )
    text(c(-5, 2.7, 3.0), 2, c("Summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    
    dev.off()
  }
  {# The plot for Figure 04 ----
    tiff("Donti_Bogdanis_Fig_04.tiff", width = 9.27, height = 12.69, units = 'in', res = 300) #you run this first, then the graph
    forest(x1, slab=paste(med_distal_df_pen_vol$Authors),
           xlim=c(-5,5), efac=.7, annosym = c(" [", ", ", "]"), 
           ylim=c(0, 36),
           alim=c(-1.5, 2.4), 
           at=(c(-1.5, -1.00, -0.50, 0, 0.50, 1.00, 1.50)),  
           order= -order(med_distal_df_pen_vol$var_5400),
           rows=c(4:18, 23:32),
           xlab="", mlab="", psize=1.)
    #addpoly(res2all,  row=-1, lty="solid", col="black", cex = 1.0, annotate = F, mlab="")
    text(c(-4.5, 0, 3.5, 4.4), 36, 
         c( "Study", "Standardized Mean \nDifference (SMD)", 
            "SMD", 
            "95%-CI"), 
         cex = 1.0)      
    abline(h=c(21.5, 3), lwd=c(1,1), lty="dotted" )
    text(c(-5), c(19, 33), c(expression(bold("Studies with > 5400 s")),
                             expression(bold("Studies with < 5400 s"))), pos=c(4,4), cex = 1.0)
    addpoly(x1a,  row=21, lty="twodash", col="white", cex = 1, mlab="" )
    addpoly(x1b,  row=2, lty="twodash", col="white", cex = 1, mlab="" )
    text(c(-5, 2.7, 3.0), 21, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    text(c(-5, 2.7, 3.0), 2, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    dev.off()
  }
  {# The plot for Figure 05  ----
    tiff("Donti_Bogdanis_Fig_05.tiff", width = 9.27, height = 12.69, units = 'in', res = 300) #you run this first, then the graph
    forest(x1, slab=paste(med_distal_df_pen_int$Authors),
           xlim=c(-5,5), efac=.7, annosym = c(" [", ", ", "]"), 
           ylim=c(0, 42),
           alim=c(-1.5, 2.4), 
           at=(c(-1.5, -1.00, -0.50, 0, 0.50, 1.00, 1.50)),  
           order= -order(med_distal_df_pen_int$var_HIGH_LOW.INTENSITY),
           rows=c(4:17, 22:32),
           xlab="", mlab="", psize=1.)
    #addpoly(res2all,  row=-1, lty="solid", col="black", cex = 1.0, annotate = F, mlab="")
    text(c(-4.5, 0, 3.5, 4.4), 41, 
         c( "Study", "Standardized Mean \nDifference (SMD)", 
            "SMD", 
            "95%-CI"), 
         cex = 1.0)      
    abline(h=c(21, 3), lwd=c(1,1), lty="dotted" )
    text(c(-5), c(18, 33), c(expression(bold("Studies with High Intensity")),
                             expression(bold("Studies with Low Intensity"))), pos=c(4,4), cex = 1.0)
    addpoly(x1a,  row=20, lty="twodash", col="white", cex = 1, mlab="" )
    addpoly(x1b,  row=2, lty="twodash", col="white", cex = 1, mlab="" )
    text(c(-5, 2.7, 3.0), 20, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    text(c(-5, 2.7, 3.0), 2, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    dev.off()
  }
  {# The plot for Figure 06 ----
    tiff("Donti_Bogdanis_Fig_06.tiff", width = 9.27, height = 12.69, units = 'in', res = 300) #you run this first, then the graph
    forest(x1, slab=paste(med_distal_df_thick_vol$Authors),
           xlim=c(-5,5), efac=.7, annosym = c(" [", ", ", "]"), 
           ylim=c(0, 42),
           alim=c(-1.5, 2.4), 
           at=(c(-1.5, -1.00, -0.50, 0, 0.50, 1.00, 1.50)),  
           order= -order(med_distal_df_thick_vol$var_5400),
           rows=c(4:23, 28:38),
           xlab="", mlab="", psize=1.)
    #addpoly(res2all,  row=-1, lty="solid", col="black", cex = 1.0, annotate = F, mlab="")
    text(c(-4.5, 0, 3.5, 4.4), 41, 
         c( "Study", "Standardized Mean \nDifference (SMD)", 
            "SMD", 
            "95%-CI"), 
         cex = 1.0)      
    abline(h=c(27.5, 3), lwd=c(1,1), lty="dotted" )
    text(c(-5), c(24, 39), c(expression(bold("Studies with > 5400 s")),
                             expression(bold("Studies with < 5400 s"))), pos=c(4,4), cex = 1.0)
    addpoly(x1a,  row=27, lty="twodash", col="white", cex = 1, mlab="" )
    addpoly(x1b,  row=2, lty="twodash", col="white", cex = 1, mlab="" )
    text(c(-5, 2.7, 3.0), 27, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    text(c(-5, 2.7, 3.0), 2, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    dev.off()
  }
  {# The plot for Figure 07  ----
    tiff("Donti_Bogdanis_Fig_07.tiff", width = 9.27, height = 12.69, units = 'in', res = 300) #you run this first, then the graph
    forest(x1, slab=paste(med_distal_df_thick_int$Authors),
           xlim=c(-5,5), efac=.7, annosym = c(" [", ", ", "]"), 
           ylim=c(0, 42),
           alim=c(-1.5, 2.4), 
           at=(c(-1.5, -1.00, -0.50, 0, 0.50, 1.00, 1.50)),  
           order= -order(med_distal_df_thick_int$var_HIGH_LOW.INTENSITY),
           rows=c(4:21, 26:38),
           xlab="", mlab="", psize=1.)
    #addpoly(res2all,  row=-1, lty="solid", col="black", cex = 1.0, annotate = F, mlab="")
    text(c(-4.5, 0, 3.5, 4.4), 41, 
         c( "Study", "Standardized Mean \nDifference (SMD)", 
            "SMD", 
            "95%-CI"), 
         cex = 1.0)      
    abline(h=c(25.5, 3), lwd=c(1,1), lty="dotted" )
    text(c(-5), c(22, 39), c(expression(bold("Studies with High Intensity")),
                             expression(bold("Studies with Low Intensity"))), pos=c(4,4), cex = 1.0)
    addpoly(x1a,  row=24, lty="twodash", col="white", cex = 1, mlab="" )
    addpoly(x1b,  row=2, lty="twodash", col="white", cex = 1, mlab="" )
    text(c(-5, 2.7, 3.0), 24, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    text(c(-5, 2.7, 3.0), 2, c("Subgroup summary", expression(italic("M"), "=")), pos=c(4), cex = 1.0)
    dev.off()
  }  
}
