`bamlss.engine.setup.Rd`

This function takes the `x`

object of a `bamlss.frame`

and adds
additional objects that are useful for model fitting engines. This is applied only
for 'regular' terms, e.g., as created by `s`

and `te`

.
For special model terms the corresponding `smooth.construct`

method is in charge
of this (see also the examples for function `bfit`

).

```
bamlss.engine.setup(x, update = "iwls", propose = "iwlsC_gp",
do.optim = NULL, df = NULL, parametric2smooth = TRUE, ...)
```

- x
The

`x`

list, as returned from function`bamlss.frame`

, holding all model matrices and other information that is used for fitting the model.- update
Sets the updating function for model terms, see function

`bfit`

.- propose
Sets the propose function for model terms, see function

`GMCMC`

.- do.optim
Adds list element

`"do.optim"`

in the`"state"`

element, see the details below.- df
The initial degrees of freedom that should be assigned to a smooth model term, based on the trace of the smoother matrix. Note that

`df`

can be a named numeric vector. If the names match the labels of the model terms, the corresponding`df`

are used, e.g.,`df = c("s(x1)" = 1, "s(x2)" = 2)`

sets different`df`

s for each term.- parametric2smooth
Should parametric model terms be transformed into an artificial smooth model term and be added to the

`"smooth.construct"`

object within the`x`

list? This feature is handy, since algorithms can then cycle over the`"smooth.construct"`

object, only.- ...
Currently not used.

For each model term in the `"smooth.construct"`

object of the `x`

list (as returned
from `bamlss.frame`

), this function adds a named list called `"state"`

with the
following entries:

`"parameters"`

: A numeric vector. Regression coefficients are named with`"b"`

, smooth variances are named with`"tau2"`

.`"fitted.values"`

: Given the`"parameters"`

, the actual fitted values of the model term.`"edf"`

: Given the smoothing variances, the actual equivalent degrees of freedom (edf) of the model term.`"do.optim"`

: Should an optimizer function try to find optimum smoothing variances?

The state will be changed in each iteration and can be passed outside an updating function.

Additionally, if missing in the `xt`

argument of a model term (see, e.g., function
`s`

for `xt`

) the function adds the corresponding log-prior and its first
and second order derivatives w.r.t. regression coefficients in functions `grad()`

and
`hess()`

.

Also, objects named `"lower"`

and `"upper"`

are added to each model term. These
indicate the lower and upper boundaries of the parameter space.

A transformed `x`

list, as returned from function `bamlss.frame`

.

```
d <- GAMart()
bf <- bamlss.frame(num ~ s(x1) + s(x2), data = d, family = "gaussian")
names(bf$x$mu$smooth.construct)
#> [1] "s(x1)" "s(x2)"
bf$x <- bamlss.engine.setup(bf$x, df = c("s(x1)" = 1, "s(x2)" = 3))
names(bf$x$mu$smooth.construct)
#> [1] "s(x1)" "s(x2)" "model.matrix"
names(bf$x$mu$smooth.construct[["s(x1)"]])
#> [1] "term" "bs.dim" "fixed" "dim"
#> [5] "p.order" "by" "label" "xt"
#> [9] "id" "sp" "drop.null" "X"
#> [13] "S" "UZ" "Xu" "df"
#> [17] "shift" "rank" "null.space.dim" "plot.me"
#> [21] "side.constrain" "repara" "S.scale" "X.dim"
#> [25] "fit.fun" "prior" "grad" "hess"
#> [29] "binning" "nobs" "weights" "rres"
#> [33] "fit.reduced" "fxsp" "a" "b"
#> [37] "edf" "lower" "upper" "state"
#> [41] "sparse.setup" "added" "pid" "update"
#> [45] "propose"
names(bf$x$mu$smooth.construct[["s(x1)"]]$state)
#> [1] "parameters" "fitted.values" "edf" "do.optim"
sapply(bf$x$mu$smooth.construct, function(x) {
c(x$state$edf, get.state(x, "tau2"))
})
#> $`s(x1)`
#> tau21
#> 1.000000e+00 2.956634e-05
#>
#> $`s(x2)`
#> tau21
#> 3.0000000 0.6222542
#>
#> $model.matrix
#>
#> 1
#>
```