% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/log_lik.R
\name{log_lik.brmsfit}
\alias{log_lik.brmsfit}
\alias{log_lik}
\alias{logLik.brmsfit}
\title{Compute the Pointwise Log-Likelihood}
\usage{
\method{log_lik}{brmsfit}(
  object,
  newdata = NULL,
  re_formula = NULL,
  resp = NULL,
  ndraws = NULL,
  draw_ids = NULL,
  pointwise = FALSE,
  combine = TRUE,
  add_point_estimate = FALSE,
  cores = NULL,
  ...
)
}
\arguments{
\item{object}{A fitted model object of class \code{brmsfit}.}

\item{newdata}{An optional data.frame for which to evaluate predictions. If
\code{NULL} (default), the original data of the model is used. \code{NA}
values within factors (excluding grouping variables) are interpreted as if
all dummy variables of this factor are zero. This allows, for instance, to
make predictions of the grand mean when using sum coding. \code{NA} values
within grouping variables are treated as a new level.}

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

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

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

\item{draw_ids}{An integer vector specifying the posterior draws to be used.
If \code{NULL} (the default), all draws are used.}

\item{pointwise}{A flag indicating whether to compute the full
log-likelihood matrix at once (the default), or just return
the likelihood function along with all data and draws
required to compute the log-likelihood separately for each
observation. The latter option is rarely useful when
calling \code{log_lik} directly, but rather when computing
\code{\link{waic}} or \code{\link{loo}}.}

\item{combine}{Only relevant in multivariate models.
Indicates if the log-likelihoods of the submodels should
be combined per observation (i.e. added together; the default)
or if the log-likelihoods should be returned separately.}

\item{add_point_estimate}{For internal use only. Ensures compatibility
with the \code{\link{loo_subsample}} method.}

\item{cores}{Number of cores (defaults to \code{1}). On non-Windows systems,
this argument can be set globally via the \code{mc.cores} option.}

\item{...}{Further arguments passed to \code{\link{prepare_predictions}}
that control several aspects of data validation and prediction.}
}
\value{
Usually, an S x N matrix containing the pointwise log-likelihood
 draws, where S is the number of draws and N is the number
 of observations in the data. For multivariate models and if
 \code{combine} is \code{FALSE}, an S x N x R array is returned,
 where R is the number of response variables.
 If \code{pointwise = TRUE}, the output is a function
 with a \code{draws} attribute containing all relevant
 data and posterior draws.
}
\description{
Compute the Pointwise Log-Likelihood
}
\details{
\code{NA} values within factors in \code{newdata},
  are interpreted as if all dummy variables of this factor are
  zero. This allows, for instance, to make predictions of the grand mean
  when using sum coding.

In multilevel models, it is possible to
allow new levels of grouping factors to be used in the predictions.
This can be controlled via argument \code{allow_new_levels}.
New levels can be sampled in multiple ways, which can be controlled
via argument \code{sample_new_levels}. Both of these arguments are
documented in \code{\link{prepare_predictions}} along with several
other useful arguments to control specific aspects of the predictions.
}
