Defines a mapper that adds the effects of each submapper.
The ibm_n()
method returns the sum of ibm_n(mappers[[k]])
, and
ibm_values()
returns seq_len(ibm_n(mapper))
.
Usage
bru_mapper_sum(mappers, single_input = FALSE)
# S3 method for class 'bru_mapper_sum'
ibm_n(mapper, inla_f = FALSE, multi = FALSE, ...)
# S3 method for class 'bru_mapper_sum'
ibm_n_output(mapper, input, state = NULL, ...)
# S3 method for class 'bru_mapper_sum'
ibm_values(mapper, inla_f = FALSE, multi = FALSE, ...)
# S3 method for class 'bru_mapper_sum'
ibm_is_linear(mapper, multi = FALSE, ...)
# S3 method for class 'bru_mapper_sum'
ibm_jacobian(
mapper,
input,
state = NULL,
inla_f = FALSE,
multi = FALSE,
...,
sub_lin = NULL
)
# S3 method for class 'bru_mapper_sum'
ibm_eval(mapper, input, state, multi = FALSE, ..., sub_lin = NULL)
# S3 method for class 'bru_mapper_sum'
ibm_linear(mapper, input, state, ...)
# S3 method for class 'bru_mapper_sum'
ibm_invalid_output(mapper, input, state, multi = FALSE, ...)
# S3 method for class 'bru_mapper_sum'
x[i, drop = TRUE]
# S3 method for class 'bru_mapper_sum'
ibm_names(mapper)
# S3 method for class 'bru_mapper_sum'
ibm_names(mapper) <- value
Arguments
- mappers
A list of
bru_mapper
objects.- single_input
logical. If
TRUE
, the input is passed to all sub-mappers. Otherwise, the input should be a list, data.frame, or matrix. If themappers
list has named entries, theinput
can reference their corresponding sub-mapper using its name.- mapper
A mapper S3 object, inheriting from
bru_mapper
.- inla_f
logical; when
TRUE
foribm_n()
andibm_values()
, the result must be compatible with theINLA::f(...)
and correspondingINLA::inla.stack(...)
constructions. Foribm_{eval,jacobian,linear}
, theinput
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 bybru_mapper_collect
.- multi
logical; If
TRUE
(or positive), recurse one level into sub-mappers- ...
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)
- sub_lin
Internal, optional pre-computed sub-mapper information
- x
object from which to extract element(s)
- i
indices specifying element(s) to extract
- drop
logical; For
[.bru_mapper_sum
, whether to extract an individual mapper wheni
identifies a single element. IfFALSE
, a list of sub-mappers is returned (suitable e.g. for creating a newbru_mapper_sum
object). Default:TRUE
- value
a character vector of the same length as the number of sub-mappers in the mapper
Value
A bru_mapper_sum
object.
[
-indexing abru_mapper_sum
extracts a subsetbru_mapper_sum
object (for dropFALSE
) or an individual sub-mapper (for dropTRUE
, andi
identifies a single element)
The
names()
method forbru_mapper_sum
returns the names from the sub-mappers list
Methods (by generic)
ibm_jacobian(bru_mapper_sum)
: Accepts a list with named entries, or a list with unnamed but ordered elements. The names must match the sub-mappers, seeibm_names.bru_mapper_sum()
. Each list element should take a format accepted by the corresponding sub-mapper. In case each element is a vector, the input can be given as a data.frame with named columns, a matrix with named columns, or a matrix with unnamed but ordered columns.ibm_invalid_output(bru_mapper_sum)
: Accepts a list with named entries, or a list with unnamed but ordered elements. The names must match the sub-mappers, seeibm_names.bru_mapper_sum()
. Each list element should take a format accepted by the corresponding sub-mapper. In case each element is a vector, the input can be given as a data.frame with named columns, a matrix with named columns, or a matrix with unnamed but ordered columns.
See also
bru_mapper, bru_mapper_generics
Other mappers:
bru_get_mapper()
,
bru_mapper()
,
bru_mapper.fm_mesh_1d()
,
bru_mapper.fm_mesh_2d()
,
bru_mapper_aggregate()
,
bru_mapper_collect()
,
bru_mapper_const()
,
bru_mapper_factor()
,
bru_mapper_fmesher()
,
bru_mapper_generics
,
bru_mapper_harmonics()
,
bru_mapper_index()
,
bru_mapper_linear()
,
bru_mapper_logsumexp()
,
bru_mapper_marginal()
,
bru_mapper_matrix()
,
bru_mapper_mesh_B()
,
bru_mapper_multi()
,
bru_mapper_pipe()
,
bru_mapper_repeat()
,
bru_mapper_scale()
,
bru_mapper_shift()
,
bru_mapper_taylor()
Examples
(m <- bru_mapper_sum(list(
a = bru_mapper_index(3),
b = bru_mapper_index(2)
)))
#> sum(a = index, b = index)
ibm_n(m)
#> [1] 5
ibm_values(m)
#> [1] 1 2 3 4 5
ibm_jacobian(m, list(a = 1:3, b = c(1, 1, 2)))
#> 3 x 5 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 1 . . 1 .
#> [2,] . 1 . 1 .
#> [3,] . . 1 . 1
ibm_eval(
m,
list(a = 1:3, b = c(1, 1, 2)),
seq_len(ibm_n(m))
)
#> [1] 5 6 8