Remember that a standard mediation model is just the combination of two regressions. The “a-path” is the effect of condition (and perhaps a moderator) on the mediator variable. The “b-path” is the effect of the mediator (and perhaps a moderator) on the DV controlling for the other a-path variables (condition and perhaps a moderator).
So, that being said, the first step is to set up the regression models for your a-path and b-path.
This model will only accept numeric variables, so re-code your string variables to numeric if needed before beginning.
For everything except SEM, we will be using the mediate package in R, so remember to install it and then call it into your library
library(mediation)
The first step in using the mediate package is to set up your regression equations for the a-path and the b-path. Let’s imagine a simple mediation where norm violation mediates the effect of condition on brand attitude.
lm is the function that calls a regression (i.e., a linear model). If you need to call something more complex (like a multi-level model using lmer), you can do that too. Just check that the mediation package accommodates that type of input.
a.path = lm(normViolation ~ condition, data = dta)
You must begin by dummy-coding the variable and then entering all the dummies into the a-path. Let’s imagine for this example that condition has 3 levels: recognized, control, and unrecognized (the referent condition)
a.path = lm(normViolation ~ recognized + control, data = dta)
Now, we look at the effect of the mediator on the DV controlling for condition
# If condition just has two levels
b.path = lm(Abr ~ normViolation + condition, data = dta)
#If condition is dummy coded, you must control for all the dummy variables
b.path = lm(Abr ~ normViolation + recognized + control, data = dta)