Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

TruncatedDistribution

Distribution Truncation Wrapper


Description

A wrapper for truncating any probability distribution at given limits.

Details

The pdf and cdf of the distribution are required for this wrapper, if unavailable decorate with FunctionImputation first.

Truncates a distribution at lower and upper limits on a left-open interval, using the formulae

f_T(x) = f_X(x) / (F_X(upper) - F_X(lower))

F_T(x) = (F_X(x) - F_X(lower)) / (F_X(upper) - F_X(lower))

where f_T/F_T is the pdf/cdf of the truncated distribution T = Truncate(X, lower, upper) and f_X, F_X is the pdf/cdf of the original distribution. T is supported on (].

Super classes

Methods

Public methods


Method new()

Creates a new instance of this R6 class.

Usage
TruncatedDistribution$new(distribution, lower = NULL, upper = NULL)
Arguments
distribution

([Distribution])
Distribution to wrap.

lower

(numeric(1))
Lower limit to huberize the distribution at. If NULL then the lower bound of the Distribution is used.

upper

(numeric(1))
Upper limit to huberize the distribution at. If NULL then the upper bound of the Distribution is used.

Examples
TruncatedDistribution$new(
  Binomial$new(prob = 0.5, size = 10),
  lower = 2, upper = 4
)

# alternate constructor
truncate(Binomial$new(), lower = 2, upper = 4)

Method setParameterValue()

Sets the value(s) of the given parameter(s).

Usage
TruncatedDistribution$setParameterValue(
  ...,
  lst = NULL,
  error = "warn",
  resolveConflicts = FALSE
)
Arguments
...

ANY
Named arguments of parameters to set values for. See examples.

lst

(list(1))
Alternative argument for passing parameters. List names should be parameter names and list values are the new values to set.

error

(character(1))
If "warn" then returns a warning on error, otherwise breaks if "stop".

resolveConflicts

(logical(1))
If FALSE (default) throws error if conflicting parameterisations are provided, otherwise automatically resolves them by removing all conflicting parameters.


Method clone()

The objects of this class are cloneable with this method.

Usage
TruncatedDistribution$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Examples

## ------------------------------------------------
## Method `TruncatedDistribution$new`
## ------------------------------------------------

TruncatedDistribution$new(
  Binomial$new(prob = 0.5, size = 10),
  lower = 2, upper = 4
)

# alternate constructor
truncate(Binomial$new(), lower = 2, upper = 4)

distr6

The Complete R6 Probability Distributions Interface

v1.5.2
MIT + file LICENSE
Authors
Raphael Sonabend [aut, cre] (<https://orcid.org/0000-0001-9225-4654>), Franz Kiraly [aut], Peter Ruckdeschel [ctb] (Author of distr), Matthias Kohl [ctb] (Author of distr), Nurul Ain Toha [ctb], Shen Chen [ctb], Jordan Deenichin [ctb], Chengyang Gao [ctb], Chloe Zhaoyuan Gu [ctb], Yunjie He [ctb], Xiaowen Huang [ctb], Shuhan Liu [ctb], Runlong Yu [ctb], Chijing Zeng [ctb], Qian Zhou [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.