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 function:
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, ...)

## Arguments

x For function 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.

## Value

Function 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.

plot(samps)
}
# }