bru_mapper
objectsConstructors for bru_mapper
objects
bru_mapper(...)bru_mapper_define(mapper, new_class = NULL, methods = NULL, ...)
# S3 method for default
bru_mapper(...)
# S3 method for inla.mesh
bru_mapper(mesh, ...)
# S3 method for inla.mesh.1d
bru_mapper(mesh, indexed = NULL, ...)
bru_mapper_index(n = 1L, ...)
bru_mapper_taylor(offset, jacobian, state0, ..., values_mapper = NULL)
bru_mapper_linear(...)
bru_mapper_matrix(labels, ...)
bru_mapper_factor(values, factor_mapping, ...)
bru_mapper_const(...)
bru_mapper_offset(...)
bru_mapper_scale(mapper, ...)
bru_mapper_multi(mappers, ...)
bru_mapper_collect(mappers, hidden = FALSE, ...)
bru_mapper_harmonics(
order = 1,
scaling = 1,
intercept = TRUE,
interval = c(0, 1),
...
)
Deprecated, alternative way to supply optional method definitions.
For bru_mapper_define
, a prototype mapper object, see Details.
For bru_mapper_scale
, a mapper to be scaled.
If non-NULL
, this is added at the front of the class definition
Optional list
of named method definitions; See Details.
An inla.mesh.1d
or inla.mesh.2d
object to use as a mapper
logical; If TRUE
, the ibm_values()
output will be the
integer indexing sequence for the latent variables (needed for spde
models).
If FALSE
, the knot
locations are returned (useful as an interpolator for rw2
models
and similar).
Default: NULL
, to force user specification of this parameter
Size of a model for bru_mapper_index
For bru_mapper_taylor
, an offset vector evaluated
at state0
For bru_mapper_taylor
, the Jacobian matrix,
evaluated at state0
, or, a named list of such matrices.
May be NULL
or an empty list, for a constant mapping.
For bru_mapper_taylor
, the state the linearisation
was evaluated at, or a list of length matching the jacobian
list.
NULL
is interpreted as 0.
mapper object to be used for ibm_n
and
ibm_values
for inla_f=TRUE
(experimental, currently unused)
Column labels for matrix mappings
Input values calculated by input_eval.bru_input()
character; selects the type of factor mapping.
'contrast'
for leaving out the first factor level.
'full'
for keeping all levels.
A list of bru_mapper
objects
logical
, set to TRUE
to flag that the mapper is to be used
as a first level input mapper for INLA::f()
in a model that requires making
only the first mapper visible to INLA::f()
and INLA::inla.stack()
, such
as for "bym2" models, as activated by the inla_f
argument to ibm_n
,
ibm_values
, and ibm_jacobian
. Set to FALSE
to always access the full
mapper, e.g. for rgeneric
models
For bru_mapper_harmonics
, specifies the maximum cos
/sin
order. (Default 1)
For bru_mapper_harmonics
, specifies an optional vector of
scaling factors of length intercept + order
, or a common single scalar.
logical; For bru_mapper_harmonics
, if TRUE
, the first
basis function is a constant. (Default TRUE
)
numeric length-2 vector specifying a domain interval.
Default c(0, 1)
.
bru_mapper
Generic mapper S3 constructor, used for constructing
mappers for special objects. See below for details of the
default constructor bru_mapper_define()
that can be used to define
new mappers in user code.
bru_mapper_define
adds the new_class
and "bru_mapper" class
names to the inheritance list for the input mapper
object, unless the object
already inherits from these.
If provided, mapper method functions are added to an environment
.envir
in the object. The generic methods look for these
functions first,
and otherwise call UseMethod()
. This is an alternative to using .S3method()
to register the methods, e.g.
.S3method("ibm_jacobian", "my_mapper_class", ibm_jacobian.my_mapper_class)
.
bru_mapper.default
calls bru_mapper_define
, passing all
arguments along. Mapper implementations should call bru_mapper_define()
instead, and supply at least a new_class
class name.
Use of the bru_mapper.default
will be deprecated from version 2.7.0.
bru_mapper_taylor
provides a pre-computed affine mapping,
internally used to represent and evaluate linearisation information.
The state0
information indicates for which state the offset
was evaluated;
The affine mapper output is defined as
effect(state) = offset + jacobian %*% (state - state0)
For bru_mapper_scale()
, mapper
is a mapper to be scaled.
The input
format for the ibm_eval
and ibm_jacobian
methods is
list(mapper = input_to_the_inner_mapper, scale = scaling_weights)
bru_mapper_multi
constructs a kronecker product mapping
bru_mapper_collect
constructs concatenated collection mapping
bru_mapper_harmonics
constructs a mapper for cos
/sin
functions
of orders 1 (if intercept
is TRUE
, otherwise 0) through order
. The total
number of basis functions is intercept + 2 * order
.
Optionally, each order can be given a non-unit scaling, via the scaling
vector, of length intercept + order
. This can be used to
give an effective spectral prior. For example, let
scaling = 1 / (1 + (0:4)^2)
A1 = bru_mapper_harmonics(order = 4)
u1 <- A1 %*% rnorm(9, sd = scaling)
Then, with
A2 = bru_mapper_harmonics(order = 4, scaling = scaling)
u2 = A2 %*% rnorm(9)
the stochastic properties of u1
and u2
will be the same, with scaling^2
determining the variance for each frequency contribution.
The period for the first order harmonics is shifted and scaled to match
interval
.
bru_mapper_methods for specific method implementations, and bru_get_mapper for hooks to extract mappers from latent model object class objects.
mapper <- bru_mapper_index(5)
ibm_jacobian(mapper, input = c(1, 3, 4, 5, 2))
Run the code above in your browser using DataLab