pp_check_ordbeta {ordbetareg}R Documentation

Accurate Posterior Predictive Plots for Ordbetareg Models

Description

The standard brms::pp_check plot available via brms is not accurate for ordbetareg models because an ordered beta regression has both continuous and discrete components. This function implements a bar plot and a density plot for the continuous and discrete elements separately, and will return accurate posterior predictive plots relative to the data.

Usage

pp_check_ordbeta(
  model = NULL,
  type = "both",
  ndraws = 10,
  cores = NULL,
  group = NULL,
  new_theme = NULL,
  outcome_label = NULL,
  animate = FALSE,
  reverse_bounds = TRUE,
  facet_scales = "fixed"
)

Arguments

model

A fitted ordbetareg model.

type

Default is "both" for creating both a discrete (bar) and continuous (density) plot. Can also be "discrete" for only the bar plot for discrete values (0/1) or "continuous" for continuous values (density plot).

ndraws

Number of posterior draws to use to calculate estimates and show in plot. Defaults to 10.

cores

Number of cores to use to produce posterior predictive distribution. Defaults to NULL or 1 core.

group

A factor variable of the same number of rows as the data that is used to broduce grouped (faceted) plots of the posterior distribution.

new_theme

Any additional themes to be added to ggplot2 (default is NULL).

outcome_label

A character value that will replace the name of the outcome in the plot (default is the name of the response variable in the data frame).

animate

Whether to animate each posterior draw for continuous distributions (defaults to FALSE).

reverse_bounds

Whether to plot data using the original bounds in the data (i.e. not 0 and 1).

facet_scales

The option passed on to the facet_wrap function in ggplot2 for the type of scale for facetting if passing a variable for group. Defaults to "fixed" scales but can be set to "free_y" to allow probability density/bar count scales to vary or "free" to allow both x and y axes to vary (i.e., also outcome axis ticks).

Value

If "both", prints both plots and returns a list of both plots as ggplot2 objects. Otherwise, prints and returnst the specific plot as a ggplot2 object.

Examples


# need a fitted ordbetareg model

data("ord_fit_mean")

out_plots <- pp_check_ordbeta(ord_fit_mean)

# view discrete bar plot

out_plots$discrete

# view continuous density plot

out_plots$continuous

# change title using ggplot2 ggtitle function

out_plots$discrete + ggplot2::ggtitle("New title")


[Package ordbetareg version 0.7.2 Index]