OLS: Baron-Kenny style Mediated Effects

Description Usage Arguments Value Examples

View source: R/OLS.R

Description

OLS is used to estimate mediated effects (Baron and Kenny, 1986) in linear models using Ordinary Least Squares based methods. Linear models are assumed for the conditional expectation of mediator given exposure and confounders, and for the conditional expectation of outcome given mediator, exposure and confounders. As with the plmed function, the confounder set is the union terms in the mediator.formula, and outcome.formula. Missing data behaviour is always na.action=na.omit.

Usage

1
OLS(exposure.variable, mediator.formula, outcome.formula, data, weights)

Arguments

exposure.variable

a character string naming the 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 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 outcome variable of interest.

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 OLS is called.

Value

An object of class plmed with, Natural Direct Effect (NDE) and Natural Indirect Effect (NIDE) estimates, as well as the effect of exposure on mediator (X_on_M) and the effect of mediator on outcome (M_on_Y). Estimated standard errors, and Wald based test statistics are also returned, as is the Likelihood Ratio (LR) based test statitic.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#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,1/(exp(-Z)+1))
M <- beta[1]*X + Z +rnorm(N)
Y <- beta[2]*M + beta[3]*X + Z +rnorm(N)

OLS("X",M~Z,Y~Z)

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