bru_set_missing: Set missing values in observation models

View source: R/bru.inference.R

bru_set_missingR Documentation

Set missing values in observation models

Description

Set all or parts of the observation model response data to NA, for example for use in cross validation (with bru_rerun()) or prior sampling (with bru_rerun() and generate()).

Usage

bru_set_missing(object, keep = FALSE, ...)

## S3 method for class 'bru'
bru_set_missing(object, keep = FALSE, ...)

## S3 method for class 'bru_obs_list'
bru_set_missing(object, keep = FALSE, ...)

## S3 method for class 'bru_obs'
bru_set_missing(object, keep = FALSE, ...)

Arguments

object

A bru, bru_obs or bru_obs_list object

keep

For bru_obs, a single logical or an integer vector; If TRUE, keep all the response data, if FALSE (default), set all of it to NA. An integer vector determines which elements to keep (for positive values) or to set as missing (negative values).

For bru and bru_obs_list, a logical scalar or vector, or a list, see Details.

...

Additional arguments passed on to the bru_obs method. Currently unused.

Details

For bru and bru_obs_list,

  • keep must be either a single logical, which is expanded to a list,

  • a logical vector, which is converted to a list,

  • an unnamed list of the same length as the number of observation models, with elements compatible with the bru_obs method, or

  • a named list with elements compatible with the bru_obs method, and only the named bro_obs models are acted upon, i.e. the elements not present in the list are treated as keep = TRUE.

E.g.: keep = list(b = FALSE) sets all observations in model b to missing, and does not change model a.

E.g.: keep = list(a = 1:4, b = -(3:5)) keeps only observations 1:4 of model a, marking the rest as missing, and sets observations 3:5 of model b to missing.

Examples

obs <- c(
  A = bru_obs(y_A ~ ., data = data.frame(y_A = 1:6)),
  B = bru_obs(y_B ~ ., data = data.frame(y_B = 11:15))
)
bru_response_size(obs)
lapply(
  bru_set_missing(obs, keep = FALSE),
  function(x) {
    x[["response_data"]][["BRU_response"]]
  }
)
lapply(
  bru_set_missing(obs, keep = list(B = FALSE)),
  function(x) {
    x[["response_data"]][["BRU_response"]]
  }
)
lapply(
  bru_set_missing(obs, keep = list(1:4, -(3:5))),
  function(x) {
    x[["response_data"]][["BRU_response"]]
  }
)

inlabru documentation built on Aug. 9, 2025, 1:08 a.m.