Learn R Programming

sensmediation (version 0.2.0)

sensmediation: Estimate natural direct and indirect effects based on parametric regression models and perform sensitivity analysis

Description

Function to estimate the natural direct and indirect effects based on parametric regression models. Standard errors for the effects are calculated using the delta method. The function also gives sensitivity analysis results for unobserved confounding. Implements methods introduced in Lindmark, de Luna and Eriksson (2018).

Usage

sensmediation(med.model, out.model, exp.model = NULL, exp.name = NULL,
  med.name = NULL, type = "my", Rho = 0, progress = TRUE,
  conf.level = 0.95, covariates = NULL, alt.decomposition = FALSE,
  control.value = 0, exp.value = 1, covariance = NULL, med.full = NULL,
  out.full = NULL, all.interactions = NULL, ...)

Arguments

med.model

Fitted glm model object representing the mediator model at the basis of the estimation (see Details for more information).

out.model

Fitted glm model object representing the outcome model at the basis of the estimation (see Details for more information).

exp.model

Fitted glm model object representing the exposure model. Should be provided if type="zm" or type="zy".

exp.name

A character string indicating the name of the exposure variable used in the models.

med.name

A character string indicating the name of the mediator used in the models.

type

the type of confounding for which the sensitivity analysis is to be performed. type="my", the default, corresponds to unobserved mediator-outcome confounding, type="zm" to exposure-mediator confounding and type="zy" to exposure-outcome confounding.

Rho

The sensitivity parameter vector. If type="my" the correlation between the error terms in the mediator and outcome models. If type="zm" the correlation between the error terms in the exposure and mediator models. If type="zy" the correlation between the error terms in the exposure and outcome models.

progress

Logical, indicating whether or not the progress (i.e. the proc.time for each Rho) of the optimization will be output

conf.level

the confidence level to be used for confidence intervals and uncertainty intervals.

covariates

if conditional effects are to be estimated the named list of covariate values (see Details). Covariates not specified are marginalized over.

alt.decomposition

logical indicating whether or not alternative definitions of the direct and indirect effects should be used (see Details).

control.value

value of the exposure variable used as the control (unexposed) condition, default is 0.

exp.value

value of the exposure variable used as the exposure condition, default is 1.

covariance, med.full, out.full, all.interactions

arguments used in previous versions of the package that are now deprecated.

...

Additional arguments to be passed on to the maxLik function. Can be used to set the method and control arguments of the maxLik function (see coefs.sensmed).

Value

sensmediation returns an object of class "effectsMed".

The function summary (summary.effectsMed) gives a summary of the results in the form of a table with the estimated effects and results of the sensitivity analysis. The function plot (plot.effectsMed) plots the estimated natural indirect or direct effects with confidence intervals over the range of the sensitivity parameter.

call

The matched call

Rho

The sensitivity parameter vector.

type

character, the type of confounding the sensitivity analysis is performed for.

coefs.sensmed

a list with the output from coefs.sensmed

NIE

matrix with the estimated NIEs (or NIE*s if alt.decomposition=TRUE) over the range of the sensitivity parameter Rho.

NDE

matrix with the estimated NDEs (or NDE*s if alt.decomposition=TRUE) over the range of the sensitivity parameter Rho.

std.errs

list with the standard errors of the NIE (NIE*), NDE (NDE*) and total effect over the range of the sensitivity parameter Rho.

CI

a list with the confidence intervals of the NIE (NIE*), NDE (NDE*) and total effect over the range of the sensitivity parameter Rho.

UI

matrix with the uncertainty intervals for the NIE (NIE*) and NDE (NDE*) over the range of the sensitivity parameter Rho.

conf.level

numeric, the confidence level used for confidence intervals and uncertainty intervals.

covariates

list of the covariate values that the effects are conditioned on.

exp.name

character vector containing the name of the exposure variable.

med.name

character vector containing the name of the mediator variable.

alt.decomposition

logical, indicating whether the alternative definitions of the direct and indirect effects have been used

med.model

if type="zy", the mediator model input.

out.model

if type="zm", the outcome model input.

Details

To obtain the ML estimates of the regression parameters used to calculate mediation effects and perform sensitivity analysis sensmediation calls coefs.sensmed. The maximization of the log-likelihood is performed using maxLik, the default is to use the Newton-Raphson method and an analytic gradient and Hessian.

The mediator and outcome models (and exposure model for type = "zm" or "zy") should be fitted using glm and can be of two types, probit models (family = binomial(link = 'probit')) for binary mediators or outcomes (exposures) and linear regression models (family = gaussian) for continuous mediators or outcomes (exposures). The outcome model may contain exposure-mediator, exposure-covariate, mediator-covariate and exposure-mediator-covariate interactions. The mediator model may contain exposure-covariate interactions. All models may also contain interactions between covariates. Note, however that interactions may not be included in a model without also including the main effects of the interacting variables. That is, interactions should be specified either as X1*X2 or X1 + X2 + X1:X2, not as X1:X2 alone.

To obtain results conditional on specific covariate values, these values should be provided through the covariates argument as a named list. The names of the list item(s) should match names from names(med.model$coefficients) and/or names(out.model$coefficients) (see Examples). The effects will be averaged over covariates not specified in the list.

The total effect can be decomposed into a direct and indirect effect in different ways. Let z be the exposure value and z* the control (unexposed) value. The default is to give the decomposition into the "pure direct effect" E(Y(z,M(z*)))-E(Y(z*,M(z*))) (here denoted NDE) and the "total indirect effect" E(Y(z,M(z)))-E(Y(z,M(z*))) (denoted NIE). Setting alt.decomposition=TRUE instead gives the decomposition into the "total direct effect" E(Y(z,M(z)))-E(Y(z*,M(z))) (here denoted NDE*) and "pure indirect effect" E(Y(z*,M(z)))-E(Y(z*,M(z*))) (denoted NIE*).

Standard errors for the effects are calculated using the delta method.

References

Lindmark, A., de Luna, X., Eriksson, M. (2018) Sensitivity Analysis for Unobserved Confounding of Direct and Indirect Effects Using Uncertainty Intervals, Statistics in Medicine, 37(10), pp 1744--1762.

See Also

more.effects which can be used to calculate additional direct and indirect effects with sensitivity analysis using the same sensitivity parameter without running the optimization again.

Examples

Run this code
# NOT RUN {
#Examples with simulated data

#######################################
# Binary mediator, continuous outcome #
#######################################

###Binary exposure:

##Simulated data:
require(mvtnorm)
require(maxLik)

n <- 1000
set.seed(102677)

x <- rnorm(n)

z.star <- -0.5 + 0.1*x + rnorm(n)
z <- ifelse(z.star > 0, 1, 0)

R <- 0.5
Sigma <- cbind(c(1,R), c(R,1))
epsilon <- rmvnorm(n, sigma = Sigma)

m.star <- -1.2 + 0.8*z + 0.13*x + epsilon[,1]
m <- ifelse(m.star > 0, 1, 0)

y <- -1 + 0.05*z + 3*m + 0.5*x + epsilon[,2]

#Models:
z.model <- glm(z ~ x, family = binomial(link = 'probit'))
m.model <- glm(m ~ z + x, family = binomial(link = 'probit'))
y.model <- glm(y ~ z + m + x)


##Estimation of NIE, NDE and sensitivity analyses to mediator-outcome confounding:
effects.my <- sensmediation(med.model = m.model, out.model = y.model, exp.name = "z",
              med.name = "m", Rho = seq(0, 0.5, 0.1))
summary(effects.my)
summary(effects.my, non.sign = TRUE)
plot(effects.my)
plot(effects.my, effect="direct")

##Estimation of NIE, NDE and sensitivity analyses to exposure-mediator confounding:
# }
# NOT RUN {
  effects.zm <- sensmediation(med.model = m.model, out.model = y.model, exp.model = z.model,
            type = "zm", Rho = seq(0, 0.5, 0.1), exp.name = "z", med.name = "m")
  summary(effects.zm)
# }
# NOT RUN {
##Additional effects using more.effects:
#Results with conf.level = 0.99:
effects.my.99 <- more.effects(sensmed.object = effects.my, conf.level = 0.99)
summary(effects.my.99)
#Conditional effects and sensitivity analysis to mediator-outcome confounding:
eff.my.cond <- more.effects(sensmed.object = effects.my, covariates = list(x = 1))
summary(eff.my.cond)


###Continuous exposure:
#Models:
z.model.cont <- glm(z.star ~ x)
m.model.contz <- glm(m ~ z.star + x, family=binomial(link='probit'))
y.model.contz <- glm(y ~ z.star + m + x)

##Estimation of NIE, NDE and sensitivity analyses to mediator-outcome confounding:
eff.my.contz <- sensmediation(med.model = m.model.contz, out.model = y.model.contz,
           Rho = seq(0, 0.5, 0.1), exp.name = "z.star", med.name = "m",
           control.value = 0, exp.value = 2)
summary(eff.my.contz)

##Estimation of NIE, NDE and sensitivity analyses to exposure-mediator confounding:
eff.zm.contz <- sensmediation(med.model = m.model.contz, out.model = y.model.contz,
                 exp.model = z.model.cont, type = "zm", Rho = seq(0, 0.5, 0.1),
                 exp.name = "z.star", med.name = "m", control.value = 0, exp.value = 2)
summary(eff.zm.contz)


# }

Run the code above in your browser using DataLab