Added analytic implementations for score() and
hessian() (both observed and expected) for many of the
classic distributions, including fast C implementations that can be
parallelized and that can compute both score and Hessian in a single
call if needed, e.g., for implementing Newton-type optimization steps
(#137 and #138 and #139 and #143 and #145 by Reto Stauffer). More
distributions and methods will be added in the next versions.
Functionality for automatically setting up testthat
test suites that test the infrastructure for a distribution for a number
of valid and invalid parameter combinations. These are not included in
the package but can be found on GitHub at https://github.com/zeileis/distributions3/tree/main/tests/testthat
(#145 and #146 by Reto Stauffer). The tests compare analytic
implementations with the numeric fallback methods (e.g., for moments and
derivatives) and assure consistent handling of function inputs, outputs,
errors, etc.
Added checks for valid parameters in distribution construction
functions, e.g., making sure in Normal(mu, sigma) that both
mu and sigma can be coerced to numeric and
that sigma is non-negative (#135 and #145 by Reto Stauffer
and Achim Zeileis).
Streamline dots ... handling in prodist
generic/methods (#140 and #141 by Achim Zeileis).
Change order of parameters/arguments for zero-inflated and hurdle
count distributions (Poisson and negative binomial) to list the
probability pi (for zero-inflation or hurdle crossing,
respectively) before the count parameters lambda or
mu/theta, respectively (#145 and #149 by Achim
Zeileis).
Computing many densities/probabilities/quantiles for a single
distribution is handled more efficiently by a single call in
apply_dpqr() now (#147 and #151 by Achim Zeileis).
Rename the generalized Pareto distribution from GP()
to the somewhat more explicit GPareto() (#136 and #145 by
Reto Stauffer and Achim Zeileis).
New Empirical() distribution based on a random
sample. This is particularly useful when forecasts are
represented by samples rather than by parametric distributions (#98 and
#120 by Reto Stauffer).
New SinhArcsinh() distribution implementing the
Sinh-Arcsinh distribution from Jones and Pewsey (2009,
Biometrika) (#128 by Reto Stauffer).
Fallback methods for all standard distributions3
methods such as cdf(), pdf(),
quantile(), random(), and moments such as
mean(), variance(), skewness(),
and kurtosis(). These leverage those methods that are
available but fill the gaps using numerical integration/differentiation
(#120 by Reto Stauffer).
New generic functions score() and
hessian() to compute the score (first derivative of the
log-likelihood with respect to the parameters) and Hessian
(corresponding second derivative). There are numeric fallback methods
for general distribution objects and analytic methods for a few
distributions. The hessian() methods should typically have
an argument expected which allows to select whether the
observed (expected = FALSE) or expected
(expected = TRUE) Hessian should be computed. Some methods
may only support one or the other specification and throw an error
message otherwise (#124 and #128 by Reto Stauffer and Achim
Zeileis).
All distribution constructor functions such as
Poisson() and Binomial() now have default
arguments for all distribution parameters. Typically, these new defaults
are empty so that for example Poisson() yields a Poisson
distribution of length zero. Only those distributions which already
previously had a default such as Normal(mu = 0, sigma = 1)
yield a distribution of length one (#26 and #129 by Reto
Stauffer).
Methods for crps() function from the scoringRules
package for computing the (continuous) ranked probabiity score of a
distribution. This is a useful proper scoring rule as an alternative to
the log-likelihood. A numerical fallback method is provided as well (#88
and #120 by Reto Stauffer and Achim Zeileis).
Streamline the apply_dpqr() workhorse function to
avoid unnecessary computations more carefully (#123 and #125 by Achim
Zeileis).
Reduce the hard dependencies: ggplot2 is now a
“Suggests” dependency and the usage of glue is replaced by
base R function sprintf() (#126 and #125 by Achim
Zeileis).
Avoid using rlang::check_dots_used() multiple times
when calling a single method. For generic functions from
distributions3, such as cdf() and
variance() etc., the call to
rlang::check_dots_used() is directly in the generic. For
generic functions defined elsewhere, namely quantile() and
mean() from base R and crps() from
scoringRules, all methods call
rlang::check_dots_used() themselves (#127 by Reto
Stauffer).
Achim Zeileis (@zeileis) takes over maintenance from Alex Hayes (@alexpghayes). All URLs, links, and documentation updated correspondingly.
Fix incorrect moment calculations and documentation (reported by @vincenzocoia in #114, fixed by @zeileis in #115)
ggplot2 (#111)New PoissonBinomial() distribution, a generalization
of the binomial distribution. The Poisson binomial is characterized by n
independent Bernoulli trials but with potentially different success
probabilities. The
d/p/q/r functions
employ the efficient implementation from the PoissonBinomial
package, if available. In case it is not available, fallback computation
based on a normal approximation are provided - with a warning, by
default (#100).
The prodist() methods for various count regression
objects now distinguish between computations for the classic pscl package and the
newer countreg
package (currently on Codeberg, soon to be released to CRAN).
The simulate() method for distribution
objects is now better aligned with simulate.lm() in base R:
It now always returns a data.frame with seed
attribute.
New simulate() default method which leverages
prodist() and subsequently uses the simulate()
method for distribution objects.
New prodist() methods for distribution
objects which just returns the unmodified distribution
object itself.
The format() method - and hence the
print() method - for distribution objects has
been simplified. For example, now Normal(mu = 0, sigma = 1)
is used instead of Normal distribution (mu = 0, sigma = 1)
in order to yield a more compact output, especially for vectors of
distributions (#101).
Added an as.character() method which essentially
calls format(..., digits = 15, drop0trailing = TRUE). This
mimics the behavior and precision of base R for real vectors. Note that
this enables using match() for distribution
objects.
Added a duplicated() method which relies on the
corresponding method for the data.frame of parameters in a
distribution.
Enabled the inclusion of distribution vectors as
columns in tibble data objects, see
?vec_proxy.distribution for further details and a practical
example.
Fixed errors in notation of cumulative distribution function in
the documentation of HurdlePoisson() and
HurdleNegativeBinomial() (by @dkwhu in #94 and #96).
The prodist() method for glm objects
can now also handle family specifications from
MASS::negative.binomial(theta) with fixed
theta (reported by Christian Kleiber).
Replace ellipsis dependency by rlang as
the former will be deprecated/archived
(by @olivroy in
#105).
Further small improvements in methods and manual pages.
New generics is_discrete() and
is_continous() with methods for all distribution objects in
the package. The is_discrete() methods return
TRUE for every distribution that is discrete on the entire
support and FALSE otherwise. Analogously,
is_continuous() returns TRUE for every
distribution that is continuous on the entire support and
FALSE otherwise. Thus, for mixed discrete-continuous
distributions both methods should yield FALSE
(#90).
New logical argument elementwise = NULL in
apply_dpqr() and hence inherited in cdf(),
pdf(), log_pdf(), and quantile().
It provides type-safety when applying one of the functions to a vector
of distributions d to a numeric argument x
where both d and x are of length n > 1. By
setting elementwise = TRUE the function is applied
element-by-element, also yielding a vector of length n. By setting
elementwise = FALSE the function is applied for all
combinations yielding an n-by-n matrix. The default
elementwise = NULL corresponds to FALSE if
d and x are of different lengths and
TRUE if the are of the same length n > 1 (#87).
Extended support for various count data distributions, now enompassing both the Poisson and negative binomial distributions along with various adjustments for zero counts (hurdle, inflation, and truncation, respectively). More details are provided in the following items (#86).
New d/p/q/r
functions for hnbinom, zinbinom,
ztnbinom, and ztpois similar to the
corresponding nbinom and pois functions from
base R.
New HurdleNegativeBinomial(),
ZINegativeBinomial(), ZTNegativeBinomial(),
and ZTPoisson() distribution constructors along with the
corresponding S3 methods for the “usual” generics (except
skewness() and kurtosis()).
New prodist() methods for extracting the
fitted/predicted probability distributions from models estimated by
hurdle(), zeroinfl(), and
zerotrunc() objects from either the pscl
package or the countreg package.
Added argument prodist(..., sigma = "ML") to the
lm method for extracting the fitted/predicted probability
distribution from a linear regression model. In the previous version the
prodist() method always used the least-squares estimate of
the error variance (= residual sum of squares divided by the residual
degrees of freedom, n - k), as also reported by the
summary() method. Now the default is to use the
maximum-likelihood estimate instead (divided by the number of
observations, n) which is consistent with the logLik()
method. The previous behavior can be obtained by specifying
sigma = "OLS" (#91).
Similarly to the lm method the glm
method prodist(..., dispersion = NULL) now, by default,
uses the dispersion estimate that matches the
logLik() output. This is based on the deviance divided by
the number of observations, n. Alternatively,
dispersion = "Chisquared" uses the estimate employed in the
summary() method, based on the Chi-squared statistic
divided by the residual degrees of freedom, n - k.
Small improvements in methods for various distribution objects:
Added support() method for GEV-based distributions
(GEV(), GP(), Gumbel(),
Frechet()). Added a random() method for the
Tukey() distribution (using the inversion method).
Vectorized univariate distribution objects by Moritz Lang and
Achim Zeileis (#71 and #82). This allows representation of fitted
probability distributions from regression models. New helper functions
are provided to help setting up such distribution objects in a unified
way. In particular, apply_dpqr() helps to apply the
standard d/p/q/r
functions available in base R and many packages. The accompanying manual
page provides some worked examples and further guidance.
New vignette (by Achim Zeileis) on using
distributions3 to go from basic probability theory to
probabilistic regression models. Illustrated with Poisson GLMs for the
number of goals per team in the 2018 FIFA World Cup explained by the
teams’ ability differences. (#74)
New generic function prodist() to extract fitted
(in-sample) or predicted (out-of-sample) probability distributions from
model objects like lm, glm, or
arima. (#83)
Extended support for count data distributions (by Achim Zeileis): Alternative parameterization for negative binomial distribution (commonly used in regression models), zero-inflated Poisson, and zero-hurdle Poisson. (#80 and #81)
Added a plotting generic for univariate distributions (#56 by Paul Northrop).
Added support for the generalized extreme value (GEV), Frechet, Gumbel, reversed Weibull and generalized Pareto (GP) distributions (#52 by Paul Northrop)
Added support for the Erlang distribution (#54 by Alessandro Gasparini).
Various minor bug fixes.
distributions3 for CRAN.Added a NEWS.md file to track changes to the
package.
Initial release.