| tulpa_eb | R Documentation |
Estimate one or more random-effect covariances Sigma by maximizing the
Laplace marginal likelihood over them (plus the hyperprior), then report the
fixed effects conditional on the maximizer. This is the plug-in ("ML-II" /
empirical-Bayes) counterpart of tulpa_re_cov_nested(), which integrates over
Sigma instead of fixing it at the maximizer.
tulpa_eb(
y,
n_trials = NULL,
X,
re_terms,
family = "binomial",
phi = 1,
phi2 = NULL,
prior_sigma = NULL,
eta = NULL,
hyperprior = c("proper", "flat"),
log_prior_theta = NULL,
beta_prior = NULL,
offset = NULL,
n_quad = 1L,
marginal = FALSE,
estimate_phi = FALSE,
X_zi = NULL,
zi_prior_sd = 2.5,
control = list()
)
y, n_trials, X, family, phi |
Passed to |
re_terms |
Either a single random-effect term or a list of them; see
|
phi2 |
Optional second dispersion, threaded into every inner
|
prior_sigma, eta |
Hyperparameters of the PC + LKJ prior used when
|
hyperprior |
|
log_prior_theta |
Optional |
beta_prior |
Optional Gaussian prior on the fixed effects, threaded into
every inner |
offset |
Optional observation-level offset on the linear predictor
(length |
n_quad |
Quadrature order for the inner marginal. |
marginal |
Report fixed-effect intervals that carry the hyperparameter
uncertainty, instead of the intervals conditional on |
estimate_phi |
Estimate the family's dispersion alongside the
random-effect covariances, instead of conditioning on The dispersion enters unpenalized – the hyperprior covers the covariance
coordinates only – so this is the ML-II estimate of Available for every family carrying a dispersion, which is every front-door
family except Alongside |
X_zi |
Optional zero-inflation design matrix ( |
zi_prior_sd |
Prior SD on |
control |
A named list of numerical knobs: |
Blocks, coordinates and the default hyperprior are exactly those of
tulpa_re_cov_nested() – a correlated (1 + x | g) term is a full
Sigma = L L' in log-Cholesky coordinates, an uncorrelated (1 + x || g)
term is diagonal in log-SD coordinates, and a scalar (1 | g) term is the
degenerate one-coefficient block. Both functions call the same outer
objective and the same optimizer, so tulpa_eb()$theta_hat and
tulpa_re_cov_nested()$theta_hat are the same estimate on the same data –
which requires hyperprior to default the same way on both: "proper", the
PC + LKJ prior (see re_cov_pc_lkj_prior()) at the anchor every scale axis
of the engine defaults to, which at small G keeps a block off the
sigma = 0 boundary. hyperprior = "flat" maximizes the marginal likelihood
alone.
The marginal likelihood is marginal over the fixed effects too: the inner
Laplace approximation integrates beta out together with the random
effects (under beta_prior, or the inner solve's vague N(0, 100^2) default)
rather than profiling it. hyperprior = "flat" is therefore a RESTRICTED,
REML-type estimate, not maximum likelihood: for a gaussian response it is
REML, and for a non-gaussian one it agrees with
glmmTMB(..., REML = TRUE), not with the ML fit of lme4::glmer() or
glmmTMB(..., REML = FALSE). On a binomial random intercept with 40 groups
of 6 the three read RE SDs of 0.7931 (tulpa_eb), 0.7931 (glmmTMB REML) and
0.7594 (ML); the fixed effects at theta_hat match the REML fit's as well.
The restriction is what removes ML's downward bias in the variance
components when beta is estimated from the same data, and it carries over
to n_quad > 1 and to estimate_phi = TRUE. Validating against glmer()
should expect exactly that gap.
The reported fixed-effect covariance is the conditional one at theta_hat
(solve(H_beta)). It does not include the hyperparameter uncertainty that
tulpa_re_cov_nested() integrates over, so EB intervals are narrower –
increasingly so as the number of groups falls. Use the nested integrator when
the variance components themselves, or calibrated fixed-effect intervals, are
the target; use EB when the point estimate is, or as a fast starting fit.
A tulpa_fit with:
mode, H_beta: the fixed-effect (and, on the n_quad = 1 path, random-
effect) mode and the fixed-effect precision at theta_hat, driving
coef/confint/vcov/summary.
map: the Sigma / sigma / rho summary at theta_hat (a single list
for one block, a named list of them for several).
Sigma: the estimated covariance (a matrix for one block, a named list
of matrices for several).
theta_hat, log_marginal, layout, n_blocks, n_coefs.
converged: whether the inner Newton solve at theta_hat converged.
outer_convergence: optim's code for the maximization over Sigma
(0 on success). A non-zero value also warns.
With marginal = TRUE and a correction that formed: cov_marginal (the
widened fixed-effect covariance, which vcov / summary / confint
then report), cov_conditional (the solve(H_beta) they would otherwise
have reported, kept so the two are comparable on one fit), H_theta and
theta_cov (the outer Hessian at theta_hat and its inverse, named by
theta_names), and the marginal_step / marginal_richardson actually
used. All absent when the correction was not requested or could not be
formed, so is.null(fit$cov_marginal) tests whether the reported
intervals are marginal. A requested correction that fails warns and
leaves the conditional covariance in place.
Casella (1985). An introduction to empirical Bayes data analysis. The American Statistician 39(2):83-87. Rue, Martino & Chopin (2009). Approximate Bayesian inference for latent Gaussian models by using integrated nested Laplace approximations. JRSS-B 71(2):319-392.
tulpa_re_cov_nested() to integrate over Sigma rather than fix it;
tulpa_laplace() for the inner solve.
set.seed(1)
G <- 30L; per <- 10L; n <- G * per
grp <- rep(seq_len(G), each = per); x <- rnorm(n)
b <- rnorm(G, 0, 0.8)
y <- rpois(n, exp(0.3 + 0.5 * x + b[grp]))
re_term <- list(idx = grp, n_groups = G, n_coefs = 1L)
fit <- tulpa_eb(y, NULL, cbind(1, x), re_term, family = "poisson")
fit$map$sigma # empirical-Bayes RE standard deviation
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.