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.

Details

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.

See also

Other decorators: CoreStatistics, ExoticStatistics

Super class

distr6::DistributionDecorator -> FunctionImputation

Public fields

packages

Packages required to be installed in order to construct the distribution.

Active bindings

methods

Returns the names of the available methods in this decorator.

Methods

Inherited methods


Method decorate()

Decorates the given distribution with the methods available in this decorator.

Usage

FunctionImputation$decorate(distribution, n = 1000)

Arguments

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.


Method clone()

The objects of this class are cloneable with this method.

Usage

FunctionImputation$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

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