| Title: | Model-Robust Standardization for Longitudinal Cluster-Randomized Trials |
|---|---|
| Description: | Provides estimation and leave-one-cluster-out jackknife standard errors for four longitudinal cluster-randomized trial estimands: horizontal individual average treatment effect (h-iATE), horizontal cluster average treatment effect (h-cATE), vertical individual average treatment effect (v-iATE), and vertical cluster-period average treatment effect (v-cATE), using unadjusted and augmented (model-robust standardization) estimators. The working model may be fit using linear mixed models for continuous outcomes or generalized estimating equations and generalized linear mixed models for binary outcomes. Period inclusion for aggregation is determined automatically: only periods with both treated and control clusters are included in the construction of the marginal means and treatment effect contrasts. See Fang et al. (2025) <doi:10.48550/arXiv.2507.17190>. |
| Authors: | Xi Fang [aut, cre], Fan Li [aut] |
| Maintainer: | Xi Fang <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-06-01 08:18:36 UTC |
| Source: | https://github.com/cran/MRStdLCRT |
Fits unadjusted and augmented (model-robust standardization) estimators for four longitudinal cluster-randomized trial (L-CRT) estimands, with inference based on leave-one-cluster-out (delete-1) jackknife standard errors.
mrstdlcrt_fit( data, formula, cluster_id = "cluster", period = "period", trt = "trt", method = c("gee", "lmer", "glmer"), family = c("gaussian", "binomial"), corstr = "independence", scale = c("RD", "RR", "OR") )mrstdlcrt_fit( data, formula, cluster_id = "cluster", period = "period", trt = "trt", method = c("gee", "lmer", "glmer"), family = c("gaussian", "binomial"), corstr = "independence", scale = c("RD", "RR", "OR") )
data |
A |
formula |
A model formula for the working model. May include interactions and (for
|
cluster_id |
Character string giving the cluster identifier column name. |
period |
Character string giving the period identifier column name. May be numeric, integer, or a factor; ordering is taken from the natural order of the column. |
trt |
Character string giving the binary treatment column name (0/1). |
method |
Working model fitting method: |
family |
Outcome family: |
corstr |
Correlation structure passed to |
scale |
For |
The four supported estimands are:
Horizontal individual average treatment effect (individual-weighted within each period).
Horizontal cluster average treatment effect (cluster-weighted within each period).
Vertical individual average treatment effect (period-weighted; individuals weighted within period).
Vertical cluster-period average treatment effect (period-weighted; cluster-period cells equally weighted within period).
For each estimand, the function returns point estimates under:
an unadjusted estimator based on cluster-period means, and
an augmented estimator that combines model-based counterfactual predictions with a design-based correction term (model-robust standardization).
Data structure. The input data must contain:
(i) a cluster identifier cluster_id, (ii) a period identifier period,
(iii) a binary treatment indicator trt coded as 0/1 (or coercible to 0/1),
and (iv) the outcome appearing on the left-hand side of formula.
Treatment must be constant within cluster-period. Within each
(cluster, period) cell, trt is required to be constant; otherwise the
function errors and prints example problematic cells.
Automatic period inclusion (mixture rule). Marginal means and treatment contrasts are aggregated using only “mixed” periods—periods in which both treated and control clusters are observed. Periods with all clusters in the same arm contribute no information to between-arm contrasts and are excluded automatically.
Working model options.
method = "lmer"Linear mixed model via lme4 for continuous outcomes.
method = "glmer"Logistic mixed model via lme4 for binary outcomes.
method = "gee"Generalized estimating equations via gee. Random-effects
terms in formula (e.g., (1|cluster)) are ignored automatically.
For family = "binomial", treatment effects can be reported on the risk-difference
scale (scale = "RD"), log risk-ratio scale (scale = "RR"), or log odds-ratio
scale (scale = "OR"). For family = "gaussian", effects are mean differences
(and scale is ignored).
Inference. Standard errors are computed using a delete-1 cluster jackknife:
refit the procedure leaving out one cluster at a time, compute the jackknife covariance,
and report per-estimand jackknife SEs. Downstream methods summary
and plot use t-critical values with df = I - 1,
where I is the number of clusters.
An object of class "mrs" with components:
estimatesA tibble of unadjusted and adjusted point estimates for the four estimands.
jk_seA tibble of corresponding delete-1 cluster jackknife standard errors.
jk_cov_unadj, jk_cov_aug
Jackknife covariance matrices for unadjusted and adjusted estimators.
repsInternal components used for fitting and aggregation (including kept periods and mixture table).
metaMetadata: call, method/family/scale, kept periods, cluster/period counts, etc.
The class has print, summary,
and plot methods.
Fang, X. and Li, F. (2025). Model-Robust Standardization for Longitudinal Cluster-Randomized Trials. arXiv:2507.17190.
data(sw_c) # Keep the example fast for R CMD check: use a small subset of clusters cl_keep <- sort(unique(sw_c$cluster))[1:6] dat <- sw_c[sw_c$cluster %in% cl_keep, ] fit <- mrstdlcrt_fit( data = dat, formula = y ~ trt + factor(period) + x1 + x2 + (1 | cluster), cluster_id = "cluster", period = "period", trt = "trt", method = "lmer", family = "gaussian" ) fit summary(fit, show_counts = FALSE, ics = "none") plot(fit)data(sw_c) # Keep the example fast for R CMD check: use a small subset of clusters cl_keep <- sort(unique(sw_c$cluster))[1:6] dat <- sw_c[sw_c$cluster %in% cl_keep, ] fit <- mrstdlcrt_fit( data = dat, formula = y ~ trt + factor(period) + x1 + x2 + (1 | cluster), cluster_id = "cluster", period = "period", trt = "trt", method = "lmer", family = "gaussian" ) fit summary(fit, show_counts = FALSE, ics = "none") plot(fit)
Plots unadjusted vs adjusted estimates with t-based confidence intervals computed from delete-1 cluster jackknife SEs (df = I - 1). Facets by estimand.
## S3 method for class 'mrs' plot(x, level = 0.95, estimand = NULL, point_size = 2.8, ...)## S3 method for class 'mrs' plot(x, level = 0.95, estimand = NULL, point_size = 2.8, ...)
x |
An object of class |
level |
Confidence level. |
estimand |
Optional subset of estimands to plot. |
point_size |
Point size. |
... |
Unused. |
Invisibly returns a ggplot2 object.
data(sw_c) dat <- sw_c[sw_c$cluster %in% sort(unique(sw_c$cluster))[1:6], ] fit <- mrstdlcrt_fit( data = dat, formula = y ~ trt + factor(period) + x1 + x2 + (1 | cluster), cluster_id = "cluster", period = "period", trt = "trt", method = "lmer", family = "gaussian" ) plot(fit)data(sw_c) dat <- sw_c[sw_c$cluster %in% sort(unique(sw_c$cluster))[1:6], ] fit <- mrstdlcrt_fit( data = dat, formula = y ~ trt + factor(period) + x1 + x2 + (1 | cluster), cluster_id = "cluster", period = "period", trt = "trt", method = "lmer", family = "gaussian" ) plot(fit)
Print method for mrs objects
## S3 method for class 'mrs' print(x, ...)## S3 method for class 'mrs' print(x, ...)
x |
An object of class |
... |
Unused. |
x invisibly.
Prints key diagnostics (kept periods / mixture table), and per-estimand point estimates with delete-1 cluster jackknife SEs and t-based confidence intervals (df = I - 1). Optionally prints an ICS linear-contrast F-test.
## S3 method for class 'mrs' summary( object, level = 0.95, estimand = NULL, digits = 6, show_counts = TRUE, ics = "global", ics_method = c("both", "unadjusted", "adjusted"), ics_tol = 1e-10, ... )## S3 method for class 'mrs' summary( object, level = 0.95, estimand = NULL, digits = 6, show_counts = TRUE, ics = "global", ics_method = c("both", "unadjusted", "adjusted"), ics_tol = 1e-10, ... )
object |
An object of class |
level |
Confidence level for Wald-type confidence intervals. |
estimand |
Optional subset of estimands to print. |
digits |
Digits to print. |
show_counts |
If |
ics |
ICS test specification. Use |
ics_method |
Which covariance to use for ICS test: |
ics_tol |
Numerical tolerance for rank / generalized inverse. |
... |
Unused (accepts |
Invisibly returns a list containing printed tables/metadata and (if requested) ICS results.
data(sw_c) dat <- sw_c[sw_c$cluster %in% sort(unique(sw_c$cluster))[1:6], ] fit <- mrstdlcrt_fit( data = dat, formula = y ~ trt + factor(period) + x1 + x2 + (1 | cluster), cluster_id = "cluster", period = "period", trt = "trt", method = "lmer", family = "gaussian" ) summary(fit, show_counts = FALSE, ics = "none")data(sw_c) dat <- sw_c[sw_c$cluster %in% sort(unique(sw_c$cluster))[1:6], ] fit <- mrstdlcrt_fit( data = dat, formula = y ~ trt + factor(period) + x1 + x2 + (1 | cluster), cluster_id = "cluster", period = "period", trt = "trt", method = "lmer", family = "gaussian" ) summary(fit, show_counts = FALSE, ics = "none")
A toy dataset with cluster, period, and individual records for illustrating estimands in stepped wedge CRT with a binary outcome.
data(sw_b)data(sw_b)
A data frame with columns:
Cluster identifier (integer).
Period index (integer).
Individual identifier within cluster-period (integer).
Treatment indicator (0/1).
Auxiliary covariate (0/1).
Auxiliary covariate (numeric).
Outcome (0/1, binary).
data(sw_b) head(sw_b)data(sw_b) head(sw_b)
A toy dataset with cluster, period, and individual records for illustrating estimands in stepped wedge CRT with a continuous outcome.
data(sw_c)data(sw_c)
A data frame with columns:
Cluster identifier (integer).
Period index (integer).
Individual identifier within cluster-period (integer).
Treatment indicator (0/1).
Auxiliary covariate (0/1).
Auxiliary covariate (numeric).
Outcome (numeric, continuous).
data(sw_c) head(sw_c)data(sw_c) head(sw_c)
A small simulated 2×2 crossover trial dataset with a binary outcome.
xo_bxo_b
A tibble/data.frame with one row per subject and the following columns:
Integer cluster ID (hospital)
Integer period (1 or 2)
Integer subject index within cluster-period
Treatment indicator (0 = control, 1 = treatment)
Continuous covariates
Binary covariate (0/1)
Dummy variables for a 3-level categorical covariate (level 1 is reference)
Observed binary outcome (0/1)
data(xo_b) str(xo_b) head(xo_b)data(xo_b) str(xo_b) head(xo_b)
A small simulated 2×2 crossover trial dataset with a continuous outcome.
xo_cxo_c
A tibble/data.frame with one row per subject and the following columns:
Integer cluster ID (hospital)
Integer period (1 or 2)
Integer subject index within cluster-period
Treatment indicator (0 = control, 1 = treatment)
Continuous covariates
Binary covariate (0/1)
Dummy variables for a 3-level categorical covariate (level 1 is reference)
Observed continuous outcome
data(xo_c) str(xo_c) head(xo_c)data(xo_c) str(xo_c) head(xo_c)