| Title: | Stacked Linear Mixed-Effects Framework for Multivariate Meta-Analysis |
| Version: | 0.1.1 |
| Description: | Implements the Stacked Linear Mixed-Effects (SLIM) framework for multivariate meta-analysis with correlated endpoints, as described in Rabbee (2026) <doi:10.1186/s12874-026-02852-x>. SLIM enables joint modeling of multiple endpoints across studies, estimation of between-study correlation structure, translation of treatment effects between endpoints via the eta coefficient, hypothesis testing for effect heterogeneity across strata (Cochran's Q and Dunnett tests), and sample size calculations for trial design. Built on top of the 'metafor' package. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Depends: | R (≥ 3.5.0) |
| Imports: | metafor, ggplot2, grid, gridExtra, mvtnorm, stats, clubSandwich |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0) |
| VignetteBuilder: | knitr |
| URL: | https://github.com/rabbee001/slimeta |
| BugReports: | https://github.com/rabbee001/slimeta/issues |
| LazyData: | true |
| NeedsCompilation: | no |
| Packaged: | 2026-11-11 22:07:39 UTC; nusrat.rabbee |
| Author: | Nusrat Rabbee [aut, cre] |
| Maintainer: | Nusrat Rabbee <rabbee@berkeley.edu> |
| Repository: | CRAN |
| Date/Publication: | 2026-12-04 15:50:02 UTC |
slimeta: Stacked Linear Mixed-Effects Framework for Multivariate Meta-Analysis
Description
The slimeta package implements the Stacked Linear Mixed-Effects (SLIM) framework for multivariate meta-analysis with correlated endpoints.
Main functions
-
slim_fit: Fit a SLIM model via metafor::rma.mv() -
slim2EP_plot_by_covariate: Panel plot of model vs observed by covariate -
slim2EP_plot_by_study: Scatter plot with E(Y2|Y1) line -
slim_eta_by_stratum: Test eta heterogeneity (Cochran's Q) -
slim_eta_dunnett: Test eta heterogeneity (Dunnett test) -
slim_sample_size: Sample size calculation
Helper functions
-
slim_transform: Transform y and SE (log, logit, sqrt) -
slim_backtransform: Back-transform to original scale -
apply_display_scale: Apply multiplier for display
Mathematical framework
The SLIM model is:
Y_{ij} = \mu_j + u_{ij} + \varepsilon_{ij}
where (u_{i1}, u_{i2})' \sim N(0, G) and G is the between-study
covariance matrix with elements \tau_{11}, \tau_{12}, \tau_{22}.
Key quantities:
-
R^2_{between} = \tau_{12}^2 / (\tau_{11} \times \tau_{22}) -
\eta = \tau_{12} / \tau_{11}(translation coefficient) -
E(Y_2 | Y_1) = \mu_2 + \eta \times (Y_1 - \mu_1)
Author(s)
Maintainer: Nusrat Rabbee rabbee@berkeley.edu
References
Rabbee N. (2026). Stacked Linear Mixed-Effects Models for Evidence Synthesis with Multiple Correlated Endpoints.
See Also
Useful links:
Abdominal Aortic Aneurysm (AAA) Meta-Analysis Data
Description
A dataset containing growth rate and rupture risk estimates from multiple studies of abdominal aortic aneurysm, stratified by initial diameter. This dataset demonstrates SLIM's ability to jointly model correlated endpoints across studies.
Usage
aaa
Format
A data frame with 148 rows and 9 variables:
- Diameter
Initial AAA diameter category (mm): 30, 35, 40, 45, or 50
- Study
Study/center name
- Endpoint
Endpoint type: "GrowthRate" or "RuptureRisk"
- y
Analysis value: GrowthRate in mm/yr, RuptureRisk on log scale
- se
Standard error of y
- Mean
Original mean (GrowthRate in mm/yr, RuptureRisk as proportion)
- Mean1000
RuptureRisk per 1000 patient-years (NA for GrowthRate)
- logMean
Log-transformed mean for RuptureRisk (NA for GrowthRate)
- logSE
Standard error on log scale for RuptureRisk (NA for GrowthRate)
Source
Thompson SG, Brown LC, Sweeting MJ, Bown MJ, Kim LG; Multicentre Aneurysm Screening Study (MASS) Group. Systematic review and meta-analysis of the growth and rupture rates of small abdominal aortic aneurysms: implications for surveillance intervals and their cost-effectiveness. Health Technology Assessment. 2013;17(41):1-118. doi:10.3310/hta17410
Data manually extracted from multiple published AAA surveillance studies as compiled in the systematic review.
Examples
data(aaa)
head(aaa)
# RuptureRisk is stored on the log scale in aaa, but slim_fit() applies the
# log transform itself. Supply the rate and its SE on the original scale.
aaa_fit <- aaa
rup <- aaa_fit$Endpoint == "RuptureRisk"
aaa_fit$y[rup] <- aaa_fit$Mean[rup]
aaa_fit$se[rup] <- aaa_fit$Mean[rup] * aaa_fit$se[rup]
result <- slim_fit(
data = aaa_fit,
formula = ~ 0 + Endpoint:factor(Diameter),
trial_col = "Study",
endpoint_col = "Endpoint",
y_col = "y",
se_col = "se",
transform = list(RuptureRisk = "log"),
display_scale = list(RuptureRisk = 1000)
)
result$eta
result$pooled
Apply display scaling to output
Description
Applies a multiplier or transformation for display purposes only. Useful for converting units (e.g., per 1000 patient-years).
Usage
apply_display_scale(est, ci.lb, ci.ub, spec)
Arguments
est |
Numeric vector of estimates |
ci.lb |
Numeric vector of CI lower bounds |
ci.ub |
Numeric vector of CI upper bounds |
spec |
Scaling specification: numeric multiplier (e.g., 1000) or "log" |
Value
Data frame with scaled values (same structure as input)
Examples
# Convert to per 1000 patient-years
apply_display_scale(est = 0.005, ci.lb = 0.003, ci.ub = 0.008, spec = 1000)
Panel plot of two endpoints by covariate levels
Description
Creates a side-by-side panel plot comparing model estimates to observed means across levels of a covariate (e.g., diameter strata).
Usage
slim2EP_plot_by_covariate(
result,
data,
endpoints,
covariate,
title = NULL,
output = "both",
save_to = NULL,
width = 10,
height = 5
)
Arguments
result |
Output from |
data |
Original data frame |
endpoints |
Character vector of length 2: c("EP1", "EP2"). Order determines panel order. |
covariate |
Column name for x-axis covariate (e.g., "Diameter") |
title |
Plot title |
output |
What to return: "plot", "table", or "both" (default) |
save_to |
File path to save plot (NULL = display only) |
width |
Plot width in inches |
height |
Plot height in inches |
Value
A list with components plot (ggplot object) and table
(data frame with observed and model estimates per covariate level).
Examples
data(aaa)
# RuptureRisk is stored on the log scale in aaa, but slim_fit() applies the
# log transform itself. Supply the rate and its SE on the original scale.
aaa_fit <- aaa
rup <- aaa_fit$Endpoint == "RuptureRisk"
aaa_fit$y[rup] <- aaa_fit$Mean[rup]
aaa_fit$se[rup] <- aaa_fit$Mean[rup] * aaa_fit$se[rup]
result <- slim_fit(
data = aaa_fit,
formula = ~ 0 + Endpoint:factor(Diameter),
trial_col = "Study",
endpoint_col = "Endpoint",
y_col = "y",
se_col = "se",
transform = list(RuptureRisk = "log"),
display_scale = list(RuptureRisk = 1000)
)
out <- slim2EP_plot_by_covariate(
result,
data = aaa_fit,
endpoints = c("GrowthRate", "RuptureRisk"),
covariate = "Diameter",
title = "AAA: Model vs Observed by Diameter"
)
out$plot
Scatter plot of two endpoints by study
Description
Creates a scatter plot of one endpoint vs another, with each point representing a study. Includes the conditional expectation line E(Y2|Y1) = mu2 + eta*(Y1-mu1) with confidence band.
Usage
slim2EP_plot_by_study(
result,
data,
endpoints,
title = NULL,
show_line = TRUE,
show_band = TRUE,
color_by = NULL,
facet_by = NULL,
facet_scales = "free",
eta_by_stratum = NULL,
scale = "original",
y_scale = "linear",
pct_changes = c(-0.1, -0.2, -0.3),
output = "both",
save_to = NULL,
width = 7,
height = 6
)
Arguments
result |
Output from |
data |
Original data frame |
endpoints |
Character vector of length 2: c("X", "Y"). First is X-axis, second is Y-axis. |
title |
Plot title |
show_line |
Show E(Y|X) regression line (default: TRUE) |
show_band |
Show conditional CI band (default: TRUE) |
color_by |
Column name to color points by (optional) |
facet_by |
Column name to facet panels by (optional, e.g., "Diameter") |
facet_scales |
"free" or "fixed" axis scales across facets |
eta_by_stratum |
Output from |
scale |
"original" (back-transformed, default) or "transformed" |
y_scale |
Y-axis scale: "linear" (default) or "log" |
pct_changes |
Percent changes for translation table (default: -10 percent, -20 percent, -30 percent) |
output |
What to return: "plot", "table", or "both" (default) |
save_to |
File path to save plot |
width |
Plot width in inches |
height |
Plot height in inches |
Value
A list with components plot (ggplot object), table
(data frame with observed X, Y and model E(Y|X) per study), translation
(data frame showing X percent change to Y percent change), and eta
(translation coefficient tau_XY/tau_XX).
Examples
data(aaa)
# RuptureRisk is stored on the log scale in aaa, but slim_fit() applies the
# log transform itself. Supply the rate and its SE on the original scale.
aaa_fit <- aaa
rup <- aaa_fit$Endpoint == "RuptureRisk"
aaa_fit$y[rup] <- aaa_fit$Mean[rup]
aaa_fit$se[rup] <- aaa_fit$Mean[rup] * aaa_fit$se[rup]
result <- slim_fit(
data = aaa_fit,
formula = ~ 0 + Endpoint:factor(Diameter),
trial_col = "Study",
endpoint_col = "Endpoint",
y_col = "y",
se_col = "se",
transform = list(RuptureRisk = "log"),
display_scale = list(RuptureRisk = 1000)
)
out <- slim2EP_plot_by_study(
result,
data = aaa_fit,
endpoints = c("GrowthRate", "RuptureRisk"),
title = "AAA: Growth vs Rupture",
facet_by = "Diameter",
facet_scales = "fixed",
y_scale = "log"
)
out$plot
out$translation
Back-transform estimates to original scale
Description
Reverses transformations applied by slim_transform.
Usage
slim_backtransform(est, ci.lb, ci.ub, type = "identity")
Arguments
est |
Numeric vector of estimates |
ci.lb |
Numeric vector of CI lower bounds |
ci.ub |
Numeric vector of CI upper bounds |
type |
Transformation type that was applied: "log", "logit", "sqrt", or "identity" |
Value
Data frame with columns:
est |
Back-transformed estimates |
ci.lb |
Back-transformed CI lower bounds |
ci.ub |
Back-transformed CI upper bounds |
Examples
# Back-transform log-scale estimates
slim_backtransform(est = -0.5, ci.lb = -1.0, ci.ub = 0.0, type = "log")
Test whether eta varies by stratum (Cochran's Q)
Description
Fits separate SLIM models per stratum, extracts stratum-specific eta with CI, and performs Cochran's Q test for heterogeneity.
Usage
slim_eta_by_stratum(
data,
strata_col,
endpoints,
trial_col = "trial",
endpoint_col = "endpoint",
y_col = "y",
se_col = "se",
transform = list(),
display_scale = list(),
struct = c("UN", "CS")
)
Arguments
data |
Data frame in stacked format |
strata_col |
Column name for stratification variable (e.g., "Diameter") |
endpoints |
Character vector of length 2: c("EP1", "EP2") |
trial_col |
Column name for trial/study/center identifier |
endpoint_col |
Column name for endpoint identifier |
y_col |
Column name for effect estimate |
se_col |
Column name for standard error |
transform |
Named list of transformations |
display_scale |
Named list of display scaling |
struct |
Variance structure passed to |
Details
Cochran's Q tests H0: eta is constant across all strata. The test statistic is Q = sum(w_d * (eta_d - eta_pooled)^2), which follows chi-squared(k-1) under H0, where k is the number of strata.
Limitation: Assumes eta estimates are independent. When same centers appear
in multiple strata, this assumption is violated. Use slim_eta_dunnett
for a more powerful test that accounts for this correlation.
Value
A list with eta_table (data frame with stratum, eta, se_eta,
ci_lb, ci_ub), Q_test (list with Q, df, p_value for Cochran's Q),
pooled_eta (inverse-variance weighted pooled eta), and se_pooled
(standard error of pooled eta).
See Also
slim_eta_dunnett for a more powerful test
Examples
data(aaa)
# RuptureRisk is stored on the log scale in aaa, but slim_fit() applies the
# log transform itself. Supply the rate and its SE on the original scale.
aaa_fit <- aaa
rup <- aaa_fit$Endpoint == "RuptureRisk"
aaa_fit$y[rup] <- aaa_fit$Mean[rup]
aaa_fit$se[rup] <- aaa_fit$Mean[rup] * aaa_fit$se[rup]
eta_test <- slim_eta_by_stratum(
data = aaa_fit,
strata_col = "Diameter",
endpoints = c("GrowthRate", "RuptureRisk"),
trial_col = "Study",
endpoint_col = "Endpoint",
y_col = "y",
se_col = "se",
transform = list(RuptureRisk = "log")
)
eta_test$eta_table # stratum-specific eta
eta_test$Q_test # Cochran's Q test of a common eta
Dunnett test for eta heterogeneity across strata
Description
A more powerful alternative to Cochran's Q that accounts for correlation between stratum-specific eta estimates due to shared centers.
Usage
slim_eta_dunnett(
result,
eta_by_stratum,
data,
strata_col,
trial_col = "trial",
endpoint_col = "endpoint"
)
Arguments
result |
Output from |
eta_by_stratum |
Output from |
data |
Original data frame |
strata_col |
Column name for stratification variable |
trial_col |
Column name for trial/study/center identifier |
endpoint_col |
Column name for endpoint identifier |
Details
The Dunnett test computes contrasts delta_d = eta_d - eta_global and tests whether any delta significantly differs from zero using the multivariate t distribution with the correlation structure induced by shared centers.
QC requirement: n_complete > k (number of complete centers must exceed number of strata). A warning is issued if n_complete < 2k due to low power.
The variance of each contrast is: Var(delta_d) = Var(eta_d) + Var(eta_global) - 2w_dVar(eta_d)
where w_d is the inverse-variance weight of stratum d in the pooled estimate.
Value
A list with test_stat (Dunnett max-abs-t), p_value (joint p-value),
df (degrees of freedom = n_centers - 3), n_complete (complete centers),
n_centers, n_strata, contrasts (data frame with eta_d - eta_global,
SE, t-stat, adjusted p-value), corr_matrix, qc_pass (logical), and
qc_message (status message).
References
Dunnett CW (1955). A Multiple Comparison Procedure for Comparing Several Treatments with a Control. Journal of the American Statistical Association.
See Also
slim_eta_by_stratum for Cochran's Q test
Examples
data(aaa)
# RuptureRisk is stored on the log scale in aaa, but slim_fit() applies the
# log transform itself. Supply the rate and its SE on the original scale.
aaa_fit <- aaa
rup <- aaa_fit$Endpoint == "RuptureRisk"
aaa_fit$y[rup] <- aaa_fit$Mean[rup]
aaa_fit$se[rup] <- aaa_fit$Mean[rup] * aaa_fit$se[rup]
result <- slim_fit(
data = aaa_fit,
formula = ~ 0 + Endpoint:factor(Diameter),
trial_col = "Study",
endpoint_col = "Endpoint",
y_col = "y",
se_col = "se",
transform = list(RuptureRisk = "log"),
display_scale = list(RuptureRisk = 1000)
)
eta_test <- slim_eta_by_stratum(
data = aaa_fit,
strata_col = "Diameter",
endpoints = c("GrowthRate", "RuptureRisk"),
trial_col = "Study",
endpoint_col = "Endpoint",
y_col = "y",
se_col = "se",
transform = list(RuptureRisk = "log")
)
dunnett <- slim_eta_dunnett(
result = result,
eta_by_stratum = eta_test,
data = aaa_fit,
strata_col = "Diameter",
trial_col = "Study",
endpoint_col = "Endpoint"
)
dunnett$p_value # p > 0.05 -> common eta appropriate
dunnett$contrasts # see which strata differ from global
Fit a SLIM (Stacked Linear Mixed-Effects) model
Description
Fits a multivariate meta-analysis model for correlated endpoints using
metafor::rma.mv(). The SLIM framework enables joint modeling of
multiple endpoints across studies with estimation of the between-study
covariance structure.
Usage
slim_fit(
data,
formula,
random = NULL,
trial_col = "trial",
endpoint_col = "endpoint",
y_col = "y",
se_col = "se",
transform = list(),
display_scale = list(),
method = "REML",
struct = c("UN", "CS"),
satterthwaite = TRUE
)
Arguments
data |
Data frame in stacked (long) format with one row per study-endpoint |
formula |
Formula for fixed effects (passed to mods argument of rma.mv).
Typically |
random |
Formula for random effects. Default: |
trial_col |
Column name for trial/study/center identifier |
endpoint_col |
Column name for endpoint identifier |
y_col |
Column name for effect estimate (mean, proportion, etc.) |
se_col |
Column name for standard error |
transform |
Named list of transformations by endpoint.
E.g., |
display_scale |
Named list of display scaling by endpoint.
E.g., |
method |
Estimation method (default: "REML") |
struct |
Variance structure of G, passed to |
satterthwaite |
If TRUE (default), the CIs for the pooled means use
cluster-robust (CR2) variance estimation with Satterthwaite degrees of
freedom from |
Details
The SLIM model is:
Y_{ij} = \mu_j + u_{ij} + \varepsilon_{ij}
where:
-
\mu_j= population mean for endpoint j -
u_{ij}= study-level random effect -
\varepsilon_{ij} \sim N(0, V_{ij})= sampling error (known)
The random effects follow a bivariate normal:
(u_{i1}, u_{i2})' \sim N(0, G)
where G is the between-study covariance matrix with elements tau11, tau12, tau22.
The translation coefficient eta = tau12/tau11 enables prediction of one endpoint from another via E(Y2|Y1) = mu2 + eta * (Y1 - mu1).
Value
A list with class "slim_fit" containing: fit (rma.mv model object),
pooled (data frame of pooled estimates with CIs), G (between-study
covariance matrix), R2_between (between-study R-squared), eta
(translation coefficient), se_eta (standard error of eta), ci_eta
(95 percent CI for eta: delta method when struct = "UN", profile CI
for rho when struct = "CS"), ci_rho (95 percent profile CI for
the between-study correlation rho), and metadata columns (transform, display_scale,
endpoint_col, trial_col, y_col, se_col).
References
Rabbee N. (2026). Stacked Linear Mixed-Effects Models for Evidence Synthesis with Multiple Correlated Endpoints.
Viechtbauer W. (2010). Conducting meta-analyses in R with the metafor package. Journal of Statistical Software, 36(3), 1-48.
Examples
data(aaa)
# RuptureRisk is stored on the log scale in aaa, but slim_fit() applies the
# log transform itself. Supply the rate and its SE on the original scale.
aaa_fit <- aaa
rup <- aaa_fit$Endpoint == "RuptureRisk"
aaa_fit$y[rup] <- aaa_fit$Mean[rup]
aaa_fit$se[rup] <- aaa_fit$Mean[rup] * aaa_fit$se[rup]
result <- slim_fit(
data = aaa_fit,
formula = ~ 0 + Endpoint:factor(Diameter),
trial_col = "Study",
endpoint_col = "Endpoint",
y_col = "y",
se_col = "se",
transform = list(RuptureRisk = "log"),
display_scale = list(RuptureRisk = 1000)
)
result$eta # translation coefficient
result$ci_eta # 95% CI for eta
result$R2_between # between-study R-squared
result$pooled # pooled estimates
Forest plot of endpoints by study
Description
Creates a forest plot showing effect estimates with confidence intervals for each study, faceted by endpoint. Studies are ordered by the overall mean of the first endpoint for consistent comparison across panels.
Usage
slim_forest(
data,
trial_col,
endpoint_col,
y_col,
se_col,
endpoints = NULL,
strata_col = NULL,
transform = list(),
title = NULL,
save_to = NULL,
width = 10,
height = 8
)
Arguments
data |
Data frame in stacked format |
trial_col |
Column name for trial/study identifier |
endpoint_col |
Column name for endpoint identifier |
y_col |
Column name for effect estimate |
se_col |
Column name for standard error |
endpoints |
Character vector of endpoints to include (default: all) |
strata_col |
Column name for stratification (optional). If NULL, aggregates across strata using inverse-variance weighting. |
transform |
Named list of transformations to apply for display.
E.g., |
title |
Plot title |
save_to |
File path to save plot |
width |
Plot width in inches |
height |
Plot height in inches |
Value
A list of ggplot objects (one per endpoint, or grid if stratified)
Examples
data(aaa)
# RuptureRisk is stored on the log scale in aaa, but slim_fit() applies the
# log transform itself. Supply the rate and its SE on the original scale.
aaa_fit <- aaa
rup <- aaa_fit$Endpoint == "RuptureRisk"
aaa_fit$y[rup] <- aaa_fit$Mean[rup]
aaa_fit$se[rup] <- aaa_fit$Mean[rup] * aaa_fit$se[rup]
# Overall (aggregated across strata)
slim_forest(
data = aaa_fit,
trial_col = "Study",
endpoint_col = "Endpoint",
y_col = "y",
se_col = "se",
endpoints = c("GrowthRate", "RuptureRisk")
)
# By stratum
slim_forest(
data = aaa_fit,
trial_col = "Study",
endpoint_col = "Endpoint",
y_col = "y",
se_col = "se",
strata_col = "Diameter"
)
Apply Bayesian prior adjustment to treatment effects
Description
Pre-processes treatment effects (e.g., rate ratios near zero) by applying Bayesian shrinkage with a prior distribution. This helps stabilize extreme estimates before stacking in the SLIM model.
Usage
slim_prior_adjust(
data,
y_col,
se_col,
prior_type = c("normal", "flat", "halfnormal"),
prior_mean = 0,
prior_sd = NULL,
scale = c("log", "original"),
min_value = 1e-06,
suffix = "_adj"
)
Arguments
data |
Data frame containing treatment effects |
y_col |
Column name for treatment effect estimates |
se_col |
Column name for standard errors |
prior_type |
Type of prior: "normal" (default), "flat", or "halfnormal" |
prior_mean |
Prior mean (default: 0, i.e., no effect) |
prior_sd |
Prior standard deviation. If NULL, estimated empirically from the data using the median SE. |
scale |
Scale of the treatment effects: "log" (default) or "original". If "original" and values are rate/risk ratios, they will be log-transformed before applying the prior, then back-transformed. |
min_value |
Minimum allowed value before transformation (default: 1e-6). Values below this are set to min_value to avoid log(0). |
suffix |
Suffix for new columns (default: "_adj") |
Details
For a normal prior N(prior_mean, prior_sd^2) and observed effect y with standard error se, the posterior is:
posterior\_mean = \frac{y/se^2 + prior\_mean/prior\_sd^2}{1/se^2 + 1/prior\_sd^2}
posterior\_var = \frac{1}{1/se^2 + 1/prior\_sd^2}
This shrinks extreme estimates toward the prior mean, with shrinkage proportional to uncertainty (larger SE = more shrinkage).
A flat prior (prior_type = "flat") returns the original estimates unchanged, which is useful as a baseline comparison.
The half-normal prior (prior_type = "halfnormal") uses |N(0, prior_sd^2)|, appropriate when effects are expected to be non-negative (e.g., hazard ratios > 1).
Value
Data frame with additional columns for adjusted estimates:
{y_col}{suffix} (posterior mean) and {se_col}{suffix}
(posterior SD).
Examples
# Shrink extreme or imprecise log rate ratios toward the prior mean (0)
d <- data.frame(
study = paste0("S", 1:8),
log_RR = c(-1.2, -0.4, -0.1, 0.05, 0.3, -0.7, -2.0, 0.6),
SE_log_RR = c(0.50, 0.30, 0.20, 0.90, 0.25, 0.40, 0.80, 0.35)
)
d_adj <- slim_prior_adjust(
data = d,
y_col = "log_RR",
se_col = "SE_log_RR",
prior_sd = 1.0
)
# Adjusted columns are added with the suffix "_adj"
d_adj[, c("study", "log_RR", "log_RR_adj", "SE_log_RR", "SE_log_RR_adj")]
Visualize prior adjustment effect
Description
Creates a diagnostic plot comparing original vs prior-adjusted estimates.
Usage
slim_prior_plot(
data,
y_col,
se_col,
suffix = "_adj",
title = "Prior Adjustment: Original vs Adjusted"
)
Arguments
data |
Data frame output from |
y_col |
Original y column name |
se_col |
Original SE column name |
suffix |
Suffix used in slim_prior_adjust (default: "_adj") |
title |
Plot title |
Value
A ggplot object
Examples
d <- data.frame(
study = paste0("S", 1:8),
log_RR = c(-1.2, -0.4, -0.1, 0.05, 0.3, -0.7, -2.0, 0.6),
SE_log_RR = c(0.50, 0.30, 0.20, 0.90, 0.25, 0.40, 0.80, 0.35)
)
d_adj <- slim_prior_adjust(d, y_col = "log_RR", se_col = "SE_log_RR", prior_sd = 1.0)
slim_prior_plot(d_adj, y_col = "log_RR", se_col = "SE_log_RR")
Calculate sample size for a trial based on SLIM estimates
Description
Uses pooled estimates from slim_fit to calculate required
sample size for a trial. Supports stratified designs with enrollment
weights and multi-arm trials with unequal allocation.
Usage
slim_sample_size(
result,
endpoint,
effect_size,
sd = NULL,
strata_col = NULL,
weights = NULL,
adjustments = list(),
power = 0.9,
alpha = 0.05,
n_arms = 2,
arm_props = NULL
)
Arguments
result |
Output from |
endpoint |
Primary endpoint to power on |
effect_size |
Treatment effect: numeric (absolute delta_mu) or string like "-20 percent" (relative) |
sd |
Standard deviation of the endpoint. If NULL, estimated from G matrix. |
strata_col |
Column name for stratification (NULL = unstratified) |
weights |
Enrollment weights by stratum (NULL = equal weights). Must sum to 1. |
adjustments |
Named list of adjustments to baseline, e.g., list(statin = -0.63) |
power |
Target power (default: 0.90) |
alpha |
Significance level (default: 0.05, two-sided) |
n_arms |
Number of arms (default: 2) |
arm_props |
Proportion of patients in each arm (default: equal). Must sum to 1. |
Details
The sample size formula for a two-sample comparison is:
N = var\_factor \times (z_\alpha + z_\beta)^2 \times SD^2 / \Delta\mu^2
where var_factor = 1/p1 + 1/p2 for arm proportions p1, p2.
For stratified designs, the weighted treatment effect is:
\Delta\mu_{weighted} = \sum_d w_d \times \Delta\mu_d
The translation via eta provides the implied effect on the secondary endpoint:
\Delta\mu_2 = \eta \times \Delta\mu_1
Value
A list containing: n_per_arm (required N per arm), n_total
(total sample size), n_arms, arm_props, effect_size_input,
effect_size_weighted (weighted delta_mu), sd_pooled, mu_baseline
(if unstratified), power, alpha, strata_table (if stratified),
adjustments, and translation (implied effect on other endpoint via eta).
Examples
data(aaa)
# RuptureRisk is stored on the log scale in aaa, but slim_fit() applies the
# log transform itself. Supply the rate and its SE on the original scale.
aaa_fit <- aaa
rup <- aaa_fit$Endpoint == "RuptureRisk"
aaa_fit$y[rup] <- aaa_fit$Mean[rup]
aaa_fit$se[rup] <- aaa_fit$Mean[rup] * aaa_fit$se[rup]
result <- slim_fit(
data = aaa_fit,
formula = ~ 0 + Endpoint:factor(Diameter),
trial_col = "Study",
endpoint_col = "Endpoint",
y_col = "y",
se_col = "se",
transform = list(RuptureRisk = "log"),
display_scale = list(RuptureRisk = 1000)
)
# 2-arm, 1:1 allocation
ss <- slim_sample_size(
result = result,
endpoint = "GrowthRate",
effect_size = -0.67, # absolute
sd = 3.5,
strata_col = "Diameter",
weights = c(0.05, 0.45, 0.45, 0.03, 0.02),
adjustments = list(statin = -0.63),
power = 0.90,
alpha = 0.05
)
ss$n_total # total required
ss$translation # implied effect on other endpoint
# 2-arm, 2:1 allocation (treatment:control)
ss2 <- slim_sample_size(
result = result,
endpoint = "GrowthRate",
effect_size = -0.67,
sd = 3.5,
strata_col = "Diameter",
weights = c(0.05, 0.45, 0.45, 0.03, 0.02),
arm_props = c(1/3, 2/3) # control, treatment
)
ss2$n_total
Transform endpoint values for model fitting
Description
Applies variance-stabilizing transformations to endpoint values and their standard errors using the delta method.
Usage
slim_transform(y, se, type = "identity")
Arguments
y |
Numeric vector of endpoint values |
se |
Numeric vector of standard errors |
type |
Transformation type: "log", "logit", "sqrt", or "identity" |
Details
The delta method is used to transform standard errors:
log: SE_new = SE / y
logit: SE_new = SE / (y * (1 - y))
sqrt: SE_new = SE / (2 * sqrt(y))
identity: no transformation
Value
List with components:
y |
Transformed endpoint values |
se |
Transformed standard errors (via delta method) |
Examples
# Log-transform rupture rates
y <- c(0.5, 1.2, 0.8)
se <- c(0.1, 0.2, 0.15)
slim_transform(y, se, type = "log")