View source: R/envelopeorchestrator.R
| EnvelopeCentering | R Documentation |
EnvelopeCentering() computes an initial dispersion and the expected
posterior weighted RSS (closed form under the Normal posterior for
coefficients) for use in envelope construction when the dispersion is
unknown. The dispersion-anchoring loop updates dispersion from the Gamma
posterior using that expected RSS each iteration.
This step is typically called inside rIndepNormalGammaReg() before
EnvelopeOrchestrator, but may be used directly for diagnostics
or custom workflows.
EnvelopeCentering(
y,
x,
mu,
P,
offset,
wt,
shape,
rate,
Gridtype = 2L,
verbose = FALSE
)
y |
Numeric response vector of length |
x |
Numeric design matrix of dimension |
mu |
Numeric vector of prior means (length |
P |
Numeric matrix of prior precision ( |
offset |
Numeric vector of length |
wt |
Numeric vector of prior weights. |
shape |
Numeric. Shape parameter of the Gamma prior for the dispersion. |
rate |
Numeric. Rate parameter of the Gamma prior for the dispersion. |
Gridtype |
Integer. Grid construction method (default |
verbose |
Logical. Reserved for API compatibility; currently unused in C++. |
The function first obtains an initial dispersion via lm.wfit residual
variance, then iteratively: (1) computes the expected weighted RSS under the
Normal posterior (closed form), (2) updates the
dispersion via the Gamma posterior using the expected RSS. The result is used
as dispersion2 and RSS_Post2 in downstream envelope construction
(e.g., EnvelopeOrchestrator).
This anchors the joint Normal–Gamma accept–reject construction in
\insertCiteNygren2006glmbayes; see vignettes Chapter-A07,
Chapter-A11, and \insertCiteglmbayesChapterA08,glmbayesIndNormGammaVignetteglmbayes.
A list with components:
dispersionNumeric. Anchored dispersion value.
RSS_postNumeric. Expected posterior weighted RSS (closed form; last iteration).
EnvelopeOrchestrator for envelope construction;
EnvelopeBuild, EnvelopeDispersionBuild;
rindepNormalGamma_reg for the full simulation routine;
rlmb for the user-facing linear-model interface.
############################### Start of EnvelopeCentering example ####################
# This example demonstrates EnvelopeCentering in isolation. It computes an
# initial dispersion and posterior RSS for use in envelope construction when
# the dispersion is unknown (Gaussian regression with Normal-Gamma prior).
# This is Step A of the full pipeline in Ex_EnvelopeDispersionBuild and
# Ex_rIndepNormalGammaReg_std.
ctl <- c(4.17, 5.58, 5.18, 6.11, 4.50, 4.61, 5.17, 4.53, 5.33, 5.14)
trt <- c(4.81, 4.17, 4.41, 3.59, 5.87, 3.83, 6.03, 4.89, 4.32, 4.69)
group <- gl(2, 10, 20, labels = c("Ctl", "Trt"))
weight <- c(ctl, trt)
ps <- Prior_Setup(weight ~ group, gaussian())
x <- as.matrix(ps$x)
y <- as.vector(ps$y)
mu <- ps$mu
Sigma <- ps$Sigma
shape <- ps$shape
rate <- ps$rate
n_obs <- length(y)
wt <- rep(1, n_obs)
offset2 <- rep(0, n_obs)
# Reconstruct coefficient precision P (matches rindepNormalGamma_reg)
Rchol <- chol(Sigma)
Pinv <- chol2inv(Rchol)
P <- 0.5 * (Pinv + t(Pinv))
Gridtype_core <- as.integer(2)
###############################################################################
# EnvelopeCentering: initial dispersion + dispersion anchoring loop
###############################################################################
centering <- EnvelopeCentering(
y = y,
x = x,
mu = as.vector(mu),
P = P,
offset = offset2,
wt = wt,
shape = shape,
rate = rate,
Gridtype = Gridtype_core,
verbose = FALSE
)
centering$dispersion
centering$RSS_post
###############################################################################
# End of EnvelopeCentering example
###############################################################################
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.