R/DistributionDecorator_FunctionImputation.R
FunctionImputation.Rd
This decorator imputes missing pdf/cdf/quantile/rand methods from R6 Distributions
by using strategies dependent on which methods are already present in the distribution. Unlike
other decorators, private methods are added to the Distribution, not public methods.
Therefore the underlying public [Distribution]$pdf
, [Distribution]$pdf
,
[Distribution]$quantile
, and [Distribution]$rand
functions stay the same.
Decorator objects add functionality to the given Distribution object by copying methods in the decorator environment to the chosen Distribution environment.
All methods implemented in decorators try to exploit analytical results where possible, otherwise numerical results are used with a message.
Other decorators:
CoreStatistics
,
ExoticStatistics
distr6::DistributionDecorator
-> FunctionImputation
packages
Packages required to be installed in order to construct the distribution.
methods
Returns the names of the available methods in this decorator.
Inherited methods
decorate()
Decorates the given distribution with the methods available in this decorator.
distribution
Distribution
Distribution to decorate.
n
(integer(1))
Grid size for imputing functions, cannot be changed after decorating.
Generally larger n
means better accuracy but slower computation, and smaller n
means worse accuracy and faster computation.
if (requireNamespace("GoFKernel", quietly = TRUE) &&
requireNamespace("pracma", quietly = TRUE)) {
pdf <- function(x) ifelse(x < 1 | x > 10, 0, 1 / 10)
x <- Distribution$new("Test",
pdf = pdf,
support = set6::Interval$new(1, 10, class = "integer"),
type = set6::Naturals$new()
)
decorate(x, "FunctionImputation", n = 1000)
x <- Distribution$new("Test",
pdf = pdf,
support = set6::Interval$new(1, 10, class = "integer"),
type = set6::Naturals$new(),
decorators = "FunctionImputation"
)
x <- Distribution$new("Test",
pdf = pdf,
support = set6::Interval$new(1, 10, class = "integer"),
type = set6::Naturals$new()
)
FunctionImputation$new()$decorate(x, n = 1000)
x$pdf(1:10)
x$cdf(1:10)
x$quantile(0.42)
x$rand(4)
}
#> Test is now decorated with FunctionImputation
#> Test is now decorated with FunctionImputation.
#> Results from numeric calculations are approximate only. Better results may be available.
#> Results from numeric calculations are approximate only. Better results may be available.
#> Results from numeric calculations are approximate only. Better results may be available.
#> [1] 4 4 5 3