4

I want to "draw" a mediator analysis with LaTeX, e.g. with TikZ. Unfortunately, I did not find any template for such a graphic; plus, I am lacking of skill to do it on my own (but very willing to learn!). Thus, I cannot offer a MWE! :(

The graphic shown below is made with Microsoft PP and displays some random variable names and values which should be replaceable with other variable names and values...

Example

Can someone reproduce such a mediator model with TikZ? I also wonder if the font in the graphic will be the same like my document settings?

1
  • 1
    The font will be the same. You can have a look at the tutorials in the TikZ manual to get started... even if you provide a minimal example that doesn't do anything, just loads the correct packages, it will help us here :-)
    – darthbith
    Feb 1, 2015 at 12:59

2 Answers 2

7

I won't provide explanations but suggest you to read pgfmanual. There are nice tutorials there as commented by darthbith. What you want can be easily done.

\documentclass[tikz,border=4]{standalone}
\usepackage{siunitx}
\usetikzlibrary{positioning}
\tikzset{mynode/.style={draw,text width=1in,align=center}
}
\begin{document}
  \begin{tikzpicture}
    \node[mynode] (m){Mediator};
    \node[mynode,below left=of m](a) {Variable A};
    \node[mynode,below right=of m](b) {Variable B};
    \draw[-latex] (a.north) -- node[auto,font=\footnotesize] {$b=-0.56$, $p=0.04$} (m.west);
    \draw[-latex] (m.east) -- node[auto,font=\footnotesize] {$b=-0.44$, $p<0.001$} (b.north);
    \draw[-latex] (a.east) --
            node[below=3mm,font=\footnotesize,align=center] {Direct effect, $b=0.55$,
                 $p=0.03$ \\ Indirect effect, $b=0.16$, \SI{90}{\percent} CI [ 0.04,0.36]}
                 (b.west);
  \end{tikzpicture}
\end{document}

enter image description here

0
3

Here's one for two mediators:

\documentclass[tikz,border=4]{standalone}
\usepackage{siunitx}
\usetikzlibrary{positioning}
\tikzset{mynode/.style={draw,text width=1in,align=center}
}
\begin{document}
    \begin{tikzpicture}
    \node[mynode] (m1){M1};
    \node[mynode, right=3cm of m1] (m2){M2}; % Manual adjustment of sep
    \node[mynode,below left=of m1](a){X};
    \node[mynode,below right=of m2](b){Y};
    \draw[-latex] (a.north) -- node[auto,font=\footnotesize] {A}(m1.west);
    \draw[-latex] (m1.east) -- node[auto,font=\footnotesize] {B} (m2.west);
    \draw[-latex] (m2.east) -- node[auto,font=\footnotesize] {C} (b.north);
    \draw[-latex] (a.east) --
            node[below=3mm,font=\footnotesize,align=center] {Direct effect, $b=0.55$,
                 $p=0.03$ \\ Indirect effect, $b=0.16$, \SI{90}{\percent} CI [ 0.04,0.36]}
                 (b.west);
  \end{tikzpicture}

\end{document}

Multiple serial mediators

And another for two parallel single mediators:

\documentclass[tikz,border=4]{standalone}
\usepackage{siunitx}
\usetikzlibrary{positioning}
\tikzset{mynode/.style={draw,text width=1in,align=center}
}
\begin{document}
  \begin{tikzpicture}
    \node[mynode] (m1){Mediator 1};
    \node[mynode,below left=of m1](a) {Variable A};
    \node[mynode,below right=of m1](b) {Variable B};
    \node[mynode,below = 2.5cm of m1] (m2){Mediator 2};

    \draw[-latex] (a.north) -- node[auto,font=\footnotesize] {A} (m1.west);
    \draw[-latex] (m1.east) -- node[auto,font=\footnotesize] {B} (b.north);
    \draw[-latex] (a.east) --
            node[below,font=\footnotesize,align=center] {C}
                 (b.west);
    \draw[-latex] (a.south) -- node[below,font=\footnotesize] {D} (m2.west);
    \draw[-latex] (m2.east) -- node[below,font=\footnotesize] {E} (b.south);
  \end{tikzpicture}
\end{document}

Parallel mediation diagram

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .