Last chance! 50% off unlimited learning
Sale ends in
This sampler function for BAMLSS is an interface to the JAGS library
using package rjags
. The function basically interprets the
bamlss.frame
into BUGS code, similar to the jagam
function of
package mgcv
. I.e., the function uses the random effects representation of
smooth terms, see the transformer function randomize
to generate the BUGS code.
Note that estimating BAMLSS with JAGS is not very efficient.
Also note that this function is more experimental and support is only provided for a small
number of bamlss.family
objects.
Function BUGSeta()
therefore computes the code and data for one parameter of
the modeled distribution. Function BUGSmodel()
then collects all parameter model code
and data, which can be send to JAGS.
## Sampler functions:
sam_JAGS(x, y, family, start = NULL,
tdir = NULL, n.chains = 1, n.adapt = 100,
n.iter = 4000, thin = 2, burnin = 1000,
seed = NULL, verbose = TRUE, set.inits = TRUE,
save.all = FALSE, modules = NULL, ...)JAGS(x, y, family, start = NULL,
tdir = NULL, n.chains = 1, n.adapt = 100,
n.iter = 4000, thin = 2, burnin = 1000,
seed = NULL, verbose = TRUE, set.inits = TRUE,
save.all = FALSE, modules = NULL, ...)
## Function to interpret an additive predictor into BUGS code:
BUGSeta(x, id = NULL, ...)
## Function to interpret the full BAMLSS:
BUGSmodel(x, family, is.stan = FALSE, reference = NULL, ...)
Function sam_JAGS()
returns samples of parameters. The samples are provided as a mcmc
matrix. If n.chains > 1
, the samples are provided as a mcmc.list
.
Function BUGSeta()
returns the BUGS model code and preprocessed data for one
additive predictor. Function BUGSmodel()
then combines all single BUGS code chunks and
the data and creates the final BUGS model code that can be send to JAGS.
For function sam_JAGS()
and BUGSmodel()
the x
list, as returned from
function bamlss.frame
, holding all model matrices and other information that is
used for fitting the model. For function BUGSeta()
argument x
is one element of
the x
object, i.e., one parameter.
The model response, as returned from function bamlss.frame
.
A bamlss family object, see family.bamlss
.
A named numeric vector containing possible starting values, the names are based on
function parameters
.
The path to the temporary directory that should be used.
Specifies the number of sequential MCMC chains that should be run with JAGS.
Specifies the number of iterations that should be used as an initial adaptive phase.
Sets the number of MCMC iterations.
Defines the thinning parameter for MCMC simulation. E.g., thin = 10
means,
that only every 10th sampled parameter will be stored.
Sets the burn-in phase of the sampler, i.e., the number of starting samples that should be removed.
Sets the seed.
Print information during runtime of the algorithm.
Should initial values of BAMLSS parameters
be provided to JAGS,
if available. Set in argument start
.
Should all JAGS files be saved in tdir
.
Specify additional modules that should be loaded, see function load.module
.
Character, the current parameter name for which the BUGS code should be produced.
Should the BUGS code be translated to STAN code. Note that this is only experimental.
A character
specifying a reference category, e.g., when
fitting a multinomial model.
Currently not used.
bamlss
, bamlss.frame
,
bamlss.engine.setup
, set.starting.values
, bfit
,
GMCMC
if (FALSE) ## Simulated data example illustrating
## how to call the sampler function.
## This is done internally within
## the setup of function bamlss().
d <- GAMart()
f <- num ~ s(x1, bs = "ps")
bf <- bamlss.frame(f, data = d, family = "gaussian")
## First, find starting values with optimizer.
opt <- with(bf, opt_bfit(x, y, family))
## Sample with JAGS.
if(require("rjags")) {
samps <- with(bf, sam_JAGS(x, y, family, start = opt$parameters))
plot(samps)
b <- bamlss(f, data = d, family = "gaussian", sampler = sam_JAGS)
plot(b)
}
Run the code above in your browser using DataLab