This vignette shows examples of all currently supported varcov_type metric options for within-study variance-covariance computation in mars.

library(mars)

1. Correlation Metrics

For synthesized correlation matrices, use:

  • simple
  • weighted
  • average
cor_dat <- data.frame(
  study = c("s1", "s1", "s1", "s2", "s2", "s2"),
  numID = c(1, 2, 3, 1, 2, 3),
  ri = c(0.20, 0.12, 0.08, 0.25, 0.15, 0.11),
  N = c(100, 100, 100, 120, 120, 120)
)

S_cor_simple <- mars:::within_varcov(
  data = cor_dat,
  N = "N",
  effect_name = "ri",
  study = "study",
  type = "simple"
)

S_cor_weighted <- mars:::within_varcov(
  data = cor_dat,
  N = "N",
  effect_name = "ri",
  study = "study",
  type = "weighted"
)

S_cor_average <- mars:::within_varcov(
  data = cor_dat,
  N = "N",
  effect_name = "ri",
  study = "study",
  type = "average"
)

S_cor_simple[[1]]
#>             [,1]        [,2]        [,3]
#> [1,] 0.009216000 0.000643776 0.001069184
#> [2,] 0.000643776 0.009714074 0.001913318
#> [3,] 0.001069184 0.001913318 0.009872410
S_cor_weighted[[1]]
#>              [,1]         [,2]        [,3]
#> [1,] 0.0089936224 0.0007533087 0.001179743
#> [2,] 0.0007533087 0.0096315569 0.002148884
#> [3,] 0.0011797431 0.0021488845 0.009815143
S_cor_average[[1]]
#>              [,1]         [,2]        [,3]
#> [1,] 0.0090131289 0.0007445448 0.001170920
#> [2,] 0.0007445448 0.0096388215 0.002129556
#> [3,] 0.0011709204 0.0021295562 0.009820315

2. SMD by Outcome (existing)

For multiple SMD outcomes within study, use:

  • outcome
smd_outcome_dat <- data.frame(
  study = c("s1", "s1", "s2", "s2"),
  d = c(0.30, 0.42, 0.20, 0.27),
  nt = c(40, 40, 36, 36),
  nc = c(40, 40, 36, 36),
  r2do = c(0.7, 0.7, 0.7, 0.7)
)

S_smd_outcome <- mars:::within_varcov(
  data = smd_outcome_dat,
  N = NULL,
  effect_name = "d",
  study = "study",
  type = "outcome"
)

S_smd_outcome[[1]]
#>            [,1]       [,2]
#> [1,] 0.05056250 0.03538587
#> [2,] 0.03538587 0.05110250

3. SMD with Shared Control Group

For multiple treatment arms sharing one control within study, use:

  • smd_shared_control (aliases: smd_control, control)
smd_shared_dat <- data.frame(
  study = c("s1", "s1", "s2", "s2"),
  effID = c(1, 2, 1, 2),
  yi = c(0.22, 0.35, 0.18, 0.28),
  nt = c(50, 55, 48, 46),
  nc = c(60, 60, 52, 52),
  control_id = c("c1", "c1", "c2", "c2")
)

S_smd_control <- mars:::within_varcov(
  data = smd_shared_dat,
  N = NULL,
  effect_name = "yi",
  study = "study",
  type = "smd_shared_control"
)

S_smd_control[[1]]
#>            [,1]       [,2]
#> [1,] 0.03688667 0.01730833
#> [2,] 0.01730833 0.03538109

4. Log Relative Risk (shared control)

Use:

  • log_rr (aliases: rr, relative_risk, risk_ratio)

Required columns are treatment/control events and totals (for example, tpos, tneg, cpos, cneg), or equivalent aliases.

rr_dat <- data.frame(
  study = c("s1", "s1", "s2", "s2"),
  effID = c(1, 2, 1, 2),
  tpos = c(20, 18, 16, 14),
  tneg = c(30, 37, 32, 30),
  cpos = c(15, 15, 14, 14),
  cneg = c(45, 45, 38, 38),
  control_id = c("c1", "c1", "c2", "c2")
)
nt <- rr_dat$tpos + rr_dat$tneg
nc <- rr_dat$cpos + rr_dat$cneg
rr_dat$yi <- log((rr_dat$tpos / nt) / (rr_dat$cpos / nc))

S_log_rr <- mars:::within_varcov(
  data = rr_dat,
  N = NULL,
  effect_name = "yi",
  study = "study",
  type = "log_rr"
)

S_log_rr[[1]]
#>      [,1]       [,2]
#> [1,] 0.08 0.05000000
#> [2,] 0.05 0.08737374

5. Log Odds Ratio (shared control)

Use:

  • log_or (aliases: or, log_odds_ratio)
or_dat <- rr_dat
or_dat$yi <- log((or_dat$tpos / or_dat$tneg) / (or_dat$cpos / or_dat$cneg))

S_log_or <- mars:::within_varcov(
  data = or_dat,
  N = NULL,
  effect_name = "yi",
  study = "study",
  type = "log_or"
)

S_log_or[[1]]
#>            [,1]       [,2]
#> [1,] 0.17222222 0.08888889
#> [2,] 0.08888889 0.17147147

6. Single-arm Proportions

Use:

  • proportion (alias: prop)

Required columns: events and totals (for example, events, n).

prop_dat <- data.frame(
  study = c("s1", "s1", "s2", "s2"),
  effID = c(1, 2, 1, 2),
  events = c(14, 18, 10, 13),
  n = c(60, 62, 55, 57)
)
prop_dat$yi <- prop_dat$events / prop_dat$n

S_prop <- mars:::within_varcov(
  data = prop_dat,
  N = NULL,
  effect_name = "yi",
  study = "study",
  type = "proportion"
)

S_prop[[1]]
#>             [,1]        [,2]
#> [1,] 0.002981481 0.000000000
#> [2,] 0.000000000 0.003323151

7. Proportion Differences / Risk Difference (shared control)

Use:

  • proportion_diff (aliases: prop_diff, risk_difference)
pd_dat <- rr_dat
nt <- pd_dat$tpos + pd_dat$tneg
nc <- pd_dat$cpos + pd_dat$cneg
pd_dat$yi <- (pd_dat$tpos / nt) - (pd_dat$cpos / nc)

S_prop_diff <- mars:::within_varcov(
  data = pd_dat,
  N = NULL,
  effect_name = "yi",
  study = "study",
  type = "proportion_diff"
)

S_prop_diff[[1]]
#>          [,1]        [,2]
#> [1,] 0.007925 0.003125000
#> [2,] 0.003125 0.007128005

8. Generic Diagonal Options

For purely diagonal within-study structures:

  • univariate (vector per study, for univariate analysis)
  • multilevel (diagonal matrix per study)
diag_dat <- data.frame(
  study = c("s1", "s1", "s2"),
  vi = c(0.04, 0.05, 0.03)
)

S_uni <- mars:::within_varcov(
  data = diag_dat,
  N = NULL,
  effect_name = "yi",
  study = "study",
  type = "univariate",
  variance = "vi"
)

S_ml <- mars:::within_varcov(
  data = diag_dat,
  N = NULL,
  effect_name = "yi",
  study = "study",
  type = "multilevel",
  variance = "vi"
)

S_uni[[1]]
#> [1] 0.04 0.05
S_ml[[1]]
#>      [,1] [,2]
#> [1,] 0.04 0.00
#> [2,] 0.00 0.05

These same varcov_type values can be passed to mars() / estimation() for multivariate analyses.