# Creating graph for an absorbing markov chain

I have the problem to create the following graph

It should have the following style

The code is given by

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,automata,positioning}
\newcommand{\N}{\mathbb{N}} % natuerliche Zahlen
\newcommand{\Z}{\mathbb{Z}} % ganze Zahlen
\newcommand{\Q}{\mathbb{Q}} % rationale Zahlen
\newcommand{\R}{\mathbb{R}} % reelle Zahlen
\newcommand{\Prob}{\mathbb{P}} % Symbol fuer Wahrscheinlichkeitsmaß
\newcommand{\E}{\mathbb{E}} % Symbol fuer Erwartungswert
\newcommand{\QAt}{\mathbf{Q}_{A_{2}A_{2}}}
\newcommand{\QAo}{\mathbf{Q}_{A_{1}A_{1}}}
\newcommand{\QAot}{\mathbf{Q}_{A_{1}A_{2}}}
\newcommand{\QAto}{\mathbf{Q}_{A_{2}A_{1}}}
\newcommand{\QAtC}{\mathbf{Q}_{A_{2}C}}
\newcommand{\QAtw}{\mathbf{Q}_{A_{2}\{\omega\}}}
\newcommand{\QAow}{\mathbf{Q}_{A_{1}\{\omega\}}}
\newcommand{\I}{\mathbf{I}}
\newcommand{\vf}{\mathbf{v}}
\newcommand{\Df}{\mathbf{D}}
\newcommand{\af}{\pmb{\alpha}}
\newcommand{\eef}{\mathbf{e}}
\newcommand{\Psf}{\pmb{\Psi}}
\newcommand{\Phf}{\pmb{\Phi}}
\newcommand{\bef}{\pmb{\beta}}
\newcommand{\Pf}{\mathbf{P}}
\newcommand{\Qf}{\mathbf{Q}}
\newcommand{\mf}{\mathbf{m}}
\newcommand{\ef}{\pmb{\varepsilon}}
\newcommand{\Hf}{\mathbf{H}}
\newcommand{\Ef}{\mathbf{E}}
\newcommand{\Mf}{\mathbf{M}}
\newcommand{\Vf}{\mathbf{V}}
\newcommand{\gf}{\mathbf{g}}
\newcommand{\QSo}{\mathbf{Q}_{S' S'}}
\newcommand{\QSot}{\mathbf{Q}_{S' S''}}
\newcommand{\QSt}{\mathbf{Q}_{S'' S''}}
\newcommand{\UP}[2]{\makebox[0pt]{\smash{\raisebox{1.5em}{$\phantom{#2}#1$}}}#2}
\newcommand{\LF}[1]{\makebox[0pt]{$#1$\hspace{4.5em}}}
\newcommand{\zfo}{\mathbf{z}_{1}}
\newcommand{\zft}{\mathbf{z}_{2}}
\newcommand{\zf}{\mathbf{z}}
\begin{document}}

\begin{tikzpicture}[->,>=stealth,shorten >=1pt,auto,node distance=2.5cm,
semithick]
\tikzset{every state/.append style={fill=red,draw=none,text=white}}

\node[state]         (A)                    {$\{\omega\}$};
\node[state]         (B) [below=of A] {$A_{2}(1)$};
\node[state]         (C) [below=of B] {$A_{1}(1)$};
\node[state]         (D) [below=of C] {$\{\omega\}$};
\node[state]         (F) [right=of B] {$A_{2}(2)$};
\node[state]         (E) [above=of F] {$\{\omega\}$};
\node[state]         (G) [below=of F] {$A_{1}(2)$};
\node[state]         (H) [below=of G] {$\{\omega\}$};
\node[state]         (J) [right=of F] {$A_{2}(m)$};
\node[state]         (I) [above=of J] {$\{\omega\}$};
\node[state]         (K) [below=of J] {$A_{1}(m)$};
\node[state]         (L) [below=of K] {$\{\omega\}$};
\node[state]         (M) [right=of J] {$A_{2}$\scriptsize(m+1)};

\path (B) edge              node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (A)
edge [loop left]  node {$\QAt$}                         (B)
edge              node {$\QAto$}                        (C)
(C) edge [loop left]  node {$\QAo$}                         (C)
edge              node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (D)
edge [right]      node {$\QAot$}                        (F)
(F) edge              node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (E)
edge [loop left]  node {$\QAt$}                         (F)
edge              node(aux) {$\QAto$}                        (G)
(G) edge [loop left]  node {$\QAo$}                         (G)
edge              node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (H)
(J) edge              node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (I)
edge [loop left]  node {$\QAt$}                         (J)
edge              node {$\QAto$}                        (K)
(K) edge [loop left]  node {$\QAo$}                         (K)
edge              node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (L)
edge [right]      node {$\QAot$}                        (M)
(M) edge [loop left]  node {$\I$}                           (M);
\node[right=2mm of aux,font=\bfseries\Huge]{\dots};
\end{tikzpicture}
\end{document}

Thanks for any help

• It would be helpful if you composed a fully compilable minimal working example (MWE) including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – user36296 Jan 4 at 16:49
• I'am Sorry...I have edited my question – wayne Jan 4 at 17:49
• Unfortunately your code does not compile, there is no documentclass etc. – user36296 Jan 4 at 17:52
• Why is this so important for you? I only want to create the graph at the top using tikz – wayne Jan 4 at 17:54
• A working example gives the people who are trying to help you something to start with. Setting up a document boring and might deter people from starting to solve your problem. – user36296 Jan 4 at 18:04

Here is some starting point:

\documentclass[tikz, border=3mm]{standalone}
\usetikzlibrary{automata,chains,positioning}

\begin{document}

\begin{tikzpicture}[
auto,
node distance = 14mm,
start chain = going right,
state/.append style = {
thick,
minimum width=3em,
on chain,
fill=red,
draw=none,
text=white
},
]

\node (s0)[state]    {$1$};
\node (s1)[state]    {$2$};
\node (s2)[state]    {$3$};
\node (s3)[state]    {$r-2$};
\node (s4)[state]    {$r-1$};

\draw[->] (s0) edge[bend left] node (a1) {p} (s1)
(s1) edge[bend left] node (b1) {q} (s0)
(s1) edge[bend left] node (a2) {p} (s2)
(s2) edge[bend left] node (b2) {q} (s1)
(s3) edge[bend left] node (a4) {p} (s4)
(s4) edge[bend left] node (b4) {q} (s3)
;

\node[state,node distance=3cm] (a) [below=of s2] {$\alpha$};
\draw[->] (s4.south west) edge node {p} (a);
\draw[<-] (a) edge node {q} (s0.south east);
\node[node distance=0.3cm,right=of s2] {$\ldots$};
\path (a) edge [loop below] node {Q} (a);

\end{tikzpicture}

\end{document}

• @wayne In your graph at the top, there is no loop - and the code of the other one is still not compilable. – user36296 Jan 4 at 19:41
• @wayne Just stick \node{p} into the obvious place (that is, before the end point (a)) in the last two \draw commands. That may not do what you want perfectly, so tweak the positioning of the nodes a bit by saying something like \node[below], \node[below=2pt] (moving them 2pt further from the anchor point), or perhaps \node[below left] and \node[below right]. But really, what you were given is explicitly a starting point. The purpose of this site is not to get other people to do your work for you. Rather, it is to get people unstuck when they're stuck. – Harald Hanche-Olsen Jan 5 at 11:35
• @wayne My motivation to invest further work in this answer is very low. There is still no compilable example in your answer and for most of your previous questions users gave you nice answers, but you did not mark any of them as accepted. – user36296 Jan 5 at 13:03
• @wayne Thanks for accepting the answers to your previous questions! In exchange I added some p and q. – user36296 Jan 5 at 14:00
• @wayne Will you make the code in your question compilable? – user36296 Jan 5 at 14:24

EDIT: a new version. I have done some changes. You can change the size the character similary where there are a large p and and large 1.

\documentclass[a4paper,12pt]{article}
\usepackage{tikz, tikz-cd,amsmath}
\usepackage{graphicx}
\newcommand*\nci[1]{\tikz[baseline=(char.base)]{
\node[shape=circle, draw=red, fill=red, draw,inner sep=7pt] (char) {#1};}}
\begin{document}
\begin{tikzcd}[column sep=1.6in,row sep=1.1in]
\nci{\textcolor{white}{\resizebox{.5cm}{!}{1}}}\arrow[r, "\resizebox{.5cm}{!}{$p$}", bend left=15] \arrow[rrd, "q"'] & \nci{\textcolor{white}{2}} \arrow[l, "q", bend left=15] \arrow[r, "p", bend left=15] & \nci{\textcolor{white}{3}}\cdots  \arrow[l, "q", bend left=15] & \qquad \cdots \nci{\textcolor{white}{$r-2$}} \arrow[r, "p", bend left=10] & \nci{\textcolor{white}{$r-1$}} \arrow[lld, "p"'] \arrow[l, "q", bend left=10] \\
&  & \alpha &  &
\end{tikzcd}
}
\end{document}

Here a version with tikz-cd simply to compare with what you want. Of course you can increase the size of the characters etc.

\documentclass[a4paper,12pt]{standalone}
\usepackage{tikz-cd,amsmath}

\begin{document}
\begin{tikzcd}[column sep=1.6in,row sep=1.1in]
1 \arrow[r, "p", bend left=15] \arrow[rrd, "q"'] & 2 \arrow[l, "q", bend left=15] \arrow[r, "p", bend left=15] & 3\cdots  \arrow[l, "q", bend left=15] & \qquad \cdots r-2 \arrow[r, "p", bend left=10] & r-1 \arrow[lld, "p"'] \arrow[l, "q", bend left=10] \\
&  & \alpha &  &
\end{tikzcd}
\end{document}
• It does not compile. Can you please add the code using tikzpicture – wayne Jan 4 at 18:01
• @wayne it compiles fine for me on a current texlive2018. Did you actually tried? – Ulrike Fischer Jan 4 at 20:03

Here is a solution that uses the chain concept with TikZ (see section 19 from page 257 of 3.0.1a manual). The first string defines nodes 1; 2; 3; ...; n-1 and n-2. The second chain reuses these nodes and places the arrows in the opposite direction.

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{graphs,quotes}
\begin{document}

\begin{tikzpicture}
\graph[grow right=20mm,edges=bend left,edge node={node [yshift=3pt, midway]{p}}] {
1 -> 2   -> 3-!-4/$\cdots$   -!- 5/{$n-2$}->6/{$n-1$}  ;
};
\graph[use existing nodes,edges=bend right,grow right=20mm,edge node={node [yshift=3pt, midway]{q}}]  {
1 <- 2   <- 3-!-4/$\cdots$   -!- 5/{$n-2$}<-6/{$n-1$}  ;
};
\node at (5,-2)(a){a}edge [loop below] node {s} ();;
\graph[use existing nodes,edges={bend right=10}]{ 1.south->[edge label'=q](a)<-[edge label=p]6.south;};
\end{tikzpicture}
\end{document}
• how can I add a loop to the node $a$? – wayne Jan 4 at 19:18
• A loop up or down? – AndréC Jan 4 at 19:25
• I added a loop below node $a$ – AndréC Jan 4 at 19:29