If a distribution is not yet supported, you can vectorise p/d/q/r functions
using this function. dist_wrap()
stores the distributions parameters, and
provides wrappers which call the appropriate p/d/q/r functions.
Using this function to wrap a distribution should only be done if the distribution is not yet available in this package. If you need a distribution which isn't in the package yet, consider making a request at https://github.com/mitchelloharawild/distributional/issues.
dist_wrap(dist, ..., package = NULL)
The name of the distribution used in the functions (name that is prefixed by p/d/q/r)
Named arguments used to parameterise the distribution.
The package from which the distribution is provided. If NULL, the calling environment's search path is used to find the distribution functions. Alternatively, an arbitrary environment can also be provided here.
dist <- dist_wrap("norm", mean = 1:3, sd = c(3, 9, 2))
density(dist, 1) # dnorm()
#> [1] 0.13298076 0.04405414 0.12098536
cdf(dist, 4) # pnorm()
#> [1] 0.8413447 0.5879296 0.6914625
quantile(dist, 0.975) # qnorm()
#> [1] 6.879892 19.639676 6.919928
generate(dist, 10) # rnorm()
#> [[1]]
#> [1] 1.2972540 3.1616407 4.0014076 2.5839985 4.4908178 1.5194110 2.7337518
#> [8] 0.6519739 3.7135634 0.9502399
#>
#> [[2]]
#> [1] -6.3006767 -7.5410310 -14.0847968 -7.5989660 -8.1684625 5.4854102
#> [7] 13.4323704 -12.8150605 0.8875634 -6.7447659
#>
#> [[3]]
#> [1] 5.1371747 7.6325057 -0.3657468 3.2717509 3.9968755 5.6669259
#> [7] 2.9540909 2.6169535 2.1187702 -0.8828120
#>
library(actuar)
#>
#> Attaching package: ‘actuar’
#> The following objects are masked from ‘package:stats’:
#>
#> sd, var
#> The following object is masked from ‘package:grDevices’:
#>
#> cm
dist <- dist_wrap("invparalogis", package = "actuar", shape = 2, rate = 2)
density(dist, 1) # actuar::dinvparalogis()
#> [1] 0.512
cdf(dist, 4) # actuar::pinvparalogis()
#> [1] 0.9694675
quantile(dist, 0.975) # actuar::qinvparalogis()
#> [1] 4.429922
generate(dist, 10) # actuar::rinvparalogis()
#> [[1]]
#> [1] 2.4489800 0.5297217 1.1958833 1.8463625 0.5069038 0.6664091 0.7003416
#> [8] 0.5153026 0.5795374 5.1623398
#>