No articles match
Core 01: Overview of the glmbayesCore package14 days ago
Ecosystem | Primary R entry points | Vignette index by Part | Legacy map (glmbayes appendices → Core) | Reserved numbers (future)
Core 20-S01: Model setup and identifiability14 days ago
1. User interface | 1.1 Formula rules | 1.2 Arguments | 1.3 Returned fields | 1.4 check_identifiability() | 2. Example: Big Word Club | 2.1 The sampler design | 2.2 The hyper-design matrices | 2.3 The reference fit | 2.4 Identifiability at two levels | 2.5 Calling check_identifiability() directly | 3. Lineage: what runs inside model_setup() | 3.1 Call tree | 3.2 Helper reference | 3.3 Exploring the internals | 4. Next
Core 20-S02: Calibrating mixed-model priors with Prior_Setup_GLMM()14 days ago
1. User interface | 1.1 Arguments | 1.2 Returned fields | 2. Example: Big Word Club | 2.1 Pooled measurement dispersion (dispformula = ~1) | 2.2 Block 2: Normal priors on (\gamma_k) | 2.3 Block 2: the (\tau^2_k) centres and Gamma priors | 2.4 Block 1: the pooled measurement-precision prior | 2.5 Per-group measurement dispersion (dispformula = ~ school_id) | 2.6 Non-Gaussian families and failed defaults | 3. Lineage: what runs inside Prior_Setup_GLMM() | 3.1 Call tree | 3.2 Helper reference | 3.3 How the stages map to returned fields | 4. Next
Core 20-S03: From calibrated priors to pfamily objects — pfamily_list() and dGamma_list()14 days ago
Core 20-S03: From calibrated priors to pfamily objects | 1. User interface | 1.1 pfamily_list() | 1.2 dGamma_list() | 2. Example | 2.1 Normal priors with fixed (\tau^2_k) (default) | 2.2 Independent Normal–Gamma priors (sample (\tau^2_k)) | 2.3 Mixing prior types | 2.4 Per-group measurement-variance priors | 2.5 Changing the truncation windows | 2.6 Pooled measurement dispersion | 2.7 Putting it together | 3. Lineage | 3.1 Call trees | 3.2 Helper reference | 3.3 Where the values come from | 4. Next
Core 20-S04: Row-group priors and samplers14 days ago
1. User interface | 1.1 Group specifications and normalize_group() | 1.2 Prior_SetupGroup() | 1.3 rNormal_reg_group() and rNormalGLM_reg_group() | 2. Examples | 2.1 Group partitions | 2.2 Independent priors per species | 2.3 Converting to pfamily objects | 2.4 Gaussian group draws with one shared prior | 2.5 Gaussian group draws with per-group priors from Prior_SetupGroup() | 2.6 Non-Gaussian group draws | 3. Lineage | 3.1 Prior_SetupGroup() and its pfamily_list() method | 3.2 The groupwise samplers (R to C++) | 3.3 Helper reference: R | 3.4 Helper reference: C++ (glmbayes::sim::group) | 4. Role in the mixed-model samplers
Core 20: Mixed-model design and priors in glmbayesCore — overview14 days ago
Core 20: Mixed-model design and priors — overview | 1. Where these functions sit | 2. The two-block structure | 3. What Part 4 covers | 4. Package-wide lineage | 5. Where the code lives | 6. Naming conventions for helpers | 7. Requirements and current limitations | 8. Related documentation in the package
Chapter 00: Introduction16 days ago
Part 1: An Introduction | Part 2: Bayesian regression models | Part 3: Generalized Linear Models | Part 4: Advanced Topics | Part 5: Simulation Methods and Technical Implementation | Companion textbooks
Chapter A01: A detailed overview of the glmbayes package16 days ago
Introduction | Loading the package | Accessing package information, general documentation, and demos | Using the lmb and glmb functions and their methods | The lmb and glmb functions | Specifying Priors | Prior Family Functions | Other Prior Related Functions | Method functions | The rlmb and rglmb functions and their summary functions | Calling the rlmb and rglmb functions | Methods for The rlmb, rglmb, and their summary functions | Advanced Topics | Simulation Functions | Normal_ct Functions | Envelope-based sampling (glmbayesCore) | Utility Functions
Core 02: Overview of Estimation Procedures17 days ago
Introduction | 1. rglmb/rlmb, pfamilies, and the Simulation Architecture | 1.1 How glmb and lmb use rglmb and rlmb respectively | 1.2 pfamilies: the Bayesian analogue of family() | pfamily name Prior components in prior_list | 1.3 The uniform simfunction interface | 1.4 How rglmb and rlmb select the simfunction | 1.5 The four core simfunctions | 1.6 Inspecting the Simulation Function Used: the simfunction() Generic | 1.7 Summary | 2. Mapping Families and Pfamilies to Simulation Functions | 2.1 Mappings to Simulation Functions | 2.2 Mapping Simulation Functions to Primary C++ Routines | 3. Conjugate vs. Envelope-Based Sampling | 3.1 Conjugate Cases | 3.2 Envelope-Based Cases | 4. Theoretical Foundations and Cross-References | 5. Overview of Each Simulation Function | Simfunction Supported Families and Links | 5.1 rNormal_reg | 5.2 rNormalGamma_reg | 5.3 rindepNormalGamma_reg | 5.4 rGamma_reg | 6. Use in Gibbs Samplers and Custom Algorithms | 7. Source Code and File Structure | 7.1 C and C++ Backends Used by the Simfunctions | 7.2 Utility Functions | 8. Summary
Core 03: Simulation Methods - Likelihood Subgradient Densities17 days ago
1. Introduction | 2. Overview of the Main Simulation Function: .rNormalGLM_cpp | 3. Input Validation and Preprocessing | 4. Posterior Optimization | 5. Model Standardization with Theoretical Underpinnings: glmb_Standardize_Model() | Implementation Details: glmb_Standardize_Model() | 6. Envelope Sizing | 1. Gridtype 1: Static Threshold Test | 2. Gridtype 2: Dynamic Envelope via EnvelopeOpt(a, n) | 3. Gridtype 3: Always Three-Point Grid | 4. Gridtype 4: Always Single-Point Grid (Mode Only) | Deep Dive: Gridtype 1 — Static Threshold Envelope | Deep Dive: Gridtype 2 — Adaptive Envelope via EnvelopeOpt() | 6. Building the Envelope | 1. Compute width parameters ( \omega_i ) from the diagonal precision matrix | 2. Construct intervals around the posterior mode ( \theta^\star ) | 3. Select tangency points ( \theta^\star \pm \omega_i ) | 4. Build the full grid of tangency points | 5. Evaluate negative log-likelihood and gradients at each grid point | 6. Call Set_Grid_C2_pointwise to evaluate restricted multivariate normal log-densities | 7. Call setlogP_C2 to compute component log-probabilities and constants | 8. Normalize probabilities (PLSD) and optionally sort grid components | 7. Simulation Execution | 8. Post-Processing and Output | 8.1 Reverse-transformation pipeline | 8.2 Returned object (fields you can rely on)
Core 04: Accept–Reject Sampling for Dispersion in Gamma Regression17 days ago
1. Introduction | 1.2 Likelihood | [\ell_i(v) | v\log v | v\log \mu_i+(v-1)\log y_i | \log\Gamma(v) | [\ell(v) | \sum_{i=1}^nw_i\left[v\log v | 1.3 Prior | 1.4. Posterior Log‑Density | [f(v) | 2. The sampler | 2.1 Proposal Distribution | [\begin{aligned}\log p_{prop}(v) & = (a_0+ \frac{1}{2}\sum_i w_i )\log [ b_0 - \bar{c}(v_{\text{tangent}})] ;-; \log\Gamma(a_0+ \frac{1}{2}\sum_i w_i ) \[4pt]& ;+; ((a_0+ \frac{1}{2}\sum_i w_i ) - 1)\log v ;-; [ b_0 - \bar{c}(v_{\text{tangent}})] v.\end{aligned}] | 2.2 Bounding function | [\log h(v) | \ell(v) | \bigl[\ell(v_{\text{tangent}}) | \bar{c}(v_{\text{tangent}})(v - v_{\text{tangent}})\bigr] | 2.3 Equivalence Claim | 2.4 Implementation Outline
Core 05: Accept–Reject Sampling for gaussian Regression models with independent normal-gamma priors17 days ago
Envelope construction with independent Normal–Gamma prior (Gaussian regression) | 1. Model Setup (Gaussian Regression with Independent Normal–Gamma Prior) | 1.1 Weighted log‑likelihood | [\mathrm{RSS}(\beta) | [\ell(\beta,\phi) | [\ell(\beta,\tau) | 1.2 Independent Normal–Gamma prior | [\log p(\beta,\tau) | [p_{\text{trunc}}(\tau) | \frac{\tau^{a_0 - 1} e^{-b_0\tau}}{F_{\Gamma}(\tau_{\max};a_0,b_0) | 2. Full Joint Log‑Posterior (Gaussian Case, Weighted) | [\log p(\beta,\tau \mid y) | 3. General Sampling Process | 4. Main Proposition and Supporting claims | | Constant | Definition | Description ||----------|------------|-------------|| Posterior Gamma parameters | $\text{shape}2 = \text{Shape} + \tfrac{n{w}}{2}$ $\text{rate}2 = \text{Rate} + \mathrm{RSS}{\text{post}}/2$ | Posterior shape and rate parameters. || Envelope dispersion anchor | $d^{}_{1} = \dfrac{\text{rate}2}{\text{shape}2 - 1}$ | Dispersion used for baseline envelope. || Dispersion bounds | $\begin{aligned}& \text{low} \[4pt]& \text{upp}\end{aligned}$ | Lower and upper bounds for dispersion. || Tangency offset vector | $B(d) = P\mu + \dfrac{1}{d},X^\top W(\alpha - y)$ | Offset vector used in the inverse map $c^{-1}(\bar c, d)$. || Tangency slope components | $\begin{aligned} Q &= X^\top X \ A(d) &= Q + dP \ r &= X^\top(y-\alpha) \ V(d) &= \bar c_j - P,A(d)^{-1}(r + d,\bar c_j) \end{aligned}$ | Components for quad–linear slope term. || Tangency inverse map | $c^{-1}(\bar c, d) = A(d)^{-1}(\bar c - B(d))$ | Maps gradient vector $\bar c$ and dispersion $d$ to tangency point $\theta$. || Tangency map | $\theta(d) = c^{-1}(\bar c_j, d)$ | Tangency point in coefficient space at dispersion $d$. || Tangency face energy | (g{1j}(d) = -\tfrac12,\theta(d)^\top P,\theta(d) + \bar c_j^\top \theta(d)) | Quadratic–linear face energy at dispersion (d). || Baseline face constant | (g{1j}(d^{}{1})) | Face‑specific constant obtained by evaluating (g{1j}(d)) at the anchor (d^{}{1}). || Derivative of face energy | $\begin{aligned} & g'{1j}(d) = V(d)^\top A(d)^{-1},\bar c_j \[6pt] & \qquad -, \Big( V(d)^\top A(d)^{-1} P,A(d)^{-1} \[2pt] & \qquad\qquad\qquad;;\times \big(r + d,\bar c_j\big) \Big) \end{aligned}$ | Derivative of $g_{1j}(d)$ with respect to dispersion. || Derivative at the anchor | $\begin{aligned}& g'_{1j}(d^{}{1}) = V(d^{*}{1})^\top A(d^{}_{1})^{-1},\bar c_j \[6pt]& \qquad -, \Big( V(d^{}{1})^\top A(d^{*}{1})^{-1} P,A(d^{}_{1})^{-1} \[2pt]& \qquad\qquad\qquad;;\times \big(r + d^{}{1},\bar c_j\big) \Big)\end{aligned}$ | Value of the derivative at the envelope anchor $d^{*}{1}$. || Tangency face energy | (g_{1j}(d) = -\tfrac12,\theta(d)^\top P,\theta(d) + \bar c_j^\top \theta(d)) | Quadratic–linear face energy at dispersion (d). || Mean quad–linear slope | $\mathrm{m}{g'{1}} = \displaystyle \operatorname*{mean}\limits_{j}!\big(g'{1j}(d^{*}{1})\big)$ | Average derivative $g'{1j}(d^{*}{1})$ across faces. || Supporting line for face (j) | (g_{2j}(d) = g_{1j}(d^{}_{1}) + (d - d^{}{1}),g'{1j}(d^{}{1})) | Linear supporting line of (g{1j}(d)) at the anchor (d^{}{1}). || Extrapolated face constants | $\begin{aligned}& g{2j}(\text{upp}) = g_{1j}(d^{}_{1}) \[2pt]& \qquad\qquad;; +, (\text{upp}-d^{}{1}), g'{1j}(d^{}{1}) \[6pt]& g{2j}(\text{low}) = g_{1j}(d^{}{1}) \[2pt]& \qquad\qquad;; +, (\text{low}-d^{*}{1}), g'{1j}(d^{*}{1})\end{aligned}$ | Linear extrapolations to dispersion bounds. || Endpoint maxima | $\begin{aligned}\mathrm{max_upp} & = \max_j!\big(g_{2j}(\text{upp})\big) \[8pt]\mathrm{max_low} & = \max_j!\big(g_{2j}(\text{low})\big)\end{aligned}$ | Maxima at upper and lower dispersion bounds. || Mean lower-bound maximum | $\begin{aligned}&\mathrm{max_low_mean} \[4pt]&= \mathrm{max_upp} \[4pt]&\quad - \mathrm{m}{g'{1}},(\text{upp}-\text{low})\end{aligned}$ | Linearized lower-bound maximum. || Global line parameters | $\text{lmc}2 = \dfrac{\mathrm{max_upp} - \mathrm{max_low_mean}}{\text{upp}-\text{low}}$ $\text{lmc}1 = \mathrm{max_low_mean} - \text{lmc}2,\text{low}$ | Slope and intercept of global affine bound. || Log–linear anchor | $d^{*}{2} = \dfrac{\text{upp}-\text{low}}{\log(\text{upp}/\text{low})}$ | Anchor point for log–tilt. || Log–tilt coefficients | $\begin{aligned} & \mathrm{lm_log2} = \[4pt]& \text{lmc}2,d^{*}{2} \[4pt]& \mathrm{lm_log1} = \[4pt]& \text{lmc}1 + \text{lmc}2 d^{*}{2} - \text{lmc}2\log(d^{*}{2}) \[4pt]& \mathrm{max_LL_log_disp} =\[4pt]& \mathrm{lm_log1} + \mathrm{lm_log2}\log(\text{upp}) \end{aligned}$ | Coefficients for log–tilt bounding function. || Face-specific RSS | $\mathrm{RSS}j(d) = \sum{i=1}^n w_i,(y_i - x_i^\top c^{-1}(\bar c_j,d))^2$ | Residual sum of squares for face $j$ at dispersion $d$. || Global minimum RSS | $\mathrm{RSS_Min} = \min{j};\min{d\in[\text{low},,\text{upp}]};\mathrm{RSS}j(d)$ | Global minimum RSS across all faces and dispersion values. || UB2 term | $\mathrm{UB2}j(d) = \dfrac{1}{2d}\big(\mathrm{RSS}j(d) - \mathrm{RSS_Min}\big)$ | Nonnegative UB2 bound for face $j$. || Per-face UB2 minimum | $\mathrm{UB2_Min}j = \min{d\in[\text{low},,\text{upp}]}\mathrm{UB2}j(d)$ | Minimum UB2 value for face $j$. || Per‑face shift (UB3A) | $\begin{aligned}& \mathrm{lg_prob_factor1}{j} = \[4pt]& \max\Big{, g{2j}(\text{upp}) - \mathrm{max_upp}, \[-2pt]& \qquad;; g{2j}(\text{low}) - \mathrm{max_low} \Big}\end{aligned}$ | Raw per‑face shift used in UB3A construction. || Per‑face shift (PLSD) | $\begin{aligned}& \mathrm{lg_prob_factor2}{j} = \[4pt]& \mathrm{lg_prob_factor1}{j} ;-; \mathrm{UB2_Min}{j}\end{aligned}$ | UB2‑adjusted shift used in PLSD mixture weights. || Global affine bound (g3_j) | $\displaystyleg3{j}(d) | From the definitions of the global affine bound,[\mathrm{lmc}_2 | \frac{\mathrm{max_upp} - \mathrm{max_low}}{\text{upp} - \text{low}},\qquad\mathrm{lmc}_1 | At (d = \text | 4.2 Proposal distributions | Gamma proposal in dispersion (d) (with truncation) | Mixture of truncated normals for (\beta) (two-step sampling) | 4.3 Correction terms | 4.4 Proposition: Log‑posterior decomposition in dispersion form | Explanation | Proof of Proposition | 5. Supporting Claims | 5.1 Claim 1 | (1a) | (1b) | (1c) | (2a) | (2b) | (3a) | (3b) | (4a) | (4b) | (4c) | (4d) | (5a) | F_{\Gamma}!\Big(\tfrac{1}{\mathrm{disp}{\mathrm{upper}}};\text{Shape},\text{Rate}\Big)\Bigg) \[6pt]&\quad + \log!\Bigg(F{\Gamma}!\Big(\tfrac{1}{\mathrm{disp}{\mathrm{lower}}};\text{Shape} + \tfrac{n{2}}{2} - \mathrm{lm_log2},\text{Rate} + \tfrac{\mathrm{RSS}_{\mathrm{Min}}}{2}\Big)\[-2pt]&\qquad\qquad\qquad | (5b) | (5c) | (5d) | F_{\Gamma}(\tfrac{1}{\mathrm{disp}{\mathrm{upper}}};\text{Shape},\text{Rate})\Big) \[4pt]&\quad - \log!\Big(F{\Gamma}(\tfrac{1}{\mathrm{disp}{\mathrm{lower}}};\text{Shape} + n{2}/2 - \mathrm{lm_log2},\text{Rate} + \mathrm{RSS}_{\mathrm{Min}}/2)\[-2pt]&\qquad\qquad\qquad | 5.2 Claim 2 | 5.3 Claim 3 | 5.4 Claims 4 and 5 | [g3_{j}(d) = \mathrm{lg_prob_factor1_j} + \text{lmc}_1 + \text{lmc}_2,d.] | By definition of the per‑face UB3A shift,[\mathrm{lg_prob_factor1}_j | 5.5 Claims 6 and 7 | 5.5.1 Notation and setup | 5.5.2 Remarks for Claim 6 | Proof. From the definition of the tangency point in implementationnotation,[\beta_j(d) | A(d)^{-1},\bigl(\bar{c}_j - B_0(d)\bigr),]with(A(d) = P + \mathrm{base_A}/d)and(B_0(d) = \mathrm{base_B0}/d + P\mu.)Rewriting in terms of (t = 1/d) and using (A(t) = P + tQ),(B_0(t) = t,\mathrm{base_B0} + P\mu),we obtain[\tilde{\beta}_j(t) | A(t)^ | A(t)^{-1},\bigl(\bar{c}_j - P\mu - P\hat{\beta}\bigr) | A(t)^{-1} r^{*}_j.]Substituting this into the exact decomposition of Remark 5.5.1 with(\beta = \beta_j(d)) and (t = 1/d) gives[\mathrm{RSS}_j(d) | \mathrm{RSS}_{ML}+(\beta_j(d) - \hat{\beta})^{T} Q (\beta_j(d) - \hat{\beta}) | Proof. For (t > 0), we have(A(t) = P + tQ \succ tQ) in the Loewner order, so(A(t)^{-1} \prec (tQ)^{-1}). Therefore[\tilde{M}(t) | A(t)^ | 5.5.3 Claim 6: RSS decomposition and lower bound | 5.5.4 Remarks for Claim 7 | Proof. From Remark 5.5.2 and the definition of (\mathrm{UB2}_j(d)),[\mathrm{UB2}_j(d) | \frac{1}{2d}\Bigl(\mathrm{RSS}_{ML}+ (r^{}_j)^{T} \tilde{M}(1/d), r^{}j- \mathrm{RSS}{\mathrm{Min}}\Bigr).]Writing (t = 1/d) and using (\tilde{M}(t) = Q^{-1/2}(K + tI)^{-2}Q^{-1/2}),we obtain[(r^{}_j)^{T} \tilde{M}(t), r^{}_j | v_j^{T}(K + tI)^{-2}v_j = g_j(t),]and hence[\tilde{\mathrm{UB2}}_j(t) | Proof. In the eigenbasis of (K+tI), write (v_j) in coordinates(v_j = \sum_i \sqrt | \frac | \frac | Remark 5.5.7 (Critical points of (\tilde | Proof. From Remark 5.5.4 and Remark 5.5.5,[\tilde | \frac | By Remark 5.5.6, we can write[\frac | Remark 5.5.8 (Inflection points of (\tilde | Proof. From Remark 5.5.5,[\tilde{\mathrm{UB2}}_j''(t)= g_j'(t) + \frac{t}{2},g_j''(t)= -2, v_j^{T}(K+tI)^{-3} v_j+ 3t, v_j^{T}(K+tI)^{-4} v_j.]Writing this in the eigenbasis of (K+tI), let(\mu_i = \lambda_i + t) denote the eigenvalues of (K+tI) and write[v_j^{T}(K+tI)^{-3} v_j= \sum_i w_i \mu_i^{-3},\qquadv_j^{T}(K+tI)^{-4} v_j= \sum_i w_i \mu_i^{-4},]for some weights (w_i \ge 0) (not all zero). Then[\tilde{\mathrm{UB2}}_j''(t)= \sum_i w_i\Bigl(-2,\mu_i^{-3} + 3t,\mu_i^{-4}\Bigr)= \sum_i w_i \mu_i^{-4},\bigl(-2\mu_i + 3t\bigr).]At an inflection point (t^{}), we have (\tilde{\mathrm{UB2}}_j''(t^{}) = 0),so[0= \sum_i w_i \mu_i^{-4},\bigl(-2\mu_i + 3t^{*}\bigr).]Define normalized weights[\alpha_i | 5.5.5 Claim 7: UB2 derivatives and endpoint minimization | Any critical point (t^ | 5.5.5(') Corrected minimization for anisotropic (K)
Core 06: Overview of Envelope Related Functions17 days ago
1. Introduction and Purpose | 1.1 Why Envelopes? | 1.2 High-Level Flow | 2. Theoretical Foundation | 2.1 Posterior and Definition 2 (paper Section 2) | (c) for all (\theta\in\Theta),[q(\theta) | 2.2 Claim 1: finite mixture of normal priors | Suppose (\pi(\theta) = \sum_{i=1}^{k} p_i,\pi_i(\theta\mid \mu_i,\Sigma_i)) and (c(\bar{\theta})) is a subgradient for (-\log g) at (\bar{\theta}). Then[\mathrm{MGF}!\big(-c(\bar{\theta})\big) | \sum_{i=1}^{k} p_i,\exp!\Big(-c(\bar{\theta})^T\mu_i + \tfrac12,c(\bar{\theta})^T\Sigma_i,c(\bar{\theta})\Big),]and the generalized likelihood-subgradient density is again a mixture of multivariate normals:[q(\theta) = \sum_{i=1}^{k} \tilde{p}_i,\pi_i(\theta\mid \tilde{\mu}_i,\Sigma_i),]with[\tilde{p}_i | 2.3 Theorem 1: envelope dominance and tangency | Define[a(\bar{\theta}) | \frac{g(\bar{\theta}),\mathrm{MGF}!\big(-c(\bar{\theta})\big)}{f(y),\exp!\big(-c(\bar{\theta})^T\bar{\theta}\big)},]and[h_{\bar{\theta}}(\theta) | Then Theorem 1 states[a(\bar{\theta}),q_{\bar{\theta}}(\theta)\gea(\bar{\theta}),h_{\bar{\theta}}(\theta),q_{\bar{\theta}}(\theta) | 2.4 Models in standard form | [\mathbb{E}_{\tilde{q}^{\bar{\theta}}}[\theta_r \mid \theta \in A] | 2.5 Construction of restricted subgradient densities | [\tilde{q}_{\bar{\theta}}(\theta) | [\tilde{a}(\theta_{\text{bar}}) | [\int_{\theta \in A} q_{\bar{\theta}}(\theta), d\theta | 2.6 Mixture construction and tractable probabilities | [\tilde{p}_i | [\int_{\theta\in A_i} q^{{\bar{\theta}}}(\theta), d\theta | \displaystyle\prod_{r=1}^{p}\Bigl[\Phi!\bigl(l_{U,r}^{(i)} + c_{r}(\bar{\theta})\bigr) | 2.7 Log-scale properties of the envelope function | [\log h_{\bar{\theta}}(\theta) | 2.8 Standard form: Definition 3 and Remarks 11-15 (paper Section 3.3) | 2.10 Remarks 7-8: sampling restricted normals (paper) | 2.11 Theorem 2: univariate Normal data, three intervals, and (\tilde{a}\to 2/\sqrt{\pi}) | Let (\theta^\ast) be the posterior mode. Define (univariate case)[\omega | \frac | 2.12 Multivariate partition in standard form (paper; Remark 16) | Let (\theta^\ast) be the unique posterior mode. For each coordinate (i), define[\omega_i | 2.13 Theorem 3 (paper) | 3. Function Map and Workflow | 3.1 Where Envelopes Are Used | 3.2 Pipeline Order | 4. Envelope Functions Reference | 5. Gridtype and Envelope Sizing | 6. Central Distributions: Normal_ct, Gamma_ct, InvGamma_ct | 7. Cross-References
Core 07: Parallel Sampling Implementation using RcppParallel17 days ago
1. Introduction | 2. Where Parallel Sampling Is Used | 3. Why Parallel Sampling Cannot Be Interrupted | 4. Pilot-Based Time Estimation and Opt-In | 5. rNormalGLM Pilot Logic (Non-Gaussian GLMs) | 5.1 Single-Draw Test | 5.2 max_draws Cap and Zero Accepts | 5.3 Calibration Run and Refined Estimate | 5.4 Five-Minute Safeguard | 5.5 Diagnostics (verbose = TRUE) | 6. rIndepNormalGammaReg Pilot Logic | 6.1 Single-Draw Test | 6.2 Calibration Run | 6.3 Time Estimate | 6.4 Five-Minute Safeguard | 7. EnvelopeDispersionBuild Pilot (Envelope Construction) | 7.1 Five-Minute Safeguard | 8. Choosing Serial vs Parallel | 9. Technical Details | 9.1 RcppParallel Worker Pattern | 9.2 Thread Safety | 9.3 Dependencies | 10. Troubleshooting | 11. Cross-References
Core 08: Accelerated EnvelopeBuild Implementation using OpenCL17 days ago
1. Introduction | 2. Architecture Overview | 2.1 Call Path | 3. Program Construction | 3.1 Assembly Order | 3.2 load_kernel_source and load_kernel_library | 4. Ported Math Libraries (nmath / rmath / dpq) | 4.1 nmath | 4.2 rmath | 4.3 dpq | 5. Family/Link Kernels | 5.1 Kernel Structure | 6. f2_f3_opencl Flow | 7. f2_f3_kernel_runner | 8. Pilot and Safeguards | 8.1 Pilot Logic | 8.2 When the Pilot Runs | 9. Installation and Availability | 10. Cross-References
Core 09: Implementation Companion for Independent Normal-Gamma17 days ago
1. Introduction | 2. Core Function #1: rIndepNormalGammaReg (non-_std) - Internal Workflow | 2.1 Stage A: EnvelopeCentering() for dispersion2 and RSS_Post2 | 2.2 Stage B: Posterior mode (bstar) and Hessian (A1) | 2.3 Stage C: Standardization (glmb_Standardize_Model) | 2.4 Stage D: EnvelopeOrchestrator() - envelope + dispersion refinement | 2.5 Stage E: Delegation to rIndepNormalGammaReg_std / _parallel | 2.6 Stage F: Back-transform and return values | 3. Core Function #2: EnvelopeOrchestrator - Composition of Envelope Steps | 3.1 Orchestrator inputs and internal Gamma anchoring | 3.2 Step 1: EnvelopeBuild() call (coefficient-envelope) | 3.3 Step 2 (Deep Dive): EnvelopeDispersionBuild() - dispersion-aware extension | 3.3.1 Inputs and the role of RSS_Post2 | 3.3.2 Dispersion interval construction (low, upp) | 3.3.3 Anchor dispersion and face slopes | 3.3.4 RSS/UB minimization and construction of UB_list | 3.3.5 Gamma tilt parameters (gamma_list) | 3.3.6 Returned object summary | 3.4 Step 3: EnvelopeSort() (component reordering) | 4. Simulation Execution: rIndepNormalGammaReg_std - Serial Accept-Reject Loop | 4.1 Precomputation (Inv_f3_precompute_disp) | 4.2 Proposal generation (per accepted draw) | 4.3 Accept-reject test statistic | 4.4 Record outputs | 5. Dataflow: From EnvelopeOrchestrator Outputs to the Sampler | 5.1 What the sampler reads from Env | 5.2 What the sampler reads from gamma_list / UB_list | 6. Practical Knobs and Diagnostics | 6.1 Tuning parameters | 6.2 Interpreting iters_out | 6.3 Minimal examples | 7. Cross-References
Core 10: Technical Derivations for Priors Returned by `Prior_Setup()17 days ago
1. Introduction | 1. Introductory Discussion | 2. Default Priors for Coefficient Means and Covariance Matrices | 2.1 How prior means are determined | 2.2 Data precision $P(\beta)$. | 2.3 Zellner-type prior using $P(\beta^{\ast})$ | 2.3.1 Precision mapping and default covariance scaling | [\Sigma_0 = \Sigma / d,]so[\Sigma_0^ | d,\Sigma^ | d,\frac | 2.3.2 Posterior mean and Variance under dNormal() | dNormal() (Gaussian, coefficient-scale covariance Sigma).For Gaussian likelihood precision $P(\beta^\ast)$ and prior precision$\Sigma^{-1}$,[E(\beta\mid y) | \bigl(P(\beta^\ast)+\Sigma^ | The posterior covariance is[\mathrm{Var}(\beta\mid y) | \bigl(P(\beta^\ast)+\Sigma^ | 2.3.3 Marginal posterior mean under dNormal_Gamma() | dNormal_Gamma() (Gaussian conjugate Normal--Gamma, using Sigma_0).The marginal posterior mean is[E(\beta\mid y) | E_{\tau\mid y}!\left[E(\beta\mid \tau,y)\right].]For fixed $\tau$,[E(\beta\mid \tau,y) | \bigl(\tau X^ | 2.4 Vector pwt and optional sd | 3. Default Priors for Dispersion, Shape, and Rate Parameters | 3.1 Posterior pieces: contribution from likelihood + Normal block | and the marginal quadratic term[S_ | 3.2 Prior-strength parameterization from pwt | The scalar prior‑weight pwt is mapped to an effective prior sample size[n_ | \frac | The dispersion‑free covariance used in dNormal_Gamma() is[\Sigma_0 | \frac | 3.3 Gaussian prior-family calibration and parameter mapping | 3.3.1 Default calibration and posterior Gamma shape/rate | Let (n_w=\sum_i w_i) be the effective sample size (n_effective).For scalar pwt, Prior_Setup() defines the effective prior sample size[n_ | \frac | 3.3.2 Conjugate Normal–Gamma posterior (dNormal_Gamma()) | Theorem 1 (Conjugate posterior under the default dNormal_Gamma() calibration) | Let the prior be[\beta\mid\tau\sim N(\mu,\tau^{-1}\Sigma_0),\qquad\tau\sim\Gamma(a_0,b_0),]with[\Sigma_0 | \frac | (i) Posterior mean of (\beta) | [\mu_ | \mathrm{pwt},\mu+(1-\mathrm{pwt}),\hat\beta | (ii) Posterior dispersion‑free covariance | [\Sigma_ | (\Sigma_0^ | \frac{n_{\mathrm{prior}}}{n_{\mathrm{prior}}+n_w},\Sigma_0 | (iii) Posterior Gamma shape | (iv) Posterior Gamma rate | (v) Marginal posterior mean of (\beta) | (vi) Posterior expectation of (\sigma^2=1/\tau) | For (a_n>1),[\mathbb{E}[\sigma^2\mid y] | \frac | (vii) Marginal posterior covariance of (\beta) | Let[V_n=\Sigma_ | Then[\mathrm{Cov}(\beta\mid y) | \mathbb{E}[\sigma^2\mid y],V_n | Interpretation | Theorem 2 (Weak‑prior limit of the dNormal_Gamma() posterior) | Under the default calibration of Theorem 1, let[n_ | (i) Limiting posterior mean of (\beta) | [\mu_ | \lim_ | (ii) Limiting dispersion‑free covariance | [\Sigma_ | \lim_ | (iii) Limiting Gamma shape | [a_ | \lim_{n_{\mathrm{prior}}\to 0^+} a_n | (iv) Limiting Gamma rate | [b_ | \lim_{n_{\mathrm{prior}}\to 0^+} b_n | (v) Limiting marginal mean of (\beta) | [\mathbb{E}{\Pi{0}}[\beta\mid y] | \mu_ | (vi) Limiting expectation of (\sigma^2 = 1/\tau) | For (\tau\mid y \sim \Gamma(a_{\Pi_{0}},b_{\Pi_{0}})),[\mathbb{E}{\Pi{0}}[\sigma^2\mid y] | \frac | (vii) Limiting marginal covariance of (\beta) | [\mathrm{Cov}{\Pi{0}}(\beta\mid y) | \mathbb | Proof of Theorem 2. | By Theorem 1, for each (n_{\mathrm{prior}}>0) the dNormal_Gamma posterior is Normal–Gamma withhyperparameters[\mu_{\mathrm{post}}(n_{\mathrm{prior}}),\quad\Sigma_{0,\mathrm{post}}(n_{\mathrm{prior}}),\quada_n(n_{\mathrm{prior}}),\quadb_n(n_{\mathrm{prior}}),]given explicitly by[\mu_{\mathrm{post}}(n_{\mathrm{prior}}) | \frac{n_{\mathrm{prior}}}{n_{\mathrm{prior}}+n_w},\mu+\frac{n_w}{n_{\mathrm{prior}}+n_w},\hat\beta,][\Sigma_{0,\mathrm{post}}(n_{\mathrm{prior}}) | \frac{n_w}{n_{\mathrm{prior}}+n_w},G^{-1},][a_n(n_{\mathrm{prior}}) | \frac{n_{\mathrm{prior}}+k+n_w}{2},\qquadb_n(n_{\mathrm{prior}}) | 3.3.3 Posterior covariance under dNormal() with default dispersion | Covariance under fixed (\sigma^2) | From Section 2.3.2, under scalar pwt,[\mathrm{Var}(\beta\mid y,\sigma^2) | For weighted Gaussian regression,[P(\beta^\ast) | \sigma^{-2}X^{\mathsf T}W_{\mathrm{obs}}X,]so[\mathrm{Var}(\beta\mid y,\sigma^2) | Using[n_ | \frac | \frac{n_w}{n_w+n_{\mathrm{prior}}},]this becomes[\mathrm{Var}(\beta\mid y,\sigma^2) | Default dispersion | To choose a default fixed value of (\sigma^2), Prior_Setup() uses theposterior mean from the Normal–Gamma model (Theorem 1 (vi)):[\mathrm | Substituting this into the covariance expression gives[\mathrm{Var}(\beta\mid y,\mathrm{dispersion}_{\mathrm{default}}) | Calibrated prior covariance returned by Prior_Setup() | With the same default dispersion, Prior_Setup() returns the coefficient‑scaleprior covariance[\Sigma_ | Weak‑prior limit | 3.3.4 Independent Normal–Gamma Prior | Coefficient-scale covariance:[\Sigma | ING Gamma shape:[\mathrm | a_0 + \frac | Gamma rate:[\texttt | b_0 | Theorem 3 (Weak-prior limit of the Independent Normal–Gamma posterior) | From the posterior ratio identity in A.2 and Lemma B, we have, for each (n_{\mathrm{prior}}>0),[\Pi^{(\mathrm{ING})}{n{\mathrm{prior}}}(\mathrm{d}\beta,\mathrm{d}\tau) | Let (f\colon\mathbb | For the moment statements, take (f(\beta,\tau)=\beta_j),(f(\beta,\tau)=\tau^{-1}), and(f(\beta,\tau)=(\beta-\mathbb{E}{\Pi_0}[\beta])(\beta-\mathbb{E}{\Pi_0}[\beta])^\top) componentwise.Lemma A again applies because Assumptions 4–5 ensure that the NG Gamma parametersstay uniformly bounded away from zero, giving uniform integrability of the correspondingNG moments.The same envelope (M) from Claim B.2 transfers this to the ING path via the ratiorepresentation. Hence dominated convergence applies to these (unbounded) test functionsas well, yielding[\mathbb{E}{\Pi^{(\mathrm{ING})}{n_{\mathrm{prior}}}}[\beta]\to\mathbb{E}{\Pi_0}[\beta]=\hat\beta,\quad\mathbb{E}{\Pi^{(\mathrm{ING})}{n{\mathrm{prior}}}}[\tau^{-1}]\to\mathbb{E}_{\Pi_0}[\tau^{-1}] | \frac{\mathrm{RSS}w}{n_w-p},]and[\mathrm{Cov}{\Pi^{(\mathrm{ING})}{n{\mathrm{prior}}}}(\beta\mid y)\to\mathrm{Cov}_{\Pi_0}(\beta\mid y) | 3.3.5 dGamma() Prior (Fixed $\beta$, Gamma Prior on Precision) | Prior on (\tau) (fixed-$\beta$ path) | Posterior for (\tau) given (y) and fixed (\beta^{+}) | Posterior expectation of (\sigma^2 = 1/\tau) | For (a_n > 1),[E[\sigma^2 \mid y, \beta^{+}] | \frac | This completes the description of the fixed-$\beta$ Gamma prior used by dGamma() andrGamma_reg(). | Appendix A: Technical Ingredients for the ING Weak‑Prior Limit | A.1 Common Gaussian Setup | A.2 Posterior Ratio Representation | NG prior (Theorem 1, §3.3.2) | For each (n_{\mathrm{prior}} > 0),[\beta \mid \tau \sim N!\left(\mu,;\tau^{-1}\Sigma_0\right),\qquad\tau \sim \Gamma!\left(a_0(n_{\mathrm{prior}}),, b_0(n_{\mathrm{prior}})\right),]where the dispersion–free Zellner matrix is[\Sigma_0 | ING prior (§3.3.4) | The ING prior uses a fixed coefficient–scale covariance and a Gamma shape shifted by (p/2):[\beta \mid n_{\mathrm{prior}} \sim N!\left(\mu,;\Sigma(n_{\mathrm{prior}})\right),\qquad\tau \sim \Gamma!\left(a_0(n_{\mathrm{prior}})+\tfrac{p}{2},; b_0(n_{\mathrm{prior}})\right),]with (\beta) and (\tau) independent, and[\Sigma(n_{\mathrm{prior}}) | Ratio of prior kernels | Define[R_{n_{\mathrm{prior}}}(\beta,\tau) | Because the ING Gamma shape equals the NG Gamma shape plus (p/2), the (\tau)-powers match and cancel.The ratio therefore reduces to[R_{n_{\mathrm{prior}}}(\beta,\tau) | Posterior ratio identity | A.3 Lemma A: Uniform moment bounds for the NG path | Lemma A (Uniform moment bounds for the NG posterior) | Claim A.1 (Continuity and compactness of NG hyperparameters) | [\mu_{\mathrm{post}}(n_{\mathrm{prior}}) | [\Sigma_{0,\mathrm{post}}(n_{\mathrm{prior}}) | [a_n(n_{\mathrm{prior}}) | \frac{n_{\mathrm{prior}} + k + n_w}{2},\qquadb_n(n_{\mathrm{prior}}) | Proof of Lemma A | Bounds for (\tau) | [\mathbb{E}[\tau \mid y, n_{\mathrm{prior}}] | \frac{a_n(n_{\mathrm{prior}})}{b_n(n_{\mathrm{prior}})},\qquad\mathbb{E}[\tau^2 \mid y, n_{\mathrm{prior}}] | Bounds for (\beta) | [\mathbb{E}[\beta \mid y, n_{\mathrm{prior}}] | [\mathrm{Cov}(\beta \mid y, n_{\mathrm{prior}}) | [\mathbb{E}[\sigma^2 \mid y, n_{\mathrm{prior}}] | [\mathbb{E}\bigl[|\beta|^2 \mid y, n_{\mathrm{prior}}\bigr] | A.4 Lemma B: Ratio convergence and domination | Let (R_{n_{\mathrm{prior}}}(\beta,\tau)) be the posterior density ratio[R_{n_{\mathrm{prior}}}(\beta,\tau) | Claim B.1 (Explicit prior ratio and quadratic form) | Then (\tilde R_{n_{\mathrm{prior}}}) can be written in the form[\tilde R_{n_{\mathrm{prior}}}(\beta,\tau) | From Section A.2, the NG and ING prior kernels are[\pi^{(\mathrm{NG})}{n{\mathrm{prior}}}(\beta,\tau)\propto\tau^{a_0(n_{\mathrm{prior}})+p/2-1}\exp!\left(-b_0(n_{\mathrm{prior}})\tau-\frac{\tau}{2}(\beta-\mu)^\top\Sigma_0^{-1}(\beta-\mu)\right),][\pi^{(\mathrm{ING})}{n{\mathrm{prior}}}(\beta,\tau)\propto\tau^{a_0(n_{\mathrm{prior}})+p/2-1}\exp!\left(-b_0(n_{\mathrm{prior}})\tau\right)\exp!\left(-\frac{1}{2}(\beta-\mu)^\top\Sigma(n_{\mathrm{prior}})^{-1}(\beta-\mu)\right),]with[\Sigma_0 | \frac{1-pwt}{pwt},(X^\top W_{\mathrm{obs}}X)^{-1},\qquad\Sigma(n_{\mathrm{prior}}) | The (\tau)-powers match (ING shape = NG shape (+;p/2)), so[\tilde R_{n_{\mathrm{prior}}}(\beta,\tau) | \frac | Then[\tilde R_{n_{\mathrm{prior}}}(\beta,\tau) | Using the explicit formula for (\Sigma(n_ | \frac{n_{\mathrm{prior}}}{n_w},\frac{n_w - p}{\mathrm{Smarg}},(X^\top W_{\mathrm{obs}}X),]we see that (\Sigma(n_{\mathrm{prior}})^{-1}\to 0) as (n_{\mathrm{prior}}\to 0^+).This uses Assumptions 2–3 to ensure the scalar prefactor is positive.Hence, for each fixed (\beta),[h_{n_{\mathrm{prior}}}(\beta) | Claim B.2 (Uniform envelope and integrability) | [M(\beta,\tau) | Recall[R_{n_{\mathrm{prior}}}(\beta,\tau) | \frac | \tilde R_ | \iint L(y\mid\beta,\tau),\pi^ | Step 1: Envelope for (\tilde R_{n_{\mathrm{prior}}}). | From Claim B.1 and the explicit formulas in A.2,[\log \tilde R_{n_{\mathrm{prior}}}(\beta,\tau) | Step 2: Boundedness of the normalizing–constant ratio. | Step 3: Envelope for (R_{n_{\mathrm{prior}}}) and integrability under (\Pi_0). | Combining Steps 1–2,[\bigl|R_{n_{\mathrm{prior}}}(\beta,\tau)\bigr|\leK,M_0(\beta,\tau) | Write both posteriors as[\pi^{(\cdot)}{n{\mathrm{prior}}}(\beta,\tau\mid y)\proptoL(y\mid\beta,\tau),\pi^{(\cdot)}{n{\mathrm{prior}}}(\beta,\tau),]with the common Gaussian likelihood (L(y\mid\beta,\tau)) from Section A.1.The likelihood cancels in the posterior ratio, so[R_{n_{\mathrm{prior}}}(\beta,\tau) | \frac | \tilde R_ | \iint L,\pi^ | By Claim B.1,[\tilde R_{n_{\mathrm{prior}}}(\beta,\tau) | In our explicit construction, (q_{n_{\mathrm{prior}}}(\beta)) does not depend on(n_{\mathrm{prior}}) at all, and[h_{n_{\mathrm{prior}}}(\beta) | Next, write the normalizing–constant ratio as[\frac | \frac | \frac | Finally,[R_{n_{\mathrm{prior}}}(\beta,\tau) | A.8 Summary | Appendix B: Derivation of Theorem 1 (Conjugate Normal–Gamma posterior) | B.1 Setup and joint kernel | Under the Zellner calibration in §3.3.2,[\Sigma_0 | \frac | The joint prior–likelihood kernel in ((\beta,\tau)) is[\pi(\beta,\tau\mid y)\propto\tau^{a_0-1}\exp(-b_0\tau),\tau^{p/2}\exp!\Bigl(-\tfrac{\tau}{2}(\beta-\mu)^\top\Sigma_0^{-1}(\beta-\mu)\Bigr),\tau^{n_w/2}\exp!\Bigl(-\tfrac{\tau}{2}\mathrm{RSS}_w(\beta)\Bigr),]where[\mathrm{RSS}_w(\beta) | B.2 Posterior Normal block: mean and dispersion‑free covariance | Write[G_{\mathrm{post}} := G + \Sigma_0^{-1},]and complete the square:[(\beta-\hat\beta)^\top G(\beta-\hat\beta)+(\beta-\mu)^\top\Sigma_0^{-1}(\beta-\mu) | Using (\Sigma_0^ | \Bigl(1+\frac{n_w}{n_{\mathrm{prior}}}\Bigr)G | \frac | Substituting into (\mu_ | \frac | G_ | \frac | B.3 Posterior Gamma block: shape and rate | The integral over (\beta) is a multivariate Gaussian integral:[\int \tau^{p/2}\exp!\Bigl(-\tfrac{\tau}{2}Q(\beta)\Bigr),d\beta | After cancellation, the only remaining powers of (\tau) are[a_0 - 1 + \frac{n_w}{2},]so the posterior Gamma shape is[a_n | a_0 + \frac | \frac | Thus[b_n = b_0 + \frac | \frac | B.4 Marginal moments of (\beta) and (\sigma^2) | Given (\tau), the posterior factorizes as[\beta\mid\tau,y \sim N\bigl(\mu_ | \frac | \frac{n_{\mathrm{prior}}+n_w}{n_w},G^{-1},][a_n | \frac{n_{\mathrm{prior}}+k+n_w}{2},\qquadb_n | Marginal mean of (\beta).Using the law of total expectation,[E[\beta\mid y] | E_\tau\bigl[E[\beta\mid\tau,y]\bigr] | E_\tau[\mu_{\mathrm{post}}] | \mu_{\mathrm{post}},]since (\mu_{\mathrm{post}}) does not depend on (\tau). Thus[E[\beta\mid y] | Marginal mean of (\sigma^2 = \tau^{-1}).For (\tau\sim\Gamma(a_n,b_n)) with shape–rate parameterization,[E[\tau^{-1}\mid y] | Substituting the expressions for (a_n) and (b_n),[E[\sigma^2\mid y] | \frac | Marginal covariance of (\beta).By the law of total covariance,[\mathrm{Cov}(\beta\mid y) | E_\tau\bigl[\mathrm{Cov}(\beta\mid\tau,y)\bigr]+\mathrm{Cov}\tau\bigl(E[\beta\mid\tau,y]\bigr).]Since (E[\beta\mid\tau,y]=\mu{\mathrm{post}}) does not depend on (\tau), the second term vanishes and[\mathrm{Cov}(\beta\mid y) | E_\tau\bigl[\tau^{-1}\Sigma_{0,\mathrm{post}}\bigr] | Substitute:[a_n-1 | \frac{n_{\mathrm{prior}}+k+n_w}{2}-1 | \frac{n_{\mathrm{prior}}+k+n_w-2}{2},]so[E[\tau^{-1}\mid y] | \frac | Step 2: (\Sigma_ | Under the Zellner calibration,[\Sigma_0 | \frac | Hence[\Sigma_0^{-1} + G | \Bigl(\frac{\mathrm{pwt}}{1-\mathrm{pwt}} + 1\Bigr)G | \frac | Now use the mapping between (\mathrm | \frac | Thus[\Sigma_ | (1-\mathrm | Step 3: Combine the pieces.Putting Steps 1 and 2 together,[\mathrm{Cov}(\beta\mid y) | E[\tau^ | In particular, the covariance can be written as[\mathrm{Cov}(\beta\mid y)
Core 11: Large models — GPU acceleration using OpenCL (backend installation)17 days ago
Introduction | What you see when you load glmbayesCore | Enabling GPU acceleration: three steps | Step 1: Check whether OpenCL is already enabled | Step 2: Ensure dependencies are OpenCL-ready | Step 3: Reinstall glmbayesCore from source | Windows | Linux / macOS | After the install | Verifying the setup | Running a GPU-accelerated model | Appendix A: AMD GPUs on Linux (ROCm OpenCL)
Chapter 16: Large models — GPU acceleration using OpenCL18 days ago
Introduction | What you see when you load glmbayes | Enabling GPU acceleration: three steps | Step 1: Check whether OpenCL is already enabled | Step 2: Ensure backend dependencies are OpenCL-ready | Step 3: Reinstall glmbayesCore from source | Windows | Linux / macOS | After the install | Verifying the setup | Running a GPU-accelerated model | Appendix A: AMD GPUs on Linux (ROCm OpenCL)
Chapter C03: Total variation distances between multivariate normal densities2 months ago
Total variation distances between multivariate normal densities | Definitions | Distance between multivariate normal densities with the same variance-covariance matrix | Distance between multivariate normal densities with the same mean vectors | Distances between multivariate normal densities | Convergence rates for two-block Gibbs samplers for multivariate normal densities | Convergence of mean vectors | Convergence of variance-covariance matrices | Convergence bounds and geometric ergodicity for the two-block Gibbs sampler | Proofs | Proof for densities with shared mean vector | Proof for densities with shared variance-covariance matrix | Proof for convergence of variance-covariance matrices | Proof for convergence of mean vectors | Proof of geometric ergodicity | Special case derivations | How the package evaluates these results | See also
Chapter C05: Total Variation Bounds for Restricted Two-block Gibbs Samplers2 months ago
1. Introduction | 1.1 Problem and setting | 1.2 Statement of the main results (informal) | 1.3 Relation to Rosenthal (1995) | 2. The Conditional Bound | 2.1 Two-block Gibbs sampler and the restricted kernel | 2.2 Total variation and L1 distance | 2.3 Truncation: $\pi(\cdot\mid C_d)$ vs. $\pi$ | 2.4 Theorem 1 — geometric convergence of the restricted chain | 3. The Hierarchical GLMM Model | 3.1 Model and hypotheses | 3.2 Propriety of the flat-prior posterior | 3.3 The mean map and the marginal $\gamma$-chain | 3.4 Theorem 2 — existence of a certified safe set (statement) | 4. The Refresh Measure $Q$ | 4.1 Proper population prior ($\Lambda_\gamma\succ0$) | 4.2 Flat-prior limit ($\Lambda_\gamma\downarrow0$) | 4.3 Summary: existence and nondegeneracy of $Q$ | 5. The Minorization Constant and the Certified Set | 5.1 The minorization profile $\varepsilon(\gamma)$ | 5.2 Convexity, coercivity, and compactness of $\widetilde C_d$ | 5.3 The attained constant $\varepsilon_d$ | 5.4 Flat-prior limit ($\Lambda_\gamma\downarrow0$) | 5.5 Closed form under Gaussian closure | 6. Proof of Theorem 2 | 6.1 Assembly of §4–§5 | 6.2 Lifting to the joint $(\gamma,\beta)$ chain | 7. Scope and Extensions | 7.1 Symmetric case: sharper constants | 7.2 What is and is not certified | 7.3 Open problems | Appendix — Proofs | A.1 Proofs for §3.2 (propriety of the flat-prior posterior) and §3.3 (mean map) | A.2 Proofs for §4 | A.3 Proofs for §5 | A.4 Proof of Theorem 2 | References
Chapter C01: The Gaussian example -- model, data and design2 months ago
The theoretical model | Group effects | Population effects | What is fixed and what has a prior | The Big Word Club data | Variables used | The model being estimated | How the population effects are indexed | The priors | See also
Chapter C02: The exact Gaussian iid sampler2 months ago
Prior specification | Estimating the model using the default settings | Properties of the posterior and the iid sampling procedure | Marginal distribution of the population effects | Conditional distribution of the group effects | Drawing from the posterior | Summarizing the output | Appendix: the reference lmer fit | See also
Chapter C04: The two-block Gibbs sampler2 months ago
Prior specification | Estimating the model using the default settings | Properties of the posterior and the two-block Gibbs procedure | Block 1: group effects given the population effects | Block 2: population effects given the group effects | One sweep and one stored draw | Where the sweep count comes from | The rate matrix for this design | From the rate to a certified sweep count | Summarizing the output | Variance convergence during the main phase | See also
Chapter 00: Introduction and roadmap2 months ago
What this package covers | The five parts | Part 1 — Foundations | Part 2 — Specifying a model | Part 3 — Convergence and variance components | Part 4 — Generalized linear mixed models | Part 5 — Extensions and comparisons | Background reading in the wider ecosystem | A first look | Which chapter answers your question | Companion textbook | See also
Chapter 01: Getting started2 months ago
The data | The formula | Inspecting the design | Setting up priors | Fitting | Reading more | Standard accessors | Comparing with lme4 | What to read next | See also
Chapter 02: From lm and glm to mixed models2 months ago
Chapter 02: From lm/glm to mixed models | Three ways to handle groups | The parameterization | The level-2 design | The two restrictions | One grouping factor | Uncorrelated random effects: || not | | Every fixed effect must have a home | Log-concave likelihoods | See also
Chapter 03: The prior workflow2 months ago
Step 1: model_setup() | Step 2: Prior_Setup_GLMM() | The prior-weight idea | What gets centered where | The fields | The ING window | Step 3: pfamily_list() | Overriding a prior by hand | Putting it together | Checking prior sensitivity | See also
Chapter 04: Linear mixed models with lmerb()2 months ago
The data and the question | A first model: random slopes only | Adding cross-level moderation | Priors | Fitting | Reading the result | The full summary | Per-school coefficients | What changed relative to Chapter 01 | See also
Chapter 05: Reading the output2 months ago
Two blocks, two prefixes | print() | summary() | Pr(Prior_tail) | Accessors | ranef() | coef() | fixef() | The raw draws | Credible intervals | Dispersion and convergence metadata | Quick reference | See also
Chapter 06: Convergence and tv_tol2 months ago
The contract | When sweeps are needed at all | What m_convergence responds to | The sweep history | Convergence plots | Verifying the certificate empirically | What convergence does not mean | See also
Chapter 07: Estimated variance components and the pilot stage2 months ago
Fixed versus sampled | The truncation window | Fitting | What the variance components look like | The cost of honesty | The pilot stage | Reading the summary | When to sample the variance components | See also
Chapter 08: Observation dispersion2 months ago
The default: one fixed variance | Per-group dispersion | Fitting | Reading the dispersion | Sampling a single scalar | Choosing | See also
Chapter 09: Poisson GLMMs2 months ago
What changes for non-Gaussian responses | The model | Priors and fitting | Interpreting on the count scale | The full summary | Convergence | Cost | See also
Chapter 10: Binomial GLMMs2 months ago
Setting up | Full rank is not the same as estimable | Fitting | Reading it on the probability scale | Per-state effects | Why the sweep count is higher | The full summary | Practical notes for binary data | See also
Chapter 11: Point estimates without simulation2 months ago
Iterated conditional modes | It really is the posterior mean | What you get and what you do not | The non-Gaussian case | When to use it | See also
Chapter 12: Row-block models2 months ago
When you want this | A worked example | Comparing blocks | Versus the hierarchical fit | Generalized responses | What you give up | See also
Chapter 13: Comparison with lme4 and glmmTMB2 months ago
Same model, three packages | What is actually different | The feature matrix | Variance components | Choosing | Interface differences to remember | See also
Chapter B00: Engine roadmap and notation2 months ago
Two vignette series, two audiences | The B-series | The model | Symbol table | Internal storage | Full conditionals | Correspondence to lme4 | Model restrictions | Naming conventions in the code | See also
Chapter B01: The two-block Gibbs architecture2 months ago
Why two blocks | One sweep | Replicate chains, not one long chain | The call stack | Route selection | Sweep-outer versus chain-outer | Inside Block 1 | Inside Block 2 | Where C++ takes over | What one sweep stores | See also
Chapter B02: Ergodicity and total-variation convergence2 months ago
The scalar picture | The multivariate rate | Computing it without forming (P_{22}) | A worked case with a closed form | From the rate to a total-variation bound | The full-rank conditions | Level 1: each group's design must be full column rank | Level 2: the retained groups must identify (\gamma) | Beyond the Gaussian case | See also
Chapter B03: Calibrating m_convergence2 months ago
The pipeline | What tv_tol means | Why one extra sweep | Starting points and the (D_0) term | The pilot / main cost trade-off | From a pfamily_list | When certification fails | See also
Chapter B04: The known-vcov Gaussian route and the exact iid sampler2 months ago
Chapter B04: The known-vcov Gaussian route | Route selection | Why the route is exact | Two engines behind one route | The exact iid engine | The symmetry precondition | The Gibbs engine on an exact target | The precision matrix P | The compiled kernel | Working example | When the route does not apply | See also
Chapter B05: Estimated variance components (ING Block 2)2 months ago
Chapter B05: Estimated variance components | Block 2 as a regression on the random effects | Two ways to update | Method A: closed-form conditional mode | Method B: rglmb(), the production path | Plug-ins and where the prior is calibrated | The truncation window | What the chain looks like | Why a pilot stage becomes necessary | Selecting components individually | See also
Chapter B06: The extended local rate diagnostic2 months ago
Why a single (\lambda^*) stops being enough | What the engine certifies instead | The extended rate | The new blocks | The residuals only make it worse | Using it | Reading the output | Two checks worth running | Scanning over draws | The marginal route | Theorem or heuristic: the honest table | See also
Chapter B07: Per-group measurement dispersion2 months ago
The model, and what dispformula selects | Calibrating (\sigma^2_j): why the within-group RSS is the wrong target | The marginal sum of squares | The Gamma parameters | rate versus rate_gamma | Folding in hyperparameter uncertainty | The truncation window | dGamma_list() | What Block 1 does with it | Effect on the rate | Caveats | See also
Chapter B08: Design, identifiability and rank conditions2 months ago
What model_setup() returns | Level 1: within-group rank | What failure means, and what it does not | The estimability check | Level 2: across-group rank | Why this one is fatal | Fixed-effect grammar | Reading the print output | A worked failure | See also
Chapter B09: Row-block engines2 months ago
The engines | The partition object | Block 1 of the mixed-model sampler | lmbBlock() and glmbBlock() are not these engines | Per-block prior calibration | Identifiability, without a second level | Who owns what | See also
Chapter B10: Sweep history and convergence plots2 months ago
Why the ensemble view is the right one | The object | Which engines populate it | Reading the two plots | plot_mean_convergence() | plot_var_convergence() | Multiple chains and n_chains | Using the history programmatically | Interpreting a pilot history | See also
Chapter 12: The nmathopencl R API --- Distribution Functions on the GPU4 months ago
Overview | Checking availability | Normal distribution | Distribution families | Gamma | Binomial | Poisson | Beta | Additional families | Noncentral distributions | Special functions and math support | R extension utilities (R_ext) | RNG core | Fallback behavior in detail | Performance notes
Chapter 00: nmathopencl --- Package Overview5 months ago
What is nmathopencl? | Three-layer architecture | C++ layout inside the package DLL | Related packages | R-side API families | Checking OpenCL availability | Vignette guide
Chapter 01: Setting Up OpenCL and Enabling GPU Acceleration5 months ago
Overview | When you load nmathopencl | What the message means | opencltools as imported dependency | What "compiling with OpenCL" means | Enabling OpenCL for nmathopencl | Step 1: Read the load message | Step 2: If OpenCL is not enabled at all | Step 3: If opencltools is enabled but nmathopencl is not | Verifying the setup | Validating GPU calls with the exported wrappers | Troubleshooting common failures | nmathopencl_has_opencl() returns FALSE after driver installation | Compilation fails with CL/cl.h: No such file or directory | Runtime error: clGetPlatformIDs: CL_PLATFORM_NOT_FOUND_KHR | PATH warnings from opencltools::diagnose_glmbayes() | For package developers: next steps
Chapter 03: Structure of nmath Kernel Programs5 months ago
Why "programs" rather than compiled objects | No #include on the device | The four-layer program structure | Layer 0: OPENCL.cl --- the global configuration header | Layer 1: The upstream shim layer | Type stubs | Capability macros | Runtime no-ops | Math declarations | The design principle | Layer 2: The nmath library and its annotation scheme | @provides and @depends annotations | Only the required subset is loaded | Layer 3: The kernel function | Assembling the program in C++ | What this means for downstream developers
Chapter 05: Kernels, Kernel Runners, and Kernel Wrappers5 months ago
Introduction | How this chapter is organized | The computation in the example: GLM log-posterior over a grid | Serial vs. parallel execution: the fundamental concept | The serial (CPU) mental model | The parallel (GPU) mental model | When OpenCL is not available | Summary | The kernel wrapper | General description | Example: f2_f3_opencl from ex_glmbayes | Step 1 — Convert C++ input types to flat std::vector | Step 2 — Allocate output buffers | Step 3 — Select the kernel and assemble the program string | Step 4 — Dispatch to the runner | Step 5 — Convert outputs from plain C++ back to the required return types | The kernel runner | Example: f2_f3_kernel_runner from ex_glmbayes | Step 1 — Select a device | Step 2 — Create a context and command queue | Step 3 — Compile the program on-device | Step 4 — Allocate device buffers and transfer input data | Step 5 — Bind kernel arguments | Step 6 — Launch the kernel | Step 7 — Read results back to the host (blocking) | Step 8 — Release all resources | The kernel (*.cl) | Example: f2_f3_binomial_logit from ex_glmbayes | The kernel signature | The parallel execution body | The complete call chain | CRAN safety: how the architecture prevents build failures | Applying the pattern in your package | File layout | Type conversion reference | Headers and DESCRIPTION
Chapter 06: Integrating Kernel Wrappers into Your Codebase5 months ago
Introduction | The two integration patterns | Pattern 1: wrapper with a direct R interface | Pattern 2: wrapper as an internal C++ component | Pattern 1 in detail: dnorm_opencl | The R wrapper | The .opencl_try_or_fallback helper | The C++ kernel wrapper | Pattern 2 in detail: f2_f3_opencl | The exported R function | The C++ dispatcher | Why a dedicated CPU implementation? | Choosing between the two patterns | Naming conventions | Summary
Chapter 09: Generic OpenCL Kernel Runners (openclPort layer)5 months ago
The openclPort namespace | opencl_dbl_scalar_kernel_runner | Declaration | Arguments | What it does | Argument layout contract | Example: calling the runner from a kernel wrapper | Error-handling utilities | opencl_status_name | opencl_status_hint | opencl_read_platform_info_str / opencl_read_device_info_str | opencl_make_context_error | Other utilities in openclPort | Rcpp -> std::vector conversion | Device probing (C++ / openclPort) | OpenCL build configuration | Using openclPort from a downstream package
Chapter 10: Case Study --- Building Custom GLM Kernels (ex_glmbayes)5 months ago
Overview | Step 1 --- Identify the nmath functions your kernel needs | Step 2 --- Extract the minimal nmath subset | Step 3 --- Write the kernel files | Step 4 --- Write the kernel runner (C++) | Step 5 --- Write the kernel wrapper (C++) | Why load_library_for_kernel() rather than load_kernel_library()? | Step 6 --- Write the Rcpp export wrappers (C++ and R) | Step 7 --- Implement the CPU fallback | File inventory | OpenCL source (inst/cl/) | C++ source (src/) | C++ headers (src/) | R source (R/) | Adapting this pattern for a new package
Chapter 11: Testing, Debugging, and Benchmarking GPU Kernels5 months ago
Correctness testing | Debugging kernel failures | Benchmarking
Chapter 02: Adding USE_OPENCL and has_opencl() to Your Package5 months ago
Overview | Why a static src/Makevars breaks CRAN | The configure → USE_OPENCL → has_opencl() chain | Adding has_opencl() to your package | C++ side | R side | Case 1: New package with no existing src/Makevars | Case 2: Existing package with a static src/Makevars | What is preserved | Caveats | Guarding OpenCL code in C++ | Testing the CPU-only path before CRAN submission | DESCRIPTION dependencies | Migration note
Chapter 04: The nmath OpenCL Library5 months ago
What is inst/cl/nmath/? | Annotation scheme | File families | Infrastructure / header files | Core math helpers | Density functions (d*) | CDF functions (p*) | Quantile functions (q*) | Random-variate generators (r*) | Special functions | Additional utilities | Cycle-breaking artifacts | The ex_glmbayes_nmath/ subset | Porting fidelity
Chapter 07: Kernels --- Writing and Using OpenCL Kernel Files5 months ago
What is a kernel? | Anatomy of a simple kernel | Standard argument layout | The *_ex_kernel.cl variants | Kernel file index | Density kernels | CDF kernels | Quantile kernels | Random-variate kernels | Special function kernels | Math support kernels | RNG core kernels | Utility kernels | Bessel kernels (standard and extended) | Program assembly | Writing a custom kernel
Chapter 08: Kernel Loading --- load_kernel_source and load_kernel_library5 months ago
The assembly problem | opencltools::load_kernel_source() | opencltools::load_kernel_library() | The annotation format | The topological sort algorithm | Verbose output | Cycle detection and breaking | Assembling a complete program | Using libraries from another package | Dependency index --- faster, kernel-specific loading | Building the index --- write_kernel_dependency_index() | Loading with the index --- load_library_for_kernel() (R) | Extracting a subset --- extract_library_subset() | C++ equivalent --- openclPort::load_library_for_kernel() | Error messages
Chapter 05: Model predictions and posterior predictive checks (+ bayesplot ppc_*)5 months ago
Introduction | Reviewing Model Predictions | Predictions for Actual Data | Predictions for "New" Data | Reviewing Model Residuals | Posterior predictive checks with 'bayesplot' (optional) | Using the DIC Statistic | Running The Probit Model | Running The Clog-Log Model | Running The Reverse Clog-Log Model | Comparing the DIC Statistics | Plotting Predictions and Residuals For the Additional Models | Probit Model | clog-log Model | Reverse clog-log Model
Chapter 06: Deviance residuals, model statistics and posterior inference (+ bayestestR)5 months ago
Introduction | Reviewing Model Predictions | Predictions for Actual Data | Predictions for "New" Data | Reviewing Model Residuals | Posterior predictive checks with 'bayesplot' (optional) | Using the DIC Statistic | Running The Probit Model | Running The Clog-Log Model | Running The Reverse Clog-Log Model | Comparing the DIC Statistics | Plotting Predictions and Residuals For the Additional Models | Probit Model | clog-log Model | Reverse clog-log Model
Chapter 12: Visualizing posteriors with bayesplot5 months ago
1. Purpose | 2. Minimal binomial fit (Menarche) | 3. Coefficient trace and density overlays | 4. Posterior predictive checks | See also
Chapter 13: Bayesian inference and decision making with bayestestR5 months ago
1. Purpose | 2. Example: logistic regression posterior for coefficients | 3. Point and interval summaries | See also
Chapter 02-S02: Normal–Normal Conjugacy for One Mean5 months ago
1. The model | 1.1 Likelihood | 1.2 Prior | 1.3 Posterior derivation | 2. bayesrules illustration | 3. Real data: Old Faithful waiting times | 3.1 Fitting with lmb() | 4. Connection to glmbayes | See also
Chapter 02-S03: Beta–Binomial Conjugacy for One Proportion5 months ago
1. The model | 1.1 Likelihood | 1.2 Prior | 1.3 Posterior derivation | 1.4 The posterior mean as a compromise | 2. bayesrules illustration | 3. Real data: the Bechdel test | 3.1 Fitting with glmb() using dBeta() | 4. Connection to glmbayes | See also
Chapter 02-S04: Gamma–Poisson Conjugacy for One Count Rate5 months ago
1. The model | 1.1 Likelihood | 1.2 Prior | 1.3 Posterior derivation | 2. bayesrules illustration | 3. Fitting with glmb() | 4. Connection to glmbayes | Appendix A. Heart transplant mortality (@Albert2009) | A.1 Fitting with glmb() | See also
Chapter 02-S05: Gamma–Gamma Conjugacy for One Response Rate5 months ago
1. The model | 1.1 Likelihood | 1.2 Prior | 1.3 Posterior derivation | 2. Illustration with base-R plots | 3. Real data: Boston Marathon finishing times | 3.1 Fitting with glmb() | 4. Connection to glmbayes | See also
Chapter 10: Models for the Poisson family5 months ago
1. Introductory Discussion | 2. Poisson Likelihood and Model Structure | 2.1 Weighted Poisson Log‑Likelihood | [\ell(\beta) | \sum_{i=1}^n\left[w_i y_i \log(\mu_i) | \sum_{i=1}^n\left[w_i y_i \eta_i | 2.2 Exponential‑Family Representation | 2.3 Log Link and Its Properties | 2.4 Likelihood, Prior, and Posterior (Normal Prior on beta) | [\log p(\beta) | [\log p(\beta \mid y) | w_i e^{\eta_i}\right] | 3. Data Setup | 4. Classical Poisson Regression | 4.1 Interpretation of the Classical Output | 5. Bayesian Poisson Regression with glmb() | 5.1 Setting the Prior | 5.2 Calling glmb() | 6. Printing and Summarizing the Bayesian Output | 6.1 Posterior Mean Coefficients | 6.2 Effective Number of Parameters | 6.3 DIC | 7. Comparison of Classical and Bayesian Estimates | 8. Credible Intervals and Posterior Interpretation | 9. Concluding Remarks | Appendix A. Bayes Rules! companion — equality_index Poisson regression
Chapter 01: Getting started — Setting up OpenCL5 months ago
Introduction | 1. Download and install build tools | 1.1 Windows: Install Rtools | 1.2 Linux: Install compiler toolchain and R development headers | Installing the latest R on Ubuntu/Debian (optional but recommended) | 1.3 macOS: Install Xcode Command Line Tools and GCC | 2. Install OpenCL components | 2.1 Windows | 2.2 Linux | 2.2.1 OpenCL implementation (vendor runtime) | 2.2.2 OpenCL header files | 2.2.3 OpenCL runtime (ICD loader) | 2.2.4 OpenCL development library (linker symlink) | 2.2.5 Verify OpenCL platforms with clinfo (Linux, recommended) | 2.3 macOS | 3. Install opencltools from source (for OpenCL) | 4. Load the package | 5. Check for OpenCL availability | 5.1 Full diagnostic | 6. Verify the kernel-loading path | Appendix A: AMD GPUs on Linux (ROCm OpenCL recommended) | Install ROCm OpenCL (Ubuntu LTS) | Supported AMD GPUs | Other AMD OpenCL stacks | References
Chapter 02: Using a ported library — assembling kernel programs5 months ago
Introduction | 1. Anatomy of a ported library | 1.1 Shard annotations | 2. The nmath module | 3. Loading kernel source files | 3.1 Single file | 3.2 A whole library directory | 4. Program assembly | 5. Minimal subsetting — loading only the nmath shards a kernel needs | 6. Annotating your kernel files | 6.1 Declare the library (one line, written by you) | 6.2 Step 1 — scan source, write direct-call tags | 6.3 Step 2 — compute transitive closure | 7. Verifying portability | 8. Maintaining a library index | Cross-references
Chapter 03: Kernel runners and wrappers — the glmbayes pattern5 months ago
Introduction | 1. Architecture overview | Call path | 2. Kernel structure | Step 1 — Work-item mapping | Step 2 — Prior term | Step 3 — Prior gradient | Step 4 — Data loop | Step 5 — Write outputs | 2.1 Supported family/link kernels in glmbayes | 3. The kernel wrapper | Linking against opencltools | 4. The kernel runner | 5. Fail gracefully — the dispatch pattern | 6. The pilot pattern | 7. Setting up OpenCL before first use | Cross-references | References
Chapter 01: Getting started with glmbayes5 months ago
1. Introductory Discussion | 2. Preparing a dataframe | 3. Calling the two functions | 3.1 Using the classical glm function | 3.1.1 Calling the classical glm function | 3.2 Setting the Prior and Calling the glmb function | 3.2.1 Setting the prior | 3.2.2 Calling the glmb function | 4. Printing the output | 4.1 Printed glm output | 4.1.1 Coefficients | 4.1.2 Null and Residual Degrees of Freedom | 4.1.3 Residual Deviance | 4.1.4 AIC | 4.2 Printed glmb output | 4.2.1 Posterior Mean Coefficients | 4.2.2 Effective Number of Parameters | 4.2.3 Expected Residual Deviance | 4.2.4 DIC | 5. Textbook Content Mappings | 5.1 Agresti - Foundations of Linear and Generalized Linear Models
Chapter 02-S01: Conjugate Models — Introduction and Overview5 months ago
1. What is Bayesian inference, and why does it matter? | 1.1 The big picture | 1.2 Bayes' theorem | 1.3 Why conjugacy is a gift | 2. Three principles that run through all conjugate models | 2.1 The posterior is always a compromise | 2.2 Credible intervals mean what you think they mean | 2.3 The conjugate prototype and the regression generalization | 3. Putting it all together: from simple models to regression | 3.1 Roadmap | 3.2 What conjugacy gives you — and what it does not | See also
Chapter 03: Estimating Bayesian linear models5 months ago
1. Introductory discussion | 2. Linear Model Structure and Gaussian Likelihood (Fixed Dispersion) | 2.1 Gaussian Log‑Likelihood (Fixed Dispersion) | [\ell(\beta) | 2.2 Normal Prior on (\beta) | 2.3 Log‑Posterior and Conjugate Updating | [\Sigma_ | [\mu_ | 2.4 Why Fixing Dispersion Matters | 3. Sample Data - Dobson's Plant weight data | 4. Calling the two functions | 4.1 Using the classical lm function | 4.1.1 Calling the classical lm function | 4.2 Setting the prior and calling the lmb function | 4.2.1 Setting the prior | 4.2.2 Calling the lmb function | 5. Summarizing the output | 5.1 Summarizing the lm output | 5.1.1 Residual summary | 5.1.2 Coefficient Estimates and Hypothesis Tests | 5.1.3 Model fit statistics | 5.2 Summarizing the lmb output | 5.2.1 Prior and maximum‐likelihood estimates | 5.2.2 Posterior estimates | 5.2.3 Directional Prior-Posterior Summaries | 5.2.4 Distribution percentiles
Chapter 08: Estimating Bayesian generalized linear models5 months ago
General Discussion | The Age of Menarche Data | Variable Transformation and Preliminary Setup | Setting prior point estimates, associated credible intervals, and correlation | Mapping the prior to the link scale | Running the Model | Appendix A. Bayes Rules! companion — logistic priors on weather_perth | Concluding Discussion
Chapter 09: Models for the Binomial family5 months ago
1. Introductory Discussion | 2. Binomial Likelihood and Weighted Formulation | 2.1 Linear predictor and mean structure | 2.2 Weighted binomial log‑likelihood | [\ell(\beta) | 2.3 Exponential‑family representation | The binomial likelihood belongs to the exponential family [@McCullagh1989; @Agresti2015].For a model with linear predictor[\eta_i = x_i^\top \beta,]and mean[\mu_i = g^{-1}(\eta_i),]the contribution of observation (i) to the log‑likelihood can be written as[\ell_i(\beta) | 2.4 Link functions | 3. Specifying Binomial Models in glmbayes | 3.1 Prior Specification | 4. Logit Link: Likelihood, Prior, Posterior | Weighted Log-Likelihood | [\ell_{\text{logit}}(\beta) | Normal Prior | [\log p(\beta) | Log-Posterior | [\log p(\beta \mid y) | \sum_{i=1}^nw_i\Big[y_i,\eta_i - \log(1+e^{\eta_i})\Big] | 4.1 Example Data | 4.2 Prior Setup | 4.3 Fit the Model | 4.4 Summary | 5. Probit Link: Likelihood, Prior, Posterior | [\ell_{\text{probit}}(\beta) | \sum_{i=1}^nw_i\Big[y_i \log\Phi(\eta_i)+(1-y_i)\log\big(1-\Phi(\eta_i)\big)\Big] | 5.1 Prior Setup | 5.2 Fit the Model | 5.3 Summary | 6. Complementary Log-Log (cloglog) Link: Likelihood, Prior, Posterior | [\ell_{\text{cloglog}}(\beta) | \sum_{i=1}^nw_i\Big[y_i \log!\big(1 - e^{-e^{\eta_i}}\big)+(1-y_i)\big(-e^{\eta_i}\big)\Big] | 6.1 Prior Setup | 6.2 Fit the Model | 6.3 Summary | 7. Comparing Link Functions | 8. Concluding Discussion | Appendix A. Bayes Rules! companion — Perth rain (weather_perth)
Chapter 11: Models for the Gamma family5 months ago
1. Introductory Discussion | 2. Gamma Likelihood and Model Structure (Log Link, Fixed Dispersion) | 2.1 Weighted Gamma Log-Likelihood (Log Link) | [\ell(\beta) | \sum_{i=1}^nw_i\left[-\frac{1}{\phi},\eta_i | 2.2 Exponential-Family Representation | 2.3 Log Link and Its Properties | 2.4 Likelihood, Prior, and Posterior (Normal Prior on (\beta)) | [\log p(\beta) | [\log p(\beta \mid y) | \frac{1}{\phi},y_i e^{-\eta_i}\right] | 3. Link Functions for Gamma GLMs | 4. Gamma Regression Example: Insurance Claims | 4.1 Data Setup | 4.2 Classical Gamma Regression Using glm() | 5. Bayesian Gamma Regression (fixed dispersion) with glmb() | 5.1 Estimating Dispersion via gamma.dispersion() | 5.2 Prior Setup Using Prior_Setup() | 5.3 Fitting the Bayesian Gamma Model | 5.4 Summarizing the Bayesian Model | 6. Interpretation and Model Diagnostics | 6.1 Coefficients | 6.2 Dispersion | 6.3 DIC and Model Fit | 7. Concluding Discussion | Appendix A. Bayes Rules! companion
Chapter 04: Tailoring priors — leveraging the Prior_Setup function5 months ago
1. Introductory Discussion | 2. The default prior specification | 2.1 Identifiability and Full–Rank Likelihood Covariance | 2.2 Canonical Precision Definitions and Scaling | 2.3 Posterior Mean via Precision Matrices | 2.4 The impact of the "null_model" and "null_effects" defaults for the interpretation of model diagnostics | 3. Adjusting the strength of priors using pwt, n_prior, and sd | 3.1 Data Setup and Visualization | 3.2 Using the pwt argument to adjust the Zellner g-prior | 3.3 Using n_prior as an alternative | 3.4 Directly Specifying Prior Standard Deviations with sd | 4. Adjusting the prior means using intercept_source, effects_source, and mu | 4.1 Using intercept_source and effects_source | 4.2 The role of the intercept_source in setting the prior mean for the intercept | 4.2.1 Intercept Prior: Centered at Full Model MLE | 4.2.2 Effect Priors: Centered at Zero | 4.2.3 Summary | 4.3 The role of the effects_source in setting the prior mean for the model effects | 4.4 Manually Setting Prior Means Using mu | 4.4.1 How mu interacts with the other arguments | 4.4.2 Requirements for user‑specified mu | 4.4.3 When manual mu is useful | 4.4.4 Example: specifying a custom prior mean | 4.4.5 Relationship between mu and prior strength | 4.4.6 Summary | 5. Practical Considerations for Prior Means and Prior Strength | 5.1 Centering and Scaling of Predictors | 5.2 Choosing the Prior Mean for the Intercept | 5.3 Choosing the Prior Means for the Effects | 5.4 When to Specify mu Directly | 5.5 Choosing the Strength of the Prior | 5.6 Interaction Between Prior Location and Prior Strength | 5.7 Summary
Chapter 07: Foundations of GLMs — families, links, and log-concave likelihoods5 months ago
1. Conceptual Overview | 1.1 Exponential Families: A Unifying Framework | 1.2 Canonical Link Functions | 1.3 Why Log-Concavity Matters | (a) Existence of gradients and subgradients | (b) Any local maximum is a global maximum | (c) Validity of envelope construction methods | (d) Simplified Bayesian computation | 2. Generalized Linear Models in Practice: Formulas, Families, and Links | 2.1 The Formula Interface and the Linear Predictor | 2.2 Family Objects: How glm Receives the Distribution and Link | Specifying a non‑default link | Binomial response formats | Quasi‑families | 2.3 Link Functions: Connecting Means to Linear Predictors | 2.4 How glm Combines Formulas, Families, and Links | A critical example: how glm receives formula, family, and link | 2.5 Transition to the Complete Family–Link Reference | 3. Families and Link Functions in glm() | 3.1 Families and Link Functions in Base R | Notes | 3.2 How Families and Links Fit the Exponential‑Family Structure | 3.3 Where to Find the Full Mathematical Forms | 3.4 Why This Matters for Bayesian GLMs | 4. Bayesian GLMs with glmb() | 4.1 Relationship to Classical GLMs | 4.2 The pfamily Argument: Specifying Priors | 4.3 Supported Likelihood Families | 4.4 A Direct Illustration: Calling glmb() with Formulas, Families, and Priors | 4.5 Posterior Sampling | 4.6 Returned Object | 4.7 Related Functions | 5. Log‑Concavity, Envelopes, and Posterior Computation | 5.1 Why Log‑Concavity Matters | 5.2 Envelope Construction | 5.3 Posterior Computation Strategy | 5.4 Summary | Appendix A. Full Exponential‑Family Forms for All glm() Families and Links | Appendix A. Exponential-family and link reference tables | A.1 Gaussian Family | A.2 Binomial Family | A.3 Poisson Family | A.4 Gamma Family | A.5 Inverse Gaussian Family | A.6 Quasi Families
Chapter 15: Estimating models with unknown dispersion parameters5 months ago
1. Introduction | 2. Exponential-Family Background and Log-Concavity | [\ell(\beta,\phi) | 2.2 Special Case: Weighted Gaussian Linear Regression | Weighted log-likelihood | [\ell(\beta,\tau) | Exponential-family identification | [c(y_i,\phi) | Weighted least squares representation | Log-Concavity Properties in the Weighted Gaussian Case | Concavity in ( \beta )For fixed ( \phi ), the negative weighted log-likelihood is[-\ell(\beta \mid \phi) | Concavity in precision ( \tau = 1/\phi )Rewriting the weighted likelihood in terms of ( \tau ):[\ell(\beta,\tau) | 2.3 Special Case: Gamma Regression With a Log Link | Log‑concavity | Implications for Bayesian GLMs | 3. Gaussian Model With Unknown Dispersion | 3. Priors for Gaussian Models With Unknown Dispersion | [\mathrm{RSS}(\beta) | 3.1 Prior on the Dispersion Only (Gamma Prior on Precision) | [\log p(\tau) | 3.2 Joint Conjugate Normal–Gamma Prior | Log-prior | [\log p(\beta,\tau) | Log-posterior | [\log p(\beta,\tau \mid y) | 3.3 Independent Normal–Gamma Prior | 3.3.1 Independent Normal Gamma Prior in glmbayes | 3.3.2 Two-Block Gibbs Sampling using glmbayes | 3.3.3 Comparison of the Two Samplers | 4. Gamma Regression Models With Unknown Dispersion | 4.1 Prior on the Dispersion Only (Gamma Prior on Precision) | [\log p(\tau \mid \beta,y) | 4.2 Independent Normal–Gamma Prior | Log‑prior | Log‑posterior | 4.3 Conditional Sampling for the Dispersion Parameter | 8. Summary | A1: Posterior Distribution Details for Conjugate Normal-Gamma prior | A1.1 Marginal Posterior for ( \tau ) | [S_ | Equivalently, expanding ( (I + X\Sigma_{0}X^{\mathsf T})^{-1} ) with theSherman--Morrison--Woodbury formula gives the same middle matrix in theprecision form[G - G\left(\Sigma_{0}^{-1} + G\right)^{-1}G | A1.2 Conditional Posterior for ( \beta ) | [V_ | \left(\Sigma_ | A1.3 Sampling the Posterior | Step 1: Draw the marginal posterior for ( \tau ) | Step 2: Draw ( \beta ) conditionally on each sampled ( \tau ) | [V_ | [m_ | Result: Pure i.i.d. Monte Carlo Sampling | A2. Detailed sampling procedured for the Independent Normal-Gamma prior | A2.1 iid Sampling Under Truncated Gamma Priors | A3. Posterior mean of ( \beta ) and marginal covariance (Zellner-type prior) | A3.1 Weighted likelihood and prior precision | [\mathrm | A3.2 Posterior mean of ( \beta ) | [\tau G + \tau \frac{pwt}{1-pwt} G | [\mathrm{Cov}(\beta \mid \tau, y) | \frac | [\boxed{E(\beta \mid y) | (1-pwt),\hat\beta + pwt,\mu_ | A3.3 Marginal covariance of ( \beta ) and the Gamma parameters | [V_ | [\boxed{\mathrm{Cov}(\beta \mid y) | E(\tau^ | [S_ | This is the same scalar as the augmented residual sum of squares S produced byrNormal_reg.wfit() (Section A1).Under the Zellner (g)-prior of A3.1, the prior covariance is(\Sigma_ | Limit (pwt\to 0) and coefficient covariance.Under the Zellner decomposition above, (pwt\to 0^{+}) forces(S_{\mathrm{marg}}\to \mathrm{RSS}) (for fixed data and (\mu_{0}), with afinite mismatch quadratic), not only when (\mu_{0}=\hat\beta).Since (b_{n} = b_{0} + \tfrac{1}{2} S_{\mathrm{marg}}), the marginal Gamma ratethen limits to (b_{0} + \tfrac{1}{2}\mathrm{RSS}) whenever (b_{0}) is heldfixed along the path; (E(\tau^{-1}\mid y)=b_{n}/(a_{n}-1)) therefore ties toRSS through (b_{n}) in the same limit.At the same time, ((1-pwt),G^{-1}\to G^{-1}) from A3.2--A3.3.Thus (\mathrm{Cov}(\beta \mid \tau,y) = \tau^{-1}(1-pwt),G^{-1}) tends to(\tau^{-1}G^{-1}) (likelihood-only WLS covariance given (\tau)), and[\mathrm{Cov}(\beta \mid y) | Prior_Setup() dispersion and the Gamma rates (b_{0}), (b_{n}) | Special case: (b_{0} = \frac{1}{2}(n_{\mathrm{prior}}/n_{w}),S_{\mathrm{marg}}) | [\frac | \frac | Growth of (n_ | \frac | dGamma posterior with fixed (\beta): general form and special choices | Hence, for (n_{\mathrm{prior}}+n_w>2),[E(\tau^{-1}\mid y,\beta) | \frac | Choice (\beta=\beta_\star) (posterior mode from dNormal_Gamma) and weak-prior limit | Using the weighted least-squares decomposition:[\mathrm{RSS}_w(\beta) | \mathrm{RSS}_w(\hat\beta)+(\beta-\hat\beta)^\top G(\beta-\hat\beta),\qquadG=X^\top W X,]so[\mathrm{RSS}w(\beta\star) | Under scalar Zellner weighting, (\beta_\star=(1-pwt)\hat\beta+pwt,\mu_0), giving[\mathrm{RSS}w(\beta\star)
Chapter A12: Technical Derivations for Priors Returned by `Prior_Setup()5 months ago
Chapter A12: Technical Derivations for Priors Returned by Prior_Setup() | 1. Introduction | 1. Introductory Discussion | 2. Default Priors for Coefficient Means and Covariance Matrices | 2.1 How prior means are determined | 2.2 Data precision $P(\beta)$. | 2.3 Zellner-type prior using $P(\beta^{\ast})$ | 2.3.1 Precision mapping and default covariance scaling | [\Sigma_0 = \Sigma / d,]so[\Sigma_0^ | d,\Sigma^ | d,\frac | 2.3.2 Posterior mean and Variance under dNormal() | dNormal() (Gaussian, coefficient-scale covariance Sigma).For Gaussian likelihood precision $P(\beta^\ast)$ and prior precision$\Sigma^{-1}$,[E(\beta\mid y) | \bigl(P(\beta^\ast)+\Sigma^ | The posterior covariance is[\mathrm{Var}(\beta\mid y) | \bigl(P(\beta^\ast)+\Sigma^ | 2.3.3 Marginal posterior mean under dNormal_Gamma() | dNormal_Gamma() (Gaussian conjugate Normal--Gamma, using Sigma_0).The marginal posterior mean is[E(\beta\mid y) | E_{\tau\mid y}!\left[E(\beta\mid \tau,y)\right].]For fixed $\tau$,[E(\beta\mid \tau,y) | \bigl(\tau X^ | 2.4 Vector pwt and optional sd | 3. Default Priors for Dispersion, Shape, and Rate Parameters | 3.1 Posterior pieces: contribution from likelihood + Normal block | and the marginal quadratic term[S_ | 3.2 Prior-strength parameterization from pwt | The scalar prior‑weight pwt is mapped to an effective prior sample size[n_ | \frac | The dispersion‑free covariance used in dNormal_Gamma() is[\Sigma_0 | \frac | 3.3 Gaussian prior-family calibration and parameter mapping | 3.3.1 Default calibration and posterior Gamma shape/rate | Let (n_w=\sum_i w_i) be the effective sample size (n_effective).For scalar pwt, Prior_Setup() defines the effective prior sample size[n_ | \frac | 3.3.2 Conjugate Normal–Gamma posterior (dNormal_Gamma()) | Theorem 1 (Conjugate posterior under the default dNormal_Gamma() calibration) | Let the prior be[\beta\mid\tau\sim N(\mu,\tau^{-1}\Sigma_0),\qquad\tau\sim\Gamma(a_0,b_0),]with[\Sigma_0 | \frac | (i) Posterior mean of (\beta) | [\mu_ | \mathrm{pwt},\mu+(1-\mathrm{pwt}),\hat\beta | (ii) Posterior dispersion‑free covariance | [\Sigma_ | (\Sigma_0^ | \frac{n_{\mathrm{prior}}}{n_{\mathrm{prior}}+n_w},\Sigma_0 | (iii) Posterior Gamma shape | (iv) Posterior Gamma rate | (v) Marginal posterior mean of (\beta) | (vi) Posterior expectation of (\sigma^2=1/\tau) | For (a_n>1),[\mathbb{E}[\sigma^2\mid y] | \frac | (vii) Marginal posterior covariance of (\beta) | Let[V_n=\Sigma_ | Then[\mathrm{Cov}(\beta\mid y) | \mathbb{E}[\sigma^2\mid y],V_n | Interpretation | Theorem 2 (Weak‑prior limit of the dNormal_Gamma() posterior) | Under the default calibration of Theorem 1, let[n_ | (i) Limiting posterior mean of (\beta) | [\mu_ | \lim_ | (ii) Limiting dispersion‑free covariance | [\Sigma_ | \lim_ | (iii) Limiting Gamma shape | [a_ | \lim_{n_{\mathrm{prior}}\to 0^+} a_n | (iv) Limiting Gamma rate | [b_ | \lim_{n_{\mathrm{prior}}\to 0^+} b_n | (v) Limiting marginal mean of (\beta) | [\mathbb{E}{\Pi{0}}[\beta\mid y] | \mu_ | (vi) Limiting expectation of (\sigma^2 = 1/\tau) | For (\tau\mid y \sim \Gamma(a_{\Pi_{0}},b_{\Pi_{0}})),[\mathbb{E}{\Pi{0}}[\sigma^2\mid y] | \frac | (vii) Limiting marginal covariance of (\beta) | [\mathrm{Cov}{\Pi{0}}(\beta\mid y) | \mathbb | Proof of Theorem 2. | By Theorem 1, for each (n_{\mathrm{prior}}>0) the dNormal_Gamma posterior is Normal–Gamma withhyperparameters[\mu_{\mathrm{post}}(n_{\mathrm{prior}}),\quad\Sigma_{0,\mathrm{post}}(n_{\mathrm{prior}}),\quada_n(n_{\mathrm{prior}}),\quadb_n(n_{\mathrm{prior}}),]given explicitly by[\mu_{\mathrm{post}}(n_{\mathrm{prior}}) | \frac{n_{\mathrm{prior}}}{n_{\mathrm{prior}}+n_w},\mu+\frac{n_w}{n_{\mathrm{prior}}+n_w},\hat\beta,][\Sigma_{0,\mathrm{post}}(n_{\mathrm{prior}}) | \frac{n_w}{n_{\mathrm{prior}}+n_w},G^{-1},][a_n(n_{\mathrm{prior}}) | \frac{n_{\mathrm{prior}}+k+n_w}{2},\qquadb_n(n_{\mathrm{prior}}) | 3.3.3 Posterior covariance under dNormal() with default dispersion | Covariance under fixed (\sigma^2) | From Section 2.3.2, under scalar pwt,[\mathrm{Var}(\beta\mid y,\sigma^2) | For weighted Gaussian regression,[P(\beta^\ast) | \sigma^{-2}X^{\mathsf T}W_{\mathrm{obs}}X,]so[\mathrm{Var}(\beta\mid y,\sigma^2) | Using[n_ | \frac | \frac{n_w}{n_w+n_{\mathrm{prior}}},]this becomes[\mathrm{Var}(\beta\mid y,\sigma^2) | Default dispersion | To choose a default fixed value of (\sigma^2), Prior_Setup() uses theposterior mean from the Normal–Gamma model (Theorem 1 (vi)):[\mathrm | Substituting this into the covariance expression gives[\mathrm{Var}(\beta\mid y,\mathrm{dispersion}_{\mathrm{default}}) | Calibrated prior covariance returned by Prior_Setup() | With the same default dispersion, Prior_Setup() returns the coefficient‑scaleprior covariance[\Sigma_ | Weak‑prior limit | 3.3.4 Independent Normal–Gamma Prior | Coefficient-scale covariance:[\Sigma | ING Gamma shape:[\mathrm | a_0 + \frac | Gamma rate:[\texttt | b_0 | Theorem 3 (Weak-prior limit of the Independent Normal–Gamma posterior) | From the posterior ratio identity in A.2 and Lemma B, we have, for each (n_{\mathrm{prior}}>0),[\Pi^{(\mathrm{ING})}{n{\mathrm{prior}}}(\mathrm{d}\beta,\mathrm{d}\tau) | Let (f\colon\mathbb | For the moment statements, take (f(\beta,\tau)=\beta_j),(f(\beta,\tau)=\tau^{-1}), and(f(\beta,\tau)=(\beta-\mathbb{E}{\Pi_0}[\beta])(\beta-\mathbb{E}{\Pi_0}[\beta])^\top) componentwise.Lemma A again applies because Assumptions 4–5 ensure that the NG Gamma parametersstay uniformly bounded away from zero, giving uniform integrability of the correspondingNG moments.The same envelope (M) from Claim B.2 transfers this to the ING path via the ratiorepresentation. Hence dominated convergence applies to these (unbounded) test functionsas well, yielding[\mathbb{E}{\Pi^{(\mathrm{ING})}{n_{\mathrm{prior}}}}[\beta]\to\mathbb{E}{\Pi_0}[\beta]=\hat\beta,\quad\mathbb{E}{\Pi^{(\mathrm{ING})}{n{\mathrm{prior}}}}[\tau^{-1}]\to\mathbb{E}_{\Pi_0}[\tau^{-1}] | \frac{\mathrm{RSS}w}{n_w-p},]and[\mathrm{Cov}{\Pi^{(\mathrm{ING})}{n{\mathrm{prior}}}}(\beta\mid y)\to\mathrm{Cov}_{\Pi_0}(\beta\mid y) | 3.3.5 dGamma() Prior (Fixed $\beta$, Gamma Prior on Precision) | Prior on (\tau) (fixed-$\beta$ path) | Posterior for (\tau) given (y) and fixed (\beta^{+}) | Posterior expectation of (\sigma^2 = 1/\tau) | For (a_n > 1),[E[\sigma^2 \mid y, \beta^{+}] | \frac | This completes the description of the fixed-$\beta$ Gamma prior used by dGamma() andrGamma_reg(). | Appendix A: Technical Ingredients for the ING Weak‑Prior Limit | A.1 Common Gaussian Setup | A.2 Posterior Ratio Representation | NG prior (Theorem 1, §3.3.2) | For each (n_{\mathrm{prior}} > 0),[\beta \mid \tau \sim N!\left(\mu,;\tau^{-1}\Sigma_0\right),\qquad\tau \sim \Gamma!\left(a_0(n_{\mathrm{prior}}),, b_0(n_{\mathrm{prior}})\right),]where the dispersion–free Zellner matrix is[\Sigma_0 | ING prior (§3.3.4) | The ING prior uses a fixed coefficient–scale covariance and a Gamma shape shifted by (p/2):[\beta \mid n_{\mathrm{prior}} \sim N!\left(\mu,;\Sigma(n_{\mathrm{prior}})\right),\qquad\tau \sim \Gamma!\left(a_0(n_{\mathrm{prior}})+\tfrac{p}{2},; b_0(n_{\mathrm{prior}})\right),]with (\beta) and (\tau) independent, and[\Sigma(n_{\mathrm{prior}}) | Ratio of prior kernels | Define[R_{n_{\mathrm{prior}}}(\beta,\tau) | Because the ING Gamma shape equals the NG Gamma shape plus (p/2), the (\tau)-powers match and cancel.The ratio therefore reduces to[R_{n_{\mathrm{prior}}}(\beta,\tau) | Posterior ratio identity | A.3 Lemma A: Uniform moment bounds for the NG path | Lemma A (Uniform moment bounds for the NG posterior) | Claim A.1 (Continuity and compactness of NG hyperparameters) | [\mu_{\mathrm{post}}(n_{\mathrm{prior}}) | [\Sigma_{0,\mathrm{post}}(n_{\mathrm{prior}}) | [a_n(n_{\mathrm{prior}}) | \frac{n_{\mathrm{prior}} + k + n_w}{2},\qquadb_n(n_{\mathrm{prior}}) | Proof of Lemma A | Bounds for (\tau) | [\mathbb{E}[\tau \mid y, n_{\mathrm{prior}}] | \frac{a_n(n_{\mathrm{prior}})}{b_n(n_{\mathrm{prior}})},\qquad\mathbb{E}[\tau^2 \mid y, n_{\mathrm{prior}}] | Bounds for (\beta) | [\mathbb{E}[\beta \mid y, n_{\mathrm{prior}}] | [\mathrm{Cov}(\beta \mid y, n_{\mathrm{prior}}) | [\mathbb{E}[\sigma^2 \mid y, n_{\mathrm{prior}}] | [\mathbb{E}\bigl[|\beta|^2 \mid y, n_{\mathrm{prior}}\bigr] | A.4 Lemma B: Ratio convergence and domination | Let (R_{n_{\mathrm{prior}}}(\beta,\tau)) be the posterior density ratio[R_{n_{\mathrm{prior}}}(\beta,\tau) | Claim B.1 (Explicit prior ratio and quadratic form) | Then (\tilde R_{n_{\mathrm{prior}}}) can be written in the form[\tilde R_{n_{\mathrm{prior}}}(\beta,\tau) | From Section A.2, the NG and ING prior kernels are[\pi^{(\mathrm{NG})}{n{\mathrm{prior}}}(\beta,\tau)\propto\tau^{a_0(n_{\mathrm{prior}})+p/2-1}\exp!\left(-b_0(n_{\mathrm{prior}})\tau-\frac{\tau}{2}(\beta-\mu)^\top\Sigma_0^{-1}(\beta-\mu)\right),][\pi^{(\mathrm{ING})}{n{\mathrm{prior}}}(\beta,\tau)\propto\tau^{a_0(n_{\mathrm{prior}})+p/2-1}\exp!\left(-b_0(n_{\mathrm{prior}})\tau\right)\exp!\left(-\frac{1}{2}(\beta-\mu)^\top\Sigma(n_{\mathrm{prior}})^{-1}(\beta-\mu)\right),]with[\Sigma_0 | \frac{1-pwt}{pwt},(X^\top W_{\mathrm{obs}}X)^{-1},\qquad\Sigma(n_{\mathrm{prior}}) | The (\tau)-powers match (ING shape = NG shape (+;p/2)), so[\tilde R_{n_{\mathrm{prior}}}(\beta,\tau) | \frac | Then[\tilde R_{n_{\mathrm{prior}}}(\beta,\tau) | Using the explicit formula for (\Sigma(n_ | \frac{n_{\mathrm{prior}}}{n_w},\frac{n_w - p}{\mathrm{Smarg}},(X^\top W_{\mathrm{obs}}X),]we see that (\Sigma(n_{\mathrm{prior}})^{-1}\to 0) as (n_{\mathrm{prior}}\to 0^+).This uses Assumptions 2–3 to ensure the scalar prefactor is positive.Hence, for each fixed (\beta),[h_{n_{\mathrm{prior}}}(\beta) | Claim B.2 (Uniform envelope and integrability) | [M(\beta,\tau) | Recall[R_{n_{\mathrm{prior}}}(\beta,\tau) | \frac | \tilde R_ | \iint L(y\mid\beta,\tau),\pi^ | Step 1: Envelope for (\tilde R_{n_{\mathrm{prior}}}). | From Claim B.1 and the explicit formulas in A.2,[\log \tilde R_{n_{\mathrm{prior}}}(\beta,\tau) | Step 2: Boundedness of the normalizing–constant ratio. | Step 3: Envelope for (R_{n_{\mathrm{prior}}}) and integrability under (\Pi_0). | Combining Steps 1–2,[\bigl|R_{n_{\mathrm{prior}}}(\beta,\tau)\bigr|\leK,M_0(\beta,\tau) | Write both posteriors as[\pi^{(\cdot)}{n{\mathrm{prior}}}(\beta,\tau\mid y)\proptoL(y\mid\beta,\tau),\pi^{(\cdot)}{n{\mathrm{prior}}}(\beta,\tau),]with the common Gaussian likelihood (L(y\mid\beta,\tau)) from Section A.1.The likelihood cancels in the posterior ratio, so[R_{n_{\mathrm{prior}}}(\beta,\tau) | \frac | \tilde R_ | \iint L,\pi^ | By Claim B.1,[\tilde R_{n_{\mathrm{prior}}}(\beta,\tau) | In our explicit construction, (q_{n_{\mathrm{prior}}}(\beta)) does not depend on(n_{\mathrm{prior}}) at all, and[h_{n_{\mathrm{prior}}}(\beta) | Next, write the normalizing–constant ratio as[\frac | \frac | \frac | Finally,[R_{n_{\mathrm{prior}}}(\beta,\tau) | A.8 Summary | Appendix B: Derivation of Theorem 1 (Conjugate Normal–Gamma posterior) | B.1 Setup and joint kernel | Under the Zellner calibration in §3.3.2,[\Sigma_0 | \frac | The joint prior–likelihood kernel in ((\beta,\tau)) is[\pi(\beta,\tau\mid y)\propto\tau^{a_0-1}\exp(-b_0\tau),\tau^{p/2}\exp!\Bigl(-\tfrac{\tau}{2}(\beta-\mu)^\top\Sigma_0^{-1}(\beta-\mu)\Bigr),\tau^{n_w/2}\exp!\Bigl(-\tfrac{\tau}{2}\mathrm{RSS}_w(\beta)\Bigr),]where[\mathrm{RSS}_w(\beta) | B.2 Posterior Normal block: mean and dispersion‑free covariance | Write[G_{\mathrm{post}} := G + \Sigma_0^{-1},]and complete the square:[(\beta-\hat\beta)^\top G(\beta-\hat\beta)+(\beta-\mu)^\top\Sigma_0^{-1}(\beta-\mu) | Using (\Sigma_0^ | \Bigl(1+\frac{n_w}{n_{\mathrm{prior}}}\Bigr)G | \frac | Substituting into (\mu_ | \frac | G_ | \frac | B.3 Posterior Gamma block: shape and rate | The integral over (\beta) is a multivariate Gaussian integral:[\int \tau^{p/2}\exp!\Bigl(-\tfrac{\tau}{2}Q(\beta)\Bigr),d\beta | After cancellation, the only remaining powers of (\tau) are[a_0 - 1 + \frac{n_w}{2},]so the posterior Gamma shape is[a_n | a_0 + \frac | \frac | Thus[b_n = b_0 + \frac | \frac | B.4 Marginal moments of (\beta) and (\sigma^2) | Given (\tau), the posterior factorizes as[\beta\mid\tau,y \sim N\bigl(\mu_ | \frac | \frac{n_{\mathrm{prior}}+n_w}{n_w},G^{-1},][a_n | \frac{n_{\mathrm{prior}}+k+n_w}{2},\qquadb_n | Marginal mean of (\beta).Using the law of total expectation,[E[\beta\mid y] | E_\tau\bigl[E[\beta\mid\tau,y]\bigr] | E_\tau[\mu_{\mathrm{post}}] | \mu_{\mathrm{post}},]since (\mu_{\mathrm{post}}) does not depend on (\tau). Thus[E[\beta\mid y] | Marginal mean of (\sigma^2 = \tau^{-1}).For (\tau\sim\Gamma(a_n,b_n)) with shape–rate parameterization,[E[\tau^{-1}\mid y] | Substituting the expressions for (a_n) and (b_n),[E[\sigma^2\mid y] | \frac | Marginal covariance of (\beta).By the law of total covariance,[\mathrm{Cov}(\beta\mid y) | E_\tau\bigl[\mathrm{Cov}(\beta\mid\tau,y)\bigr]+\mathrm{Cov}\tau\bigl(E[\beta\mid\tau,y]\bigr).]Since (E[\beta\mid\tau,y]=\mu{\mathrm{post}}) does not depend on (\tau), the second term vanishes and[\mathrm{Cov}(\beta\mid y) | E_\tau\bigl[\tau^{-1}\Sigma_{0,\mathrm{post}}\bigr] | Substitute:[a_n-1 | \frac{n_{\mathrm{prior}}+k+n_w}{2}-1 | \frac{n_{\mathrm{prior}}+k+n_w-2}{2},]so[E[\tau^{-1}\mid y] | \frac | Step 2: (\Sigma_ | Under the Zellner calibration,[\Sigma_0 | \frac | Hence[\Sigma_0^{-1} + G | \Bigl(\frac{\mathrm{pwt}}{1-\mathrm{pwt}} + 1\Bigr)G | \frac | Now use the mapping between (\mathrm | \frac | Thus[\Sigma_ | (1-\mathrm | Step 3: Combine the pieces.Putting Steps 1 and 2 together,[\mathrm{Cov}(\beta\mid y) | E[\tau^ | In particular, the covariance can be written as[\mathrm{Cov}(\beta\mid y)
Chapter 14: Informative priors — centering and differential prior weights5 months ago
General Discussion | The Age of Menarche Data | Variable Transformation and Preliminary Setup | Setting prior point estimates, associated credible intervals, and correlation | Mapping the prior to the link scale | Running the Model | Concluding Discussion
Chapter 17: Linear mixed-effects models5 months ago
1. Use Case 1: Dispersion and Regression Coefficients (Gaussian) | 2. Use Case 2: Hierarchical (Random Effects) Models | 2.1 Eight Schools with dNormal_Gamma Prior (Gibbs-suitable) | 2.2 Eight Schools with dIndependent_Normal_Gamma Prior | 3. Summary
Chapter 18: Generalized linear mixed-effects models5 months ago
1. Model Structure | 2. Data and Setup | 3. Two-Block Gibbs Sampler | 4. CODA Diagnostics | 5. Out-of-Sample Prediction | 6. Summary
Chapter A04: Directional Tail Diagnostics for Prior-Posterior Disagreement7 months ago
Directional tail diagnostic (current implementation) | Theoretical interpretation and relation to t and F | Relation to univariate t statistics | Relation to multivariate Wald/F-style tests | Interpretation: what probability is being assessed? | Univariate connection to known Bayesian tail/sign summaries | How magnitude compares to classical tests | Strong-prior regime | Weak-prior (data-dominant) limit | Scalar decomposition (normal-gamma heuristic) | Incorporating the package example (Ex_directional_tail.R) | Illustrative plots from Ex_directional_tail.R | How directional_tail() is called | How summary.glmb() uses directional tail | Minimal reproducible workflow | Supplementary notes: why the Bayesian tail can be smaller | 1.3 Different centering (posterior mean vs. OLS) and prior shrinkage
Chapter A06: Accept–Reject Sampling for Dispersion in Gamma Regression7 months ago
1. Introduction | 1.2 Likelihood | [\ell_i(v) | v\log v | v\log \mu_i+(v-1)\log y_i | \log\Gamma(v) | [\ell(v) | \sum_{i=1}^nw_i\left[v\log v | 1.3 Prior | 1.4. Posterior Log‑Density | [f(v) | 2. The sampler | 2.1 Proposal Distribution | [\begin{aligned}\log p_{prop}(v) & = (a_0+ \frac{1}{2}\sum_i w_i )\log [ b_0 - \bar{c}(v_{\text{tangent}})] ;-; \log\Gamma(a_0+ \frac{1}{2}\sum_i w_i ) \[4pt]& ;+; ((a_0+ \frac{1}{2}\sum_i w_i ) - 1)\log v ;-; [ b_0 - \bar{c}(v_{\text{tangent}})] v.\end{aligned}] | 2.2 Bounding function | [\log h(v) | \ell(v) | \bigl[\ell(v_{\text{tangent}}) | \bar{c}(v_{\text{tangent}})(v - v_{\text{tangent}})\bigr] | 2.3 Equivalence Claim | 2.4 Implementation Outline
Chapter A03: Methods available in glmbayes7 months ago