Description Usage Arguments Value Examples
plmed
is used to fit mediation effects for a continuous outcome
given a single continuous or binary mediator, a continuous or binary exposure, and a set of
variables which adjust for confounding. This function supports three fitting methods:
those based on "G-estimation
", "TTS
", and "OLS
".
For all methods, the confounder variable set is the union of terms in the exposure.formula
,
mediator.formula
, and outcome.formula
. Missing data behaviour is always na.action=na.omit
.
1 2 3 4 5 6 7 8 9 10 |
exposure.formula |
an object of class " |
mediator.formula |
an object of class " |
outcome.formula |
an object of class " |
exposure.family |
link function for the exposure model, can be can be a character string naming a family function,
a family function or the result of a call to a family function. (See family for details of family functions.)
Must be |
mediator.family |
link function for the mediator model, can be either |
data |
an optional data frame, list or environment
(or object coercible by |
weights |
an optional vector of ‘observation weights’ to be used in
the fitting process. Should be |
method |
The mediation fitting method to be used. Can be either |
An object of class plmed
with unconstrained parameter estimates,
estimated standard errors, Wald based and CUE score based test statistics (G-estimation only).
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 | #Example on Generated data
N <- 100
beta <- c(1,0,1) #Some true parameter values
#Generate data on Confounders (Z), Exposure (X)
#Mediator (M), Outcome (Y)
Z <- rnorm(N)
X <- rbinom(N,1,plogis(Z))
M <- beta[1]*X + Z +rnorm(N)
Y <- beta[2]*M + beta[3]*X + Z +rnorm(N)
plmed(X~Z,M~Z,Y~Z,method="G-estimation")
plmed(X~Z,M~Z,Y~Z,method="TTS")
plmed(X~Z,M~Z,Y~Z,method="OLS")
#Example on JobsII data from the mediation package
jobs <- mediation::jobs
Z.formula = c('econ_hard','sex','age','occp',
'marital','nonwhite','educ','income')
plmed(reformulate(Z.formula,response='treat'),
reformulate("1",response='job_seek'),
reformulate("1",response='depress2'),
data=jobs)
#Only one of the formulas must include the confounder variables
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.