[Maturing]

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)

Arguments

dist

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.

package

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.

Examples

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.980932  3.361112  2.324679 -2.057914  0.523905 -3.913104  9.517799
#>  [8]  3.885457  2.525296  1.778570
#> 
#> [[2]]
#>  [1]  -4.9606371 -14.2497478   3.6054491  -2.7319958   5.6016768   0.8967117
#>  [7]   1.3578947  20.8616093  13.8987435  12.8050310
#> 
#> [[3]]
#>  [1] 1.436251 2.117047 2.507944 3.731584 2.931734 3.592454 2.557880 3.375412
#>  [9] 2.123876 2.822533
#> 

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] 1.2316339 0.3343603 1.4845823 0.4218931 0.5844361 0.7285893 0.7838197
#>  [8] 0.3745796 0.8046028 0.3037495
#>