% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cv.R
\name{cv_imr}
\alias{cv_imr}
\title{Cross-Validated Predictive Accuracy of an IMR Fit}
\usage{
cv_imr(
  object,
  k = 5,
  rounds = 2,
  method = NULL,
  max_models = 100,
  verbose = FALSE
)
}
\arguments{
\item{object}{A fitted object of class `"imr"` returned by [imr()].}

\item{k}{Integer number of cross-validation folds per round (default `5`).
Must be at least `2`, and each availability subgroup must contain at least
`k` subjects.}

\item{rounds}{Integer number of independent cross-validation rounds to
average over (default `2`).  Must be positive.}

\item{method}{Optional compatibility argument.  If supplied, it must match
the method stored in `object`; `cv_imr()` cannot turn an IMR fit into a BMS
fit or vice versa.}

\item{max_models}{Integer maximum number of selection models used for
Bayesian model averaging (default `100`).  Must be positive.}

\item{verbose}{Logical; if `TRUE`, print the C routine's cross-validation
diagnostics.  Defaults to `FALSE`.}
}
\value{
A list with two numeric matrices, each of dimension
  `rounds` x `(n_subgroups + 1)`, whose last column corresponds to all
  subjects pooled and whose remaining columns are named by the availability
  subgroup bitstrings:
  \item{total_cindex}{Accuracy computed on the pooled cross-validated
    predictions within each availability subgroup (and overall).}
  \item{subset_cindex}{Accuracy computed fold-by-fold within each
    availability subgroup.}
  The accuracy metric (`"C-index"`, `"AUC"` or `"MSE"`) is recorded in the
  `"metric"` attribute of the returned list.
}
\description{
`cv_imr()` evaluates predictive accuracy of a model fitted with [imr()] using
repeated \eqn{K}-fold splits and Bayesian model averaging over the fitted
MCMC samples.  The sampler is not re-run inside each training fold; fit a
separate object with `method = "BMS"` if a no-borrowing comparison is needed.
The accuracy measure depends on the outcome type: the concordance index
(C-index) for right-censored outcomes, the area under the ROC curve (AUC) for
binary outcomes, and the mean squared error (MSE) for continuous outcomes.
}
\examples{
\donttest{
data("simIMR", package = "IntegMultiReg")
fit <- imr(
  platform_data_list = simIMR$platforms, outcome = simIMR$outcome,
  cov = simIMR$covariates, type_outcome = "binary",
  nu = c(-4, -3, -4), sample_mcmc = c(200, 100), ssize = 5, seed = 1
)
cv <- cv_imr(fit, k = 5, rounds = 2)
cv$total_cindex
}
}
\seealso{
[imr()], [predict.imr()]
}
