A `bru_mapper`

sub-class implementation must provide an
`ibm_jacobian()`

method. If the model size 'n' and definition
values 'values' are stored in the object itself, default methods are
available (see Details). Otherwise the
`ibm_n()`

and `ibm_values()`

methods also need to be provided.

## Usage

```
ibm_n(mapper, inla_f = FALSE, ...)
ibm_n_output(mapper, input, state = NULL, inla_f = FALSE, ...)
ibm_values(mapper, inla_f = FALSE, ...)
ibm_amatrix(mapper, input, state = NULL, inla_f = FALSE, ...)
ibm_is_linear(mapper, ...)
ibm_jacobian(mapper, input, state = NULL, inla_f = FALSE, ...)
ibm_linear(mapper, input, state = NULL, ...)
ibm_eval(mapper, input, state = NULL, ...)
ibm_names(mapper)
ibm_names(mapper) <- value
ibm_inla_subset(mapper, ...)
ibm_invalid_output(mapper, input, state, ...)
# S3 method for default
ibm_n(mapper, inla_f = FALSE, ...)
# S3 method for default
ibm_n_output(mapper, input, state = NULL, inla_f = FALSE, ...)
# S3 method for default
ibm_values(mapper, inla_f = FALSE, ...)
# S3 method for default
ibm_amatrix(mapper, ...)
# S3 method for default
ibm_is_linear(mapper, ...)
# S3 method for default
ibm_jacobian(mapper, input, state, ...)
# S3 method for default
ibm_linear(mapper, input, state, ...)
# S3 method for default
ibm_eval(mapper, input, state = NULL, ...)
# S3 method for default
ibm_names(mapper, ...)
# S3 method for default
ibm_inla_subset(mapper, ...)
# S3 method for default
ibm_invalid_output(mapper, input, state, ...)
```

## Arguments

- mapper
A mapper S3 object, inheriting from

`bru_mapper`

.- inla_f
logical; when

`TRUE`

for`ibm_n()`

and`ibm_values()`

, the result must be compatible with the`INLA::f(...)`

and corresponding`INLA::inla.stack(...)`

constructions. For`ibm_{eval,jacobian,linear}`

, the`input`

interpretation may be different. 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`

.- ...
Arguments passed on to other methods

- input
Data input for the mapper.

- state
A vector of latent state values for the mapping, of length

`ibm_n(mapper, inla_f = FALSE)`

- value
a character vector of the same length as the number of sub-mappers in the mapper

## Functions

`ibm_n()`

: Implementations must return the size of the latent vector being mapped to.`ibm_n_output()`

: Implementations must return an integer denoting the mapper output length. The default implementation returns`NROW(input)`

. Mappers such as`bru_mapper_multi`

and`bru_mapper_collect`

, that can accept`list()`

inputs require their own methods implementations.`ibm_values()`

: When`inla_f=TRUE`

, 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()`

: will become deprecated in 2.7.0. Use`ibm_jacobian`

instead. Implementations must return a (sparse) matrix of size`ibm_n_output(...)`

by`ibm_n(...)`

. The`inla_f=TRUE`

argument should only affect the allowed type of input format.`ibm_is_linear()`

: Implementations must return`TRUE`

or`FALSE`

. If`TRUE`

(returned by the default method unless the mapper contains an`is_linear`

variable), users of the mapper may assume the mapper is linear.`ibm_jacobian()`

: Implementations must return a (sparse) matrix of size`ibm_n_output(mapper, input, inla_f)`

by`ibm_n(mapper, inla_f = FALSE)`

. The`inla_f=TRUE`

argument should only affect the allowed type of input format.`ibm_linear()`

: Implementations must return a bru_mapper_taylor object The linearisation information includes`offset`

,`jacobian`

, and`state0`

. The state information indicates for which state the`offset`

was evaluated, with`NULL`

meaning all-zero. The linearised mapper output is defined as`effect(input, state) = offset(input, state0) + jacobian(input, state0) %*% (state - state0)`

. The default method calls`ibm_eval()`

and`ibm_jacobian()`

to generate the needed information.`ibm_eval()`

: Implementations must return a vector of length`ibm_n_output(...)`

. The`input`

contents must be in a format accepted by`ibm_jacobian(...)`

for the mapper.`ibm_names()`

: Implementations must return a character vector of sub-mapper names, or`NULL`

. Intended for providing information about multi-mappers and mapper collections.`ibm_names(mapper) <- value`

: Set mapper names.`ibm_inla_subset()`

: 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_invalid_output()`

: Implementations should return a logical vector of length`ibm_n_output(mapper, input, state, ...)`

indicating which, if any, output elements of`ibm_eval(mapper, input, state, ...)`

are known to be invalid. For for multi/collect mappers, a list, when given a`multi=TRUE`

argument.`ibm_n(default)`

: Returns a non-null element 'n' from the mapper object, and gives an error if it doesn't exist. If`inla_f=TRUE`

, first checks for a 'n_inla' element.`ibm_n_output(default)`

: Returns`NROW(input)`

`ibm_values(default)`

: Returns a non-null element 'values' from the mapper object, and`seq_len(ibm_n(mapper))`

if it doesn't exist.`ibm_amatrix(default)`

: Gives an error message. Mapper classes must implement their own`ibm_jacobian`

or`ibm_amatrix`

methods. New implementations should use a`ibm_jacobian`

method.`ibm_amatrix`

may become deprecated in a future version.`ibm_is_linear(default)`

: Returns logical`is_linear`

from the mapper object if it exists, and otherwise`TRUE`

.`ibm_jacobian(default)`

: Calls`ibm_amatrix`

, which by default gives an error. Mapper classes should implement their own`ibm_jacobian`

method.`ibm_linear(default)`

: Calls`ibm_eval()`

and`ibm_jacobian()`

and returns a`bru_mapper_taylor`

object. The`state0`

information in the affine mapper indicates for which state the`offset`

was evaluated; The affine mapper output is defined as`effect(input, state) = offset(input, state0) + jacobian(input, state0) %*% (state - state0)`

`ibm_eval(default)`

: Verifies that the mapper is linear with`ibm_is_linear()`

, and then computes a linear mapping as`ibm_jacobian(...) %*% state`

. When`state`

is`NULL`

, a zero vector of length`ibm_n_output(...)`

is returned.`ibm_names(default)`

: Returns`NULL`

`ibm_inla_subset(default)`

: 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).`ibm_invalid_output(default)`

: Returns an all-`FALSE`

logical vector.

## See also

bru_mapper for constructor methods, and bru_get_mapper for hooks to extract mappers from latent model object class objects.

## Examples

```
# ibm_names
mapper <- bru_mapper_multi(list(
A = bru_mapper_index(2),
B = bru_mapper_index(2)
))
ibm_names(mapper)
#> [1] "A" "B"
ibm_names(mapper) <- c("new", "names")
ibm_names(mapper)
#> [1] "new" "names"
```