% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/kfold.R
\name{kfold_predict}
\alias{kfold_predict}
\title{Predictions from K-Fold Cross-Validation}
\usage{
kfold_predict(x, method = "posterior_predict", resp = NULL, ...)
}
\arguments{
\item{x}{Object of class \code{'kfold'} computed by \code{\link{kfold}}.
For \code{kfold_predict} to work, the fitted model objects need to have
been stored via argument \code{save_fits} of \code{\link{kfold}}.}

\item{method}{Method used to obtain predictions. Can be set to
\code{"posterior_predict"} (the default), \code{"posterior_epred"},
or \code{"posterior_linpred"}. For more details, see the respective
function documentations.}

\item{resp}{Optional names of response variables. If specified, predictions
are performed only for the specified response variables.}

\item{...}{Further arguments passed to \code{\link{prepare_predictions}}
that control several aspects of data validation and prediction.}
}
\value{
A \code{list} with two slots named \code{'y'} and \code{'yrep'}.
  Slot \code{y} contains the vector of observed responses.
  Slot \code{yrep} contains the matrix of predicted responses,
  with rows being posterior draws and columns being observations.
}
\description{
Compute and evaluate predictions after performing K-fold
cross-validation via \code{\link{kfold}}.
}
\examples{
\dontrun{
fit <- brm(count ~ zBase * Trt + (1|patient),
           data = epilepsy, family = poisson())

# perform k-fold cross validation
(kf <- kfold(fit, save_fits = TRUE, chains = 1))

# define a loss function
rmse <- function(y, yrep) {
  yrep_mean <- colMeans(yrep)
  sqrt(mean((yrep_mean - y)^2))
}

# predict responses and evaluate the loss
kfp <- kfold_predict(kf)
rmse(y = kfp$y, yrep = kfp$yrep)
}

}
\seealso{
\code{\link{kfold}}
}
