% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/brmsfit-methods.R, R/generics.R
\name{LOO.brmsfit}
\alias{LOO}
\alias{LOO.brmsfit}
\title{Compute LOO}
\usage{
\method{LOO}{brmsfit}(x, ..., compare = TRUE, newdata = NULL,
  re_formula = NULL, allow_new_levels = FALSE, subset = NULL,
  nsamples = NULL, pointwise = NULL, cores = 1, wcp = 0.2,
  wtrunc = 3/4)

LOO(x, ..., compare = TRUE)
}
\arguments{
\item{x}{A fitted model object typically of class \code{brmsfit}.}

\item{...}{Optionally more fitted model objects.}

\item{compare}{A flag indicating if the WAICs 
of the models should be compared to each other.}

\item{newdata}{An optional data.frame for which to evaluate predictions.
If \code{NULL} (default), the orginal data of the model is used.}

\item{re_formula}{formula containing random effects 
to be considered in the prediction. 
If \code{NULL} (default), include all random effects; 
if \code{NA}, include no random effects.}

\item{allow_new_levels}{A flag indicating if new
levels of random effects are allowed (defaults to \code{FALSE}). 
Only relevant if \code{newdata} is provided.}

\item{subset}{A numeric vector specifying
the posterior samples to be used. 
If \code{NULL} (the default), all samples are used.}

\item{nsamples}{Positive integer indicating how many 
posterior samples should be used. 
If \code{NULL} (the default) all samples are used.
Ignored if \code{subset} is not \code{NULL}.}

\item{pointwise}{A flag indicating whether to compute the full
log-likelihood matrix at once or separately for each observation. 
The latter approach is usually considerably slower but 
requires much less working memory. Accordingly, if one runs 
into memory issues, \code{pointwise = TRUE} is the way to go.
By default, \code{pointwise} is automatically chosen based on 
the size of the model.}

\item{cores}{The number of cores to use for parallelization. 
Default is \code{1}.}

\item{wcp, wtrunc}{Parameters used for 
the Pareto smoothed importance sampling. 
See \code{\link[loo:loo]{loo}} for details.}
}
\value{
If just one object is provided, an object of class \code{ic}. 
 If multiple objects are provided, an object of class \code{iclist}.
}
\description{
Compute Leave-one-out cross-validation based on the posterior likelihood
by using the \pkg{loo} package
}
\details{
When comparing models fitted to the same data, 
 the smaller the LOO, the better the fit.
}
\section{Methods (by class)}{
\itemize{
\item \code{brmsfit}: method for class \code{brmsfit}
}}
\examples{
\dontrun{
#model with fixed effects only
fit1 <- brm(rating ~ treat + period + carry,
            data = inhaler, family = "gaussian")
LOO(fit1)

#model with an additional random intercept for subjects
fit2 <- brm(rating ~ treat + period + carry + (1|subject),
            data = inhaler, family = "gaussian")
#compare both models
LOO(fit1, fit2)                          
}

}
\author{
Paul-Christian Buerkner \email{paul.buerkner@gmail.com}
}
\references{
Vehtari, A., Gelman, A., and Gabry, J. (2015). 
Efficient implementation of leave-one-out cross-validation 
and WAIC for evaluating fitted Bayesian models.

Gelman, A., Hwang, J., & Vehtari, A. (2014). 
Understanding predictive information criteria for Bayesian models. 
Statistics and Computing, 24, 997-1016.

Watanabe, S. (2010). Asymptotic equivalence of Bayes cross validation 
and widely applicable information criterion in singular learning theory. 
The Journal of Machine Learning Research, 11, 3571-3594.
}

