Changelog
RTMBdist 1.2.0
One-step-ahead (OSA) residuals via
method = "cdf"are now available for many more distributions. During taping,pskewnorm(),pskewnorm2(),pskewt(),pskewt2()andpvm()integrate the density numerically with the AD-compatibleintegrate()ofRTMB, which is therefore now required in version 2.0 or later. Added distribution functions for the beta-binomial (pbetabinom(),pztbetabinom(),pzibetabinom(),phbetabinom()) and the beta-negative binomial (pbnbinom(),pbnbinom2()), which sum the probability mass function, and for the Skellam distribution (pskellam()), which integrates it over the first mean. OSA residuals are supported for all of these and for the wrapped Cauchy. For the two circular distributions, the circle is cut at the fixed origin-pi, which keeps the residuals valid for hidden Markov and random effects models. Also fixed OSA residuals and simulation fordztbinom(),dztnbinom()anddztnbinom2(), andNaNOSA residuals fordcombinom()when an observation equalssize.Fixed two distribution functions that gave wrong values, and with them wrong OSA residuals:
pzigamma()andpzigamma2()used the scale as a rate, so they were wrong wheneverscalewas not 1, andpzibinom()left out the binomial zeros atq = 0.Fixed derivatives of several distribution functions, which matter for gradients,
sdreport()and the Laplace approximation.pt.ad()had a zero derivative at 0, which gave wrong gradients inpt2(),pbct(),ptrunct()andptrunct2()atq = mu, and made the derivative ofdskewt()andpskewt()with respect toskewzero atskew = 0; the caution against startingskewat zero is therefore gone.ppowerexp(),ppowerexp2()andpbcpe()hadNaNgradients atq = mu,pfoldnorm()could not be differentiated with respect toq, andpgenpois()not with respect to its parameters, so its OSA residuals failed with estimated parameters. The gamma-based distribution functions (pgamma2(),pzigamma(),pzigamma2(),pgengamma(),pinvgamma(),pinvchisq()) had non-finite second or third derivatives for small arguments, inherited fromRTMB’spgamma(), which is now worked around.dskewnorm(),dskewnorm2()anddexgauss()are now accurate far in the tails. They usedlog(1e-300 + pnorm(...)), which cut the log density off there and made its gradient zero, and now usepnorm(..., log.p = TRUE).dinvgamma(),pinvgamma(),qinvgamma()andrinvgamma()can now be called withscaleinstead ofrate, which previously failed. As instats::dgamma(), giving both is an error.Fixed the copula densities
cgumbel()andcfrank(), which were wrong: the last factor of the Gumbel density and the sign in the denominator of the Frank density were incorrect, so neither integrated to one and likelihoods built with them throughdcopula()were wrong. Both now agree with thecopulapackage. The Frank density is also evaluated in a form that stays accurate for strong dependence. The copula distribution functionsCgumbel()andCfrank(), used withddcopula(), were correct and are unchanged.Added two circular-linear copula constructors for use with
dcopula(), joining a circular and a linear margin such as the turning angles and step lengths of an animal track.cjw()is the Johnson-Wehrly copula with any circular binding density, e.g.cjw(dvm, mu = 0, kappa = 2)orcjw(dwrpcauchy, mu = 0, rho = 0.5). Its dependence is a helix, so it is not symmetric in the sign of the angle.cfold()folds any of the linear copulas into a circular-linear copula that is symmetric, e.g.cfold(cgaussian(0.5)), and so links the straightness of a step to its length; this is the rectangular patchwork copula of Hodel and Fieberg (2022). Both allow for automatic differentiation.Added the distribution function (
pwrpcauchy()) and quantile function (qwrpcauchy()) of the wrapped Cauchy distribution, both in closed form. By default the circle is cut open at the antipode of the mean direction,mu - pi, the same origin as the default ofpvm(), sopwrpcauchy(mu)is one half and angles outside(mu - pi, mu + pi]are wrapped onto that interval. A fixed origin can be set withfrom; this is needed whenever the distribution function is averaged over different values ofmu, for example over hidden states or a random effect, because the average of distribution functions with different cuts is not a distribution function.pwrpcauchy()is differentiable, which makes the wrapped Cauchy usable as the turning-angle margin in copula models for step lengths and turning angles.rwrpcauchy()now generates by inversion ofpwrpcauchy()instead of callingcircular::rwrappedcauchy(), so it recycles vector parameters. Random streams for a given seed differ from earlier versions, and withwrap = FALSEthe angles now lie in[mu - pi, mu + pi]rather than[0, 2 * pi).Added the half-t (
dhalft()) and half-Cauchy (dhalfcauchy()) distributions, each with matchingp,qandrfunctions. These are the standard weakly informative priors for the standard deviation of a hierarchical model, so they are aimed squarely at models fitted by the Laplace approximation. Both distribution functions are differentiable, andphalft()differentiates with respect todfas well assigma, so the degrees of freedom can be estimated rather than fixed; one-step-ahead residuals viamethod = "cdf"are supported. The half-Cauchy is the half-t withdf = 1, and the half-normal isdfoldnorm()withmu = 0, which the half-t approaches asdfgrows.Added the Yule-Simon (
dyules()) and Waring (dwaring()) distributions, two classical long-tailed count laws, each with matchingpandrfunctions. Both are beta-geometric special cases of the beta-negative binomial, withsizefixed at one, and that restriction is what gives them a closed-form distribution function where the general beta-negative binomial has none. One-step-ahead residuals viamethod = "cdf"are available.dyules()followsVGAMand is supported on the positive integers, whiledwaring()follows theWARINGfamily ofgamlss.dist, starts at zero and hasmuas its mean. TheYULEfamily ofgamlss.distisdwaring(x, mu, mu).Added the beta-negative binomial distribution (
dbnbinom()) and its mean parameterisation (dbnbinom2()), each with a matchingrfunction. It is to the negative binomial what the beta-binomial is to the binomial, and its extra beta layer gives a considerably heavier tail. Indbnbinom2(), which follows theBNBfamily ofgamlss.dist,muis exactly the mean; this is the more stable parameterisation to estimate in, because the original one has a long likelihood ridge along whichsizeandshape2trade off. The distribution function has no closed form and is summed from the probability mass function, see above.Added the extreme value distributions: the generalised extreme value distribution (
dgev()), the generalised Pareto distribution (dgpd()) and the Frechet distribution (dfrechet()), each with matchingp,qandrfunctions. The first two cover their three shape regimes with a single expression rather than a branch on the sign ofxi, so the derivative with respect to the shape is exact atxi = 0, which is the usual starting value when the shape is estimated. Densities and distribution functions are differentiable, so simulation and one-step-ahead residuals viamethod = "cdf"are supported. UnlikeVGAM,evdandextraDistr,dgpd()returns1 / sigmarather than zero at the threshold itself, matchingstats::dexp()at zero.RTMBdistno longer masks anything instats. The AD-compatible replacements forstats::pt(),stats::plnorm(),stats::dgeom()andstats::pgeom()are exported aspt.ad(),plnorm.ad(),dgeom.ad()andpgeom.ad(), and are reached through internal S4 generics that dispatch on the argument classes: plain numeric input goes to thestatsversions, AD variables to the.adversions. Previouslypt()was exported with a reduced argument list, sopt(q, df, lower.tail = FALSE)failed for anyone who had loaded the package. As a side effectlower.tailandlog.pnow also work forpt()under automatic differentiation.Added the zero-inflated (
dzigeom()), zero-truncated (dztgeom()) and hurdle (dhgeom()) geometric distributions. These build onRTMB‘s AD-compatible negative binomial withsize = 1, sostats’ owndgeom()and friends are left untouched.Added the zero-inflated, zero-truncated and hurdle beta-binomial distributions (
dzibetabinom(),dztbetabinom(),dhbetabinom()). Their distribution functions are summed from the probability mass function, see above.The documentation of the continuous zero-inflated distributions now explains that, because the continuous part places no mass at zero,
zeroprobis exactly the probability of a zero and zero-inflation coincides with a hurdle model; GAMLSS calls these zero-adjusted rather than zero-inflated.Added the hurdle (zero-altered) count distributions: Poisson (
dhpois()), binomial (dhbinom()), negative binomial (dhnbinom()) and its mean parameterisation (dhnbinom2()), each with matchingpandrfunctions. In a hurdle distribution the probability of a zero is a free parameter and the positive counts follow the corresponding zero-truncated distribution. Unlike zero-inflation, which can only add zeros, a hurdle model allowszeroprobto be smaller than the Poisson would give on its own. The density and distribution function are both differentiable, so simulation and one-step-ahead residuals viamethod = "cdf"are supported.Fixed
pztnbinom()andpztnbinom2(), which returnedNaNinstead of 0 for quantiles below their support.
RTMBdist 1.1.0
CRAN release: 2026-09-06
Added the Johnson SU distribution in both the original parameterisation (
djsu(),pjsu(),qjsu(),rjsu()) and the moment parameterisation (djsu2(),pjsu2(),qjsu2(),rjsu2()), a four-parameter distribution on the real line covering a wide range of skewness and kurtosis. Indjsu2()the location and scale arguments are exactly the mean and standard deviation. The density and distribution function are both differentiable, so simulation and one-step-ahead residuals are supported. Unlikegamlss.dist, the reparameterisation stays finite for very largetau, where the distribution approaches the normal.Added references to the primary source for each distribution derived from
gamlss.dist, and cross-links between related families.pgenpois()and friends previously had no references at all.Removed the dependency on
gamlss.dist, which is scheduled for archival on CRAN. The quantile and random generation functions of the Box-Cox Cole-Green (qbccg(),rbccg()), Box-Cox t (qbct(),rbct()), Box-Cox power exponential (qbcpe(),rbcpe()), power exponential (qpowerexp(),rpowerexp(),qpowerexp2(),rpowerexp2()), Pareto (qpareto(),rpareto()), generalised Poisson (pgenpois(),qgenpois(),rgenpois()) and exponentially modified Gaussian (qexgauss()) distributions are now implemented natively. Results are unchanged except for the fixes below.Fixed argument recycling in
qbccg(),qbct(),qbcpe(),qgenpois()andpgenpois(). Evaluating a single quantile against vectorised parameters previously collapsed the result to length one, and a parameter vector shorter thanxsilently truncated it. These functions now return one value per recycled argument tuple.Fixed
qbct()andrbct(), which failed with an error whenmu,sigmaortauwas supplied as a vector.qpareto()now honourslower.tail, which was previously accepted but ignored.log.p = TRUEnow works inqpareto(),qbct()andqgenpois(). These previously validatedpbefore transforming it back from the log scale, so the argument could not be used.qexgauss()is substantially more accurate. It invertspexgauss()with a tighter convergence tolerance, reducing the round-trip error|p(q(p)) - p|from roughly 1e-6 to roughly 1e-14.pgenpois()no longer falls back to the Poisson distribution forphi < 1e-4and evaluates the generalised Poisson distribution function across the whole parameter range.pbetaprime(),pinvchisq()andpinvgamma()are now differentiable, so one-step-ahead residuals viamethod = "cdf"are available for the beta prime, inverse chi-squared and inverse gamma distributions.Added the Bell distribution (
dbell(),pbell(),qbell(),rbell()) and its mean parameterisation (dbell2(),pbell2(),qbell2(),rbell2()), a one-parameter distribution for overdispersed counts. Log Bell numbers are used throughout and cached, so the density stays finite well past the point at which the Bell numbers themselves overflow double precision. One-step-ahead residuals are supported viamethod = "cdf".Added
lambertW(), an AD-compatible implementation of the principal branch of the Lambert W function. Derivatives of all orders are exact, so it can be used in models fitted by Laplace approximation.Added the Conway-Maxwell-binomial distribution (
dcombinom(),pcombinom(),qcombinom(),rcombinom()), a binomial generalisation with an additional dispersion parameternu. The density and distribution function are differentiable with respect tox, so one-step-ahead residuals are supported.