NIE_binbin: Natural Indirect Effect (NIE) function for cases when...

Description Usage Arguments Note Author(s) References Examples

Description

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

Usage

1
NIE_binbin(betas, thetas, treatment, mediator, covariates, 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.

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
36
37
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')

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

## The function is currently defined as
function (betas, thetas, treatment, mediator, covariates, 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 = ":")])
    ORnie <- ((1 + exp(betas[1] + betas[treatment] * a_new + 
        covariatesTerm)) * (1 + exp(thetas[mediator] + interactionTerm * 
        a_old + betas[1] + betas[treatment] * a_old + covariatesTerm)))/((1 + 
        exp(betas[1] + betas[treatment] * a_old + covariatesTerm)) * 
        (1 + exp(thetas[mediator] + interactionTerm * a_old + 
            betas[1] + betas[treatment] * a_new + covariatesTerm)))
    unname(ORnie)
  }

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