Skip to content

Commit ade4b82

Browse files
add package comparison
1 parent c0941d0 commit ade4b82

File tree

4 files changed

+285
-10
lines changed

4 files changed

+285
-10
lines changed

README.Rmd

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ You can install alea from github with:
3939
devtools::install_github("expectopatronum/alea")
4040
```
4141

42-
## Other packages
42+
Load the package:
43+
44+
```{r load-package}
45+
library(alea)
46+
```
4347

44-
Since casting dice is a rather important and easily programmed task, there exist a few other R package. 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:
48+
## Other packages
4549

46-
* [dice](https://github.com/cran/dice): Calculate probabilities of various dice-rolling events
47-
* [Rdice](https://github.com/gennaro-tedesco/Rdice): R package to simulate dice rolls, combinatorical and best choice problems.
48-
* [diceSyntax](https://github.com/oganm/diceSyntax): dice roller with standard syntax
50+
Since casting dice is a rather important and easily programmed task, there exist a few other R package. I made a list of the ones I found and tried a few examples [here](misc/package_comparison.md).
4951

5052
## Examples
5153

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ You can install alea from github with:
2828
devtools::install_github("expectopatronum/alea")
2929
```
3030

31+
Load the package:
32+
33+
``` r
34+
library(alea)
35+
```
36+
3137
Other packages
3238
--------------
3339

34-
Since casting dice is a rather important and easily programmed task, there exist a few other R package. 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:
35-
36-
- [dice](https://github.com/cran/dice): Calculate probabilities of various dice-rolling events
37-
- [Rdice](https://github.com/gennaro-tedesco/Rdice): R package to simulate dice rolls, combinatorical and best choice problems.
38-
- [diceSyntax](https://github.com/oganm/diceSyntax): dice roller with standard syntax
40+
Since casting dice is a rather important and easily programmed task, there exist a few other R package. I made a list of the ones I found and tried a few examples [here](misc/package_comparison.md).
3941

4042
Examples
4143
--------

misc/package_comparison.Rmd

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
title: "Comparison of available dice packages"
3+
author: "Verena Haunschmid"
4+
date: "August 28, 2018"
5+
output: github_document
6+
---
7+
8+
```{r setup, include=FALSE}
9+
knitr::opts_chunk$set(echo = TRUE)
10+
library(ggplot2)
11+
```
12+
13+
## Available packages
14+
15+
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:
16+
17+
* [dice](https://github.com/cran/dice): Calculate probabilities of various dice-rolling events
18+
* [Rdice](https://github.com/gennaro-tedesco/Rdice): R package to simulate dice rolls, combinatorical and best choice problems.
19+
* [diceSyntax](https://github.com/oganm/diceSyntax): dice roller with standard syntax
20+
21+
This document shows a few of the use cases where another package might be more suitable for you.
22+
23+
### dice
24+
25+
```{r dice1}
26+
library(dice)
27+
```
28+
29+
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.
30+
31+
The first three examples are taken from the manual of the package.
32+
33+
```{r dice2}
34+
getEventProb(nrolls = 6,
35+
ndicePerRoll = 1,
36+
nsidesPerDie = 4,
37+
eventList = list(4, 3, c(1,2)),
38+
orderMatters = FALSE)
39+
```
40+
41+
```{r dice3}
42+
getEventProb(nrolls = 3,
43+
ndicePerRoll = 2,
44+
nsidesPerDie = 6,
45+
eventList = list(10, 4, c(2:6, 8:12)),
46+
orderMatters = TRUE)
47+
```
48+
49+
The function `getSumProbs()` is more straightforward.
50+
51+
```{r dice4}
52+
getSumProbs(ndicePerRoll = 5,
53+
nsidesPerDie = 6,
54+
nkept = 3,
55+
dropLowest = TRUE)
56+
```
57+
58+
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.
59+
60+
```{r dice5}
61+
probs <- getSumProbs(ndicePerRoll = 2,
62+
nsidesPerDie = 6,
63+
nkept = 2)
64+
probs <- data.frame(probs$probabilities)
65+
ggplot(probs) + geom_col(aes(x=Sum, y=Ways.to.Roll)) + scale_x_discrete(limits=probs$Sum)
66+
```
67+
68+
### Rdice
69+
70+
The package `Rdice` contains a set of function that can do similar things as `alea`.
71+
72+
```{r Rdice1}
73+
library(Rdice)
74+
```
75+
76+
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.
77+
78+
The following example is taken from the help page of the function an casts 3 6-sided dice 5 times each.
79+
80+
```{r Rdice2}
81+
dice.roll(faces = 6, dice = 3, rolls = 5)
82+
```
83+
84+
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`).
85+
86+
The package contains a [vignette](https://github.com/gennaro-tedesco/Rdice/blob/master/vignettes/Rdice-vignette.pdf) with more detailed explanations.
87+
88+
### diceSyntax
89+
90+
The package `diceSyntax` contains several functions but only documentation for `roll`.
91+
92+
The package is only available on github.
93+
94+
```{r diceSyntax1, eval=FALSE}
95+
devtools::install_github("oganm/diceSyntax")
96+
```
97+
98+
```{r diceSyntax2}
99+
library(diceSyntax)
100+
```
101+
102+
The interesting part of this package is that you can pass dice events like `4d6` in order to cast 4 6-sided dice.
103+
104+
```{r diceSyntax3}
105+
roll("4d6")
106+
```
107+
108+
More examples (e.g., keep highest/lowest 3, ...) can be found in the [README of diceSyntax](https://github.com/oganm/diceSyntax).

misc/package_comparison.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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+
![](package_comparison_files/figure-markdown_github/dice5-1.png)
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

Comments
 (0)