bru_mapper objectsMethods for bru_mapper objects
bru_mapper(...)ibm_n(mapper, inla_f = FALSE, ...)
ibm_values(mapper, inla_f = FALSE, ...)
ibm_amatrix(mapper, input, inla_f = FALSE, ...)
ibm_inla_subset(mapper, ...)
ibm_valid_input(mapper, input, inla_f = FALSE, ...)
# S3 method for default
bru_mapper(mapper, new_class = NULL, methods = NULL, ...)
# S3 method for default
ibm_inla_subset(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_linear(...)
bru_mapper_matrix(labels, ...)
bru_mapper_factor(values, factor_mapping, ...)
bru_mapper_offset(...)
bru_mapper_multi(mappers, ...)
bru_mapper_collect(mappers, hidden = FALSE, ...)
bru_mapper_harmonics(
order = 1,
scaling = 1,
intercept = TRUE,
interval = c(0, 1),
...
)
Arguments passed on to other methods
A mapper S3 object, normally inheriting from bru_mapper.
For the default bru_mapper method, a list that will be converted to a
bru_mapper object by adding class information and (optional) methods.
logical; when TRUE in ibm_n, ibm_values, and
ibm_amatrix methods, these must result in values compatible with INLA::f(...)
an specification and corresponding INLA::inla.stack(...) constructions.
Implementations do not normally need to do anything different, except
for mappers of the type needed for hidden multicomponent models such
as "bym2", which can be handled by bru_mapper_collect.
The values for which to produce validity information
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
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_amatrix. 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. See below for details of the
default constructor that can be used to define new mappers in user code.
ibm_n Generic. Implementations must return the size of the latent vector
being mapped to.
ibm_values Generic. Implementations must return a vector that
would be interpretable by an INLA::f(..., values = ...) specification.
The exception is the method for bru_mapper_multi, that returns a
multi-column data frame
ibm_amatrix Generic.
Implementations must return a (sparse) matrix of size NROW(input)
(except for the bru_mapper_multi and bru_mapper_collect methods,
that require list() inputs, and the input size is determined by the
combined inputs)
by ibm_n(mapper, inla_f = FALSE). The inla_f=TRUE argument should only affect
the allowed type of input format.
ibm_inla_subset Generic.
Implementations must return a logical vector of TRUE/FALSE for
the subset such that, given the full A matrix and values output,
A[, subset, drop = FALSE] and values[subset]
(or values[subset, , drop = FALSE] for data.frame values) are equal
to the inla_f = TRUE version of A and values. The default method uses
the ibm_values output to construct the subset indexing.
ibm_valid_input Generic.
Implementations must return a logical vector of length NROW(input) (
or for bru_mapper_multi and bru_mapper_collect a list of such
vectors)
bru_mapper.default adds the "bru_mapper" class and new_class
to an object. If provided, mapper method functions are added to an environment
.envir in the object. The generic methods ibm_n, ibm_n_inla,
ibm_values, ibm_values_inla,
ibm_amatrix, ibm_amatrix_inla,
ibm_valid_input, and ibm_valid_input_inla look for these
functions first,
and otherwise call UseMethod(). This is an alternative to using .S3method()
to register the methods, e.g.
.S3method("ibm_amatrix", "my_mapper_class", ibm_amatrix.my_mapper_class).
The default ibm_inla_subset method uses
the ibm_values output to construct the inla subset indexing, passing
extra arguments such as multi on to the methods (this means it supports
both regular vector values and multi=1 data.frame values).
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.
mapper <- bru_mapper_index(5)
ibm_amatrix(mapper, c(1, 3, 4, 5, 2))
Run the code above in your browser using DataLab