NDE_contbin: Natural Direct Effect (NDE) function for cases when mediator...

Description Usage Arguments Note Author(s) References Examples

Description

This function calculates the Natural Direct Effect (NDE) for continuous mediator and binary outcome as described in the publication of Valeri and VanderWeele (2013, doi: 10.1037/a0031034).

Usage

1
NDE_contbin(betas, thetas, treatment, mediator, covariates, variance = 1, a_old = 1, a_new = 0)

Arguments

betas

The coefficients of the regression on the mediator variable.

thetas

The coefficients of the regression on the outcome variable.

treatment

The column name in the dataframe which contains the treatment values.

mediator

The column name in the dataframe which contains the mediator values.

covariates

The column names in the dataframe which contain the covariate values.

variance

The variance from the regression on the mediator.

a_old

The old value of the treatment at which to evaluate the result (a in the publication of Valeri and VanderWeele). Default = 1.

a_new

The new value of the treatment at which to evaluate the result (a* in the publication of Valeri and VanderWeele). Default = 0.

Note

This package is under continuous (but perhaps slow) development. Users are welcome to contribute to the development.

Author(s)

Egge van der Poel (e.vanderpoel@erasmusmc.nl).

References

Valeri and VanderWeele (2013, doi: 10.1037/a0031034).

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
df <- data.frame('smoking'    = c(0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0),
                 'lbw'        = c(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                 'death'      = c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                 'drinking'   = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0),
                 'agebelow20' = c(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
                )

betas  <- c('(Intercept)' = -2.4916567, 'smoking' = 0.4905681, 'drinking' = -0.5967808, 
            'agebelow20' = 0.2305012)
thetas <- c('(Intercept)' = -6.5108483, 'smoking' = 0.5290551, 'lbw' = 3.5778582, 
            'drinking' = -0.3125368, 'agebelow20' = 0.2668849, 'smoking:lbw' = -0.5336013)
outcome='death'
treatment='smoking'
mediator='lbw'
covariates=c('drinking', 'agebelow20')

NDE_contbin(betas = betas, thetas = thetas, treatment = treatment, mediator = mediator, covariates = covariates)

## The function is currently defined as
function (betas, thetas, treatment, mediator, covariates, variance = 1, 
    a_old = 1, a_new = 0) 
{
    covariatesTerm <- 0
    for (c in covariates) {
        covariatesTerm <- covariatesTerm + betas[c] * apply(df[c], 
            2, mean, na.rm = TRUE)
    }
    interactionTerm <- ifelse(is.na(thetas[paste(treatment, mediator, 
        sep = ":")]), 0, thetas[paste(treatment, mediator, sep = ":")])
    ORnde <- exp((thetas[treatment] + interactionTerm * (betas[1] + 
        betas[treatment] * a_new + covariatesTerm + thetas[mediator] * 
        variance)) * (a_old - a_new) + 0.5 * interactionTerm^2 * 
        variance * (a_old^2 - a_new^2))
    unname(ORnde)
  }

harvard-P01/causalMediation documentation built on May 17, 2019, 3:04 p.m.