Skip to contents

Defines a repeated-space mapper that sums the contributions for each copy. The ibm_n() method returns ibm_n(mapper) * n_rep, and ibm_values() returns seq_len(ibm_n(mapper)).

Usage

bru_mapper_repeat(mapper, n_rep, interleaved = FALSE)

# S3 method for class 'bru_mapper_repeat'
ibm_n(mapper, ...)

# S3 method for class 'bru_mapper_repeat'
ibm_n_output(mapper, ...)

# S3 method for class 'bru_mapper_repeat'
ibm_values(mapper, ...)

# S3 method for class 'bru_mapper_repeat'
ibm_jacobian(
  mapper,
  input,
  state = NULL,
  inla_f = FALSE,
  multi = FALSE,
  ...,
  sub_lin = NULL
)

# S3 method for class 'bru_mapper_repeat'
ibm_eval(mapper, input, state, multi = FALSE, ..., sub_lin = NULL)

# S3 method for class 'bru_mapper_repeat'
ibm_linear(mapper, input, state, ...)

# S3 method for class 'bru_mapper_repeat'
ibm_invalid_output(mapper, input, state, ...)

Arguments

mapper

The mapper to be repeated.

n_rep

The number of times to repeat the mapper. If a vector, the non-interleaved repeats are combined into a single repeat mapping, and combined with interleaved repeats via a bru_mapper_sum() of mappers.

interleaved

logical; if TRUE, the repeated mapping columns are interleaved; (x1[1], x2[1], ..., x1[2], x2[2], ...). If FALSE (default), the repeated mapping columns are contiguous, (x1[1], x1[2], ..., x2[1], x2[2], ...), and the Jacobian is a cbind() of the Jacobians of the repeated mappers.

If n_rep is a vector, interleaved should either be a single logical, or a vector of the same length. Each element applies to the corresponding n_rep repetition specification.

...

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)

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.

multi

logical; If TRUE (or positive), recurse one level into sub-mappers

sub_lin

Internal, optional pre-computed sub-mapper information

Value

A bru_mapper_repeat or bru_mapper_sum object, or the original input mapper.

Methods (by generic)

  • ibm_jacobian(bru_mapper_repeat): The input should take the format of the repeated submapper.

  • ibm_invalid_output(bru_mapper_repeat): Passes on the input to the corresponding method.

Examples

(m0 <- bru_mapper_index(3))
#> index
(m <- bru_mapper_repeat(m0, 5))
#> repeat(5 x index)
ibm_n(m)
#> [1] 15
ibm_values(m)
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
ibm_jacobian(m, 1:3)
#> 3 x 15 sparse Matrix of class "dgCMatrix"
#>                                   
#> [1,] 1 . . 1 . . 1 . . 1 . . 1 . .
#> [2,] . 1 . . 1 . . 1 . . 1 . . 1 .
#> [3,] . . 1 . . 1 . . 1 . . 1 . . 1
ibm_eval(m, 1:3, seq_len(ibm_n(m)))
#> [1] 35 40 45

# Interleaving and grouping
(m <- bru_mapper_repeat(m0, c(2, 1, 2), c(TRUE, FALSE, FALSE)))
#> sum(1 = repeat(2 x index, interleaved), 2 = repeat(3 x index))
ibm_n(m)
#> [1] 15
ibm_values(m)
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
ibm_jacobian(m, 1:3)
#> 3 x 15 sparse Matrix of class "dgCMatrix"
#>                                   
#> [1,] 1 1 . . . . 1 . . 1 . . 1 . .
#> [2,] . . 1 1 . . . 1 . . 1 . . 1 .
#> [3,] . . . . 1 1 . . 1 . . 1 . . 1
ibm_eval(m, 1:3, seq_len(ibm_n(m)))
#> [1] 33 40 47