% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/brmsfit-methods.R, R/generics.R, R/plots.R
\name{marginal_effects.brmsfit}
\alias{marginal_effects}
\alias{marginal_effects.brmsfit}
\alias{plot.brmsMarginalEffects}
\title{Display marginal effects of predictors}
\usage{
\method{marginal_effects}{brmsfit}(x, effects = NULL, conditions = NULL,
  re_formula = NA, robust = TRUE, probs = c(0.025, 0.975),
  method = c("fitted", "predict"), ...)

marginal_effects(x, ...)

\method{plot}{brmsMarginalEffects}(x, ncol = NULL, points = FALSE,
  rug = FALSE, theme = ggplot2::theme(), ask = TRUE, plot = TRUE, ...)
}
\arguments{
\item{x}{An object usually of class \code{brmsfit}}

\item{effects}{An optional character vector naming effects
(main effects or interactions) for which to compute marginal plots.
If \code{NULL} (the default), plots for all effects are generated.}

\item{conditions}{An optional \code{data.frame} containing variable values
to marginalize on. Each effect defined in \code{effects} will
be plotted separately for each row of \code{data}. 
The row names of \code{data} will be treated as titles of the subplots. 
It is recommended to only define a few rows in order to keep the plots clear.
If \code{NULL} (the default), numeric variables will be marginalized
by using their means and factors will get their reference level assigned.}

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

\item{robust}{If \code{TRUE} (the default) the median is used as the 
measure of central tendency. If \code{FALSE} the mean is used instead.}

\item{probs}{The quantiles to be used in the computation of credible
intervals (defaults to 2.5 and 97.5 percent quantiles)}

\item{method}{Either \code{"fitted"} or \code{"predict"}. 
If \code{"fitted"}, plot marginal predictions of the regression curve. 
If \code{"predict"}, plot marginal predictions of the responses.}

\item{...}{Currently ignored.}

\item{ncol}{Number of plots to display per column for each effect.
If \code{NULL} (default), \code{ncol} is computed internally based
on the number of rows of \code{data}.}

\item{points}{Logical; indicating whether the original data points
should be added via \code{\link[ggplot2:geom_point]{geom_point}}.
Default is \code{FALSE}. Note that only those data points will be added
that match the specified conditions defined in \code{conditions}.}

\item{rug}{Logical; indicating whether a rug representation of predictor
values should be added via \code{\link[ggplot2:geom_rug]{geom_rug}}.
Default is \code{FALSE}.}

\item{theme}{A \code{\link[ggplot2:theme]{theme}} object 
modifying the appearance of the plots. 
For some basic themes see \code{\link[ggplot2:ggtheme]{ggtheme}}. 
Can be defined globally for the current session, via
\code{\link[ggplot2:theme_update]{theme_set}}.}

\item{ask}{logical; indicates if the user is prompted 
before a new page is plotted. 
Only used if \code{plot} is \code{TRUE}.}

\item{plot}{logical; indicates if plots should be
plotted directly in the active graphic device.
Defaults to \code{TRUE}.}
}
\value{
An object of class \code{brmsMarginalEffects}, which is a named list
  with one element per effect containing all information required to generate
  marginal effects plots. The corresponding \code{plot} method returns a named 
  list of \code{\link[ggplot2:ggplot]{ggplot}} objects, which can be further 
  customized using the \pkg{ggplot2} package.
}
\description{
Display marginal effects of one or more numeric and/or categorical 
predictors including interaction effects of order 2.
}
\details{
\code{NA} values within factors in \code{conditions}, 
  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.
}
\examples{
\dontrun{
fit <- brm(count ~ log_Age_c + log_Base4_c * Trt_c + (1 | patient),
           data = epilepsy, family = poisson()) 
## plot all marginal effects
plot(marginal_effects(fit), ask = FALSE)
## only plot the marginal interaction effect of 'log_Base4_c:Trt_c'
## for different values for 'log_Age_c'
mdata <- data.frame(log_Age_c = c(-0.3, 0, 0.3))
plot(marginal_effects(fit, effects = "log_Base4_c:Trt_c", 
                      data = mdata))
## also incorporate random effects variance over patients
## and add a rug representation of predictor values
plot(marginal_effects(fit, effects = "log_Base4_c:Trt_c", 
                      data = mdata, re_formula = NULL), rug = TRUE)
}

}

