Discrete Distribution Approximations

distcrete takes a distribution and a set of parameters and returns a list object with functions as elements. Each one is the equivalent to the function calls we typically expect to be able to do in R for a given distribution:

• Density e.g.dnorm
• Distribution function e.g. pnorm
• Quantile function e.g. qnorm
• Random generation e.g. rnorm

Each function created by distcrete corresponds to the first letter of the non-discrete equivalent.

set.seed(415)
d0 <- distcrete::distcrete("gamma", 1, shape = 3, w = 0)
d0$d(1:10) #> [1] 0.243022187 0.253486335 0.185086776 0.113451286 0.062683215 #> [6] 0.032332641 0.015882196 0.007521773 0.003462799 0.001558522 d0$p(c(.1,.5))
#> [1] 0.09958372 0.19115317
d0$q(c(.1,.5)) #> [1] 0 1 d0$r(10)
#>  [1]  2  3  1  2 12  2  2  4  5  3

## Allowed distributions

You can use any distribution that conforms to the following expectations:

• It has a distribution function like p[dist name] available
• It has a quantile function like q[dist name] available

These can be loaded from a package or created on the fly, but must exist when the distcrete() function is called.

## Installation

You can install it from CRAN with:

install.packages("distcrete")

You can install distcrete the most up to date version from github with:

# install.packages("devtools")
devtools::install_github("reconhub/distcrete")

## Tests

devtools::test()
#> Testing distcrete
#> Warning: encoding is deprecated; all files now assumed to be UTF-8
#> ✔ | OK F W S | Context
#>
⠏ |  0       | distcrete
⠋ |  1       | distcrete
⠙ |  2       | distcrete
⠹ |  3       | distcrete
⠸ |  4       | distcrete
⠼ |  5       | distcrete
⠴ |  6       | distcrete
⠦ |  7       | distcrete
⠧ |  8       | distcrete
⠇ |  9       | distcrete
⠏ | 10       | distcrete
⠋ | 11       | distcrete
⠙ | 12       | distcrete
⠹ | 13       | distcrete
⠸ | 14       | distcrete
⠼ | 15       | distcrete
⠴ | 16       | distcrete
⠦ | 17       | distcrete
⠧ | 18       | distcrete
⠇ | 19       | distcrete
⠏ | 20       | distcrete
⠋ | 21       | distcrete
⠙ | 22       | distcrete
⠹ | 23       | distcrete
⠸ | 24       | distcrete
⠼ | 25       | distcrete
⠴ | 26       | distcrete
⠦ | 27       | distcrete
⠧ | 28       | distcrete
⠇ | 29       | distcrete
⠏ | 30       | distcrete
⠋ | 31       | distcrete
⠙ | 32       | distcrete
⠹ | 33       | distcrete
⠸ | 34       | distcrete
⠼ | 35       | distcrete
⠴ | 36       | distcrete
⠦ | 37       | distcrete
⠧ | 38       | distcrete
⠇ | 39       | distcrete
⠏ | 40       | distcrete
⠋ | 41       | distcrete
⠙ | 42       | distcrete
⠹ | 43       | distcrete
⠸ | 44       | distcrete
⠼ | 45       | distcrete
⠴ | 46       | distcrete
⠦ | 47       | distcrete
⠧ | 48       | distcrete
⠇ | 49       | distcrete
⠏ | 50       | distcrete
⠋ | 51       | distcrete
⠙ | 52       | distcrete
⠹ | 53       | distcrete
⠸ | 54       | distcrete
⠼ | 55       | distcrete
⠴ | 56       | distcrete
⠦ | 57       | distcrete
⠧ | 58       | distcrete
⠇ | 59       | distcrete
⠏ | 60       | distcrete
⠋ | 61       | distcrete
⠙ | 62       | distcrete
⠹ | 63       | distcrete
⠸ | 64       | distcrete
⠼ | 65       | distcrete
⠴ | 66       | distcrete
⠦ | 67       | distcrete
⠧ | 68       | distcrete
⠇ | 69       | distcrete
⠏ | 70       | distcrete
⠋ | 71       | distcrete
⠙ | 72       | distcrete
⠹ | 73       | distcrete
⠸ | 74       | distcrete
⠼ | 75       | distcrete
⠴ | 76       | distcrete
⠦ | 77       | distcrete
⠧ | 78       | distcrete
⠇ | 79       | distcrete
⠏ | 80       | distcrete
⠋ | 81       | distcrete
⠙ | 82       | distcrete
⠹ | 83       | distcrete
⠸ | 84       | distcrete
⠼ | 85       | distcrete
⠴ | 86       | distcrete
⠦ | 87       | distcrete
⠧ | 88       | distcrete
⠇ | 89       | distcrete
⠏ | 90       | distcrete
⠋ | 91       | distcrete
⠙ | 92       | distcrete
⠹ | 93       | distcrete
⠸ | 94       | distcrete
⠼ | 95       | distcrete
⠴ | 96       | distcrete
⠦ | 97       | distcrete
⠧ | 98       | distcrete
⠇ | 99       | distcrete
⠏ | 100       | distcrete
⠋ | 101       | distcrete
⠙ | 102       | distcrete
⠹ | 103       | distcrete
⠸ | 104       | distcrete
⠼ | 105       | distcrete
⠴ | 106       | distcrete
⠦ | 107       | distcrete
⠧ | 108       | distcrete
⠇ | 109       | distcrete
⠏ | 110       | distcrete
⠋ | 111       | distcrete
⠙ | 112       | distcrete
⠹ | 113       | distcrete
⠸ | 114       | distcrete
⠼ | 115       | distcrete
⠴ | 116       | distcrete
⠦ | 117       | distcrete
⠧ | 118       | distcrete
⠇ | 119       | distcrete
⠏ | 120       | distcrete
⠋ | 121       | distcrete
⠙ | 122       | distcrete
⠹ | 123       | distcrete
⠸ | 124       | distcrete
⠼ | 125       | distcrete
⠴ | 126       | distcrete
⠦ | 127       | distcrete
⠧ | 128       | distcrete
⠇ | 129       | distcrete
⠏ | 130       | distcrete
⠋ | 131       | distcrete
⠙ | 132       | distcrete
⠹ | 133       | distcrete
✔ | 133       | distcrete [0.3 s]
#>
⠏ |  0       | utils
⠋ |  1       | utils
⠙ |  2       | utils
⠹ |  3       | utils
⠸ |  4       | utils
⠼ |  5       | utils
⠴ |  6       | utils
⠦ |  7       | utils
⠧ |  8       | utils
⠇ |  9       | utils
⠏ | 10       | utils
⠋ | 11       | utils
⠙ | 12       | utils
⠹ | 13       | utils
⠸ | 14       | utils
⠼ | 15       | utils
✔ | 15       | utils
#>
#> ══ Results ════════════════════════════════════════════════════════════════
#> Duration: 0.3 s
#>
#> OK:       148
#> Failed:   0
#> Warnings: 0
#> Skipped:  0