
Collect stLMM posterior samples in a data frame
as_samples.RdCollect posterior sample matrices from fitted, recovered, prediction, or fitted-value objects into a plain data frame with samples in rows and named sample columns across the top.
Arguments
- object
An
stLMM,stLMM_chains,stLMM_recovery,stLMM_recovery_chains,stLMM_prediction,stLMM_prediction_chains,stLMM_fitted_chains, or posterior sample matrix.- ...
Additional arguments passed to methods. Supported arguments include
burn,thin,metadata,include_w,combine_chains, and, for prediction objects,sample.
Details
For fitted stLMM objects, columns contain active parameter sample blocks
such as fixed effects, grouped random effects, residual variance parameters,
process variances, and process correlation parameters. Structured latent
process draws are available when they were saved during fitting or added by
recover(), and are included only when include_w = TRUE.
For recovery objects, parameter samples are aligned to
object$recover_iter before saved or recovered latent process draws are appended.
This ensures parameter columns and w_ columns describe the same retained
posterior iterations.
For multi-chain objects, samples are combined by row by default and the
.chain metadata column preserves chain membership. Set
combine_chains = FALSE to return one data frame per chain.
Prediction methods accept sample = "mu", "y", or "all".
Prediction columns are named mu_1, mu_2, and so on, or
y_1, y_2, and so on.
Value
A data frame, or a list of data frames when combine_chains = FALSE.
When metadata = TRUE, the first columns are .chain and
.iteration. .iteration is the original MCMC iteration within
chain when that metadata is available.
Examples
set.seed(1)
dat <- data.frame(y = rnorm(8), x = seq(-1, 1, length.out = 8))
fit <- stLMM(y ~ x, data = dat, n_samples = 8, warmup = FALSE, verbose = FALSE)
draws <- as_samples(fit, burn = 2, thin = 2)
newdat <- data.frame(x = c(-0.5, 0.5))
pred <- predict(fit, newdata = newdat, y_samples = TRUE)
pred_draws <- as_samples(pred, sample = "all")