Main Features
distr6 is not intended to replace the base R distributions function but instead to give an alternative that focuses on distributions as objects that can be manipulated and accessed as required. The main features therefore centre on OOP practices, design patterns and API design. Of particular note:
All distributions in base R introduced as objects with methods for common statistical functions including pdf, cdf, inverse cdf, simulation, mean, variance, skewness and kurtosis
B <- Binomial$new(prob = 0.5, size = 10)
B$pdf(1:10)
#> [1] 0.0097656250 0.0439453125 0.1171875000 0.2050781250 0.2460937500
#> [6] 0.2050781250 0.1171875000 0.0439453125 0.0097656250 0.0009765625
B$kurtosis()
#> [1] -0.2
B$rand(5)
#> [1] 7 7 4 7 6
summary(B)
#> Binomial Probability Distribution. Parameterised with:
#> prob = 0.5, qprob = 0.5, size = 10
#>
#> Quick Statistics
#> Mean: 5
#> Variance: 2.5
#> Skewness: 0
#> Ex. Kurtosis: -0.2
#>
#> Support: {0, 1,...,9, 10} Scientific Type: ℕ0
#>
#> Traits: discrete; univariate
#> Properties: symmetric; platykurtic; no skew
Flexible construction of distributions for common parameterisations
Exponential$new(rate = 2)
#> Exp(rate = 2, scale = 0.5)
Exponential$new(scale = 2)
#> Exp(rate = 0.5, scale = 2)
Normal$new(mean = 0, prec = 2)
#> Norm(mean = 0, var = 0.5, sd = 0.707106781186548, prec = 2)
Normal$new(mean = 0, sd = 3)$parameters()
#> id value support description
#> 1: mean 0 ℝ Mean - Location Parameter
#> 2: var 9 ℝ+ Variance - Squared Scale Parameter
#> 3: sd 3 ℝ+ Standard Deviation - Scale Parameter
#> 4: prec 0.1111111 ℝ+ Precision - Inverse Squared Scale Parameter
Decorators for extending functionality of distributions to more complex modelling methods
B <- Binomial$new()
decorate(B, "ExoticStatistics")
#> Binomial is now decorated with ExoticStatistics
#> Binom(prob = 0.5, qprob = 0.5, size = 10)
B$survival(2)
#> [1] 0.9453125
decorate(B, "CoreStatistics")
#> Binomial is now decorated with CoreStatistics
#> Binom(prob = 0.5, qprob = 0.5, size = 10)
B$kthmoment(6)
#> Results from numeric calculations are approximate only. Better results may be available.
#> [1] 190
S3 compatibility to make the interface more flexible for users who are less familiar with OOP
B <- Binomial$new()
mean(B) # B$mean()
#> [1] 5
variance(B) # B$variance()
#> [1] 2.5
cdf(B, 2:5) # B$cdf(2:5)
#> [1] 0.0546875 0.1718750 0.3769531 0.6230469
Wrappers including truncation, huberization and product distributions for manipulation and composition of distributions.
B <- Binomial$new()
TruncatedDistribution$new(B, lower = 2, upper = 5) #Or: truncate(B,2,5)
#> TruncBinom(Binom__prob = 0.5, Binom__qprob = 0.5,...,trunc__lower = 2, trunc__upper = 5)
N <- Normal$new()
MixtureDistribution$new(list(B,N), weights = c(0.1, 0.9))
#> Binom wX Norm
ProductDistribution$new(list(B,N))
#> Binom X Norm
Additionally set6 is used for symbolic representation of sets for Distribution typing