plmed: Partially Linear Mediation

Description Usage Arguments Value Examples

View source: R/plmed.R

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
plmed(
  exposure.formula,
  mediator.formula,
  outcome.formula,
  exposure.family = "binomial",
  mediator.family = "gaussian",
  data,
  weights,
  method = "G-estimation"
)

Arguments

exposure.formula

an object of class "formula" (or one that can be coerced to that class) where the left hand side of the formula contains the binary exposure variable of interest.

mediator.formula

an object of class "formula" (or one that can be coerced to that class) where the left hand side of the formula contains the continuous mediator variable of interest.

outcome.formula

an object of class "formula" (or one that can be coerced to that class) where the left hand side of the formula contains the continuous outcome variable of interest.

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 "binomial" when using Method="TTS". Must be "none" when using Method="OLS".

mediator.family

link function for the mediator model, can be either "gaussian" or "binomial". Must be "gaussian" when using Method="G-estimation"

data

an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which plmed is called.

weights

an optional vector of ‘observation weights’ to be used in the fitting process. Should be NULL or a numeric vector.

method

The mediation fitting method to be used. Can be either "G-estimation","TTS" or "OLS"

Value

An object of class plmed with unconstrained parameter estimates, estimated standard errors, Wald based and CUE score based test statistics (G-estimation only).

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
#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

ohines/plmed documentation built on Jan. 9, 2021, 11:59 a.m.