
Information fraction within each trial and pooled across trials
Source:R/constructions.R, R/ifrac.R
ifrac.RdDesign (default): computes information fractions within each trial from subgroup variances.
Usage
# S3 method for class 'interactmeta_da'
ifrac(x, ...)
# S3 method for class 'interactmeta_ad'
ifrac(x, ...)
# S3 method for class 'interactmeta_swada'
ifrac(x, ...)
ifrac(x, ...)
# Default S3 method
ifrac(
x,
vi = NULL,
trial = NULL,
modifier = NULL,
subgroup = NULL,
big_var = 100^2,
contrast = "all",
contrast_sep = "-",
reference = NULL,
include_combined = FALSE,
include_interaction = FALSE,
yi = NULL,
...
)
# S3 method for class 'data.frame'
ifrac(
x,
ifrac = NULL,
fit = NULL,
tau = NULL,
tau_gamma = NULL,
reference = NULL,
trial = "study",
modifier = NULL,
subgroup = "level",
ifrac_var = NULL,
contrast_sep = "-",
summary = FALSE,
prob = 0.95,
big_var = 100^2,
contrast = "all",
include_combined = FALSE,
include_interaction = FALSE,
yi = NULL,
...
)
# S3 method for class 'interactmeta'
ifrac(
x,
ifrac = c("interaction", "combined"),
ifrac_var = NULL,
summary = FALSE,
prob = 0.95,
reference = NULL,
tau_sampling = c("grid", "posterior"),
n_tau_samples = NULL,
seed = NULL,
...
)
# S3 method for class 'interactmeta_overall_ifrac'
ifrac(x, ...)Arguments
- x
Effect estimates. A numeric vector, or a data frame or
escalcobject with columnsyiandvi. If omitted,yiis used.- ...
Further arguments passed to methods.
- vi
Numeric vector. Variance of the subgroup estimate. Not used when the estimates are a data frame or
escalcobject.- trial
Trial identifier. A vector (same length as the estimates), or when the estimates are a data frame the name of the trial column (default
"study").- modifier
Modifier (the two-level within-trial contrast). A vector of level labels (same length as the estimates), or when the estimates are a data frame the name of the modifier column (default
"level", else a legacy"subgroup"column). A column name that is not in the data is an error.- subgroup
Deprecated alias for
modifier; supplying it warns.modifiertakes precedence when both are given.- big_var
Positive number. Variance used to impute a missing
trial-by-subgroupcell (yi = 0,vi = big_var). For anescalcobject, a row that already has the placeholderyi = 0andvi = 8keeps that estimate, andviis replaced bybig_var. Defaults to100^2.- contrast
Either
NULL(subgroup rows only, wideIF_<subgroup>columns), a character vector of length 2 giving the two subgroup labels to contrast within each trial (computed aslabel1 - label2, wherelabel2is the reference), or"all"(default) to add each non-reference subgroup vs the reference.- contrast_sep
String used between subgroup labels in the contrast row label. Defaults to
"-".- reference
Optional. Used when
contrast = "all". Comparisons are generated only between each non-reference subgroup and the reference subgroup (e.g.g2-g1,g3-g1, ...). IfreferenceisNULL, the reference defaults to the first level of a factormodifier, otherwise the first label in sorted unique order. Can be either an integer index or a reference level label, which must be one of the observedmodifierlevels.When supplied, extra rows per trial are added with
subgrouplabelspaste0(label1, contrast_sep, label2), andyi/vicomputed asyi1 - yi2andvi1 + vi2. Missingtrial-by-subgroupcombinations use the imputedyi=0andvi=big_var.For a fitted
interactmeta,referencemay instead name the stored non-reference subgroup to return the pooled IF in that orientation, \(1-\omega\) (seereferenceinmodifiers()).- include_combined
Logical. If
FALSE(default), return subgroup rows only. IfTRUE, append one precision-weighted combined row per trial withsubgroup = "Combined".- include_interaction
Logical. If
FALSE(default), return subgroup rows only while still usingcontrastto define the reference-centeredIF_*design columns. IfTRUEandcontrastis notNULL, append interaction/contrast rows below subgroup rows.- yi
Either a numeric vector of subgroup effect estimates, or a data frame /
escalcobject containing columnsyiandvi. When a data frame is supplied asxoryi,vimust not be passed separately;trialandmodifiername columns (defaults"study"and"level").- ifrac
For pooling only:
"interaction"(default) or"combined"("overall"is accepted with a deprecation warning).- fit, tau, tau_gamma, ifrac_var, summary, prob
Pooling options when
xis ainteractmetaor design data withIF_*columns (fitortau/tau_gammarequired for data-only pooling).- tau_sampling
For Bayesian pooling:
"grid"(default; DIRECT nodes onfit$support) or"posterior"(native marginal \(\tau\) draws).- n_tau_samples
With
tau_sampling = "posterior", overridesoptions(interactmeta.ifrac.n_tau_samples):0L= posterior median plug-in,n > 0= Monte Carlo size.- seed
Optional integer;
set.seed()before tau posterior sampling.
Value
For the design method, a tibble with one row per trial-by-subgroup combination (subgroup
levels and contrast rows when requested), including study, level
(a factor with the reference subgroup as the first level on subgroup rows),
yi, vi, and information-fraction columns. Columns yi, vi, precision
(when present), and all IF_<...> columns are numeric.
For pooling, a interactmeta_overall_ifrac object (draws with metadata), or a
summary data frame when summary = TRUE.
Details
Each component precision is defined as 1 / vi.
By default (contrast = "all"), all non-reference-vs-reference contrasts are
added per trial. Set contrast = NULL to return only subgroup rows with wide
IF_<subgroup> columns (one fraction per subgroup label).
When contrast is provided, the information fraction for each comparison is
computed as the non-reference subgroup precision divided by the total subgroup
precision within the trial. By
convention, the reference subgroup is the label after contrast_sep, i.e.
in a label like "g2-g1", "g1" is the reference subgroup.
By default, components are the observed subgroup labels. When
include_combined = TRUE, one precision-weighted combined row per trial is
appended with level = "Combined" (contribution-weighted mean \(m_j\) on the
chosen scale). When include_interaction = TRUE, contrast rows are stacked
below subgroup rows with level labels like "g2-g1" (reference after
contrast_sep), using yi and vi for the contrast estimate and variance.
Wide columns IF_<non-reference> are filled
on every row (no NA), plus precision, and a reference column (last
column). For each non-reference subgroup k, IF_k is the trial-level
information fraction \(\pi_j\). On combined
and contrast rows, precision is the sum of subgroup precisions in the trial
(or in that comparison for a single contrast).
Pooling
For a fitted interactmeta, or ifrac() data with IF_* columns,
pass ifrac to pool trial-level fractions across studies.
$$\bar{\omega} = \sum_j \pi_j w_j / \sum_j w_j.$$
With ifrac = "interaction" (default),
\(w_j = 1/(\tau_\gamma^2 + \sigma_{Aj}^2 + \sigma_{Bj}^2)\) using the
interaction-block SD \(\tau_\gamma\).
With ifrac = "combined" (combined-block / intercept SD \(\tau\)),
\(w_j = 1/(\tau^2 + \sigma_j^2)\) using the
overall-block intercept SD \(\tau\) and combined sampling variance
\(\sigma_j^2=\mathrm{Var}(m_j)=(1-\pi_j)^2\sigma_{Aj}^2+\pi_j^2\sigma_{Bj}^2\).
On Bayesian CAMS, default pooling evaluates \(\bar\omega(\tau^{(k)})\) on the
DIRECT support (tau_sampling = "grid", one value per row of
fit$support, with quadrature weights .weight). Pass tau_sampling = "posterior"
to draw \(\tau\) or \(\tau_\gamma\) from the native bayesmeta / bmr margin
via options(interactmeta.ifrac.n_tau_samples): 0L is a posterior-median
plug-in; positive n (default 1000L) enables Monte Carlo. Frequentist CAMS
uses the fitted heterogeneity only.
When modifiers(), combined(), or interactions() use at_ifrac = NULL,
they use the DIRECT grid (inner quadrature). Outer Monte Carlo over
uncertain reporting \(\pi^\star\) applies only with reporting_if_draws() or
an exogenous at_ifrac distribution; fit_reporting_if_draws() can combine
tau-posterior draws of \(\bar\omega\) with that outer layer.
Options
interactmeta.ifrac.n_tau_samplesOnly when
tau_sampling = "posterior"(orn_tau_samplesis set): default1000Lfor marginal \(\tau\) Monte Carlo;0Luses the native posterior median plug-in.
Examples
yi <- c(0.2, 0.1, 0.3, 0.15)
vi <- c(0.01, 0.04, 0.0225, 0.09)
trial <- c("A", "A", "B", "B")
level <- c("g1", "g2", "g1", "g2")
# Default: all non-reference vs reference contrasts (reference = first
# factor level, or first sorted label for character subgroups).
ifrac(yi = yi, vi = vi, trial = trial, modifier = level)
#> # A tibble: 4 × 7
#> study level yi vi precision IF_g2 reference
#> <chr> <fct> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 A g1 0.2 0.01 100 0.2 g1
#> 2 A g2 0.1 0.04 25 0.2 g1
#> 3 B g1 0.3 0.0225 44.4 0.2 g1
#> 4 B g2 0.15 0.09 11.1 0.2 g1
# Subgroup rows only, wide IF_<subgroup> for every label
ifrac(yi = yi, vi = vi, trial = trial, modifier = level, contrast = NULL)
#> # A tibble: 4 × 6
#> study level yi vi IF_g1 IF_g2
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 A g1 0.2 0.01 0.8 0.2
#> 2 A g2 0.1 0.04 0.8 0.2
#> 3 B g1 0.3 0.0225 0.8 0.2
#> 4 B g2 0.15 0.09 0.8 0.2
# Single contrast (g1 - g2, reference g2)
ifrac(
yi = yi, vi = vi, trial = trial, modifier = level,
contrast = c("g1", "g2")
)
#> # A tibble: 4 × 7
#> study level yi vi precision IF_g1 reference
#> <chr> <fct> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 A g1 0.2 0.01 100 0.8 g2
#> 2 A g2 0.1 0.04 25 0.8 g2
#> 3 B g1 0.3 0.0225 44.4 0.8 g2
#> 4 B g2 0.15 0.09 11.1 0.8 g2
# Specify reference subgroup explicitly
ifrac(yi = yi, vi = vi, trial = trial, modifier = level, reference = "g1")
#> # A tibble: 4 × 7
#> study level yi vi precision IF_g2 reference
#> <chr> <fct> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 A g1 0.2 0.01 100 0.2 g1
#> 2 A g2 0.1 0.04 25 0.2 g1
#> 3 B g1 0.3 0.0225 44.4 0.2 g1
#> 4 B g2 0.15 0.09 11.1 0.2 g1
# Append combined rows (one per trial)
ifrac(
yi = yi, vi = vi, trial = trial, modifier = level,
include_combined = TRUE
)
#> # A tibble: 6 × 7
#> study level yi vi precision IF_g2 reference
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 A g1 0.2 0.01 100 0.2 g1
#> 2 A g2 0.1 0.04 25 0.2 g1
#> 3 B g1 0.3 0.0225 44.4 0.2 g1
#> 4 B g2 0.15 0.09 11.1 0.2 g1
#> 5 A Combined 0.18 0.008 125 0.2 g1
#> 6 B Combined 0.27 0.018 55.6 0.2 g1
# Append interaction rows at the bottom
ifrac(
yi = yi, vi = vi, trial = trial, modifier = level,
include_interaction = TRUE
)
#> # A tibble: 6 × 7
#> study level yi vi precision IF_g2 reference
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 A g1 0.2 0.01 100 0.2 g1
#> 2 A g2 0.1 0.04 25 0.2 g1
#> 3 B g1 0.3 0.0225 44.4 0.2 g1
#> 4 B g2 0.15 0.09 11.1 0.2 g1
#> 5 A g2-g1 -0.1 0.05 125 0.2 g1
#> 6 B g2-g1 -0.15 0.112 55.6 0.2 g1
if (FALSE) { # \dontrun{
library(interactmeta)
e <- escalc(measure = "IRR", yi = edss$yi, vi = edss$vi, data = edss)
d <- ifrac(e, reference = "Lower", include_interaction = TRUE)
fit <- cams(d, reference = "Lower")
forestplot(fit)
plot_contribution(fit)
# Pool across trials (interaction-IF, the default)
ifrac(fit)
ifrac(fit, ifrac = "combined")
} # }