| generate_posterior_correlation | R Documentation |
Called internally by generate_posterior when
draw_correlation = TRUE, but can be used directly for finer control.
For each draw, samples the correlation parameter vector from its approximate
normal posterior, rebuilds the posterior covariance under that drawn
correlation structure without re-solving for a new coefficient mode, then
draws coefficients from the updated posterior.
generate_posterior_correlation(
object,
new_sigmasq_tilde = object$sigmasq_tilde,
new_predictors = NULL,
theta_1 = 0,
theta_2 = 0,
posterior_predictive_draw = function(N, mean, sqrt_dispersion, ...) {
rnorm(N,
mean, sqrt_dispersion)
},
draw_dispersion = TRUE,
include_posterior_predictive = FALSE,
num_draws = 1,
enforce_qp_constraints = TRUE,
correlation_param_mean = NULL,
correlation_param_vcov_sc = NULL,
correlation_VhalfInv_fxn = NULL,
correlation_Vhalf_fxn = NULL,
include_warnings = TRUE,
...
)
object |
A fitted |
new_sigmasq_tilde |
Numeric; dispersion starting value when
|
new_predictors |
Matrix or NULL; predictor matrix for posterior predictive sampling. Default uses in-sample predictors. |
theta_1 |
Numeric; shape increment for the inverse-gamma prior. Default 0. |
theta_2 |
Numeric; rate increment for the inverse-gamma prior. Default 0. |
posterior_predictive_draw |
Function; sampler for posterior predictive
realisations. Default |
draw_dispersion |
Logical; sample |
include_posterior_predictive |
Logical; generate posterior predictive draws. Default FALSE. |
num_draws |
Positive integer; number of draws (each requires one correlation parameter sample and one covariance rebuild). Default 1. |
enforce_qp_constraints |
Logical; if TRUE, enforce active QP inequality constraints during each coefficient draw via the stored elliptical-slice constrained sampler. Default TRUE. |
correlation_param_mean |
Numeric vector or NULL; mean of the
approximate normal posterior on the working scale. Default:
|
correlation_param_vcov_sc |
Matrix or NULL; variance-covariance
on the working scale. Default:
|
correlation_VhalfInv_fxn |
Function or NULL; maps parameter vector
to |
correlation_Vhalf_fxn |
Function or NULL; maps to
|
include_warnings |
Logical; emit warnings. Default TRUE. |
... |
Additional arguments forwarded to the GLM weight function,
dispersion function, and |
Each draw proceeds in three steps:
Draw correlation parameters.
\boldsymbol{\rho}^{(m)} \sim
\mathcal{N}(\hat{\boldsymbol{\rho}}_{\mathrm{REML}},
\mathbf{H}^{-1}_{\mathrm{BFGS}})
on the unbounded working scale. Draws producing a non-PD correlation
matrix are rejected and redrawn (up to 50 attempts); if all fail, the
point estimate is used with a warning.
Rebuild posterior covariance.
Using the already-expanded \mathbf{X}_k, \mathbf{A}, and
\boldsymbol{\Lambda} from the original fit, recompute only the
covariance-side quantities implied by the drawn correlation structure:
\mathbf{G}_{\mathrm{correct}}^{(m)} =
\left(\mathbf{X}^{\top} \mathbf{W}\mathbf{D}
\mathbf{V}^{-1}(\boldsymbol{\rho}^{(m)}) \mathbf{X}
+ \boldsymbol{\Lambda}\right)^{-1},
and from this the updated constraint projection
\mathbf{U}^{(m)} and effective degrees of freedom
\mathrm{trace}(\mathbf{H}^{(m)}).
The coefficient mode \hat{\boldsymbol{\beta}}_{\mathrm{raw}}
and fitted mean \tilde{\mathbf{y}} are held fixed at the
original fit values. Knot placement, partitioning, polynomial
expansion, penalty tuning, and coefficient re-estimation are all
skipped entirely.
Draw coefficients.
Updated quantities (U, Ghalf_correct, VhalfInv,
sigmasq_tilde, trace_XUGX) are passed to the stored
closure via override_* arguments so that the draw is centred
at the original mode but uses the covariance implied by the drawn
correlation structure. The stored mode object$B_raw is passed
as override_B_raw so it is not recomputed.
Why the mode is held fixed. Re-solving for a new MAP estimate under each drawn correlation structure is expensive, requires iterative solvers, and risks convergence failures on draws far from the REML estimate. The posterior draw is centred at the original mode, which remains a reasonable approximation when the REML surface is not sharply peaked. The covariance update captures the primary effect of correlation uncertainty on posterior width and shape.
BFGS inverse Hessian caveat.
The BFGS inverse Hessian approximation for the correlation parameter
covariance is asymptotically valid but may be poor for small samples,
near-boundary estimates, or multimodal REML surfaces. It is not guaranteed
to converge to the observed information matrix. Users should inspect
object$VhalfInv_params_vcov before relying on these draws.
When num_draws = 1, a named list:
List of length K+1; per-partition coefficient vectors on the original scale.
Drawn dispersion.
Posterior predictive vector (only when
include_posterior_predictive = TRUE).
Drawn correlation parameters on the working scale.
When num_draws > 1:
List of num_draws lists of K+1
coefficient vectors.
List of num_draws scalars.
N_{\mathrm{new}} \times M matrix, where
M = \mathrm{num\_draws} (only when
include_posterior_predictive = TRUE).
List of num_draws vectors.
generate_posterior,
lgspline,
lgspline.fit
## See ?generate_posterior for a complete worked example.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.