1

Part of what I work on involves sequential product multinomials, and analysis of same. In papers, or lectures, it is often useful to describe the underlying probability structure uing what we call a 'fate diagram', which, typically, is 'read' from left to right (left-most node, individual flips a coin, which may be multinomial, and follows a path based on said flip. Individual then enter a state, where gets a new coin, which is it flips, and so on...). So, a diagram starting (typically) from a single node, and then quickly branching.

To date, I've been generating these sorts of diagrams external to *TeX, using a dedicated graphics packages, but I'd like to see if there is a way I can generate those diagrams with *TeX itself. I don't have a MWE, but can provide a pointer to a graphic for a very rudimentary example of what I'm trying to 'draw':

enter image description here

The challenge is the asymmetric 'branching' I often need (on the right). This is analogous to phylogenetic trees, but I haven't been able to figure out how to arm-twist any of the packages/approaches I've found to give me the sort of thing I'm looking for.

Any suggestions appreciated -- even a simple code example render 'my example' in *TeX would be great. Tikz, PSTricks, pgfplots -- doesn't really matter much (I have no significant allegiance to any one over the other).

Thanks in advance...

  • Note that it is courteous to at least provide a minimal document containing the text you want in the diagram. Copying from an image in another application is extremely annoying! – cfr Mar 15 '15 at 14:09
  • If I had a working MWE, then it might be reasonable to assume that I wouldn't have sought help in the first place. And as for the text for the diagram, that is rather arbitrary. Presumably, it would be easy to simply substitute in A, B, C, D.... – Johnny Canuck Apr 7 '15 at 18:42
  • MnWEs are equally acceptable. And you don't say what's arbitrary. A B C D would need different settings in many cases. – cfr Apr 7 '15 at 20:28
4

You might like the flexibility of Metapost for this type of diagram. I've used the boxes library to define the text but then drawn them without boundaries.

enter image description here

prologues := 3;
outputtemplate := "%j%c.eps";
input boxes;

verbatimtex
\font\sf=phvr8r at 10pt
\def\s#1{\vbox{\halign{\hss{\sf ##}\hss\cr#1\crcr}}}\let\\\cr
etex

beginfig(1);

boxit.A(btex \s{marked and\\released alive\\at start of year} etex);
boxit.S(btex \s{survives\\year} etex);
boxit.K(btex \s{killed by\\hunter} etex);
boxit.N(btex \s{dies from\\`natural' causes} etex);

boxit.r0(btex \s{not retrieved} etex);
boxit.r1(btex \s{retrieved but\\not reported} etex);
boxit.r2(btex \s{retrieved and\\reported} etex);

 K.c - A.c  = r2.c -  K.c = 140 right;
 K.c - N.c  =  S.c -  K.c =  60 up;
r2.c - r1.c = r0.c - r2.c =  42 up;

drawunboxed(A, S, K, N, r0, r1, r2);

path p[];
p1 = A.c -- S.c cutbefore bpath A cutafter bpath S;
p2 = A.c -- K.c cutbefore bpath A cutafter bpath K;
p3 = A.c -- N.c cutbefore bpath A cutafter bpath N;

p4 = K.c -- r0.w cutbefore bpath K;
p5 = K.c -- r1.w cutbefore bpath K; 
p6 = point .37 of p5 -- r2.w;

for $=1 upto 6: draw p[$]; endfor

label(btex $S$ etex         rotated angle direction 0.5 of p1, point .5 of p1 shifted 6 up);
label(btex $K$ etex         rotated angle direction 0.5 of p2, point .5 of p2 shifted 6 up);
label(btex $1-S-K$ etex     rotated angle direction 0.5 of p3, point .5 of p3 shifted 6 up);
label(btex $1-c$ etex       rotated angle direction 0.5 of p4, point .5 of p4 shifted 6 up);
label(btex $c$ etex         rotated angle direction 0.5 of p5, point .2 of p5 shifted 6 up);
label(btex $1-\lambda$ etex rotated angle direction 0.5 of p5, point .7 of p5 shifted 6 up);
label(btex $\lambda$ etex   rotated angle direction 0.5 of p6, point .5 of p6 shifted 6 up);

endfig;
end.
2

forest is always an option:

fate forest

\documentclass[12pt, tikz]{standalone}
\usepackage{forest}
\begin{document}
\forestset{
  skip me/.style={
    shape=coordinate,
    inner sep=0pt,
    outer sep=0pt,
  },
  my label/.style n args=2{
      edge label={node [midway, sloped, #1, font=\scriptsize, inner sep=1pt] {#2}},
  },
}
\begin{forest}
  for tree={
    grow'=0,
    parent anchor=east,
    child anchor=west,
    anchor=west,
    align=center,
    if n children=3{
      for children={
        if n=2{
          calign with current edge,
        }{},
      },
    }{},
    tier/.wrap pgfmath arg={#1}{level()},
    l sep+=10mm
  }
  [marked and\\released alive\\at start of year
    [survives\\year, my label={above}{$S$}
    ]
    [killed by\\hunter, my label={above}{$K$}
      [not retrieved, tier=term, my label={above}{$1-c$}
      ]
      [, skip me, my label={below}{$c$}
        [retrieved and\\reported, my label={above}{$\lambda$}, tier=term
        ]
        [retrieved but\\not reported, my label={below}{$1-\lambda$}, tier=term
        ]
      ]
    ]
    [dies from\\natural causes, my label={below}{$1-S-K$}
    ]
  ]
\end{forest}
\end{document}
  • Indeed - thank you. I played with forest once, moons ago, and it has some attractive features - not the least of which is I have a pretty go idea of what your code does, without having to parse through the forest documentation. – Johnny Canuck Apr 7 '15 at 18:43
-1

You could adapt something like this:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}

% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]

% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]

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

\node[bag] {$\bullet$}
    child {
        node[bag] {$tail$}        
            child {
                node[end, label=right:
                    $tail$] {} 
                edge from parent
                node[above] {}         
                node[below] {$\frac12$}
            }
            child {
                node[end, label=right:
                    $head$] {}
                edge from parent
                node[above] {$\frac12$}         
                node[below] {}
            }
        edge from parent 
            node[above] {}
            node[below] {$\frac12$}
    }
    child {
        node[bag] {$head$}        
            child {
                node[end, label=right:
                    $tail$] {}
                edge from parent
                node[above] {}         
                node[below] {$\frac12$}
            }
            child {
                node[end, label=right:
                    $head$] {}
                edge from parent
                node[above] {$\frac12$}         
                node[below] {}
            }
    edge from parent         
            node[above] {$\frac12$}
            node[below] {}
    };
\end{tikzpicture}
%

\end{document}
  • Hmmm -- interesting. But when I try to compile this, I get all sorts of errors, the first one being that \only<3> is an undefined control sequence.I have what I believe is the correct package support in the preamble, but still not working... – Johnny Canuck Mar 13 '15 at 22:50
  • Did you by any chance copy this code without really understanding it and without bothering to attribute it? Why do you think patterns is required? – cfr Mar 15 '15 at 14:11
  • Right patterns was not needed. The post is edited now, but @cfr there is not need to vote down just because you have a bad day. – Toño Mar 16 '15 at 8:24
  • You haven't acknowledged the source of the code. – cfr Mar 16 '15 at 13:51
  • There is no need to assume that somebody has had a bad day just because the person down-voted an answer which happens to be yours. I down-voted your answer because of its content and for no other reason. In general, though, you should not assume that the person who down-voted is the person who comments. – cfr Mar 17 '15 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.