View source: R/bru.inference.R
bru_set_missing | R Documentation |
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()
, but see
"Prior sampling caveats" below).
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, ...)
## Default S3 method:
bru_set_missing(object, keep = FALSE, ...)
## S3 method for class 'data.frame'
bru_set_missing(object, keep = FALSE, ...)
## S3 method for class 'inla.surv'
bru_set_missing(object, keep = FALSE, ...)
object |
A |
keep |
For For |
... |
Additional arguments passed on to the |
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.
bru_set_missing(default)
: From > 2.13.0
, set missing values in any
object supporting base::is.na<-()
for positive and negative indices.
bru_set_missing(data.frame)
: From > 2.13.0
, handles data.frame
, tibbles,
including inla.mdata
.
bru_set_missing(inla.surv)
: From > 2.13.0
, handles inla.surv
.
Note that prior sampling requires special care for hyperparameters, as the prior modes are not typically useful; in the future, we plan to have a dedicated method that samples from the hyperparameters, and then uses
bru_rerun( bru_set_missing(...), options = list( control.mode = list( theta = theta_sample, fixed = TRUE) ) )
for each sample.
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"]]
}
)
(obs <- INLA::inla.mdata(y = 1:4, X = matrix(1:8, 4, 2)))
bru_set_missing(obs, keep = c(1, 4))
(obs <- INLA::inla.surv(time = 1:4, event = c(1, 0, 1, 0)))
bru_set_missing(obs, keep = c(1, 4))
(obs <- INLA::inla.surv(
time = 1:4,
event = c(1, 0, 1, 0),
cure = matrix(1:8, 4, 2)
))
bru_set_missing(obs, keep = c(1, 4))|>str()
(obs <- INLA::inla.surv(
time = 1:4,
event = c(1, 0, 1, 0),
subject = c(1, 1, 2, 1)
))
bru_set_missing(obs, keep = c(1, 4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.