inlavanilla 26.12.01
A Hessian from the hook
hess_modeofvanilla_core()now counts in the budget of the VB correction (vb_budget) as the calls that it replaces. Withouthess, these are the central differences of the gradient: 2m gradient calls and the search for their steps, which the engine works out from the diagonal of the Hessian without callinglogpost. Withhessas well, the hook replaces one call ofhessand counts as that one call. Before, the hook counted as one call in every case and its step search was left out, so the cap on the solve after a failed one-step check was far lower with the hook than without it, and such a fit could stop short where the same fit without the hook went on. Now a fit almost always has the same cap with or without the hook, and so the same VB correction to the error of the differences. The worked-out step search can differ from the real one near a test value of the search, or after a restart of the mode search, and the cap can then differ by a sweep. This matters only to a package that holds a copy of the engine and passes the hook, such as INLAvaan, and only to its fits that fail the one-step check.inla_vanilla()does not take the hook, and its fits do not change at all.The help of
inla_vanilla()and ofvb_budgetinvanilla_control()now says that withhessthe cap of the VB solve is lower than withgradalone.nlminb()useshessand usually makes fewer calls, so a fit that fails the one-step check can stop its solve sooner and land elsewhere than the same fit withouthess. A largervb_budgetnarrows the difference, andInfremoves it. Fits do not change.
inlavanilla 26.11.29-1
- The diagnostics warning’s line on the Gaussian marginals of the unscanned parameters (the
gaussian_marginalsofvanilla_core()) named all of them after any flagged VB bullet, also when none had moved. It now names only those whose own VB shift, or step still to go, is over 0.1 SDs, and is left out when there are none: a line on parameters that did not move is no use.
inlavanilla 26.11.29
-
The hook
gaussian_marginalsofvanilla_core()has changed (INLAvaan issue 37). This matters only to a package that holds a copy of the engine and passes the hook, and it changes the behaviour that the engine vignette documents.inla_vanilla()does not expose the hook, and its fits are unchanged, to the last bit.Before, a parameter of the hook kept a VB shift of zero and got the Gaussian marginal at the mode. Now it takes the VB shift like every other parameter, on every route of
vb_correction, and gets the Gaussian marginal at the VB mean, with the Laplace SD. It is still not scanned. Itsvb_shift,vb_shift_sigmaandkldhold their real values, and the VB checks apply to it. A fit with the hook now has the mode, the VB mean and the log marginal likelihood of the same fit without it.The reason is that such a parameter can depend on the others, as an intercept with a normal prior that is not flat does. The condition of the hook is now only that the log-posterior is exactly quadratic along each of its axes with the other parameters fixed. A parameter that depends on the others has a posterior mean away from its mode, and a shift held at zero also made the VB term of the log marginal likelihood wrong, in most fits too large. On a normal mean with a N(0, 1) prior and 20 observations, that mean was 0.15 posterior SDs from its posterior mean and is now 0.004 SDs from it. Nothing changes for a parameter that is separate from the others, to the accuracy of the VB rule.
One limit is new. The marginal of a parameter of the hook is now only as accurate as the VB correction, and no check compares its centre with a scan (
mean_gapisNAfor it). Where the posterior is far from Gaussian, the VB mean can be further from the posterior mean than the mode is. The engine vignette states both limits of the hook, the Gaussian shape and this one. When the VB correction did not settle, or shifted a parameter by more than 1 SD, the warning now says that the Gaussian marginals of those parameters are centred on the VB mean. The skew-normal fit computed the Mills ratio phi(u) / Phi(u), which its gradient and Hessian use, with a floor of -745 on log Phi(u). The floor made the ratio wrong for u below about -38.5, and it is now switched off, so the ratio is right for every u. Ordinary fits do not change: they evaluate the ratio only at u far above that (the lowest in any traced fit was about -12), where the two versions agree to the last bit. A scan far narrower than its grid, with one to three points within 6 of its maximum, could reach that region, and its fit can change.
inlavanilla 26.11.27
New
use_vanilla_badge()adds a README badge to a package that holds a copy of the engine. It writes.github/inlavanilla-badge.json, which shields.io reads to draw a badge with “vanilla” and the release in the lock, such as “v26.11.25-2”, and prints the line for the README.use_vanilla()rewrites the file whenever it updates the copy, so the badge follows the lock, and offersuse_vanilla_badge()at the end of its list until the file exists.A fit with
hesstakes fewer calls oflogpostto checkgradandhessat the mode (grad_gap): about 2m, where it took about 6m to 8m. The check takes its steps from the diagonal ofhess, which gives each conditional posterior SD, where it searched for them from a tiny step.grad_gapstill compares the slope and the curvature along each axis withlogpost, one parameter at a time, as it does withouthess, and a diagonal that is far off still costs a search and is still flagged. Every other number of the fit is unchanged, to the last bit. On the Political Democracy model in RTMB with a Hessian tape (m = 39) a fit takes 873 calls oflogpost, where it took 1029.
inlavanilla 26.11.25-2
A fit that fails the one-step check of the default VB correction can now take twice as many sweeps to solve the VB equation: the cap is twice the calls of the mode and Hessian over 2m + 1, where it was those calls over 2m + 1. At the old cap the solve of a hard fit often stopped short of its root. With a gradient the VB stage of such a fit now costs at most twice what the mode and Hessian did, and without one up to 2(m + 1)(m + 2) / (2m + 1) times, about m times. A fit that passes the check is unchanged, to the last bit. A fit that fails it, and whose solve stopped at the old cap, has a different VB mean and log marginal likelihood.
vanilla_control()has the new entryvb_budget, that factor of two.vb_budget = 1is the old cap, andvb_budget = Inflets the solve run until it converges or reachesvb_maxititerations.
inlavanilla 26.11.25-1
The default VB correction (
vb_correction = "onestep") now checks its one step, and solves the VB equation where the check fails. A second sweep at the step tests that the fixed-point map the step iterates is a contraction there: the step must reduce the residual of the VB equation (vb_lhatbelow 1), and the slope of the map along the step must lie between -1 and 1 at the mode and at the step (vb_j0,vb_j1). A fit that passes keeps its one step, to the last bit. A fit that fails solves the VB equation on the same sweeps by Broyden’s method, from the mode, and raises a new warning, of classinlavanilla_vb_check_warning, that the posterior is far from Gaussian along the mean correction, naming the parameter the one step moved furthest. The warning comes whether or not the solve converged.The check, the solve, the warning and the diagnostics are the same with and without a gradient. With a gradient a sweep is 2m + 1 gradients, and a fit that passes takes 4m + 2 gradient calls for its VB stage, where it took 2m + 1 gradient and 4m + 2
logpostcalls. Without one a sweep is a Stein pass of (m + 1)(m + 2) values oflogpostand each slope takes 4m more, so a fit that passes takes 2(m + 1)(m + 2) + 8m calls, where it took (m + 1)(m + 2) + 4m + 2. The sweeps are capped at the calls of the mode and Hessian over 2m + 1, the two of the check among them. With a gradient the VB stage then costs no more than the mode and Hessian. Without one, a fit that fails the check can spend up to (m + 1)(m + 2) / (2m + 1) times the calls of its mode and Hessian, about m / 2 times.This takes the place of the gain ratio and of the iteration with capped steps after a first step over 2.5 posterior SDs, which are gone. A fit whose first step was over 2.5 SDs, or whose check fails, has a different VB mean and log marginal likelihood.
vb_correction = "full"is unchanged.diagnostics()has four new global entries:vb_lhat,vb_j0andvb_j1, the numbers of that check, andvb_solve, 1 if it failed and the solve ran.vb_gain_ratiois removed, with its warning. After a solve,vb_step_sigmais the step still to go where the solve stopped, which is recorded and not flagged, and the fit still prints as converged.summary()has a line for a flagged check, andprint()counts it.For packages that copy the engine:
vanilla_core()raises the new warning itself,check_flags()has the new flagvb_checkand novb_gain, andcore$diagnostics$vbhas the new entriessolve,checkandcheck_worstand nogain_ratio.vb_correct()returns the same. Theadviceofdiagnostic_problems()no longer needsvb_full.
inlavanilla 26.11.25
This release replaces 26.11.24-1, which was withdrawn. Its changes are listed here.
New
use_vanilla()copies the engine of inlavanilla, the filesR/vanilla-*.Rbehindinla_vanilla(), into another package, so that the package can callvanilla_core()without depending on inlavanilla. It takes the files from a release on GitHub (by default that of the installed version) or from a local clone, writes the lockinst/inlavanilla.lockwith the MD5 hash of each file, and adds to the package’sDESCRIPTIONwhat the engine needs: its copyright holders,cli,statsandutilsinImports,futureandparallellyinSuggests, andR (>= 4.1.0). It removes nothing, stops when a copy was edited by hand, and ends with a list of what is still to do. Run with a newer release, it updates the copy.New
vanilla_status()checks a copy: the files match the lock and the lock matches its release, no name clashes, theDESCRIPTIONand the license suit the engine, and whether a newer release changes a copied file.use_vanilla_test()anduse_vanilla_ci()add a test and a GitHub Actions workflow that check the copy.The new vignette
vignette("engine")shows how to copy and update the engine, and documentsvanilla_core()and the functions around it. These functions change only with a NEWS bullet that says so.The skew-normal functions of the engine change. They are internal in inlavanilla, but INLAvaan, which copies the engine, exports some of them. No fit changes: on the tests, vignettes and articles, every summary, marginal, VB mean, covariance, log marginal likelihood and LOO estimate is the same to the last digit as in 26.11.24.
summary()with no probabilities,probs = numeric(0), now works when a parameter is reported on the natural scale. Before, it stopped with an error, becauseqsnorm()returnedNAfor an emptyprobs(see below). Withtransform = FALSEit already worked.-
Internal changes, for INLAvaan and other packages that copy the engine:
-
psnorm()andqsnorm()return a zero-length result when any argument has length zero, aspnorm()andqnorm()do. Before, they returnedNA. The result now keeps the names and dimensions ofqorp, as the result ofdsnorm()keeps those ofx. -
qsnorm_fast()recycles its arguments to the length of the longest, asqsnorm()does. Before, analphalonger thanpgaveNAor an error. -
fit_skew_normal()stops with an error whentempis not a single finite positive number, orthreshold_log_dropis not a single finite negative number. The error comes fromabort()inR/vanilla-utils.R, soR/vanilla-skew-normal.Rcan no longer be copied without that file. - The comments of the skew-normal functions are true in any package that copies them, and give the measured error of
qsnorm_fast(). For|alpha|up to 30 it is at most 0.085 in units ofomegadown to a tail probability of 1e-15, except in a narrow window ofalphadeep in the lighter tail.
-
inlavanilla 26.11.24
This version renames arguments and diagnostics so that inlavanilla and INLAvaan, which takes its engine from inlavanilla from its version 0.4.0, use one name for one thing. The old names of arguments still work, with a warning. A fit gives the same numbers as in 26.11.23, except where a bullet below says otherwise: on the tests, vignettes and articles, every summary, marginal, VB mean, covariance, log marginal likelihood and LOO estimate is the same to the last digit, and only the fits with
hessmake morelogpostcalls.vbis renamedvb_correction, the name INLAvaan uses, and its"off"is now"none":vb_correction = c("onestep", "full", "none").TRUEandFALSEstill mean"onestep"and"none".vbstill works, with a warning once per session, and will be removed in a later version, and a new value given to it gets an error that points tovb_correction. The fit stores the setting asfit$vb_correction, in place offit$vb.widthis renamedmarginal_scan, the name INLAvaan will use from its version 0.4.0, with the values"linear"(was"trace", the default),"exact"(was"cmp") and"laplace"(was"tk"), and one new value,"plain", a scan with no width term, which shows what the volume correction adds.widthstill works, with a warning once per session, and will be removed in a later version, and a new value given to it gets an error that points tomarginal_scan. The fit stores the setting asfit$marginal_scan, in place offit$width, and each parameter’s scan is themarginal_scancolumn offit$diagnostics$marginals(waswidth).summary()names a scan other than the default on a line that starts “Scans:”.tk_fallbackis unchanged.marginals = "skewnorm"is the new name of the skew-normal marginals, the name of INLAvaan’smarginal_method."skewnormal"still works, as an alias, and a fit stores"skewnorm"infit$marginals.New
vanilla_control()builds thecontrollist ofinla_vanilla(), with one entry per setting, so that an editor can complete the names. It has three new entries for the mode search:mode_maxit,mode_maxevalandmode_tol, theiter.max,eval.maxandrel.tolofnlminb(), with the same defaults as before (5000, 5000 and nlminb’s 1e-10).nlminb = list()still passes any othernlminb()control, such astrace = 1. Itsiter.max,eval.maxandrel.tolstill work alone, but setting one of them together with its named entry is an error. A plain list still works ascontrol. INLAvaan’sinlavaan_control()will have the same entries, from its version 0.4.0.diagnostics()has two Hessian condition numbers, each with one meaning in inlavanilla and, from its version 0.4.0, INLAvaan:hess_condis now the raw condition number of the Laplace covariance, as INLAvaan defines it, andhess_cond_coris the one that was calledhess_condbefore, on the correlation scale, free of units. For a fit saved by an earlier version,diagnostics()takes the raw one from the covariance. The fit-time warning,summary()andverbose = TRUEusehess_cond_cor, at the same level as before (1e8), so no fit warns differently.A
logpostvalue at or below -1e39 now counts as-Inf, asNAandNaNalready did. Some code returns -1e40 where it fails, as lavaan’s and INLAvaan’s likelihoods do. As a finite number it passed for a very low density: the VB fallback could take a failed node for one it can average over, and a failed start did not stop the fit.A fit with
hessnow comparesgradwithlogpostat the mode, as a fit without one does:grad_gapis no longerNAthere, and its curvature part now checks the diagonal ofhess. It reads the differences oflogpostthat set the steps of the Hessian in a fit withouthess: 2 morelogpostcalls per try of the step search, usually 3 or 4 tries per parameter, so about 6m to 8m calls, and up to 60m when the search fails. The marginals do not change, and neither does the call budget of the one-step VB correction, which leaves these calls out.A supplied
hessis now checked for symmetry at the mode, as the Hessian fromgradalready was, with a warning when it is not symmetric to 1e-3 relative to its diagonal. The fit then uses its symmetric part, as before.verbose = TRUEreports the asymmetry for both, as “Asymmetry of the Hessian”.On parallel workers (forked, or separate R sessions), a
logpost,gradorhessthat calls a global helper of the same name, such as alogpost()of the user’s own, now finds that helper. Before, the worker took it for the user’s function, which then called itself until R stopped it, and the scans ran serially, with a note whose advice to use forked workers did not help. The same holds for aloglikinloo()andwaic().When the check of a parallel worker fails with an error, the note that the scans will run serially now gives that error.
-
Internal changes, for INLAvaan and other packages that copy the engine:
- The engine, every stage of a fit, is in the files
R/vanilla-*.R, which hold only internal code: no help, exports, S3 generics or methods, and not the name of the package. Another package copies them unchanged. A check in CI keeps them so, and the tests check that they call nothing from the other files. Parallel workers load the package that holds the engine, whatever its name. -
vanilla_core()runs the stages and returns a plain list, whichinla_vanilla()turns into its fit. It raises the warnings of the stages but installs no handler, so a caller records and muffles them as it wants. It takes two hooks thatinla_vanilla()does not expose:hess_mode, a Hessian called only at the mode, andgaussian_marginals, parameters whose marginal is taken as Gaussian, with their VB shift held at zero and no scan.verbose = TRUEshows those parameters with a dash in the table of the marginals. Wherelogpostfails,gradmust return a value that is not finite. -
sn_draws()makes the copula draws ofsampling(), with the correlation matrix of the copula as an argument. - The Taylor terms of
loo()andwaic()(taylor_terms()) and their summaries are inR/vanilla-taylor.R, under INLAvaan’s names for the per-unit terms:l_star,det_term, and the leveragesk_max,k_min,k_sum(the total,-tr(Omega H_u)) andk_ssq. -
diagnostic_problems()gives the bullets of the fit-time warning, worded by a list of advice that the caller passes, so that each package names its own arguments. - CI checks the package on R 4.1, the floor in
DESCRIPTION, and checks the formatting with air, whose settings are inair.toml. - INLAvaan’s Sobol VB rule, which it drops in 0.4.0, is kept as research code in
lab/sobol-vb/, with a check that it reproduces the shifts of INLAvaan 0.3.5.
- The engine, every stage of a fit, is in the files
inlavanilla 26.11.23
When the mode search runs off, or lands far from the posterior mass, the diagnostics warning now says what can cause it and what to do: random effects in
logpostwhose scale can run to zero (a funnel), to be integrated out oflogpost.vignette("diagnostics")explains the case.Versions are now dates, as in R-INLA:
YY.MM.DD, the day of the change, with-1or-2for a second or third version published on the same day. There are no.9000development versions. This version, 26.11.23, follows 0.1.1, and a date sorts after every 0.x version, so an update installs as usual.Every stage of a fit now whitens with the same factor, the symmetric square root of the posterior covariance taken on the correlation scale. A fit without a gradient no longer depends on the order of the parameters, beyond the tolerance of the mode search: its volume correction, ridge bend and VB fallback used a Cholesky factor, as did the check of the mode and
loo(). The VB correction no longer depends on rounding error where the posterior has equal eigenvalues, as with exchangeable random effects, where it moved the VB mean by up to 0.02 posterior SDs. It also stays accurate when the posterior SDs span many orders of magnitude. The marginals change by less than 1e-4 posterior SDs, except on funnels, where the skew-normal is far off anyway. The one-step VB mean changes by up to 0.03 posterior SDs with a gradient and 0.12 without, and the log marginal likelihood by up to 0.02 and 0.18. Against HMC on 52 simulated datasets, both are as accurate as before.A fit with
coresno longer warns thatfuture::availableCores()andfuture::supportsMulticore()are deprecated. The core count and the fork check now come from parallelly, which future imports. parallelly is in Suggests.loo()andwaic()have a new argumenthessian. Withhessian = "diagonal"they take the scores and the trace of each unit’s Hessian only, with 2m + 1 calls ofloglikin place of m^2 + m + 1: the first-order LOO less half the effective number of parameters, unit by unit. It is meant for models with many parameters in which every unit is a small part of the data. The default,"full", is unchanged.New
rtmb_latent()draws the random effects of an RTMB or TMB object after a fit:sampling(fit, fun = rtmb_latent(obj))gives the posterior of the latent variables that the object integrates out, from the Gaussian approximation at their mode given each draw of the parameters. The package still calls nothing of RTMB itself. Matrix and RTMB are in Suggests, for the sparse Cholesky factor and for the tests.A new article, “Latent variables”, shows how to draw random effects, class memberships and other latent variables after a fit, with
sampling(fit, fun = ): from a closed form, by summing over classes, from a grid, and from an RTMB object with random effects.A parameter named for the scale it is on is now reported on its natural scale. With
init = c(mu = 0, log_sigma = 0),print(),summary(),coef()andplot()showsigma, andsampling()returns draws of it. The prefixes arelog_(reported throughexp()),logit_(plogis()) andatanh_(tanh()), the scales R-INLA itself uses for nearly all of its hyperparameters. The fit does not change:logpost,grad,hess, theloglikofloo()and thefunofsampling()receive the parameter as before, a prior stated on the natural scale still needs its Jacobian inlogpost, and the diagnostics keep the names ofinit. The quantiles are mapped through the transform, and the mean, SD and mode are those of the natural-scale distribution. This changes the output of existing code that uses such names:fit$summary["log_sigma", ]andsampling(fit)[, "log_sigma"]now stop with a subscript error, since the row and the column are calledsigma.transform = FALSEininla_vanilla()restores the old behaviour, andsummary(),plot()andsampling()take the same argument to show a fit on the scale oflogpost. The newfit$transformlists what was read from the names, andvignette("natural-scale")explains it.A fit now records the version of inlavanilla that made it, in
fit$version, andprint()andsummary()show it in their headers with av(“INLAvanilla v26.11.23”), so that it does not read as the date of the fit. It is the string inDESCRIPTION, not apackage_version, which would drop the leading zeros of a date.When the mode search restarts
nlminb()with the parameters rescaled, the iterations reported are now the total over both runs, not those of the run that was kept: in the progress line, inprint()andsummary(), indiagnostics()and infit$diagnostics$optim$iterations. The evaluations in theverbose = TRUEreport are totals too, and its restart line gives each run’s own iterations. On a badly scaled posterior the fit used to report “1 iteration” after a first run of several hundred.
inlavanilla 0.1.1
The mode search now allows 5000 iterations and 5000 evaluations by default, up from 1000 and 2000, so that slowly converging fits do not stop at the limit.
control$nlminbstill sets them.inla_vanilla()now goes straight to the mode. A suppliedgradused to be compared with finite differences oflogpostatinit, before anything was printed, at about 8m to 12m calls oflogpost: 175 calls and 14% of the time on an RTMB model with 21 parameters. It is now compared at the mode, for each parameter and at no cost in calls, from differences the fit takes there anyway. The newgrad_gapindiagnostics()holds the result, and the fit-time warning andsummary()flag it above 0.1. A gradient of the wrong sign, which stops the fit at the mode, is now named in the error. With a slowlogpost, the first progress line appears half a second after the start, or once the first calls are done if they take longer, and moves with every call.With a gradient, the volume correction of the skew-normal marginals now takes 4m + 1 gradient calls for all m parameters together, against 2m + 2 for each parameter, from second differences of the gradient along the principal axes of the covariance. A spatial factor model with 82 parameters, whose 3,078 latent values RTMB integrates out, went from 757 s to 193 s. The differences are central, so the correction is also closer to the exact slope (3e-5 against 2.4e-4 on a test model), and the marginals move by a few ten-thousandths of a posterior SD. Fits without a gradient are unchanged.
inla_vanilla()gainscores. Withcores = 8the per-parameter scans of the skew-normal marginals, and the calls ofloglikinloo()andwaic(), run in parallel through the future package, which is optional, with the results and the progress line of a serial fit. Forked workers are used where they are safe, and separate R sessions elsewhere. A long scan uses all the cores, a shorter one fewer, and one expected to take under a second stays serial. Withwidth = "tk", a fit of 25.5 s took 3.2 s on 12 cores. With the default width the scans are about half of a slow fit, and the same model gained about 1.5 times. Compiled code (Rcpp, TMB, RTMB) cannot be sent to separate sessions, so the fit checks a worker’s value at the mode and otherwise runs serially with a message. By default,cores = NULL, the fit followsfuture::plan()and is serial if no plan is set. An interactive fit whose scans will take more than 10 s then says once thatcoreswould help.Without a gradient, the
ridge_bendcheck of the skew-normal marginals no longer takes 2(m - 1) calls oflogpostfor every parameter. The calls of the volume correction already show which way the ridge bends, so the check costs 2 more calls per parameter, and only a value above 0.1 is taken again from the full gradient. Every value that can reach the flag is computed as before, and the marginals do not change. A fit of a logistic regression with 40 parameters without a gradient takes 23% fewer calls and is 1.3 times as fast.The VB mean correction now takes one Newton step by default,
vb = "onestep". With a gradient it costs 2m + 1 gradient calls, about one numerical Hessian, against usually four sweeps of up to (m + 1)(m + 2) + 1, and on 133 simulated datasets it was as close to the posterior mean as the full solve, or closer, on all but three.vb = "full"keeps the iterative solve, andvb = "off"(orFALSE) leaves the correction out.TRUEmeans the default.fit$vbis now the name of the method, and the headers ofprint()andsummary()name it. A first step over 2.5 posterior SDs, or a node that fails, carries on with capped steps, within the calls that the mode and Hessian took.vb_step_sigmaisNAafter a single step.After a one-step VB correction the fit checks that the step delivered what it promised.
vb_gain_ratioindiagnostics()is the rise in the expected log-posterior over the rise the step assumed, at a cost of 4m + 2 calls oflogpost. A ratio below 0.5 raises a warning that points tovb = "full", andsummary()reports it.coef()gives the posterior mean of each parameter, theMeancolumn ofsummary(), as INLAvaan’scoef()does.timing()gives the elapsed time of each stage of the fit, as INLAvaan’stiming()does:timing(fit)the total,timing(fit, what = "all")every stage.fit$timinggainsinitanddiagnostics, the time before the mode and after the marginals, so its segments now add up tototal.inla_vanilla()gainswidth, how each skew-normal scan takes the width term, the log-volume of the other parameters."trace", the default, is the linear term of INLAvaan, as before."cmp"takes it exactly along the same straight scan, from the Hessian of the other parameters at each scan point, and"tk"moves the other parameters to their conditional mode at each point and takes the height and the width there, the Laplace marginal of Tierney and Kadane (1986).tk_fallback = TRUErescans with"tk"only the parameters whose ridge bend is flagged, andfit$fallbackandsummary()list them. Both cost more calls, given in?inla_vanilla.inla_vanilla()takes the Hessian oflogpostas an optionalhess, aftergrad, asnlminb()does. With it,nlminb()takes Newton steps to the mode, and the Hessian at the mode is the supplied one. RTMB gives it with the gradient, asobj$he. The fit is the same, except that the mode is found more precisely, for a little more time (8% on a model with 39 parameters). The default marginals do not use it, butwidth = "cmp"and"tk"do. A suppliedhessis checked at the mode against central differences ofgrad, andfit$countscounts its calls.The website article “Gradients with RTMB” is now “Gradients and Hessians with RTMB”. It passes RTMB’s Hessian too, and shows where the fit uses it, what it costs and the more precise mode it finds.
The website article “Diagnostic classification models” is now “Cognitive diagnostic models”.
inlavanilla 0.1.0
- Initial version.
inla_vanilla()approximates the posterior of any log-posterior written on an unconstrained scale with the INLAvaan pipeline: a Laplace approximation, a VB mean correction (by a deterministic degree-5 cubature rule), skew-normal marginals with the volume correction, and the log marginal likelihood.sampling()gives Gaussian-copula draws of the parameters or of any function of them.print(),summary()andplot()methods report the fit and its diagnostics. -
loo()andwaic()estimate predictive accuracy from the fit and a pointwise log-likelihoodloglik(theta, ...), by the deterministic second-order Taylor approximation of Alhyari et al. (2026): no refits and no draws. The results work withloo::loo_compare(). A new vignette, “Model comparison with LOO and WAIC”, shows how. Both follow the fit’ssilent, for the warnings oflogliktoo, and pass any other object on to the loo package’s functions of the same name. - The VB correction (
vb) and the skew-normal marginals (marginals = "skewnormal"or"gaussian") can each be switched off, down to the Laplace approximation alone. - The VB correction uses a degree-5 rule built on a regular simplex, with at most (m + 1)(m + 2) + 1 nodes, against 2m^2 + 1 before, all within 3 posterior SDs. With a gradient it makes about half the calls at large m, with the same accuracy. Without one, it takes the expected gradient from values of
logpostalone, by Stein’s identity on the same nodes, instead of finite-difference gradients: at most (m + 1)(m + 2) calls per sweep instead of (m + 1)(2m^2 + 1), so it costs about as much as finding the mode. For the 39-parameter SEM of the Rcpp article that is 8,200 calls instead of 487,000. This VB mean is exact when the log-posterior is a polynomial of degree four in whitened coordinates (six with a gradient). On test models it was a median 0.015 posterior SDs from exact VB, but up to about 0.1 on strongly skewed posteriors, where a gradient gives about 0.03. - Two website articles, “Speeding up with Rcpp” and “Gradients with RTMB”, fit a structural equation model with 39 parameters from a log-posterior written in R, in C++ with an analytic gradient, and in R for RTMB, which gives the gradient by automatic differentiation, and compare the routes for speed and accuracy.
- A website article, “Multilevel models”, fits a linear mixed model with the random effects integrated out, checks its marginals against brms, and draws the random effects for a caterpillar plot.
- A website article, “Diagnostic classification models”, fits the DINA model to the ECPE data with the latent classes summed out, checks its marginals against Stan, and classifies examinees from draws.
- A website article, “Correlation matrices”, puts an LKJ prior on the correlation matrix of a multivariate normal, through its canonical partial correlations on the atanh scale, fits it to the Holzinger and Swineford tests, checks the marginals against Stan, and gives the reliability of each scale from draws.
- A website article, “Binary factor analysis”, fits a one-factor model for binary items in the delta parameterisation, with the factor integrated out by Gauss-Hermite quadrature over the counts of the response patterns.
- A website article, “Diagnostic tests without a gold standard”, fits the three latent class models of Koukounari et al. (2021) to five schistosomiasis tests: conditional independence, a person-level random effect integrated out by Gauss-Hermite quadrature, and a finite mixture with always-positive and always-negative groups. It compares their estimates with the published ones, and the models by their log marginal likelihoods.
- Three output levels: by default each stage prints one line;
verbose = TRUEadds a full diagnostic of each stage (the optimiser’s report, how the Hessian was taken, the posterior correlations, the VB iterations, a line per marginal with the flagged values marked, and the calls each stage made);silent = TRUEprints nothing and muffles warnings, for simulations. The default output is whatverbose = TRUEused to give, so code that passedverbose = FALSEto keep a fit quiet should now passsilent = TRUE. The warnings raised during a fit are kept infit$warningswhatever the level. - While a stage runs, its line is the stage’s sentence with a counter, as in INLAvaan (“Fitting 4/6 skew-normal marginals”), not a bar as wide as the console. After two seconds it ends with the time so far, or the time left where the work is known in advance (the marginals and
loo()), in the place where the finished line shows the time taken. The lines,loo()’s included, follow thecli.progress_show_afteroption when it is set (half a second otherwise), so a knitr or Quarto setup chunk can keep them out of a rendered document. - The diagnostics follow INLAvaan’s. Each parameter has the Newton step at the mode in posterior SDs (
mode_shift_sigma), the VB shift on the scale oflogpost(vb_shift) and in posterior SDs (vb_shift_sigma), with the Kullback-Leibler divergence of each shifted marginal (kld), andunscanned_mass, the mass each fitted skew-normal puts outside the scanned window; the VB columns areNAwhenvb = FALSE. The fit also records the condition number of the Hessian in posterior-SD units (hess_cond).summary()andverbose = TRUEshow the unscanned mass. - A fit whose checks look off ends with one warning, of class
inlavanilla_diagnostics_warning, headed “Fit diagnostics flagged N potential issues”, in INLAvaan’s words and at its levels: a Newton step at the mode above 0.1 posterior SDs (whatevernlminb()’s return code, with its message and a hint), an NMAD above 0.1, an unscanned mass above 0.05, a VB shift above 1 SD, and a Hessian condition number above 1e8; heavy tails are inlavanilla’s own check. Like INLAvaan, the fit only records the VB fallback.summary()flags the same checks at the same levels, and also a ridge bend above 0.25 nats, where the marginal SD may be about 10% too small, and a mean gap (between the skew-normal and VB means) above 0.1 SDs; its lines list every flagged parameter, worst first, with its value (names only for the heavy-tails check, which is yes or no). Healthy fits stay silent. A new vignette, “Diagnostics”, explains every check, with citations of Jamil and Rue (2026a). -
summary()prints the fit first (the log marginal likelihood, and the calls and time each stage took), then the posterior marginals, then the diagnostics, each under its own heading. Its table of diagnostics (VB shift, NMAD, unscanned mass, ridge bend and mean gap) has numbers formatted as a tibble prints them and the flagged values in red. One line gives the largest value of each skew-normal check that passes, and each flagged check has a line of its own. - The tables of
print()andsummary()number their rows, as a tibble does, and line up the decimal points down each column. The posterior marginals still give each parameter to three significant figures of its posterior SD, and a value that rounds to zero no longer prints as “-0.000”. -
print()andsummary()open with the log marginal likelihood and whether the fit converged, with the iterations and the time the fit took. Converged means that the computation reached its solution: no further Newton step at the mode, and no further fixed-point step at the VB mean, would move a parameter by more than 0.1 posterior SDs. The second is a new check,vb_step_sigmaindiagnostics(fit, type = "param"): where the fallback optimiser of the VB correction lands was not checked before. A correction that has not settled is flagged and raises a warning. - Printed output is never wider than 80 columns, or the console if it is narrower: the summaries, the verbose report and the fit-time warning wrap their long lines. The rendered documentation is 76 columns wide, so that no output scrolls sideways on the website.
-
diagnostics(fit)anddiagnostics(fit, type = "param")return the checks as numbers, with the names, order and print formats of INLAvaan’sdiagnostics(), followed by inlavanilla’s own.plot(fit, type = "sn_fit")andtype = "sn_fit_log"draw each skew-normal fit against the scan it was fitted to, as INLAvaan’s plot does, from the scans the fit now keeps infit$scan. - The check of a user
gradalso compares it with finite differences one curvature scale frominit, so a gradient that is wrong by a constant factor is caught even wheninitis at the mode. -
print()names the approximation on its header rule (“Skew-normal + VB”, “Skew-normal”, “Laplace + VB” or “Laplace”), assummary()now does, instead of the run time, whichsummary()still reports. It ends with a line when the fit raised warnings and one whensummary()flags any check, so a fit run withsilent = TRUEdoes not look clean when it is not. -
summary()reports the 2.5%, 50% and 97.5% quantiles by default, as R-INLA does, instead of adding the quartiles, so its table fits in 80 columns and matchesprint(). Passprobsfor others. -
print()andsummary()wrap long lines to the console width (thewidthoption in R Markdown and Quarto), and split a table too wide for it into blocks of columns, as R does for a matrix. - The VB correction no longer stops with “NA/NaN gradient evaluation” when
logpostis-Infat some of its nodes, which reach up to 3 posterior SDs from the mode, as near a boundary of the support. Its fallback optimiser now moves away from those nodes. If it finds a VB mean wherelogpostis finite at every node, the fit goes ahead. Otherwise, as for a posterior truncated within reach of the nodes, the fit stops with an error that says so and suggests a reparameterisation orvb = FALSE. - With a gradient, a VB fallback that lands short of settled is rerun once from where it landed. That happens when the optimiser starts where a node fails, and it then reported convergence well short of the VB mean: 0.29 posterior SDs on a one-parameter posterior with a boundary. Fits whose fallback settles are unchanged, and
verbose = TRUEreports the rerun. - A VB fixed-point step over 1.5 posterior SDs is now cut to 1.5, and the iteration goes on; only two such steps in a row hand over to the fallback optimiser. INLAvaan hands over at the first step over 1 SD, but on a skewed posterior the first step overshoots and the iteration then comes back. On a DINA model with 63 parameters and a gradient the handover cost 54,000 calls to reach the point that six fixed-point steps reach.
