Experimental lifecycle

dist_wrap(dist, ..., package = "stats")

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.

Details

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.

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] 8.4509168 -1.8957457 1.1058851 2.5715703 1.3184340 2.1167816 #> [7] 3.5252969 6.5824261 -2.0311212 0.4671039 #> #> [[2]] #> [1] 20.2192559 7.7097685 12.4263854 13.6148239 0.6995439 -0.2654376 #> [7] 13.2335574 3.2876717 -10.4679686 9.6014801 #> #> [[3]] #> [1] 3.305545 3.128651 4.722528 2.453397 4.121259 5.581537 6.048432 1.759274 #> [9] 4.010771 1.435945 #>
#> #> Attaching package: ‘actuar’
#> 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] 0.3760375 0.4256671 1.0826546 2.7082877 1.1292412 0.4583575 1.1193915 #> [8] 2.2116296 1.0619437 1.4243765 #>