# Draw graphical model with many nodes

So I tried to follow the answer in http://stats.stackexchange.com/questions/16750/software-for-drawing-bayesian-networks-graphical-models with limited success.

My problem is

1. How do I incorporate multiple variables without writing down all of them (eg. just say $\pi_1 - \pi_k$ or similar)
2. How do I incorporate 'ghost nodes' as seen for the ones connecting to $\pi_3, \pi_k$.

-
Have a look at tikz matrix or foreach loops with positioning library. In very few lines the job can be done. –  s__C Jul 28 '14 at 6:14
You may want to have a look to How to draw graphs in LaTeX? –  Claudio Fiandrino Jul 28 '14 at 6:18

Based on a search for matrix I came up with this: It's not the most beautiful solution, but is close to your pic.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, calc, positioning,matrix}
\tikzset{
data/.style={circle, draw, text centered, minimum height=3em ,minimum width = .5em, inner sep = 2pt},
empty/.style={circle, text centered, minimum height=3em ,minimum width = .5em, inner sep = 2pt},
}
\begin{document}
\begin{tikzpicture}[
align = flush center,
font = \small]
\matrix [
matrix of nodes,
column sep = 0.5em,
row sep = 1.3em,
draw, dashed,
nodes = {solid},
] (m)
{
|[data]|$\pi_1$ &  |[data]|$\pi_2$ & |[data]|$\pi_3$ & |[empty]| & |[data]|$\pi_K$ \\
|[data]|$C_1$ &  |[data]|$C_2$ & |[data]|$C_3$ & |[empty]| & |[data]|$C_K$ \\
|[data]|$w_1$ &  |[data]|$w_2$ & |[data]|$w_3$ & |[empty]| & |[data]|$w_K$ \\
|[data]|$D_1$ &  |[data]|$D_2$ & |[empty]| & |[empty]| & |[data]|$D_N$ \\[.7em]
};
\draw[->](m-1-1) to (m-2-1);
\draw[->](m-2-1) to (m-3-1);
\draw[->](m-3-1) to (m-4-1);
\draw[->](m-3-1) to (m-1-2);
\draw[->](m-3-1.south) to (m-4-5);

\draw[->](m-1-2) to (m-2-2);
\draw[->](m-2-2) to (m-3-2);
\draw[->](m-3-2) to (m-1-1);
\draw[->](m-3-2) to (m-1-3);
\draw[->](m-3-2.south) to (m-4-1);
\draw[->](m-3-2.south) to (m-4-5);

\draw[->](m-1-3) to (m-2-3);
\draw[->](m-2-3) to (m-3-3);
\draw[->](m-3-3) to (m-1-2);

\draw[->](m-2-4) to (m-1-3);
\draw[->](m-3-4) to (m-1-5);

\draw[->](m-1-5) to (m-2-5);
\draw[->](m-2-5) to (m-3-5);
\draw[->](m-3-5) to (m-4-5);

\end{tikzpicture}
\end{document}


-
np, use CloudConvert to convert PDF to PNG –  m0nhawk Jul 28 '14 at 8:49
@m0nhawk thanks again, i'll give it a try the next time :) –  Dan H. Jul 28 '14 at 8:51