Semiparametric estimation of mediation and spillover effects in cluster-randomized trials

2025-11-03

Introduction

This vignette demonstrates the use of the R package mediateCRT to assess mediation effects in cluster-randomized trials based on the semiparametric methods that developed in Cheng and Li (2024). The mediateCRT package is available at https://github.com/chaochengstat/mediateCRT and can be installed as follows

devtools::install_github("chaochengstat/mediateCRT")

Estimation

We focus on estimating three mediation effects, the natural indirect effect (NIE), natural direct effect (NDE), and spillover mediation effect (SME), corresponding to both cluster-level and individual-level total effects. For all \(\xi \in \{\text{NIE}_C,\text{NIE}_I,\text{NDE}_C,\text{NDE}_I,\text{SME}_C,\text{SME}_I\}\), this package can implement the following 9 estimators, and their definitions are given in Cheng and Li (2024): \(\hat \xi^{\text{mf-par}}\), \(\hat \xi^{\text{eif$_1$-par-ns}}\), \(\hat \xi^{\text{eif$_1$-par-s}}\), \(\hat \xi^{\text{eif$_1$-ml-ns}}\), \(\hat \xi^{\text{eif$_1$-ml-s}}\), \(\hat \xi^{\text{eif$_2$-par-ns}}\), \(\hat \xi^{\text{eif$_2$-par-s}}\), \(\hat \xi^{\text{eif$_2$-ml-ns}}\), and \(\hat \xi^{\text{eif$_2$-ml-s}}\).

Basic Syntax

The data-fitting functions are mediateCRT_est1 and mediateCRT_est2. Here, mediateCRT_est1 implements the first five estimators \(\hat \xi^{\text{mf-par}}\), \(\hat \xi^{\text{eif$_1$-par-ns}}\), \(\hat \xi^{\text{eif$_1$-par-s}}\), \(\hat \xi^{\text{eif$_1$-ml-ns}}\), and \(\hat \xi^{\text{eif$_1$-ml-s}}\). mediateCRT_est2 implements the last four estimators \(\hat \xi^{\text{eif$_2$-par-ns}}\), \(\hat \xi^{\text{eif$_2$-par-s}}\), \(\hat \xi^{\text{eif$_2$-ml-ns}}\), and \(\hat \xi^{\text{eif$_2$-ml-s}}\).

To implement mediateCRT_est1, one can run

mediateCRT_est1(data,id_name,N_name,A_name,M_name,Y_name,X_names,V_names,is_stab,B)

We require input the following arguments:

The output of mediateCRT_est1 includes the point estimates and 95% confidence intervals of \(\text{NIE}_C\), \(\text{NIE}_I\), \(\text{NDE}_C\), \(\text{NDE}_I\), \(\text{SME}_C\), and \(\text{SME}_I\). If we set is_stab=0, we obtain \(\hat \xi^{\text{mf-par}}\), \(\hat \xi^{\text{eif$_1$-par-ns}}\), and \(\hat \xi^{\text{eif$_1$-ml-ns}}\). If we set is_stab=1, we obtain \(\hat \xi^{\text{mf-par}}\), \(\hat \xi^{\text{eif$_1$-par-s}}\), and \(\hat \xi^{\text{eif$_1$-ml-s}}\).

The arguments and outputs in mediateCRT_est2 are exactly same tomediateCRT_est1. If we set is_stab=0, we obtain \(\hat \xi^{\text{eif$_2$-par-ns}}\) and \(\hat \xi^{\text{eif$_2$-ml-ns}}\). If we set is_stab=1, we obtain \(\hat \xi^{\text{eif$_2$-par-s}}\) and \(\hat \xi^{\text{eif$_2$-ml-s}}\).

An Illustrative Example

Please library the mrPStrata package if needed.

library("mediateCRT")

Data illustration

In this example, we shall use a simulated dataset with \(K=100\) clusters.

attach(sim_data)
head(sim_data)
#>   id  N A         C         X          M        Y
#> 1  1 30 1 0.8222691 1.0564513 0.41623910 3.135382
#> 2  1 30 1 0.8222691 2.1139818 0.82960426 5.874052
#> 3  1 30 1 0.8222691 0.8341593 3.90702928 8.342324
#> 4  1 30 1 0.8222691 2.3336988 0.07777581 5.005934
#> 5  1 30 1 0.8222691 0.7886858 3.73164428 8.115314
#> 6  1 30 1 0.8222691 1.7589154 5.00656729 9.460900

In the sim_data dataset, we include one individual-level covariate X, one cluster-level covariate C, the treatment A, the mediator M, the outcome Y, cluster id id, and cluster size N.

Implement the multiply robust estimators

Below we obtain the semiparametric estimators of the mediation effects based on mediateCRT_est1. For illustrative purposes, we set B=50 for 50 bootstrap replications.

res = mediateCRT_est1(data = sim_data,
                      id_name = "id",
                      N_name = "N",
                      A_name = "A",
                      M_name = "M",
                      Y_name = "Y",
                      X_names = "X",
                      V_names = "C",
                      is_stab = 0,
                      B = 50)

It outputs the following results

print(res)
#> $`Mediation functional Estimator`
#>              point  CI_lower  CI_upper
#> NIE_C_mf 0.8132793 0.3345614 1.2632480
#> NIE_I_mf 0.7852498 0.3730422 1.1809503
#> NDE_C_mf 1.3808324 1.2512662 1.5155552
#> NDE_I_mf 1.4133826 1.2691611 1.5583964
#> SME_C_mf 0.2400447 0.1378521 0.4595662
#> SME_I_mf 0.2404628 0.1436093 0.4117213
#> 
#> $`Doubly Robust Estimator`
#>                    point  CI_lower  CI_upper
#> NIE_C_eif1_par 0.7020979 0.3844586 1.0929240
#> NIE_I_eif1_par 0.6949289 0.3731280 1.1371124
#> NDE_C_eif1_par 1.4817074 1.2533821 1.5779282
#> NDE_I_eif1_par 1.5349045 1.2709128 1.6102049
#> SME_C_eif1_par 0.2481708 0.1214378 0.3938986
#> SME_I_eif1_par 0.2594838 0.1247150 0.4215750
#> 
#> $`Machine Learning Estimator`
#>                   point   CI_lower  CI_upper
#> NIE_C_eif1_ml 0.7194021 0.19014725 1.2486569
#> NIE_I_eif1_ml 0.7274968 0.21612863 1.2388649
#> NDE_C_eif1_ml 1.3999716 1.22754758 1.5723956
#> NDE_eif1_ml   1.4412846 1.26138734 1.6211820
#> SME_C_eif1_ml 0.2267254 0.01448015 0.4389706
#> SME_I_eif1_ml 0.2506828 0.04525479 0.4561108

Similarly, one can implement mediateCRT_est2 to explore the estimation of mediation effects under the reparameterized EIFs.