sam_BayesX  R Documentation 
This sampler function for BAMLSS is an interface to the BayesX
(https://www.unigoettingen.de/de/bayesx/550513.html
)
commandline binary from R. The sampler is based on the command line version and functions
provided in the BayesXsrc package, which can be installed using
function get_BayesXsrc()
.
## Sampler functions: sam_BayesX(x, y, family, start = NULL, weights = NULL, offset = NULL, data = NULL, control = BayesX.control(...), ...) BayesX(x, y, family, start = NULL, weights = NULL, offset = NULL, data = NULL, control = BayesX.control(...), ...) ## Sampler control: BayesX.control(n.iter = 1200, thin = 1, burnin = 200, seed = NULL, predict = "light", model.name = "bamlss", data.name = "d", prg.name = NULL, dir = NULL, verbose = FALSE, show.prg = TRUE, modeonly = FALSE, ...) ## Special BayesX smooth term constructor. sx(x, z = NULL, bs = "ps", by = NA, ...) ## Special BayesX tensor product smooth term constructor. tx(..., bs = "ps", k = 1, ctr = c("center", "main", "both", "both1", "both2", "none", "meanf", "meanfd", "meansimple", "nullspace"), xt = NULL, special = TRUE) tx2(...) tx3(..., bs = "ps", k = c(10, 5), ctr = c("main", "center"), xt = NULL, special = TRUE) tx4(..., ctr = c("center", "main", "both", "both1", "both2")) ## Smooth constructors and predict matrix. ## S3 method for class 'tensorX.smooth.spec' smooth.construct(object, data, knots, ...) ## S3 method for class 'tensorX.smooth' Predict.matrix(object, data) ## S3 method for class 'tensorX3.smooth.spec' smooth.construct(object, data, knots, ...) ## S3 method for class 'tensorX3.smooth' Predict.matrix(object, data) ## Family object for quantile regression with BayesX. quant_bamlss(prob = 0.5) ## Download the newest version of BayesXsrc. get_BayesXsrc(dir = NULL, install = TRUE)
x 
For function 
y 
The model response, as returned from function 
z 
Second variable in a 
family 
A bamlss family object, see 
start 
A named numeric vector containing possible starting values, the names are based on
function 
weights 
Prior weights on the data, as returned from function 
offset 
Can be used to supply model offsets for use in fitting,
returned from function 
data 
The model frame that should be used for modeling. Note that argument 
control 
List of control arguments to be send to BayesX. See below. 
n.iter 
Sets the number of MCMC iterations. 
thin 
Defines the thinning parameter for MCMC simulation. E.g., 
burnin 
Sets the burnin phase of the sampler, i.e., the number of starting samples that should be removed. 
seed 
Sets the seed. 
predict 
Not supported at the moment, do not modify! 
model.name 
The name that should be used for the model when calling BayesX. 
data.name 
The name that should be used for the data set when calling BayesX. 
prg.name 
The name that should be used for the 
dir 
Specifies the directory where BayesX should store all output files. For function

verbose 
Print information during runtime of the algorithm. 
show.prg 
Show the BayesX 
modeonly 
Should only the posterior mode be compute, note that this is done using fixed smoothing parameters/variances. 
bs 
A 
by 
A by variable for varying coefficient model terms. 
k 
The dimension(s) of the bases used to represent the 
... 
Not used in 
ctr 
Specifies the type of constraints that should be applied. 
xt 
A list of extra arguments to be passed to BayesX. 
special 
Should the 
object, knots 
See, function 
prob 
Numeric, specifies the quantile to be modeled, see the examples. 
install 
Should package BayesXsrc be installed? 
Function sam_BayesX()
writes a BayesX .prg
file and processes the data.
Then, the function call the BayesX binary via function
run.bayesx
. After the BayesX sampler has finished, the function
reads back in all the parameter samples that can then be used for further processing within
bamlss
, i.a.
The smooth term constructor functions s
and te
can
be used with the sam_BayesX()
sampler. When using te
note that only
one smoothing variance is estimated by BayesX.
For anisotropic penalties use function tx()
and tx3()
, the former currently
supports smooth functions of two variables, while tx3()
is supposed to model spacetime
interactions. Note that in tx3()
the first variable represents time and the 2nd and 3rd
variable the coordinates in space.
Function sam_BayesX()
returns samples of parameters. The samples are provided as a
mcmc
matrix.
Function BayesX.control()
returns a list
with control arguments for
BayesX.
Function sx()
a list
of class "xx.smooth.spec"
and "no.mgcv"
, where
"xx"
is a basis/type identifying code given by the bs
argument.
Function tx()
and tx2()
a list
of class tensorX.smooth.spec
.
Note that this interface is still experimental and needs the newest version of the BayesX
source code, which is not yet part of the BayesXsrc package on CRAN. The newest version
can be installed with function get_BayesXsrc
. Note that the function assumes that sh,
subversion (svn) and R can be run from the command line!
Note that for setting up a new family object to be used with sam_BayesX()
additional
information needs to be supplied. The extra information must be placed within the
family object in an named list
element named "bayesx"
. For each parameter of
the distribution a character string with the corresponding BayesX family
name and the
equationtype
must be supplied. See, e.g., the R code of gaussian_bamlss
how the setup works.
For function sx()
the following basis types are currently supported:
"ps"
: Pspline with second order difference penalty.
"mrf"
: Markov random fields: Defines a Markov random field prior for a
spatial covariate, where geographical information is provided by a map object in
boundary or graph file format (see function read.bnd
,
read.gra
and shp2bnd
), as an additional
argument named map
.
"re"
: Gaussian i.i.d. Random effects of a unit or cluster identification covariate.
Function tx()
currently supports smooth terms with two variables.
bamlss
, bamlss.frame
## Get newest version of BayesXsrc. ## Note: needs sh, svn and R build tools! ## get_BayesXsrc() ## Not run: if(require("BayesXsrc")) { ## Simulate some data set.seed(123) d < GAMart() ## Estimate model with BayesX. Note ## that BayesX computes starting values, so ## these are not required by some optimizer function ## in bamlss() b1 < bamlss(num ~ s(x1) + s(x2) + s(x3) + s(lon,lat), data = d, optimizer = FALSE, sampler = sam_BayesX) plot(b1) ## Same model with anisotropic penalty. b2 < bamlss(num ~ s(x1) + s(x2) + s(x3) + tx(lon,lat), data = d, optimizer = FALSE, sampler = sam_BayesX) plot(b2) ## Quantile regression. b3_0.1 < bamlss(num ~ s(x1) + s(x2) + s(x3) + tx(lon,lat), data = d, optimizer = FALSE, sampler = sam_BayesX, family = gF("quant", prob = 0.1)) b3_0.9 < bamlss(num ~ s(x1) + s(x2) + s(x3) + tx(lon,lat), data = d, optimizer = FALSE, sampler = sam_BayesX, family = gF("quant", prob = 0.9)) ## Predict quantiles. p_0.1 < predict(b3_0.1, term = "s(x2)") p_0.9 < predict(b3_0.9, term = "s(x2)") ## Plot. plot2d(p_0.1 + p_0.9 ~ x2, data = d) } ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.