bayesnec standard ggplot2 plotting method.

# S3 method for class 'bayesnecfit'
autoplot(
  object,
  ...,
  nec = TRUE,
  ecx = FALSE,
  nsec = FALSE,
  xform = NULL,
  group = NULL,
  group_aes = c("line", "colour"),
  point_alpha = 1,
  x_scale = c("recorded", "fitted"),
  which = "combined",
  xlab = "Predictor",
  ylab = NULL
)

# S3 method for class 'bayesmanecfit'
autoplot(
  object,
  ...,
  nec = TRUE,
  ecx = FALSE,
  nsec = FALSE,
  xform = NULL,
  model = NULL,
  average = TRUE,
  plot = TRUE,
  ask = TRUE,
  newpage = TRUE,
  multi_facet = TRUE,
  group = NULL,
  group_aes = c("line", "colour"),
  point_alpha = 1,
  all_models = NULL,
  x_scale = c("recorded", "fitted"),
  xlab = "Predictor",
  ylab = NULL
)

# S3 method for class 'bayesnecgroupfit'
autoplot(
  object,
  ...,
  nec = TRUE,
  ecx = FALSE,
  nsec = FALSE,
  xform = NULL,
  group = NULL,
  group_aes = c("line", "colour"),
  point_alpha = 1,
  x_scale = c("recorded", "fitted"),
  xlab = "Predictor",
  ylab = NULL
)

# S3 method for class 'bayesnecjointfit'
autoplot(
  object,
  ...,
  nec = TRUE,
  ecx = FALSE,
  nsec = FALSE,
  xform = NULL,
  group = NULL,
  group_aes = c("line", "colour"),
  point_alpha = 1,
  x_scale = c("recorded", "fitted"),
  xlab = "Predictor",
  ylab = NULL
)

Arguments

object

An object of class bayesnecfit, bayesmanecfit, bayesnecgroupfit or bayesnecjointfit.

...

Additional arguments to be passed to ggbnec_data.

nec

Should NEC values be added to the plot? Defaults to TRUE.

ecx

Should ECx values be added to the plot? Defaults to FALSE.

nsec

Should the NSEC from nsec be added to the plot? Defaults to FALSE. For grouped and joint fits, each panel uses its own level's estimate.

xform

NULL, the default, or a function applied to the axis selected by x_scale. See ggbnec_data.

group

An optional character string naming a categorical variable in the data supplied to bnec. Observations are joined through their per-level means when the variable occurs as a group-level term in the fitted formula; a level recorded at one predictor value is marked at its mean instead. A variable not fitted by the model can be shown only with group_aes = "colour"; the curve and credible band are pooled over that variable, and the legend identifies it as not fitted. A bayesnecgroupfit uses its fitted grouping variable automatically and draws one panel per level, as does a bayesnecjointfit, whose levels are coefficients of one posterior rather than separate fits.

group_aes

How should the grouping selected by group be shown? "line" (the default) draws grey per-level means. "colour" also maps the grouping to the observation fill and the per-level mean marks. The argument is ignored when group is NULL. Only "colour" is available when group is not a group-level term in the fitted formula.

point_alpha

The opacity of the observation points, a single number from 0 (transparent) to 1 (opaque, the default). It does not change the credible band or the per-level means drawn for group.

x_scale

"recorded" (the default) draws the predictor as supplied to bnec(). "fitted" draws it as transformed inside crf(), with axis labels in the supplied units. It has no effect when crf() names an untransformed predictor.

which

The curve to draw for a bayesnecfit with a two-block family ("hurdle_gamma", "zero_inflated_beta", "hurdle_poisson" or "hurdle_negbinomial"), as returned by bnec or by bnec_joint on a bnec_hurdle fit: "combined" (the default), the expected response per individual exposed; "growth", the response of survivors, which dpar = "mu" selects in ecx; "survival", the probability of a non-zero response, which dpar = "hu" ("zi" for zero_inflated_beta) selects; or "all" for a panel of each. The panels and their titles are those autoplot.bayesnechurdlefit draws for a factorised fit, and each title names the equation of its block. A growth or survival panel marks the nec parameter of its block where the block's equation is a monotone threshold equation, and otherwise the NSEC of its curve, as nec reports them, and draws the ECx that ecx returns with the matching dpar. A model set, a bayesnecgroupfit, a bayesnecjointfit and a fit of any other family draw one curve and refuse any value but "combined".

xlab

The x-axis label. Defaults to "Predictor".

ylab

The y-axis label. Defaults to NULL, which gives "Response", or for a two-block family the title of the curve drawn. Where which = "all", the panel titles name the curves and NULL leaves the axis unlabelled.

model

NULL (the default), or a character vector naming equations of the model set. Each named equation is drawn in a panel of its own, which shows the same curve and annotations as autoplot() gives for the bayesnecfit that pull_out returns for it. A name that is not an equation of the set is refused.

average

Should the model averaged predictions be plotted? Defaults to TRUE. Where model is also given, the model average takes the first panel. average = FALSE requires model.

plot

Should output ggplot output be plotted? Only relevant if model is given and multi_facet = FALSE.

ask

Indicates if the user is prompted before a new page is plotted. Only relevant if plot = TRUE and multi_facet = FALSE.

newpage

Indicates if the first set of plots should be plotted to a new page. Only relevant if plot = TRUE and multi_facet = FALSE.

multi_facet

Should all plots be plotted in one single panel via facets? Defaults to TRUE, in which case the facets of the named equations are ordered by name. Only relevant if model is given. With multi_facet = FALSE, one ggplot is built for each panel, drawn in turn only where plot = TRUE, and the list of them is returned invisibly, the model average first where it is requested and then the equations in the order given in model.

all_models

Deprecated, and to be removed in a later release; use model and average. all_models = TRUE is model = object$success_models, average = FALSE, and all_models = FALSE is the default. Supplying it gives a warning, and supplying it together with model or average is an error.

Value

A ggplot object, or, for a bayesmanecfit with multi_facet = FALSE, a list of them, returned invisibly, as described under multi_facet.

Details

Where a group-level term spans the predictor, as a plate does when each plate is tested at every concentration, the curve and credible band are those of the population curve, with every group deviation set to zero. The band is therefore the 95% credible interval of the expected response of a typical level, and it does not include the variation between levels: the observations of a level whose deviation is large can lie outside it. The NEC, NSEC and ECx lines are read from the observed levels instead (see pool in ecx), so they need not fall where the plotted curve equals the corresponding response.

Where crf() transforms the predictor inline, the default axis and estimate annotations are on the recorded scale. A supplied xform acts on that scale and gives a warning naming the inverse already applied. The fitted axis uses recorded-concentration labels, so it refuses a non-identity xform.

Examples

if (FALSE) { # \dontrun{
library(brms)
nec4param <- pull_out(manec_example, "nec4param")
autoplot(nec4param)
autoplot(nec4param, nec = FALSE)
autoplot(nec4param, ecx = TRUE, ecx_val = 50, xlab = "Concentration")
autoplot(nec4param, nec = FALSE, ecx = TRUE, nsec = TRUE, ecx_val = 10)

# plot model averaged predictions
autoplot(manec_example)
# plot the model average and each equation of the set, a facet each
autoplot(manec_example, ecx = TRUE, ecx_val = 50,
         model = c("nec4param", "ecx4param"))
# plot the equations alone, without the model average
autoplot(manec_example, model = manec_example$success_models,
         average = FALSE)
} # }
if (FALSE) { # \dontrun{
# plots multiple models, one at a time, with interactive prompt
autoplot(manec_example, ecx = TRUE, ecx_val = 50,
         model = manec_example$success_models, average = FALSE,
         multi_facet = FALSE)
} # }