# Problem with probability tree

I am trying to make in LaTeX this probability tree: I tried using the tikz package but I keep having some issues. This is the best I got so far (link: https://www.writelatex.com/855538qcgkps#/1917915/):

    \documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
\pagestyle{empty}

\tikzstyle{level 1}=[level distance=3cm, sibling distance=3cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]

\tikzstyle{bag} = [circle, minimum width=10pt, inner sep=2pt]
\tikzstyle{end} = [circle, minimum width=3pt, fill, inner sep=0pt]

\begin{tikzpicture}[grow=right, sloped]

\node[bag]{}
child {
node[bag] {O}
child {
node[end, label=right:{O}] {}
edge from parent
node[above] {}
node[below]  {$1-\lambda$}
child {
node[end, label=right: {O ...}] {}
edge from parent
node[above] {}
node[below]  {$1-\lambda$}
}
child {
node[end, label=right: {S ...}] {}
edge from parent
node[above] {$\lambda$}
node[below]  {}
}
}
child {
node[end, label=right: {S}] {}
edge from parent
node[above] {$\lambda$}
node[below]  {}
}
edge from parent
node[above] {}
node[below]  {$1-\lambda$}
}
child {
node[bag] {S}
child {
edge from parent
node[above] {1}
node[below]  {}
node[bag] {O'}
child {
edge from parent
node[above] {$1$}
node[below] {}
edge from parent
}
}
edge from parent
node[above] {$\lambda$}
node[below]  {}
};

\end{tikzpicture}
\end{document}


As you can see, they are quite different, but I can't seem to be able to progress any further, would you be able to help me? I can't seem to realize what are the errors.

Best.

## 1 Answer

I'd suggest you to use the powerful forest package (its built upon PGF/TikZ):

\documentclass{article}
\usepackage{amsmath}
\usepackage{forest}

\tikzset{
dot/.style={circle,draw,inner sep=1.2,fill=black},
}

\newcommand\Labeli{%
node[below left,midway,xshift=3pt,font=\small]{$(1-\lambda)$}
node[above right,midway,xshift=-3pt,font=\small]{$0$}%
}
\newcommand\Labelii{%
node[above left,midway,xshift=3pt,font=\small]{$S$}
node[below right,midway,xshift=-3pt,font=\small]{$(\lambda)$}%
}
\newcommand\Labeliii{%
node[above,midway,font=\small]{$0'$}
node[below,midway,font=\small]{$(1)$}%
}

\begin{document}

\begin{forest}
[ ,name=a,for tree={s sep=60pt,l sep=2cm,dot,grow=0},
[ ,name=b,edge label={\Labeli}
[ ,name=c,edge label={\Labeli}
[ ,name=d,edge label={\Labeli} ]
[ ,name=e,edge label={\Labelii} ]
]
[ ,edge label={\Labelii}
[ ,name=f,edge label={\Labeliii} ]
]
]
[ ,edge label={\Labelii}
[ ,edge label={\Labeliii}
[ ,name=g,edge label={\Labeliii} ]
]
]
]
\foreach \Nodo in {d,e,f,g}
\node[anchor=west,xshift=3pt] at (\Nodo) {$\cdots$};
\node[yshift=-1cm,name= tiii,font=\small] at (d) {$t+3$};
\node[name= tii,font=\small] at (c|-tiii) {$t+2$};
\node[name= ti,font=\small] at (b|-tiii) {$t+1$};
\node[name= t,font=\small] at (a|-tiii) {$t$};
\end{forest}

\end{document} 