Learn R Programming

distr6 (version 1.3.1)

WeightedDiscrete: WeightedDiscrete Distribution Class

Description

Mathematical and statistical functions for the WeightedDiscrete distribution, which is commonly used in empirical estimators such as Kaplan-Meier.

Value

Returns an R6 object inheriting from class SDistribution.

Constructor

WeightedDiscrete$new(data, decorators = NULL, verbose = FALSE)

Constructor Arguments

Argument Type Details
data data.frame matrix-style object of observations and probabilities. See details.

decorators Decorator decorators to add functionality. See details.

Constructor Details

The WeightedDiscrete distribution is parameterised with an object that can be coerced to a data.frame containing columns 'sample' and at least one of 'pdf' and 'cdf', see examples.

Public Variables

Variable Return
name Name of distribution.
short_name Id of distribution.
description Brief description of distribution.

Public Methods

Accessor Methods Link
decorators() decorators
traits() traits
valueSupport() valueSupport
variateForm() variateForm
type() type
properties() properties
support() support
symmetry() symmetry
sup() sup
inf() inf
dmax() dmax
dmin() dmin
skewnessType() skewnessType
kurtosisType() kurtosisType

Statistical Methods

Link
pdf(x1, ..., log = FALSE, simplify = TRUE) pdf
cdf(x1, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE) cdf
quantile(p, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE) quantile.Distribution
rand(n, simplify = TRUE) rand
mean() mean.Distribution
variance() variance
stdev() stdev
prec() prec
cor() cor
skewness() skewness
kurtosis(excess = TRUE) kurtosis
entropy(base = 2) entropy
mgf(t) mgf
cf(t) cf
pgf(z) pgf
median() median.Distribution
iqr() iqr

Parameter Methods

Link
parameters(id) parameters
getParameterValue(id, error = "warn") getParameterValue
setParameterValue(..., lst = NULL, error = "warn") setParameterValue

Validation Methods

Link
liesInSupport(x, all = TRUE, bound = FALSE) liesInSupport
liesInType(x, all = TRUE, bound = FALSE) liesInType

Representation Methods

Link
strprint(n = 2) strprint
print(n = 2) print
summary(full = T) summary.Distribution

Details

The WeightedDiscrete distribution is defined by the pmf, $$f(x_i) = p_i$$ for \(p_i, i = 1,\ldots,k; \sum p_i = 1\).

The distribution is supported on \(x_1,...,x_k\).

Sampling from this distribution is performed with the sample function with the elements given as the x values and the pdf as the probabilities. The cdf and quantile assumes that the elements are supplied in an indexed order (otherwise the results are meaningless).

References

McLaughlin, M. P. (2001). A compendium of common probability distributions (pp. 2014-01). Michael P. McLaughlin.

See Also

listDistributions for all available distributions. sample for the sampling function and Empirical for the closely related Empirical distribution.

Examples

Run this code
# NOT RUN {
x = WeightedDiscrete$new(data = data.frame(x = 1:3, pdf = c(1/5, 3/5, 1/5)))
WeightedDiscrete$new(data = data.frame(x = 1:3, cdf = c(1/5, 4/5, 1))) # equivalently

# d/p/q/r
x$pdf(1:5)
x$cdf(1:5) # Assumes ordered in construction
x$quantile(0.42) # Assumes ordered in construction
x$rand(10)

# Statistics
x$mean()
x$variance()

summary(x)

# }

Run the code above in your browser using DataLab