The function bayesx.construct
is used to provide a flexible framework to implement
new model term objects in bayesx
within the BayesX syntax.
1  bayesx.construct(object, dir, prg, data)

object 
is a smooth, shrinkage or random specification object in a STAR 
dir 

prg 
if additional data handling must be applied, e.g. storing maps ( 
data 
if additional data is needed to setup the BayesX term it is found here. 
The main idea of these constructor functions is to provide a flexible framework to implement new
model term objects in the BayesX syntax within bayesx
, i.e. for any smooth or
random term in R2BayesX a constructor function like
bayesx.construct.ps.smooth.construct
may be provided to translate R specific syntax into
BayesX readable commands. During processing with write.bayesx.input
each model
term is constructed with bayesx.construct
after another, wrapped into a full formula, which
may then be send to the BayesX binary with function run.bayesx
.
At the moment the following model terms are implemented:
"rw1"
, "rw2"
: Zero degree Psplines: Defines a zero degree Pspline with first or
second order difference penalty. A zero degree Pspline typically
estimates for every distinct covariate value in the dataset a separate
parameter. Usually there is no reason to prefer zero degree Psplines
over higher order Psplines. An exception are ordinal covariates or
continuous covariates with only a small number of different values.
For ordinal covariates higher order Psplines are not meaningful while
zero degree Psplines might be an alternative to modeling nonlinear
relationships via a dummy approach with completely unrestricted
regression parameters.
"season"
: Seasonal effect of a time scale.
"ps"
, "psplinerw1"
, "psplinerw2"
: Pspline with first or second order
difference penalty.
"te"
, "pspline2dimrw1"
: Defines a twodimensional Pspline based on the tensor
product of onedimensional Psplines with a twodimensional first order random walk
penalty for the parameters of the spline.
"kr"
, "kriging"
: Kriging with stationary Gaussian random fields.
"gk"
, "geokriging"
: Geokriging with stationary Gaussian random fields: Estimation
is based on the centroids of a map object provided in
boundary format (see function read.bnd
and shp2bnd
) as an additional
argument named map
within function sx
, or supplied within argument
xt
when using function s
, e.g., xt = list(map = MapBnd)
.
"gs"
, "geospline"
: Geosplines based on twodimensional Psplines with a
twodimensional first order random walk penalty for the parameters of the spline.
Estimation is based on the coordinates of the centroids of the regions
of a map object provided in boundary format (see function read.bnd
and
shp2bnd
) as an additional argument named map
(see above).
"mrf"
, "spatial"
: 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
(see above).
"bl"
, "baseline"
: Nonlinear baseline effect in hazard regression or multistate
models: Defines a Pspline with second order random walk penalty for the parameters of
the spline for the logbaseline effect log(λ(time)).
"factor"
: Special BayesX specifier for factors, especially meaningful if
method = "STEP"
, since the factor term is then treated as a full term,
which is either included or removed from the model.
"ridge"
, "lasso"
, "nigmix"
: Shrinkage of fixed effects: defines a
shrinkageprior for the corresponding parameters
γ_j, j = 1, …, q, q ≥q 1 of the
linear effects x_1, …, x_q. There are three
priors possible: ridge, lasso and Normal Mixture
of inverse Gamma prior.
"re"
: Gaussian i.i.d.\ Random effects of a unit or cluster identification covariate.
See function sx
for a description of the main
R2BayesX
model term constructor functions.
The model term syntax used within BayesX as a character string.
If new bayesx.construct
functions are implemented in future work, there may occur problems
with reading the corresponding BayesX output files with read.bayesx.output
,
e.g., if the new objects do not have the structure as implemented with bs = "ps"
etc.,
i.e. function read.bayesx.output
must also be adapted in such cases.
Using sx
additional controlling arguments may be supplied within the dot dot dot
“...
” argument. Please see the help site for function bayesx.term.options
for a detailed description of possible optional parameters.
Within the xt
argument in function s
, additional
BayesX specific parameters may be also supplied, see the examples below.
Nikolaus Umlauf, Thomas Kneib, Stefan Lang, Achim Zeileis.
sx
, bayesx.term.options
, s
,
formula.gam
, read.bnd
,
read.gra
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68  bayesx.construct(sx(x1, bs = "ps"))
bayesx.construct(sx(x1, x2, bs = "te"))
## now create BayesX syntax for smooth terms
## using mgcv constructor functions
bayesx.construct(s(x1, bs = "ps"))
## for tensor product Psplines,
bayesx.construct(s(x1, x2, bs = "te"))
## increase number of knots
## for a Pspline
bayesx.construct(sx(x1, bs = "ps", nrknots = 40))
## now with degree 2 and
## penalty order 1
bayesx.construct(sx(x1, bs = "ps", knots = 40, degree = 2, order = 1))
bayesx.construct(s(x1, bs = "ps", k = 41, m = c(0, 1)))
## random walks
bayesx.construct(sx(x1, bs = "rw1"))
bayesx.construct(sx(x1, bs = "rw2"))
## shrinkage priors
bayesx.construct(sx(x1, bs = "lasso"))
bayesx.construct(sx(x1, bs = "ridge"))
bayesx.construct(sx(x1, bs = "nigmix"))
## for cox models, baseline
bayesx.construct(sx(time, bs = "bl"))
## kriging
bayesx.construct(sx(x, z, bs = "kr"))
## seasonal
bayesx.construct(sx(x, bs = "season"))
## factors
bayesx.construct(sx(id, bs = "factor"))
## now with some geographical information
## note: maps must be either supplied in
## 'bnd' or 'gra' format, also see function
## read.bnd() or read.gra()
data("MunichBnd")
bayesx.construct(sx(id, bs = "mrf", map = MunichBnd))
## same with
bayesx.construct(s(id, bs = "mrf", xt = list(map = MunichBnd)))
bayesx.construct(sx(id, bs = "gk", map = MunichBnd))
bayesx.construct(sx(id, bs = "gs", map = MunichBnd))
## also vary number of knots
bayesx.construct(sx(id, bs = "gs", knots = 10, map = MunichBnd))
bayesx.construct(s(id, bs = "gs", k = 12, m = c(1, 1), xt = list(map = MunichBnd)))
## random effects
bayesx.construct(sx(id, bs = "re"))
bayesx.construct(sx(id, bs = "re", by = x1))
bayesx.construct(sx(id, bs = "re", by = x1, xt = list(nofixed=TRUE)))
## generic
## specifies some model term
## and sets all additional arguments
## within argument xt
## only for experimental use
bayesx.construct(sx(x, bs = "generic", dosomething = TRUE, a = 1, b = 2))

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.