bru_set_missing {inlabru}R 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,

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"]]
  }
)

[Package inlabru version 2.13.0 Index]