% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bru.inference.R
\name{bru_set_missing}
\alias{bru_set_missing}
\alias{bru_set_missing<-}
\alias{bru_set_missing.bru}
\alias{bru_set_missing.bru_info}
\alias{bru_set_missing.bru_obs_list}
\alias{bru_set_missing.bru_obs}
\alias{bru_set_missing.default}
\alias{bru_set_missing.data.frame}
\alias{bru_set_missing.inla.surv}
\title{Set missing values in observation models}
\usage{
bru_set_missing(object, keep = FALSE, ...)

bru_set_missing(x, ...) <- value

\method{bru_set_missing}{bru}(object, keep = FALSE, ...)

\method{bru_set_missing}{bru_info}(object, keep = FALSE, ...)

\method{bru_set_missing}{bru_obs_list}(object, keep = FALSE, ...)

\method{bru_set_missing}{bru_obs}(object, keep = FALSE, ...)

\method{bru_set_missing}{default}(object, keep = FALSE, ...)

\method{bru_set_missing}{data.frame}(object, keep = FALSE, ...)

\method{bru_set_missing}{inla.surv}(object, keep = FALSE, ...)
}
\arguments{
\item{object}{A \code{bru}, \code{bru_obs} or \code{bru_obs_list} object}

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

For \code{bru} and \code{bru_obs_list}, a logical scalar or vector, or a list, see
Details.}

\item{\dots}{Additional arguments passed on to the \code{bru_obs} and individual
data class methods.  Currently unused.}

\item{x}{Object on which to apply \code{bru_set_missing()}}

\item{value}{Value to be passed as \code{keep} to \code{bru_set_missing()}}
}
\description{
Set all or parts of the observation model response data
to \code{NA}, for example for use in cross validation (with \code{\link[=bru_rerun]{bru_rerun()}})
or prior sampling (with \code{\link[=bru_rerun]{bru_rerun()}} and \code{\link[=generate]{generate()}}, but see
"Prior sampling caveats" below).
}
\details{
For \code{bru} and \code{bru_obs_list},
\itemize{
\item{\code{keep} must be either a single logical, which is expanded to a list,}
\item{a logical vector, which is converted to a list,}
\item{an unnamed list of the same length as the number of observation
models, with elements compatible with the \code{bru_obs} method, or}
\item{a named list with elements compatible with the \code{bru_obs} method,
and only the named \code{bru_obs} models are acted upon, i.e. the elements
not present in the list are treated as \code{keep = TRUE}.}
}

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

E.g.: \code{keep = list(a = 1:4, b = -(3:5))} keeps only observations \code{1:4} of
model \code{a}, marking the rest as missing, and sets observations \code{3:5} of model
\code{b} to missing.
}
\section{Methods (by class)}{
\itemize{
\item \code{bru_set_missing(default)}: From \verb{> 2.13.0}, set missing values in any
object supporting \code{\link[base:NA]{base::is.na<-()}} for positive and negative indices.

\item \code{bru_set_missing(data.frame)}: From \verb{> 2.13.0}, handles \code{data.frame}, tibbles,
including \code{inla.mdata}.

\item \code{bru_set_missing(inla.surv)}: From \verb{> 2.13.0}, handles \code{inla.surv}.

}}
\section{Functions}{
\itemize{
\item \code{bru_set_missing(x, ...) <- value}: Setter method for \code{bru_set_missing()}

}}
\section{Prior sampling caveats}{

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

\if{html}{\out{<div class="sourceCode">}}\preformatted{bru_rerun(
  bru_set_missing(...),
  options = list(
    control.mode = list(
      theta = theta_sample,
      fixed = TRUE)
    )
  )
}\if{html}{\out{</div>}}

for each sample.
}

\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"]][[x[["response"]]]]
  }
)
lapply(
  bru_set_missing(obs, keep = list(B = FALSE)),
  function(x) {
    x[["response_data"]][[x[["response"]]]]
  }
)
lapply(
  bru_set_missing(obs, keep = list(1:4, -(3:5))),
  function(x) {
    x[["response_data"]][[x[["response"]]]]
  }
)

\dontshow{if (bru_safe_inla()) withAutoprint(\{ # examplesIf}
(obs <- INLA::inla.mdata(y = 1:4, X = matrix(1:8, 4, 2)))
bru_set_missing(obs, keep = c(1, 4))
bru_set_missing(obs) <- -(1:2)
obs
\dontshow{\}) # examplesIf}
\dontshow{if (bru_safe_inla()) withAutoprint(\{ # examplesIf}
(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))

(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))
\dontshow{\}) # examplesIf}
}
