paths: Causal Paths Analysis

Description Usage Arguments Value References See Also Examples

View source: R/paths.R

Description

paths estimates path-specific causal effects in the presence of K(≥q 1) causally ordered mediators. It implements the pure imputation estimator and the imputation-based weighting estimator (when a propensity score model is provided) as detailed in Zhou and Yamamoto (2020). The user supplies the names of the treatment, outcome, mediator variables, K+1 fitted models characterizing the conditional mean of the outcome given treatment, pretreatment confounders, and varying sets of mediators, and a data frame containing all the variables. The function returns K+1 path-specific causal effects that together constitute the total treatment effect. When K=1, the path-specific causal effects are identical to the natural direct and indirect effects in standard causal mediation analysis.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
paths(
  a,
  y,
  m,
  models,
  ps_model = NULL,
  data,
  nboot = 500,
  conf_level = 0.95,
  ...
)

## S3 method for class 'paths'
print(x, digits = 3, ...)

Arguments

a

a character string indicating the name of the treatment variable. The treatment should be a binary variable taking either 0 or 1.

y

a character string indicating the name of the outcome variable.

m

a list of K character vectors indicating the names of K causally ordered mediators M_1,…, M_K.

models

a list of K+1 fitted model objects describing how the outcome depends on treatment, pretreatment confounders, and varying sets of mediators, where K is the number of mediators.

  • the first element is a baseline model of the outcome conditional on treatment and pretreatment confounders.

  • the kth element is an outcome model conditional on treatment, pretreatment confounders, and mediators M_1,…, M_{k-1}.

  • the last element is an outcome model conditional on treatment, pretreatment confounders, and all of the mediators, i.e., M_1,…, M_K.

The fitted model objects can be of type lm, glm, gbm, wbart, or pbart.

ps_model

an optional propensity score model for treatment. It can be of type glm, gbm, ps, or pbart. When it is provided, the imputation-based weighting estimator is also used to compute path-specific causal effects.

data

a data frame containing all variables.

nboot

number of bootstrap iterations for estimating confidence intervals. Default is 500.

conf_level

the confidence level of the returned two-sided confidence intervals. Default is 0.95.

...

additional arguments to be passed to boot::boot, e.g. parallel and ncpus. For the print method, additional arguments to be passed to print.default

x

a fitted model object returned by the paths function.

digits

minimal number of significant digits printed.

Value

An object of class paths, which is a list containing the following elements

pure

estimates of direct and path-specific effects via M_1, …, M_K based on the pure imputation estimator.

hybrid

estimates of direct and path-specific effects via M_1, …, M_K based on the imputation-based weighting estimator.

varnames

a list of character strings indicating the names of the pretreatment confounders (X), treatment(A), mediators (M_1, …, M_K), and outcome (Y).

formulas

formulas for the outcome models.

classes

classes of the outcome models.

families

model families of the outcome models.

args

a list containing arguments of the outcome models.

ps_formula

formula for the propensity score model.

ps_class

class of the propensity score model.

ps_family

model family of the propensity score model.

ps_args

arguments of the propensity score model.

data

the original data.

nboot

number of bootstrap iterations.

conf_level

confidence level for confidence intervals.

boot_out

output matrix from the bootstrap iterations.

call

the matched call to the paths function.

References

Zhou, Xiang and Teppei Yamamoto. 2020. "Tracing Causal Paths from Experimental and Observational Data".

See Also

summary.paths, plot.paths, sens

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
data(tatar)

m1 <- c("trust_g1", "victim_g1", "fear_g1")
m2 <- c("trust_g2", "victim_g2", "fear_g2")
m3 <- c("trust_g3", "victim_g3", "fear_g3")
mediators <- list(m1, m2, m3)

formula_m0 <- annex ~ kulak + prosoviet_pre + religiosity_pre + land_pre +
  orchard_pre + animals_pre + carriage_pre + otherprop_pre + violence
formula_m1 <- update(formula_m0,    ~ . + trust_g1 + victim_g1 + fear_g1)
formula_m2 <- update(formula_m1,    ~ . + trust_g2 + victim_g2 + fear_g2)
formula_m3 <- update(formula_m2,    ~ . + trust_g3 + victim_g3 + fear_g3)
formula_ps <- violence ~ kulak + prosoviet_pre + religiosity_pre +
  land_pre + orchard_pre + animals_pre + carriage_pre + otherprop_pre

####################################################
# Causal Paths Analysis using GLM
####################################################

# outcome models
glm_m0 <- glm(formula_m0, family = binomial("logit"), data = tatar)
glm_m1 <- glm(formula_m1, family = binomial("logit"), data = tatar)
glm_m2 <- glm(formula_m2, family = binomial("logit"), data = tatar)
glm_m3 <- glm(formula_m3, family = binomial("logit"), data = tatar)
glm_ymodels <- list(glm_m0, glm_m1, glm_m2, glm_m3)

# propensity score model
glm_ps <- glm(formula_ps, family = binomial("logit"), data = tatar)

# causal paths analysis using glm
# note: For illustration purposes only a small number of bootstrap replicates are used
paths_glm <- paths(a = "violence", y = "annex", m = mediators,
  glm_ymodels, ps_model = glm_ps, data = tatar, nboot = 3)


####################################################
# Causal Paths Analysis using GBM
####################################################

require(gbm)

# outcome models
gbm_m0 <- gbm(formula_m0, data = tatar, distribution = "bernoulli", interaction.depth = 3)
gbm_m1 <- gbm(formula_m1, data = tatar, distribution = "bernoulli", interaction.depth = 3)
gbm_m2 <- gbm(formula_m2, data = tatar, distribution = "bernoulli", interaction.depth = 3)
gbm_m3 <- gbm(formula_m3, data = tatar, distribution = "bernoulli", interaction.depth = 3)
gbm_ymodels <- list(gbm_m0, gbm_m1, gbm_m2, gbm_m3)

# propensity score model via gbm
gbm_ps <- gbm(formula_ps, data = tatar, distribution = "bernoulli", interaction.depth = 3)

# causal paths analysis using gbm
# note: For illustration purposes only a small number of bootstrap replicates are used
paths_gbm <- paths(a = "violence", y = "annex", m = mediators,
  gbm_ymodels, ps_model = gbm_ps, data = tatar, nboot = 3)

paths documentation built on June 18, 2021, 9:07 a.m.