Hello guys,
I'm trying to specify the following model in lavaan:
Where condition is binary (either control or experimental group); and where both the mediators (habits, attitudes, system) and the outcome variable (intention) are all measured on a scale ranging from 1 to 7 ("not at all - very")*.
(*a quick aside here: can the scale be treated is continuous instead of ordinal? Would I want that? If so, why? If not, why not?)
Basically, what I'm trying to see is whether the link between condition and intention remains significant after controlling for the mediators.
(I used the approach they used
here. I attach their supplementary material. On page 12 and 13 is their mediation model.)
I could produce the above plot using lavaanPlot with the following model specifications, which I modelled after this
tutorial:
multimedmed <- '#direct effect
intention~b1*habits+b2*attitudes+b3*system+c*condition
#mediators
habits~a1*condition
attitudes~a2*condition
system~a3*condition
indirect1:= a1*b1
indirect2:= a2*b2
indirect3:= a3*b3
#total effect
total:=c+(a1*b1)+(a2*b2)+(a3*b3)
habits~~attitudes
habits~~system
system~~attitudes'
However, to let the model run, I simply changed the condition from a factor to numeric (which is not interpretable, I think) to avoid the "unordered factor(s) with more than two levels detected as exogenous covariate(s): condition" error, as I wanted to simply specify the model for a preregistration of a student project, without actually having the data yet (I just needed the graphic).
Having the data now, I noticed on
lavaan website that one must specify the exogenous categorical variables as dummy variables, which I could do for my dataset using psych's package dummy.code function.
Where I'm lost (due to not really understanding the machinery) is how to adapt the above model, which has the groups collapsed into one variable, into one where the two groups are used instead.
Any help with specifying the model is appreciated (as well as any other resources that could help me do so - I really don't understand the syntax for the mediation model in lavaan).