knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(bamlss)
library(bamlssAPI)

This is the first example from ?bamlss:

set.seed(1337)

d <- GAMart()
f <- num ~ s(x1) + s(x2) + s(x3) + te(lon, lat)
b <- bamlss(f, data = d, sampler = FALSE, verbose = FALSE)

b <- apify(b, propose = "iwlsC_gp")

nsamp <- 500

samples <- matrix(
  data     = NA_real_,
  nrow     = nsamp,
  ncol     = length(parameters(b, "mu", "s(x1)")),
  dimnames = list(NULL, names(parameters(b, "mu", "s(x1)")))
)

for (i in 1:nsamp) {
  prop <- propose(b, "mu", "s(x1)")
  if (log(runif(1)) <= prop$alpha) b <- accept(b, "mu", "s(x1)", prop)
  samples[i,] <- parameters(b, "mu", "s(x1)")
}

par(mfrow = c(ncol(samples), 2))
plot(as.mcmc(samples), auto.layout = FALSE)
par(mfrow = c(1, 1))

Some more API examples:

predictors(b)
smooths(b, predictor = "mu")
parameters(b, "mu", "s(x1)")
b <- update_logpost(b)
logpost(b)
b <- set_parameters(b, "mu", "s(x1)", parameters(b, "mu", "s(x1)") + 0.01)
outdated(fx(b, "mu", "s(x1)"))
outdated(eta(b, "mu"))
outdated(logpost(b))
b <- update_logpost(b)
logpost(b)
grad_logpost(b, "mu", "s(x1)")
hess_logpost(b, "mu", "s(x1)")


hriebl/bamlssAPI documentation built on May 3, 2020, 6:58 p.m.