% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/emmeans.R
\name{emmeans-brms-helpers}
\alias{emmeans-brms-helpers}
\alias{recover_data.brmsfit}
\alias{emm_basis.brmsfit}
\title{Support Functions for \pkg{emmeans}}
\usage{
recover_data.brmsfit(
  object,
  data,
  resp = NULL,
  dpar = NULL,
  nlpar = NULL,
  re_formula = NA,
  epred = FALSE,
  ...
)

emm_basis.brmsfit(
  object,
  trms,
  xlev,
  grid,
  vcov.,
  resp = NULL,
  dpar = NULL,
  nlpar = NULL,
  re_formula = NA,
  epred = FALSE,
  ...
)
}
\arguments{
\item{object}{An object of class \code{brmsfit}.}

\item{data, trms, xlev, grid, vcov.}{Arguments required by \pkg{emmeans}.}

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

\item{dpar}{Optional name of a predicted distributional parameter.
If specified, expected predictions of this parameters are returned.}

\item{nlpar}{Optional name of a predicted non-linear parameter.
If specified, expected predictions of this parameters are returned.}

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

\item{epred}{Logical. If \code{TRUE} compute predictions of
the posterior predictive distribution's mean
(see \code{\link{posterior_epred.brmsfit}}) while ignoring
arguments \code{dpar} and \code{nlpar}. Defaults to \code{FALSE}.
If you have specified a response transformation within the formula,
you need to set \code{epred} to \code{TRUE} for \pkg{emmeans} to
detect this transformation.}

\item{...}{Additional arguments passed to \pkg{emmeans}.}
}
\description{
Functions required for compatibility of \pkg{brms} with \pkg{emmeans}.
Users are not required to call these functions themselves. Instead,
they will be called automatically by the \code{emmeans} function
of the \pkg{emmeans} package.
}
\details{
In order to ensure compatibility of most \pkg{brms} models with
\pkg{emmeans}, predictions are not generated 'manually' via a design matrix
and coefficient vector, but rather via \code{\link{posterior_linpred.brmsfit}}.
This appears to generally work well, but note that it produces an `.@linfct`
slot that contains the computed predictions as columns instead of the
coefficients.
}
\examples{
\dontrun{
fit1 <- brm(time | cens(censored) ~ age * sex + disease + (1|patient),
            data = kidney, family = lognormal())
summary(fit1)

# summarize via 'emmeans'
library(emmeans)
rg <- ref_grid(fit1)
em <- emmeans(rg, "disease")
summary(em, point.est = mean)

# obtain estimates for the posterior predictive distribution's mean
epred <- emmeans(fit1, "disease", epred = TRUE)
summary(epred, point.est = mean)


# model with transformed response variable
fit2 <- brm(log(mpg) ~ factor(cyl), data = mtcars)
summary(fit2)

# results will be on the log scale by default
emmeans(fit2, ~ cyl)
# log transform is detected and can be adjusted automatically
emmeans(fit2, ~ cyl, epred = TRUE, type = "response")
}
}
