|
| 1 | +Comparison of available dice packages |
| 2 | +================ |
| 3 | +Verena Haunschmid |
| 4 | +August 28, 2018 |
| 5 | + |
| 6 | +Available packages |
| 7 | +------------------ |
| 8 | + |
| 9 | +Besides `alea` other packages related to casting dice are available. In case you are looking for functionality which is not provided by `alea`, this list gives you an overview over the packages I found and the description they provided: |
| 10 | + |
| 11 | +- [dice](https://github.com/cran/dice): Calculate probabilities of various dice-rolling events |
| 12 | +- [Rdice](https://github.com/gennaro-tedesco/Rdice): R package to simulate dice rolls, combinatorical and best choice problems. |
| 13 | +- [diceSyntax](https://github.com/oganm/diceSyntax): dice roller with standard syntax |
| 14 | + |
| 15 | +This document shows a few of the use cases where another package might be more suitable for you. |
| 16 | + |
| 17 | +### dice |
| 18 | + |
| 19 | +``` r |
| 20 | +library(dice) |
| 21 | +``` |
| 22 | + |
| 23 | +The package `dice` is a package for calculating probabilities of various dice-rolling events, so this is something completely different from what `alea` is doing. The package consists of two functions: (a) `getEventProb()` and (b) `getSumProbs()`. The package is not very well documented and the functionality of `getEventProb()` was not immediately clear to me. So I try to explain it in more detail. |
| 24 | + |
| 25 | +The first three examples are taken from the manual of the package. |
| 26 | + |
| 27 | +``` r |
| 28 | +getEventProb(nrolls = 6, |
| 29 | + ndicePerRoll = 1, |
| 30 | + nsidesPerDie = 4, |
| 31 | + eventList = list(4, 3, c(1,2)), |
| 32 | + orderMatters = FALSE) |
| 33 | +``` |
| 34 | + |
| 35 | + ## [1] 0.6445312 |
| 36 | + |
| 37 | +``` r |
| 38 | +getEventProb(nrolls = 3, |
| 39 | + ndicePerRoll = 2, |
| 40 | + nsidesPerDie = 6, |
| 41 | + eventList = list(10, 4, c(2:6, 8:12)), |
| 42 | + orderMatters = TRUE) |
| 43 | +``` |
| 44 | + |
| 45 | + ## [1] 0.005787037 |
| 46 | + |
| 47 | +The function `getSumProbs()` is more straightforward. |
| 48 | + |
| 49 | +``` r |
| 50 | +getSumProbs(ndicePerRoll = 5, |
| 51 | + nsidesPerDie = 6, |
| 52 | + nkept = 3, |
| 53 | + dropLowest = TRUE) |
| 54 | +``` |
| 55 | + |
| 56 | + ## $probabilities |
| 57 | + ## Sum Probability Ways to Roll |
| 58 | + ## [1,] 3 0.0001286008 1 |
| 59 | + ## [2,] 4 0.0006430041 5 |
| 60 | + ## [3,] 5 0.0019290123 15 |
| 61 | + ## [4,] 6 0.0052726337 41 |
| 62 | + ## [5,] 7 0.0115740741 90 |
| 63 | + ## [6,] 8 0.0218621399 170 |
| 64 | + ## [7,] 9 0.0380658436 296 |
| 65 | + ## [8,] 10 0.0604423868 470 |
| 66 | + ## [9,] 11 0.0855195473 665 |
| 67 | + ## [10,] 12 0.1132973251 881 |
| 68 | + ## [11,] 13 0.1356738683 1055 |
| 69 | + ## [12,] 14 0.1485339506 1155 |
| 70 | + ## [13,] 15 0.1428755144 1111 |
| 71 | + ## [14,] 16 0.1202417695 935 |
| 72 | + ## [15,] 17 0.0784465021 610 |
| 73 | + ## [16,] 18 0.0354938272 276 |
| 74 | + ## |
| 75 | + ## $average |
| 76 | + ## [1] 13.43017 |
| 77 | + |
| 78 | +For better understanding, let me compute the probabilities of a more commonly used example (e.g., for teaching). Casting a 6-sided dice for two times. |
| 79 | + |
| 80 | +``` r |
| 81 | +probs <- getSumProbs(ndicePerRoll = 2, |
| 82 | + nsidesPerDie = 6, |
| 83 | + nkept = 2) |
| 84 | +probs <- data.frame(probs$probabilities) |
| 85 | +ggplot(probs) + geom_col(aes(x=Sum, y=Ways.to.Roll)) + scale_x_discrete(limits=probs$Sum) |
| 86 | +``` |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +### Rdice |
| 91 | + |
| 92 | +The package `Rdice` contains a set of function that can do similar things as `alea`. |
| 93 | + |
| 94 | +``` r |
| 95 | +library(Rdice) |
| 96 | +``` |
| 97 | + |
| 98 | +The core function seems to be `dice.roll()`. It produced a lot of output in a complicated list structure which does not make it very useful for other applications. |
| 99 | + |
| 100 | +The following example is taken from the help page of the function an casts 3 6-sided dice 5 times each. |
| 101 | + |
| 102 | +``` r |
| 103 | +dice.roll(faces = 6, dice = 3, rolls = 5) |
| 104 | +``` |
| 105 | + |
| 106 | + ## Call: |
| 107 | + ## dice.roll(faces = 6, dice = 3, rolls = 5) |
| 108 | + ## |
| 109 | + ## Results after 5 rolls of 3 dice: |
| 110 | + ## die_1 die_2 die_3 |
| 111 | + ## 1: 1 2 2 |
| 112 | + ## 2: 3 1 6 |
| 113 | + ## 3: 2 5 4 |
| 114 | + ## 4: 5 6 3 |
| 115 | + ## 5: 3 2 2 |
| 116 | + ## |
| 117 | + ## Frequency table for each occurrency: |
| 118 | + ## die_1 die_2 die_3 N freq |
| 119 | + ## 1: 1 2 2 1 0.2 |
| 120 | + ## 2: 3 2 2 1 0.2 |
| 121 | + ## 3: 5 6 3 1 0.2 |
| 122 | + ## 4: 2 5 4 1 0.2 |
| 123 | + ## 5: 3 1 6 1 0.2 |
| 124 | + ## |
| 125 | + ## Frequency table of the sums: |
| 126 | + ## sum N freq cum_sum |
| 127 | + ## 1: 5 1 0.2 0.2 |
| 128 | + ## 2: 7 1 0.2 0.4 |
| 129 | + ## 3: 10 1 0.2 0.6 |
| 130 | + ## 4: 11 1 0.2 0.8 |
| 131 | + ## 5: 14 1 0.2 1.0 |
| 132 | + ## |
| 133 | + ## Expectation value: 9.4 |
| 134 | + |
| 135 | +The package also contains three datasets of non-transitive dice, i.e. [Efron dice](http://mathworld.wolfram.com/EfronsDice.html) (`efron`), [Miwin dice](https://en.wikipedia.org/wiki/Miwin%27s_dice) (`miwin`) and [Oskar](https://en.wikipedia.org/wiki/Nontransitive_dice#Oskar_dice) (`oskar`). |
| 136 | + |
| 137 | +The package contains a [vignette](https://github.com/gennaro-tedesco/Rdice/blob/master/vignettes/Rdice-vignette.pdf) with more detailed explanations. |
| 138 | + |
| 139 | +### diceSyntax |
| 140 | + |
| 141 | +The package `diceSyntax` contains several functions but only documentation for `roll`. |
| 142 | + |
| 143 | +The package is only available on github. |
| 144 | + |
| 145 | +``` r |
| 146 | +devtools::install_github("oganm/diceSyntax") |
| 147 | +``` |
| 148 | + |
| 149 | +``` r |
| 150 | +library(diceSyntax) |
| 151 | +``` |
| 152 | + |
| 153 | +The interesting part of this package is that you can pass dice events like `4d6` in order to cast 4 6-sided dice. |
| 154 | + |
| 155 | +``` r |
| 156 | +roll("4d6") |
| 157 | +``` |
| 158 | + |
| 159 | + ## [1] "Rolls: [ *1* *1* 3 3 ]" |
| 160 | + |
| 161 | + ## [1] 8 |
| 162 | + |
| 163 | +More examples (e.g., keep highest/lowest 3, ...) can be found in the [README of diceSyntax](https://github.com/oganm/diceSyntax). |
0 commit comments