Mediation Analysis? With 3 mediators and no control variables?

Hi all,

I am a third year student trying to teach myself mediation analysis to do for my dissertation in hope for top marks. My lecturers do not use R so I am alone in this and would massively appreciate some help!

I have been given the following code/ help:

Testing Model 6 (one predictor variable, two serial mediators (one after the other), one outcome
variable)
If my datafile was called data1, my predictor variable was called predictor, my mediator variables
were called mediator1 and mediator2, my control variables were called control1 and control 2, and
my outcome variable was called outcome, the code I would run would be:

process (data = data1, y = "outcome", x = "predictor", m = c("mediator1","mediator2"), model = 6, effsize
=1, total =1, stand =1, cov = c("control1", "control2"), boot = 10000 , modelbt = 1, seed = 654321)

However, I have 3 mediators- so do i just put the third after mediator 2? E.g.,
m = c("mediator1","mediator2","mediator3"),

Also I have no control variables, can i just take this part out? Will this matter?

Thanks so much

Megan

How questions, such as this, generally require a reprex. See the FAQ. In particular, the process() function is unknown and modelbt() appears to be from a function from outside of the R/Bioconductor mainstream the documentation for which appears to be paywalled. There is an online course but applications closed on 14 Feb. In addition, the link that the author/instructor provides for the R package download does not have either a binary or source code available.

That's not how things are supposed to work in an open-source environment.

So let's discuss, instead, the what question.

Problems to be addressed under R benefit from the application of f(x) = y—just like school algebra.

x is the data object at hand. y is the object desired and f is the function object to transform the one into the other. Any of these may be, and usually are, composite. In the case of the data described

x is a set of variables, which may be continuous, binary or categorical, y is another variable which may similarly be one of those types. In general, we are interested in evaluating P(Y|X), the probability of observing a output given an input. For that task, R provides no end of statistical tools. For example, a binary outcome might be modeled with glm() as a logistic regression model, as I discuss here.

Most of those tools provide some measure of association such as correlation and we constantly hear correlation does not imply causation because of endless examples of spurious correlation between otherwise unrelated datasets. Folklore for children notwithstanding no one has come up with a plausible causal connection between stork populations in Northern Europe and births even in light of their high degree of correlation.

But stopping at that point neglects opportunities for casual inference that do exist by considering carefully all the relationships among variables. x_1 may have a direct effect on y or an indirect effect by its effect on x_2, which is usually what we think of as a mediator. However, there are also colliders and confounders to take into account, as explained by Judea Pearl, who also has a popular account, The Book of Why. R has tools, such as daggity as illustrated by this example

library(dagitty)

dag <- dagitty(
  'dag {
A [exposure,pos="-1.243,0.333"]
W1 [pos="-1.031,-0.585"]
W2 [pos="-0.140,-0.632"]
W3 [pos="-0.550,0.629"]
Y [outcome,pos="0.160,0.328"]
A -> W3
A -> Y
W1 -> A
W1 -> Y
W2 -> A
W2 -> Y
W3 -> Y
}'
)
plot(dag)

Created on 2023-02-17 with reprex v2.0.2

The principles underlying the use of this package in the analysis of directed acyclic graphs is described in the introductory article for the package. By undertaking this type of analysis, it is possible to untangle the roles of variables and make appropriate adjustments.

Coding a solution using other packages, such as {mediation} becomes much easier after a preliminary focus on what before jumping in.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.