Description Usage Arguments Note Author(s) References Examples
This function calculates the Natural Indirect Effect (NIE) for continuous mediator and binary outcome as described in the publication of Valeri and VanderWeele (2013, doi: 10.1037/a0031034).
1 | NIE_contbin(betas, thetas, treatment, mediator, covariates, a_old = 1, a_new = 0)
|
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. |
This package is under continuous (but perhaps slow) development. Users are welcome to contribute to the development.
Egge van der Poel (e.vanderpoel@erasmusmc.nl).
Valeri and VanderWeele (2013, doi: 10.1037/a0031034).
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 | 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_contbin(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 <- exp((thetas[mediator] * betas[treatment] + interactionTerm *
betas[treatment] * a_old) * (a_old - a_new))
unname(ORnie)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.