Description Usage Arguments Details Value Bootstrap standard errors Robust standard errors Note References See Also Examples
neModel
is used to fit a natural effect model on the expanded dataset.
1 2 3 
formula 
a 
family 
a description of the error distribution and link
function to be used in the model. For 
expData 
the expanded dataset (of class 
xFit 
fitted model object representing a model for the exposure (used for inverse treatment (exposure) probability weighting). 
se 
character string indicating the type of standard errors to be calculated. The default type is based on the bootstrap (see details). 
nBoot 
number of bootstrap replicates (see 
parallel 
(only for bootstrap) The type of parallel operation to be used (if any). If missing, the default is taken from the option 
ncpus 
(only for bootstrap) integer: number of processes to be used in parallel operation: typically one would chose this to the number of available CPUs (see details). 
progress 
(only for bootstrap) logical value indicating whether or not a progress bar should be displayed. Progress bars are automatically disabled for multicore processing. 
... 
additional arguments (passed to 
This function is a wrapper for glm
, providing unbiased bootstrap (se = "bootstrap"
, the default) or robust (se = "robust"
) standard errors for the parameter estimates (see below for more details).
The formula
argument requires to be specified in function of the variables from the expanded dataset (specified in expData
) whose corresponding parameters index the direct and indirect effect.
Stratumspecific natural effects can be estimated by additionally modeling the relation between the outcome and baseline covariates.
If the set of baseline covariates adjusted for in the formula
argument is not sufficient to control for confounding (e.g. when fitting a populationaverage natural effect model),
an adequate model for the exposure (conditioning on a sufficient set of baseline covariates) should be specified in the xFit
argument.
In this case, such a model for the exposure distribution is needed to weight by the reciprocal of the probability (density) of the exposure (i.e. inverse probability weighting) in order to adjust for confounding.
Just as for ratioofmediator probability weighting (see paragraph below), this kind of weighting is done internally.
Quadratic or higherorder polynomial terms can be included in the formula
by making use of the I
function or by using the poly
function.
However, we do not recommend the use of orthogonal polynomials (i.e. using the default argument specification raw = FALSE
in poly
), as these are not compatible with the neEffdecomp
function.
In contrast to glm
, the expData
argument (rather than data
argument) requires specification of a data frame that inherits from class "expData"
,
which contains additional information about e.g. the fitted working model, the variable types or terms of this working model
and possibly ratioofmediator probability weights.
The latter are automatically extracted from the expData
object and weighting is done internally.
As the default glm
standard errors fail to reflect the uncertainty inherent to the working model(s) (i.e. either a model for the mediator or an imputation model for the outcome and possibly a model for the exposure),
bootstrap standard errors (using the boot
function from the boot package) or robust standard errors are calculated. The default type of standard errors is bootstrap standard errors.
Robust standard errors (based on the sandwich estimator) can be requested (to be calculated) instead by specifying se = "robust"
.
An object of class "neModel"
(which additionally inherits from class "neModelBoot"
if the bootstrap is used) consisting of a list of 3 objects:

the fitted natural model object (of class 

the bootstrap results (of class 

the 
See neModelmethods
for methods for neModel
objects.
The bootstrap procedure entails refitting all working models on each bootstrap sample, reconstructing the expanded dataset and subsequently refitting the specified natural effect model on this dataset.
In order to obtain stable standard errors, the number of bootstrap samples (specified via the nBoot
argument) should be chosen relatively high (default is 1000).
To speed up the bootstrap procedure, parallel processing can be used by specifying the desired type of parallel operation via the parallel
argument (for more details, see boot
).
The number of parallel processes (ncpus
) is suggested to be specified explicitly (its default is 1, unless the global option options("boot.cpus")
is specified).
The function detectCores
from the parallel package can be helpful at determining the number of available cores (although this may not always correspond to the number of allowed cores).
Robust variancecovariance matrices for the model parameters, based on the sandwich estimator, are calculated using core functions from the sandwich package.
Additional details and derivations for the sandwich estimator for natural effect models can be found in the corresponding vignette that can be obtained by the command vignette("sandwich", package = "medflex")
.
It is important to note that the original mediator(s) should not be specified in the formula
argument, as the natural indirect effect in natural effect models
should be captured solely by parameter(s) corresponding to the auxiliary hypothetical variable x* in the expanded dataset (see expData
).
Lange, T., Vansteelandt, S., & Bekaert, M. (2012). A Simple Unified Approach for Estimating Natural Direct and Indirect Effects. American Journal of Epidemiology, 176(3), 190195.
Vansteelandt, S., Bekaert, M., & Lange, T. (2012). Imputation Strategies for the Estimation of Natural Direct and Indirect Effects. Epidemiologic Methods, 1(1), Article 7.
Loeys, T., Moerkerke, B., De Smet, O., Buysse, A., Steen, J., & Vansteelandt, S. (2013). Flexible Mediation Analysis in the Presence of Nonlinear Relations: Beyond the Mediation Formula. Multivariate Behavioral Research, 48(6), 871894.
neModelmethods
, plot.neModel
, neImpute
, neWeight
, neLht
, neEffdecomp
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 56 57 58 59 60 61 62 63 64 65 66  data(UPBdata)
##############################
## weightingbased approach ##
##############################
weightData < neWeight(negaff ~ att + gender + educ + age,
data = UPBdata)
## stratumspecific natural effects
# bootstrap SE
## Not run:
weightFit1b < neModel(UPB ~ att0 * att1 + gender + educ + age,
family = binomial, expData = weightData)
summary(weightFit1b)
## End(Not run)
# robust SE
weightFit1r < neModel(UPB ~ att0 * att1 + gender + educ + age,
family = binomial, expData = weightData, se = "robust")
summary(weightFit1r)
## populationaverage natural effects
expFit < glm(att ~ gender + educ + age, data = UPBdata)
# bootstrap SE
## Not run:
weightFit2b < neModel(UPB ~ att0 * att1, family = binomial,
expData = weightData, xFit = expFit)
summary(weightFit2b)
## End(Not run)
# robust SE
weightFit2r < neModel(UPB ~ att0 * att1, family = binomial,
expData = weightData, xFit = expFit, se = "robust")
summary(weightFit2r)
###############################
## imputationbased approach ##
###############################
impData < neImpute(UPB ~ att * negaff + gender + educ + age,
family = binomial, data = UPBdata)
## stratumspecific natural effects
# bootstrap SE
## Not run:
impFit1b < neModel(UPB ~ att0 * att1 + gender + educ + age,
family = binomial, expData = impData)
summary(impFit1b)
## End(Not run)
# robust SE
impFit1r < neModel(UPB ~ att0 * att1 + gender + educ + age,
family = binomial, expData = impData, se = "robust")
summary(impFit1r)
## populationaverage natural effects
# bootstrap SE
## Not run:
impFit2b < neModel(UPB ~ att0 * att1, family = binomial,
expData = impData, xFit = expFit)
summary(impFit2b)
## End(Not run)
# robust SE
impFit2r < neModel(UPB ~ att0 * att1, family = binomial,
expData = impData, xFit = expFit, se = "robust")
summary(impFit2r)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs in the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.