
Convergence diagnostics for every sampled quantity
Source:R/extract-blavaan.R, R/extract-brms.R
apa_tidy_diagnostics.Rdapa_tidy_diagnostics() returns R-hat and bulk and tail ESS for every
variable of a fitted model's posterior, including the group-level
deviations that a parameter table does not print. It is the table
apa_convergence() reports from: a convergence statement has to cover
what was sampled, not what a table shows.
Usage
# S3 method for class 'blavaan'
apa_tidy_diagnostics(x, variables = NULL, ...)
apa_tidy_diagnostics(x, ...)
# Default S3 method
apa_tidy_diagnostics(x, variables = NULL, ...)
# S3 method for class 'runjags'
apa_tidy_diagnostics(x, ...)Arguments
- x
A fitted model, posterior draws, or anything
posterior::as_draws_df()accepts.- variables
Character vector of variables to report, in the order given, or
NULLfor every variable that is not internal — the same ruleapa_tidy()uses on the draws route: names ending in__,lprior, and names starting withprior_are dropped by default and reported when named here.- ...
Passed to the method.
Value
An apabayes_tidy tibble of type "diagnostics" with columns
term, rhat, ess_bulk and ess_tail. Its divergences
attribute is the number of divergent post-warmup transitions summed
over chains, read from the sampler's own record, for a brmsfit,
stanreg, stanfit, CmdStanMCMC or blavaan fit sampled with
NUTS; it is NA for draws, mcmc.list and runjags objects and for
fits made by optimisation, variational inference or another sampler,
which have no such record.
Details
Numbers come from posterior::summarise_draws(); apabayes computes no
diagnostic of its own.
Methods (by class)
apa_tidy_diagnostics(blavaan): Ablavaanfit, whichposterior::as_draws_df()cannot read (measured). The chains areblavaan::blavInspect(x, "mcmc"), named ascoef()names the parameters (visual=~x2,x1~~x1), and the diagnostics areposterior's, not therhatandneffblavaan prints. A multi-group fit is reported: its names carry the group suffix (visual=~x2.g2).apa_tidy_diagnostics(default): Anythingposterior::as_draws_df()accepts, which includesbrmsfit,stanreg,stanfit,CmdStanFit,mcmcandmcmc.list. One coercing method serves every supported object, as on the draws route.apa_tidy_diagnostics(runjags): Arunjagsobject keeps its chains in$mcmc;posteriorhas no method for the object itself.
See also
apa_tidy() for parameter tables.
Examples
z <- stats::qnorm(stats::ppoints(400))
z <- z[order(sin(seq_along(z)))]
draws <- posterior::as_draws_df(
data.frame(mu = 2 + z, sigma = exp(0.3 * z))
)
apa_tidy_diagnostics(draws)
#> # apabayes tidy table: diagnostics (2 rows)
#> # source: draws_df
#> # A tibble: 2 × 4
#> term rhat ess_bulk ess_tail
#> <chr> <dbl> <dbl> <dbl>
#> 1 mu 0.998 502. 248.
#> 2 sigma 0.998 502. 248.