# Imputing Covariance for Meta-Analysis in the Presence of Interaction
## 5 Example: Analyzing the 10 Cohort Studies in Table 1  
### Meta-Analysis for \(\beta_{1}\)  
We wrote custom R functions to perform meta-analysis on the data in Table 1. The following R functions conduct both fixed-effect and random-effects meta-analyses for \(\beta_{1}\).  
studies <-read.csv('[[https://raw.githubusercontent.com/envuliu/meta-analysis/main/random_effect_meta_sim.csv](https://raw.githubusercontent.com/envuliu/meta-analysis/main/random_effect_meta_sim.csv)]([https://raw.githubusercontent.com/envuliu/meta-analysis/main/random_effect_meta_sim.csv](https://raw.githubusercontent.com/envuliu/meta-analysis/main/random_effect_meta_sim.csv))', header = TRUE) b1<-studies$b1 # beta1 from the 10 cohorts var_b1 <- studies$var_b1 # variances of the coefficients fixed_effect_meta <- function(B, V) { W <- 1 / V Beta <- sum(W * B) / sum(W) Var <- 1 / sum(W) resultlist <- list('Overall beta' = Beta, 'Overall variance' = Var) return(resultlist)  
Figure 1: Schematic illustration of the meta-analytic framework.  
random_effect_meta <- function(B, V) {  W <- 1 / V  Q <- sum(W * B^2) - (sum(W * B))^2 / sum(W)  df <- length(B) - 1  c <- sum(W) - sum(W^2) / sum(W)  tau_square <- ifelse(Q > df, (Q - df) / c, 0)  V_star <- V + tau_square  W_star <- 1 / V_star  Beta_star <- sum(W_star * B) / sum(W_star)  Var_star <- 1 / sum(W_star)  resultlist <- list(  'Overall beta' = Beta_star,  'Overall variance' = Var_star)  return(resultlist)  }  fixed_b1  # $'Overall beta'  # [1] 1.040411  #  # $'Overall variance'  # [1] 0.6841809  random_b1 <- random_effect_meta(b1, var_b1)  random_b1  # $'Overall beta'  # [1] 1.014141  #  # $'Overall variance'  # [1] 0.7308388  
From the results, the overall fixed-effect estimate for \(\beta_{1}\) is 1.0404, with an overall variance of 0.6842. The overall random-effects estimate is 1.0141, with an overall variance of 0.7308.  
The meta-analysis can also be conducted using the R package'meta' [14], which can generate a forest plot (Figure 2) as follows:  
library(meta) b1.meta<- metagen(TE = b1,  seTE = sqrt(var_b1),  studlab = LETTERS[1:10],  data =,  sm = \"\",  method.tau = \"DL\",  fixed = TRUE,  random = TRUE,  title = \"Use R meta package\")  
summary(b1.meta)  forest(b1.meta)  # Review: Use R meta package  # # 95%-CI %W(common) %W(random)A 3.0014 [-0.3603; 6.3631] 23.3 22.3  # B 1.1488 [-6.3445; 8.6420] 4.7 4.9  # C 1.5819 [-6.2112; 9.3750] 4.3 4.5  # D 2.0349 [-1.7329; 5.8026] 18.5 18.1  # E -4.1218 [-8.6104; 0.3668] 13.0 13.1  # F 1.2506 [-5.3271; 7.8282] 6.1 6.3  # G 2.3383 [-2.1507; 6.8274] 13.0 13.1  # H -3.1343 [-9.0370; 2.7683] 7.5 7.8  # I 1.3066 [-5.9681; 8.5813] 5.0 5.2  # J 3.7753 [-3.8262; 11.3769] 4.5 4.8  #
Number of studies: k = 10  # # 95%-CI z p-value  # Common effect model 1.0404 [-0.5808; 2.6616] 1.26 0.2085  # Random effects model 1.0141 [-0.6614; 2.6897] 1.19 0.2355  # # Quantifying heterogeneity:  # tau^2 = 0.3376 [0.0000; 15.2185]; tau = 0.5811 [0.0000; 3.9011]  # I^2 = 4.5% [0.0%; 64.1%]; H = 1.02 [1.00; 1.67]  # # Test of heterogeneity:  # Q d.f. p-value  # 9.42 9 0.3991  # Details on meta-analytical method:  # - Inverse variance method  # - DerSimonian-Laird estimator for tau^2  # - Jackson method for confidence interval of tau^2 and tau  The results are the same as those obtained using our custom function, yielding an overall \(\hat{\beta}_{1}\)=1.0404 for the common-effect model (fixed effect) and \(\hat{\beta}_{1}\)=1.0141 for the random-effects model.