Run MCMC Sampling for a Fitted gamlss2 Model

Description

The function mcmc() runs MCMC sampling for a fitted gamlss2 model. It reuses the fitted model object and merges the MCMC output back into the original object such that standard methods (e.g., summary and plot) work as expected.

Usage

mcmc(object, n.iter = 1200, burnin = 200, thin = 1)

Arguments

object An object of class “gamlss2” (or “bamlss2”) as returned by gamlss2.
n.iter Integer, the total number of MCMC iterations.
burnin Integer, the burn-in period.
thin Integer, thinning parameter for saved samples.

Details

The function sets n.iter, burnin, and thin in the model control list and obtains starting values from the fitted object (including smoothing parameters). The MCMC sampler BS is then called and the resulting samples and posterior summaries are merged into the original model object. This approach ensures that the result retains terms, call, and related components required by extractor and plotting functions.

The function is designed to behave in line with gamlss2() interfaces with respect to weights and offset handling. If the fitted model object does not contain the required design information for MCMC sampling (e.g., if the model was fitted using a reduced control setting that drops smooth design matrices), sampling cannot be performed.

Value

A model object inheriting from “gamlss2” containing posterior samples and summary information. The object also contains:

  • samples: Posterior draws for coefficients and smoothing variances.

  • results: Model results derived from posterior means.

  • elapsed: Elapsed sampling time.

References

Umlauf, N., Klein, N., and Zeileis, A. (2018). BAMLSS: Bayesian Additive Models for Location, Scale and Shape (and Beyond). Journal of Computational and Graphical Statistics, 27(3), 612–627. doi:10.1080/10618600.2017.1407325

See Also

gamlss2, bamlss2, BS

Examples

library("gamlss2")


data("abdom", package = "gamlss.data")

## specify the model Formula
f <- y ~ s(x) | s(x) | s(x) | s(x)

## estimate model using backfitting
b <- gamlss2(f, data = abdom, family = BCT)

## run MCMC sampling
set.seed(1328)
a <- mcmc(b)

## generate more samples
a <- mcmc(a)

## posterior summary
summary(a)

## plot estimated effects
plot(a)

## plot samples
plot(a, which = "samples")

## compare estimated mean effects
plot(c(b, a))

## predict parameters using samples
pm <- predict(b, FUN = mean)
print(head(pm))
psd <- predict(b, FUN = sd)
print(head(psd))