randomize.Rd
The transformer function takes a bamlss.frame
object and transforms all
smooth.construct
s into a random effects representation. Note that this
is only possible for smooth terms with a single smoothing variance. The function
is based on function smooth2random
.
trans_random(x)
randomize(x)
Object returned from function bamlss.frame
.
The decomposition is achieved by a spectral decomposition of the penalty and design matrix by
finding a basis of the null space of the penalty matrix. This feature is used, e.g., for the
JAGS
sampler function. For more details see also jagam
.
A transformed bamlss.frame
. To each smooth.construct
model term
an element named "Xf"
, the fixed effects design matrix, and an element "rand$Xr"
,
the random effects design matrix, is added. In addition, for re-transforming parameters elements
"trans.U"
and "trans.D"
are supplied. See also function
Fahrmeir L, Kneib T, Lang S, Marx B (2013). Regression - Models, Methods and Applications. Springer-Verlag, Berlin. ISBN 978-3-642-34332-2.
Wood S.N. (2006). Generalized Additive Models: An Introduction with R. Chapman and Hall/CRC.
## Simulate data.
d <- GAMart()
## Create a "bamlss.frame".
bf <- bamlss.frame(num ~ s(x1) + s(x2) + s(x3) + s(lon,lat), data = d)
## Structure of the "s(x1)" smooth.construct.
str(bf$x$mu$smooth.construct[["s(x1)"]])
#> List of 28
#> $ term : chr "x1"
#> $ bs.dim : num 10
#> $ fixed : logi FALSE
#> $ dim : int 1
#> $ p.order : num 0
#> $ by : chr "NA"
#> $ label : chr "s(x1)"
#> $ xt :List of 2
#> ..$ center: logi TRUE
#> ..$ before: logi TRUE
#> $ id : NULL
#> $ sp : NULL
#> $ drop.null : num 0
#> $ X : num [1:500, 1:9] -0.8941 -1.1407 -0.1109 -1.1451 -0.0447 ...
#> $ S :List of 1
#> ..$ : num [1:9, 1:9] 7.73 -1.23 3.914 -0.833 -5.113 ...
#> $ UZ : num [1:502, 1:10] 1.052 0.958 0.931 0.928 0.92 ...
#> $ Xu : num [1:500, 1] -0.505 -0.494 -0.49 -0.49 -0.489 ...
#> $ df : num 9
#> $ shift : num [1(1d)] 0.508
#> $ rank : num 8
#> $ null.space.dim: num 1
#> $ plot.me : logi TRUE
#> $ side.constrain: logi TRUE
#> $ repara : logi TRUE
#> $ S.scale : num 22.3
#> $ X.dim : int 9
#> $ fit.fun :function (X, b, expand = TRUE, no.sparse.setup = FALSE)
#> ..- attr(*, ".internal")= logi TRUE
#> $ prior :function (parameters)
#> ..- attr(*, "var_prior")= chr "ig"
#> $ grad :function (score = NULL, parameters, full = TRUE)
#> $ hess :function (score = NULL, parameters, full = FALSE)
#> - attr(*, "class")= chr [1:2] "tprs.smooth" "mgcv.smooth"
#> - attr(*, "qrc")=List of 4
#> ..$ qr : num [1:10, 1] -1.96 -0.135 0.376 0.162 -0.389 ...
#> ..$ rank : int 1
#> ..$ qraux: num 1.48
#> ..$ pivot: int 1
#> ..- attr(*, "class")= chr "qr"
#> - attr(*, "nCons")= int 1
## Transform.
bf <- randomize(bf)
## New structure adding fixed
## and random effect matrices.
str(bf$x$mu$smooth.construct[["s(x1)"]])
#> List of 32
#> $ term : chr "x1"
#> $ bs.dim : num 10
#> $ fixed : logi FALSE
#> $ dim : int 1
#> $ p.order : num 0
#> $ by : chr "NA"
#> $ label : chr "s(x1)"
#> $ xt :List of 2
#> ..$ center: logi TRUE
#> ..$ before: logi TRUE
#> $ id : NULL
#> $ sp : NULL
#> $ drop.null : num 0
#> $ X : num [1:500, 1:9] -0.8941 -1.1407 -0.1109 -1.1451 -0.0447 ...
#> $ S :List of 1
#> ..$ : num [1:9, 1:9] 7.73 -1.23 3.914 -0.833 -5.113 ...
#> $ UZ : num [1:502, 1:10] 1.052 0.958 0.931 0.928 0.92 ...
#> $ Xu : num [1:500, 1] -0.505 -0.494 -0.49 -0.49 -0.489 ...
#> $ df : num 9
#> $ shift : num [1(1d)] 0.508
#> $ rank : num 8
#> $ null.space.dim: num 1
#> $ plot.me : logi TRUE
#> $ side.constrain: logi TRUE
#> $ repara : logi TRUE
#> $ S.scale : num 22.3
#> $ X.dim : int 9
#> $ fit.fun :function (X, b, expand = TRUE, no.sparse.setup = FALSE)
#> ..- attr(*, ".internal")= logi TRUE
#> $ prior :function (parameters)
#> ..- attr(*, "var_prior")= chr "ig"
#> $ grad :function (score = NULL, parameters, full = TRUE)
#> $ hess :function (score = NULL, parameters, full = FALSE)
#> $ Xf : num [1:500, 1] -0.6793 -1.2461 -0.0775 -1.7152 -0.0343 ...
#> $ rand :List of 1
#> ..$ Xr: num [1:500, 1:8] 0.03749 0.05814 0.00187 0.08334 0.003 ...
#> .. ..- attr(*, "s.label")= chr "s(x1)"
#> $ trans.D : num [1:9] 0.0563 0.0782 0.0812 0.1263 0.1379 ...
#> $ trans.U : num [1:9, 1:9] 0.0173 -0.0115 -0.0219 0.0166 0.0362 ...
#> - attr(*, "class")= chr [1:2] "tprs.smooth" "mgcv.smooth"
#> - attr(*, "qrc")=List of 4
#> ..$ qr : num [1:10, 1] -1.96 -0.135 0.376 0.162 -0.389 ...
#> ..$ rank : int 1
#> ..$ qraux: num 1.48
#> ..$ pivot: int 1
#> ..- attr(*, "class")= chr "qr"
#> - attr(*, "nCons")= int 1