crumble {crumble}R Documentation

Flexible and general mediation analysis

Description

General estimator for common mediation causal effects, including recanting twins, natural effects, organic effects, and randomized interventional effects. Interventions are specified using modified treatment policies. Nuisance parameters are estimated using the 'super learner' algorithm and 'Riesz learning'. Supports binary, categorical, and continuous exposures.

Usage

crumble(
  data,
  trt,
  outcome,
  mediators,
  moc = NULL,
  covar,
  obs = NULL,
  id = NULL,
  d0 = NULL,
  d1 = NULL,
  effect = c("RT", "N", "RI", "O"),
  weights = rep(1, nrow(data)),
  learners = "glm",
  nn_module = sequential_module(),
  control = crumble_control()
)

Arguments

data

[data.frame]
A data.frame in wide format containing all necessary variables for the estimation problem.

trt

[character]
A vector containing the column names of treatment variables.

outcome

[character(1)]
The column name of the outcome variable.

mediators

[character]
A vector containing the column names of the mediator variables.

moc

[character]
An optional vector containing the column names of the mediator-outcome confounders.

covar

[character]
An vector containing the column names of baseline covariates to be controlled for.

obs

[character(1)]
An optional column name (with values coded as 0 or 1) for whether or not the outcome is observed. Must be provided if there is missingness in the outcome! Default is NULL.

id

[character(1)]
An optional column name containing cluster level identifiers.

d0

[closure]
A two argument function that specifies how treatment variables should be shifted. See examples for how to specify shift functions for continuous, binary, and categorical exposures.

d1

[closure]
A two argument function that specifies how treatment variables should be shifted. See examples for how to specify shift functions for continuous, binary, and categorical exposures.

effect

[character(1)]
The type of effect to estimate. Options are "RT" for recanting twins, "N" for natural effects, "RI" for randomized interventional effects, and "O" for organic effects. If "RT" or "RI" is selected, moc must be provided. If "N" or "O" is selected, moc must be NULL.

weights

[numeric]
A optional vector of survey weights.

learners

[character]
A vector of mlr3superlearner algorithms for estimation of the outcome regressions. Default is "glm", a main effects GLM.

nn_module

[function]
A function that returns a neural network module.

control

[crumble_control]
Control parameters for the estimation procedure. Use crumble_control() to set these values.

Value

A crumble object containing the following components:

estimates

A list of parameter estimates.

outcome_reg

Predictions from the outcome regressions.

alpha_n

A list of density ratio estimates.

alpha_r

A list of density ratio estimates.

fits

A list of the fitted values from the outcome regressions.

call

The matched call.

effect

The estimated effect type.

Examples


if (require("mma") && torch::torch_is_installed()) {
	library(mma)
	data(weight_behavior)

	weight_behavior <- na.omit(weight_behavior)

	res <- crumble(
		data = weight_behavior,
		trt = "sports",
		outcome = "bmi",
		covar = c("age", "sex", "tvhours"),
		mediators = c("exercises", "overweigh"),
		moc = "snack",
		d0 = \(data, trt) factor(rep(1, nrow(data)), levels = c("1", "2")),
		d1 = \(data, trt) factor(rep(2, nrow(data)), levels = c("1", "2")),
		learners = c("mean", "glm"),
		nn_module = sequential_module(),
		control = crumble_control(crossfit_folds = 1L, zprime_folds = 5L, epochs = 10L)
	)

	print(res)
	tidy(res)
}


[Package crumble version 0.1.2 Index]