Generate a function that creates DISTRIBUTION
objects
Arguments
- distname
name of the distribution. By convention they are upper case
- rfunction
a function to generate random numbers from the distribution
- ovalfunc
a function that calculate the oval value, should used only the same arguments that the
rfunction
Value
A function that is able to create DISTRIBUTION
objects.
Note
The function return a new function, that have as arguments the formals
of the rfunction
plus a new argument dimnames
for the dimension
names. If The distribution is unidimensional, the default value
dimnames = "rvar"
will works well, but if not, the dimnames
argument should be specified when the generated function is used as in
the example for the new_MyDIRICHLET
Examples
new_MYDISTR <- DISTRIBUTION_factory("MYDISTR", rnorm, function(){mean})
d1 <- new_MYDISTR(0,1)
summary(d1)
#> distribution varname oval nsample mean_ sd_ lci_ median_
#> 1 MYDISTR rvar 0 10000 -0.009858114 1.012276 -2.000773 -0.01710083
#> uci_
#> 1 1.989833
require(extraDistr)
#> Loading required package: extraDistr
new_MyDIRICHLET <- DISTRIBUTION_factory('rdirichlet',
rdirichlet,
function() {
salpha = sum(alpha)
alpha / salpha
})
d2 <- new_MyDIRICHLET(c(10, 20, 70), dimnames = c("A", "B", "C"))
summary(d2)
#> distribution varname oval nsample mean_ sd_ lci_ median_
#> 1 RDIRICHLET A 0.1 10000 0.09965909 0.02975184 0.04904405 0.09726064
#> 2 RDIRICHLET B 0.2 10000 0.20059369 0.03940919 0.12952533 0.19847332
#> 3 RDIRICHLET C 0.7 10000 0.69974721 0.04472281 0.60793637 0.70023936
#> uci_
#> 1 0.1647623
#> 2 0.2819681
#> 3 0.7834416