| Type: | Package |
| Title: | Testing Equality of Natural Mediation Effects and Their Randomized Interventional Analogues |
| Version: | 0.2.1 |
| Maintainer: | Ang Yu <ang_yu@outlook.com> |
| Description: | Implements the empirical test introduced by Yu, Ge, and Elwert (2026) for detecting when randomized interventional analogues should not be interpreted as natural mediation effects. The package estimates natural effects, their randomized interventional analogues, and TE - TE^R, the difference between the total effect and its randomized interventional analogue. Rejecting TE - TE^R = 0 falsifies the composite null that the natural indirect and direct effects equal their randomized interventional analogues. The procedure remains valid in settings where the natural effects themselves are not identified, and |TE - TE^R| provides a lower bound on the total divergence between the natural and randomized interventional decompositions. |
| License: | GPL (≥ 3) |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.2.0) |
| URL: | https://github.com/ang-yu/ria.test |
| BugReports: | https://github.com/ang-yu/ria.test/issues |
| Imports: | checkmate, Matrix, origami, torch, Rsymphony, purrr, cli, S7, data.table, coro, generics, mlr3superlearner, progressr, ife (≥ 0.2.1) |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.0.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-07-12 14:31:31 UTC; Ang |
| Author: | Ang Yu [aut, cre, cph] (Author and copyright holder of
ria.test-specific extensions),
Nicholas Williams |
| Repository: | CRAN |
| Date/Publication: | 2026-07-21 10:50:07 UTC |
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- generics
Estimate randomized interventional analogues and their falsification test
Description
Estimate the total effect, its randomized interventional analogue (RIA),
their difference, and the randomized interventional indirect and direct effects.
TE - TE^R is the test statistic for the composite null
NIE = NIE^R and NDE = NDE^R.
Usage
ria.test(
data,
trt,
outcome,
mediators,
pre,
post,
obs = NULL,
id = NULL,
d0 = NULL,
d1 = NULL,
weights = rep(1, nrow(data)),
learners = "glm",
nn_module = sequential_module(),
control = ria.test.control()
)
Arguments
data |
[ |
trt |
[ |
outcome |
[ |
mediators |
[ |
pre |
[ |
post |
[ |
obs |
[ |
id |
[ |
d0 |
[ |
d1 |
[ |
weights |
[ |
learners |
[ |
nn_module |
[ |
control |
[ |
Value
A ria.test object containing TE, TE^R,
TE - TE^R, NIE^R, and NDE^R, along with the matched call.
Examples
if (torch::torch_is_installed()) {
set.seed(123)
n <- 200
w <- rnorm(n)
a <- rbinom(n, 1, plogis(w))
l <- rnorm(n, a + w)
m <- rnorm(n, a + l + w)
y <- rnorm(n, a + l + m + w)
dat <- data.frame(w, a, l, m, y)
res <- ria.test(
data = dat,
trt = "a",
outcome = "y",
mediators = "m",
pre = "w",
post = "l",
d0 = \(data, trt) rep(0, nrow(data)),
d1 = \(data, trt) rep(1, nrow(data)),
control = ria.test.control(
crossfit_folds = 1L,
mlr3superlearner_folds = 2L,
zprime_folds = 2L,
epochs = 2L,
torch_seed = 123L
)
)
print(res)
tidy(res)
}
ria.test control parameters
Description
ria.test control parameters
Usage
ria.test.control(
crossfit_folds = 10L,
mlr3superlearner_folds = 10L,
zprime_folds = 1L,
epochs = 100L,
learning_rate = 0.01,
batch_size = 64,
device = c("cpu", "cuda", "mps"),
torch_seed = NULL
)
Arguments
crossfit_folds |
[ |
mlr3superlearner_folds |
[ |
zprime_folds |
[ |
epochs |
[ |
learning_rate |
[ |
batch_size |
[ |
device |
[ |
torch_seed |
[ |
Value
A list of control parameters
Examples
if (torch::torch_is_installed()) ria.test.control(crossfit_folds = 5)
Sequential neural network module function factory
Description
Sequential neural network module function factory
Usage
sequential_module(layers = 1, hidden = 20, dropout = 0.1)
Arguments
layers |
[numeric(1)] |
|
[numeric(1)] | |
dropout |
[numeric(1)] |
Value
A function that returns a sequential neural network module.
Examples
if (torch::torch_is_installed()) sequential_module()
Tidy a ria.test object
Description
Tidy a ria.test object
Usage
## S3 method for class 'ria.test'
tidy(x, ...)
Arguments
x |
A 'ria.test' object produced by a call to [ria.test::ria.test()]. |
... |
Unused, included for generic consistency only. |
Value
A data frame summarizing the requested effect estimates.
Examples
if (torch::torch_is_installed()) {
set.seed(123)
n <- 200
w <- rnorm(n)
a <- rbinom(n, 1, plogis(w))
l <- rnorm(n, a + w)
m <- rnorm(n, a + l + w)
y <- rnorm(n, a + l + m + w)
dat <- data.frame(w, a, l, m, y)
res <- ria.test(
data = dat,
trt = "a",
outcome = "y",
mediators = "m",
pre = "w",
post = "l",
d0 = \(data, trt) rep(0, nrow(data)),
d1 = \(data, trt) rep(1, nrow(data)),
control = ria.test.control(
crossfit_folds = 1L,
mlr3superlearner_folds = 2L,
zprime_folds = 2L,
epochs = 2L,
torch_seed = 123L
)
)
print(res)
tidy(res)
}