Group Abstract Group Abstract

Message Boards Message Boards

How to draw a probability tree diagram?

Posted 1 day ago

How to use Mathematica code to effectively draw the probability tree diagram as shown in the following image?

enter image description here

vertices = {"Start", "Monday", "Tuesday", "Mon-OnTime", "Mon-Late", 
   "Tue-OnTime", "Tue-Late"};
edges = {{"Start" -> "Monday", "Monday (0.5)"}, {"Start" -> "Tuesday",
     "Tuesday (0.5)"}, {"Monday" -> "Mon-OnTime", 
    "OnTime (0.7)"}, {"Monday" -> "Mon-Late", 
    "Late (0.3)"}, {"Tuesday" -> "Tue-OnTime", 
    "OnTime (0.7)"}, {"Tuesday" -> "Tue-Late", "Late (0.3)"}};


TreePlot[edges[[All, 1]], 
 VertexLabels -> {"Start" -> "Start", "Monday" -> "Monday", 
   "Tuesday" -> "Tuesday", "Mon-OnTime" -> "OnTime", 
   "Mon-Late" -> "Late", "Tue-OnTime" -> "OnTime", 
   "Tue-Late" -> "Late"}, 
 EdgeLabels -> Thread[edges[[All, 1]] -> edges[[All, 2]]], 
 DirectedEdges -> True, ImageSize -> 500, PlotStyle -> {Black, Thick},
  VertexLabelStyle -> 14, EdgeLabelStyle -> {Blue, Italic, 12}]
POSTED BY: Jim Clinton
2 Replies

One way is to use the paclet "TriesWithFrequencies":

PacletInstall["AntonAntonov/TriesWithFrequencies"];
Needs["AntonAntonov`TriesWithFrequencies`"];

combs = Flatten[Outer[List, {"On Time", "Late"}, {"On Time", "Late"}], 1];
seqs = Flatten[MapThread[Table, {combs, {7*7, 7*3, 3*7, 3*3}}], 1];

tr = TrieCreate[seqs];
TrieForm[tr]

TrieForm[TrieNodeProbabilities[tr]]

enter image description here

POSTED BY: Anton Antonov
Posted 17 hours ago

The generation method is very useful—thank you so much! I now have a solution.

I have one more question: Is it possible to generate a tree diagram that exactly matches the one in the original question image?

POSTED BY: Jim Clinton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard