| ijse | R Documentation |
Extract matched draws and likelihood contributions from a brmsfit
object and compute IJ inference with ijse_draws.
ijse(
fit,
cluster_var = NULL,
variables = NULL,
transform = NULL,
draw_ids = NULL,
block_size = NULL,
save_influence = FALSE,
diagnostics = c("all", "posterior", "none")
)
IJ_se(fit, cluster_var = NULL)
fit |
A fitted |
cluster_var |
Optional cluster IDs in the order of the likelihood columns
returned by |
variables |
Optional exact parameter names. Defaults to parameters starting
with |
transform |
Optional function applied to the selected draws; see
|
draw_ids |
Optional strictly increasing indices of post-warmup draws,
ordered by iteration within chain, then chain. The same indices are passed
to likelihood extraction. Each retained chain requires at least two draws
when |
block_size |
|
save_influence |
Whether to retain empirical influence values. |
diagnostics |
One of |
MCMC chain diagnostics are retained for the selected or transformed quantities. The likelihood uses the brms default of conditioning on fitted group effects. This extraction choice does not establish IJ validity for arbitrary hierarchical models. For clustered working-independence models, supply cluster IDs explicitly; they are never inferred from a model formula.
Streaming respects observation permutations in brms prediction metadata.
The tested brms release does not support pointwise evaluation for regression
ARMA models; use ordinary extraction for those models. Covariance ARMA models
are rejected because brms returns conditional LOO densities instead of joint
likelihood factors. Supply one joint likelihood per independent series to
ijse_draws(). Discrete truncated models also require explicit matrix
input because the backend lower-bound normalization is not validated.
Multivariate streaming is rejected
because response-specific orderings may differ; the default dense path uses
brms's combined likelihood.
Measurement-error predictors require saved latent draws, for example
brms::save_pars(latent = TRUE) when fitting. Otherwise brms may
resample prediction latents, which do not match the fitted posterior draws.
Even with saved latents, the native likelihood conditions on them; it is not
an observed-data likelihood integrating measurement error. Missing-response
models may return non-finite likelihoods, which are rejected. Use explicitly
derived observed-data likelihoods with ijse_draws() when appropriate.
ijse() returns the structured ijse object documented
under ijse_draws. IJ_se() returns
the named numeric vector of standard errors, as in previous releases.
Use ijse() to retain estimates, both covariance types, intervals,
diagnostics and optional influence. IJ_se() returns only IJ SEs with
the same pooled formula. Ordinary extraction is the default. A positive
block_size requests brms pointwise likelihood evaluation; backend
prediction/preparation objects may still be large. This differs from
ijse_draws(), whose positive block size controls a supplied callback.
Parameter extraction and likelihood extraction share draw_ids.
Do not manually reorder parameter rows or pass cluster IDs for the original
unfiltered dataset. Keep fitting-row keys with the actual model data and
check clustered, n_obs, n_units, and unit_ids.
Correct lengths alone cannot identify mismatched scientific units.
ijse_draws, summary.ijse
# Uses an installed synthetic fit: no Stan compilation or new fitting.
if (requireNamespace("brms", quietly = TRUE)) {
examples <- readRDS(system.file("extdata", "tutorial",
"median-examples.rds", package = "IJSE"))
fit <- examples$clustered$fit
ids <- examples$clustered$cluster
result <- ijse(fit, cluster_var = ids, save_influence = TRUE)
stopifnot(result$clustered, result$n_units == 30L)
summary(result)
vcov(result)
vcov(result, type = "posterior")
confint(result, parm = "b_x", level = 0.90)
head(result$unit_ids)
stopifnot(isTRUE(all.equal(IJ_se(fit, ids), result$se)))
streamed <- ijse(fit, cluster_var = ids, block_size = 40,
diagnostics = "none")
stopifnot(isTRUE(all.equal(vcov(streamed), vcov(result))))
prediction <- ijse(fit, cluster_var = ids,
variables = c("b_Intercept", "b_x"),
transform = function(d) {
cbind(median_at_x1 = d[, "b_Intercept"] + d[, "b_x"])
}, diagnostics = "posterior")
coef(prediction)
}
# For fitting instructions, run vignette("ijse-brms", package = "IJSE").
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.