Skip to contents

glm_plotlist() formats data for plotting univariable GLM predictions with error bars for each of a number of independent variables.

Usage

glm_plotlist(
  data,
  .dep_var,
  ...,
  .ungroups = NULL,
  .conf_level = 0.95,
  .type = c("link", "response"),
  .facet_by = NULL
)

Arguments

data

a data frame, or a data frame extension (e.g. a tibble).

.dep_var

quoted name of the response variable in the data representing the number of successes and failures respectively, see Details; default cbind(pn, qn).

...

<tidy-select> independent variables to be included in the plot data.

.ungroups

a named character vector of ungrouped levels of independent variables specified in .ind_var, see details; default NULL.

.conf_level

the confidence level required for the error bars; default 0.95. If NA, error bars are standard error.

.type

the type of prediction required. The default is on the scale of the linear predictors; the alternative "response" is on the scale of the response variable; default "link".

.facet_by

NULL, the default; or, if the output is to be combined into a single object to be used for a faceted plot, a character vector of length one used to name an additional column containing the names of the independent variables.

Value

If the argument .facet_by is NULL, a list of "glm_plotdata" objects suitable for producing multiple plots using ggplot(). Otherwise, a single "glm_plotdata" object with an additional column taking its name from .facet_by and containing the names of the independent variables.

Details

glm_plotlist() invokes glm_plotdata() to create a list of "glm_plotdata" objects for plotting univariable GLM predictions with error bars for each of a number of independent variables in data. Independent variables to be included are selected using the ... argument with the <tidy-select> syntax of package dplyr, including use of “selection helpers”.

Like glm_plotdata(), glm_plotlist() allows exploration of proposed groupings of levels of independent variables (e.g. as obtained using add_grps() or fct_collapse()) and inclusion of both grouped and ungrouped levels in the "glm_plotdata" objects comprising its output list. In such cases, the .ungroups argument is used to provide a named character vector of the names of the corresponding factors in data giving the grouped and ungrouped levels of the form ungrouped_name = "grouped_name"; levels not otherwise mentioned will be left as is.

The grouped levels are used as the independent variable in the GLM invoked by glm_plotdata() and are output in the column grouped within the corresponding "glm_plotdata" object, while the ungrouped levels are shown in the column level, see glm_plotdata().

The .conf_level and .type arguments are handled as for glm_plotdata().

glm_plotlist() may be used in conjunction with lapply() (or purrr package map()) to rapidly obtain multiple plots of univariable GLMs for a number of independent variables.

Levels of independent variables for which the observed values are all zero or all one are not included in the output, although they are taken into consideration in calculating denominators in the case of grouped levels.

See also

Examples

# Coming soon!