Changelog
RTMBdist 1.2.1
CRAN release: 2026-11-06
-
mcreport()gains aparargument for the mean of the samples, which defaults toobj$env$last.par.bestas before. A supplied precision matrixQ, dense or sparse, is now used for models without random effects too instead of being ignored with a warning.Qmay also be the joint precision of the model parameters and trailing hyperparameters, such as log smoothing parameters, withpargiven for all coordinates; the hyperparameters are then sampled and dropped, so the parameter samples account for their uncertainty.
RTMBdist 1.2.0
CRAN release: 2026-10-31
Added the Poisson-inverse Gaussian (
dpig()) and Sichel (dsichel()) distributions, each with matchingpandrfunctions. The Poisson-inverse Gaussian is the standard alternative to the negative binomial for overdispersed counts: a Poisson whose mean follows an inverse Gaussian, parameterised as thePIGfamily ofgamlss.dist, so thatmuis the mean and the variance ismu + sigma * mu^2, the same as fordnbinom2()withsize = 1 / sigma. Compared with the negative binomial it has a heavier right tail and more zeros. The Sichel distribution, theSICHELfamily ofgamlss.dist, mixes the Poisson over a generalised inverse Gaussian instead and adds a shape parameternu; the Poisson-inverse Gaussian is its special casenu = -1/2. Both mass functions involve Bessel functions whose order grows with the count, whichbesselK()cannot evaluate for large counts and strong overdispersion because it overflows; for orders above 50, the uniform asymptotic expansion of the Bessel function is used instead, so the mass functions and their derivatives stay finite and accurate for any count.nucan be estimated, as the derivative with respect to the order is available. The distribution functions are summed from the mass functions, so one-step-ahead residuals viamethod = "cdf"are supported.Added the wrapped normal (
dwrpnorm()) and cardioid (dcard()) distributions, each with matchingpandrfunctions, joining the von Mises and wrapped Cauchy as turning-angle distributions for movement models and as binding densities forcjw(). The wrapped normal density is a sum over the windings of the normal density forsigma < 2and its Fourier series otherwise, each truncated where the remaining terms are below1e-20. The distribution functions are in closed form and cut the circle open wherepwrpcauchy()does, atmu - pior atfrom, and one-step-ahead residuals viamethod = "cdf"cut it at-pi, as for the other circular distributions.Added the generalised beta distribution of the second kind (
dgb2()) and its special cases, the Dagum (ddagum()), Singh-Maddala or Burr XII (dsinmad()) and Lomax or Pareto II (dlomax()) distributions, each with matchingp,qandrfunctions. These are the standard models for income, wealth and claim sizes. The distribution functions are incomplete beta functions, computed with the upper tail directly rather than as1 - p, and all of them are differentiable, so one-step-ahead residuals viamethod = "cdf"are supported. The log-logistic distributiondllogis()is the GB2 withshape2 = shape3 = 1.Added the Birnbaum-Saunders or fatigue life distribution (
dbisa()), with matchingp,qandrfunctions, the standard model for time to failure under cumulative damage. Density, distribution and quantile function are in closed form and differentiable, and both tails of the distribution function are accurate; the quantile function is written asscale * exp(2 * asinh(shape * z / 2)), which avoids the cancellation of the textbook formula for small probabilities.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 wrong gradients and Hessians of the distribution functions built on the incomplete beta function:
pbeta2(),qbeta2(),pbetaprime(),qbetaprime(),pzibeta(),pzoibeta(),poibeta(),pnbinom2(),pztnbinom(), the new GB2 family and the families built on these.RTMB’spbeta()andqbeta()(version 2.0) have wrong, often zero, derivatives in the shape parameters when a shape is an integer or half-integer, as for integer counts inpnbinom2()or integer starting values, and inaccurate second derivatives close to such values. This is fixed in the development version ofTMB; until it reaches CRAN, the shapes are moved slightly off these values and the results extrapolated back, which keeps values accurate to about1e-11.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.rskewt()andrskewt2()now recycle vector parameters. They calledsn::rst(), which is not vectorised over its parameters, and failed for example when simulating from a hidden Markov model with state-dependent parameters. The same held forpskewt(),qskewt(),pskewt2()andqskewt2()with vectorskewordf, which now callsn::pst()andsn::qst()once for each distinct pair ofskewanddf.rskewt()andrskewnorm()(and with themrskewt2()andrskewnorm2()) now draw from the stochastic representation of the skew normal and skew t distributions instead of calling thesnpackage, which is also much faster for vector parameters. Random streams for a given seed differ from earlier versions.pskewt(),pskewt2(),pskewnorm()andpskewnorm2()are now accurate in both tails. Outside of AD they used thesnpackage throughout, whose values are inaccurate in the tails: the upper tail was computed as1 - p, which loses all precision there,sn::psn()is far off in the light tail (e.g.7e-22instead of9e-31atz = -5,alpha = 2), andsn::pst()is off by over 1% beyond 30 scale units for non-integerdf. Where the requested tail probability is below1e-5orqis that far out, the tail is now integrated numerically, as is already done during taping, which also makeslog.p = TRUEaccurate where the probability underflows.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.Added three examples to the Worked Examples vignette: the five largest annual sea levels at Venice with a latent random-walk trend (
dgev(),pgev()), the ETAS model for earthquake aftershocks (dlomax(),plomax(),dgpd()), and pooling opinion polls with house effects (dbetabinom()).
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.