Learn R Programming

MRStdLCRT (version 0.1.1)

mrstdlcrt_fit: Model-robust standardization for longitudinal cluster-randomized trials

Description

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.

Usage

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")
)

Value

An object of class "mrs" with components:

estimates

A tibble of unadjusted and adjusted point estimates for the four estimands.

jk_se

A tibble of corresponding delete-1 cluster jackknife standard errors.

jk_cov_unadj, jk_cov_aug

Jackknife covariance matrices for unadjusted and adjusted estimators.

reps

Internal components used for fitting and aggregation (including kept periods and mixture table).

meta

Metadata: call, method/family/scale, kept periods, cluster/period counts, etc.

The class has print, summary, and plot methods.

Arguments

data

A data.frame containing the outcome, trt, period, cluster_id, and any covariates appearing in formula.

formula

A model formula for the working model. May include interactions and (for "lmer"/"glmer") random effects terms. For "gee", random effects terms are removed prior to fitting.

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: "gee", "lmer", or "glmer".

family

Outcome family: "gaussian" for continuous outcomes or "binomial" for binary outcomes.

corstr

Correlation structure passed to gee when method = "gee" (e.g., "independence", "exchangeable", "ar1").

scale

For family = "binomial" only: "RD" (risk difference), "RR" (log risk ratio), or "OR" (log odds ratio).

Details

The four supported estimands are:

h-iATE

Horizontal individual average treatment effect (individual-weighted within each period).

h-cATE

Horizontal cluster average treatment effect (cluster-weighted within each period).

v-iATE

Vertical individual average treatment effect (period-weighted; individuals weighted within period).

v-cATE

Vertical cluster-period average treatment effect (period-weighted; cluster-period cells equally weighted within period).

For each estimand, the function returns point estimates under:

  1. an unadjusted estimator based on cluster-period means, and

  2. 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.

References

Fang, X. and Li, F. (2025). Model-Robust Standardization for Longitudinal Cluster-Randomized Trials. arXiv:2507.17190.

Examples

Run this code
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)

Run the code above in your browser using DataLab