| Title: | Stacked Linear Mixed-Effects Framework for Multivariate Meta-Analysis |
|---|---|
| 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. |
| Authors: | Nusrat Rabbee [aut, cre] |
| Maintainer: | Nusrat Rabbee <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-12-04 20:08:25 UTC |
| Source: | https://github.com/cran/slimeta |
The slimeta package implements the Stacked Linear Mixed-Effects (SLIM) framework for multivariate meta-analysis with correlated endpoints.
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
slim_transform: Transform y and SE (log, logit, sqrt)
slim_backtransform: Back-transform to original scale
apply_display_scale: Apply multiplier for display
The SLIM model is:
where and is the between-study
covariance matrix with elements .
Key quantities:
(translation coefficient)
Maintainer: Nusrat Rabbee [email protected]
Rabbee N. (2026). Stacked Linear Mixed-Effects Models for Evidence Synthesis with Multiple Correlated Endpoints.
Useful links:
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.
aaaaaa
A data frame with 148 rows and 9 variables:
Initial AAA diameter category (mm): 30, 35, 40, 45, or 50
Study/center name
Endpoint type: "GrowthRate" or "RuptureRisk"
Analysis value: GrowthRate in mm/yr, RuptureRisk on log scale
Standard error of y
Original mean (GrowthRate in mm/yr, RuptureRisk as proportion)
RuptureRisk per 1000 patient-years (NA for GrowthRate)
Log-transformed mean for RuptureRisk (NA for GrowthRate)
Standard error on log scale for RuptureRisk (NA for GrowthRate)
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.
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$pooleddata(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
Applies a multiplier or transformation for display purposes only. Useful for converting units (e.g., per 1000 patient-years).
apply_display_scale(est, ci.lb, ci.ub, spec)apply_display_scale(est, ci.lb, ci.ub, spec)
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" |
Data frame with scaled values (same structure as input)
# Convert to per 1000 patient-years apply_display_scale(est = 0.005, ci.lb = 0.003, ci.ub = 0.008, spec = 1000)# Convert to per 1000 patient-years apply_display_scale(est = 0.005, ci.lb = 0.003, ci.ub = 0.008, spec = 1000)
Reverses transformations applied by slim_transform.
slim_backtransform(est, ci.lb, ci.ub, type = "identity")slim_backtransform(est, ci.lb, ci.ub, type = "identity")
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" |
Data frame with columns:
est |
Back-transformed estimates |
ci.lb |
Back-transformed CI lower bounds |
ci.ub |
Back-transformed CI upper bounds |
# Back-transform log-scale estimates slim_backtransform(est = -0.5, ci.lb = -1.0, ci.ub = 0.0, type = "log")# Back-transform log-scale estimates slim_backtransform(est = -0.5, ci.lb = -1.0, ci.ub = 0.0, type = "log")
Fits separate SLIM models per stratum, extracts stratum-specific eta with CI, and performs Cochran's Q test for heterogeneity.
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") )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") )
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 |
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.
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).
slim_eta_dunnett for a more powerful test
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 etadata(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
A more powerful alternative to Cochran's Q that accounts for correlation between stratum-specific eta estimates due to shared centers.
slim_eta_dunnett( result, eta_by_stratum, data, strata_col, trial_col = "trial", endpoint_col = "endpoint" )slim_eta_dunnett( result, eta_by_stratum, data, strata_col, trial_col = "trial", endpoint_col = "endpoint" )
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 |
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.
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).
Dunnett CW (1955). A Multiple Comparison Procedure for Comparing Several Treatments with a Control. Journal of the American Statistical Association.
slim_eta_by_stratum for Cochran's Q test
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 globaldata(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
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.
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 )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 )
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 |
The SLIM model is:
where:
= population mean for endpoint j
= study-level random effect
= sampling error (known)
The random effects follow a bivariate normal:
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).
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).
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.
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 estimatesdata(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
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.
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 )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 )
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 |
A list of ggplot objects (one per endpoint, or grid if stratified)
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" )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" )
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.
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" )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" )
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") |
For a normal prior N(prior_mean, prior_sd^2) and observed effect y with standard error se, the posterior is:
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).
Data frame with additional columns for adjusted estimates:
{y_col}{suffix} (posterior mean) and {se_col}{suffix}
(posterior SD).
# 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")]# 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")]
Creates a diagnostic plot comparing original vs prior-adjusted estimates.
slim_prior_plot( data, y_col, se_col, suffix = "_adj", title = "Prior Adjustment: Original vs Adjusted" )slim_prior_plot( data, y_col, se_col, suffix = "_adj", title = "Prior Adjustment: Original vs Adjusted" )
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 |
A ggplot object
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")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")
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.
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 )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 )
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. |
The sample size formula for a two-sample comparison is:
where var_factor = 1/p1 + 1/p2 for arm proportions p1, p2.
For stratified designs, the weighted treatment effect is:
The translation via eta provides the implied effect on the secondary endpoint:
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).
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_totaldata(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
Applies variance-stabilizing transformations to endpoint values and their standard errors using the delta method.
slim_transform(y, se, type = "identity")slim_transform(y, se, type = "identity")
y |
Numeric vector of endpoint values |
se |
Numeric vector of standard errors |
type |
Transformation type: "log", "logit", "sqrt", or "identity" |
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
List with components:
y |
Transformed endpoint values |
se |
Transformed standard errors (via delta method) |
# 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")# 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")
Creates a side-by-side panel plot comparing model estimates to observed means across levels of a covariate (e.g., diameter strata).
slim2EP_plot_by_covariate( result, data, endpoints, covariate, title = NULL, output = "both", save_to = NULL, width = 10, height = 5 )slim2EP_plot_by_covariate( result, data, endpoints, covariate, title = NULL, output = "both", save_to = NULL, width = 10, height = 5 )
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 |
A list with components plot (ggplot object) and table
(data frame with observed and model estimates per covariate level).
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$plotdata(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
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.
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 )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 )
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 |
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).
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$translationdata(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