Package 'vizdraws'

Title: Visualize Draws from the Prior and Posterior Distributions
Description: Interactive visualization for Bayesian prior and posterior distributions. This package facilitates an animated transition between prior and posterior distributions. Additionally, it splits the distribution into bars based on the provided 'breaks,' displaying the probability for each region. If no 'breaks' are provided, it defaults to zero.
Authors: Ignacio Martinez [aut, cre], Linus Marco [aut], Dan Thal [aut]
Maintainer: Ignacio Martinez <[email protected]>
License: GPL-3
Version: 2.0.0.9000
Built: 2024-11-06 02:39:57 UTC
Source: https://github.com/ignacio82/vizdraws

Help Index


Visualize Probabilities using a Lollipop Chart

Description

This function creates a lollipop chart to visualize probabilities.

Usage

lollipops(
  data,
  plotBackgroundColor = "white",
  plotBackgroundOpacity = 0.8,
  title = "Probability of an impact",
  leftArea = "Negative",
  rightArea = "Positive",
  mediumText = 18,
  bigText = 28,
  width = NULL,
  height = NULL,
  elementId = NULL,
  logoPath = NULL,
  logoSize = 100,
  logoLocation = c("bottom-left", "top-left", "top-right", "bottom-right"),
  rightAreaText = "A positive impact is not necesarly a large impact.",
  leftAreaText = "A negative impact is not necesarly a large impact."
)

Arguments

data

A data frame containing the probabilities to visualize.

plotBackgroundColor

The background color of the plot.

plotBackgroundOpacity

The opacity of the plot background.

title

The title of the plot.

leftArea

The label for the left area of the plot.

rightArea

The label for the right area of the plot.

mediumText

The font size for medium text elements.

bigText

The font size for big text elements.

width

The width of the widget (optional).

height

The height of the widget (optional).

elementId

The element ID of the widget (optional).

logoPath

Logo path. Defaults to NULL.

logoSize

Logo size. Defaults to FALSE.

logoLocation

Logo location. c('bottom-right', 'top-left', 'top-right', 'bottom-left').

rightAreaText

The tooltip text for the right area of the plot.

leftAreaText

The tooltip text for the left area of the plot.

Details

The data frame should have three columns: 'name', 'value', and 'color'. The 'name' column specifies the names of the data points, while the 'value' column specifies the corresponding probabilities. The 'color' column specifies the color of each lollipop.

Value

A HTML widget object representing the lollipop chart.

Examples

data <- data.frame(
  Name = c("Outcome 1", "Outcome 2", "Outcome 3"),
  Prior = c(0.5, 0.5, 0.5),
  Posterior = c(0.2, 0.6, 0.9)
)
lollipops(data,
  logoPath = 'https://upload.wikimedia.org/wikipedia/commons/b/b8/YouTube_Logo_2017.svg',
  logoLocation = 'bottom-left')

vizdraws

Description

Visualize Draws from Prior or Posterior Distributions

Usage

vizdraws(
  prior = NULL,
  posterior = NULL,
  MME = 0,
  threshold = NULL,
  units = NULL,
  quantity = FALSE,
  tense = c("future", "past"),
  backgroundColor = "#FFFFFF",
  backgroundOpacity = 0.9,
  xlab = NULL,
  breaks = NULL,
  break_names = NULL,
  colors = NULL,
  width = NULL,
  height = NULL,
  xlim = NULL,
  font_scale = 1,
  display_mode_name = FALSE,
  title = "",
  stop_trans = FALSE,
  percentage = FALSE,
  elementId = NULL,
  logoPath = NULL,
  logoSize = 100,
  logoLocation = c("bottom-right", "top-left", "top-right", "bottom-left")
)

Arguments

prior

(optional) Prior distribution or draws from it. Supported distributions: 'Normal', 'uniform', 'beta', and 'gamma'. Provide either this or the posterior.

posterior

(optional) Draws from the posterior distribution. Provide either this or the prior.

MME

Minimum meaningful effect. If not provided, MME is set to zero.

threshold

If the probability is greater than this threshold, a decision is considered comfortable.

units

Optional argument to specify the units of x (e.g., dollars or applications).

quantity

Defaults to FALSE. When set to true, the text will reflect predicting a quantity rather than a treatment effect.

tense

Either "future" or "past." This is the tense used in the description if quantity is set to TRUE. NULL.

backgroundColor

Defaults to '#FFFFFF'.

backgroundOpacity

Defaults to 0.9.

xlab

Defaults to NULL.

breaks

Defaults to NULL.

break_names

Defaults to NULL.

colors

Colors for the left, middle, and right areas. Defaults to c("#e41a1c", "#377eb8", "#4daf4a").

width

Width for shiny.

height

Height for shiny.

xlim

Defaults to NULL.

font_scale

Defaults to 1.

display_mode_name

Defaults to FALSE.

title

Defaults to ''.

stop_trans

Defaults to FALSE. When set to true, the initial transition stops at posterior density.

percentage

Defaults to FALSE. When set to true, the x-axis tick format will be set to percentage.

elementId

Use an explicit element ID for the widget (rather than an automatically generated one). elementID for shiny.

logoPath

Logo path. Defaults to NULL.

logoSize

Logo size. Defaults to FALSE.

logoLocation

Logo location. c('bottom-right', 'top-left', 'top-right', 'bottom-left').

Details

A function to visualize draws from either the prior or posterior distribution, facilitating interpretation and decision-making.

Value

A HTML widget object.

Examples

if(interactive()){
  set.seed(9782)
  library(vizdraws)
  vizdraws(prior = rnorm(100000))
}

Shiny bindings for vizdraws

Description

Output and render functions for using vizdraws within Shiny applications and interactive Rmd documents.

Usage

vizdrawsOutput(outputId, width = "100%", height = "100%")

rendervizdraws(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width, height

Must be a valid CSS unit (like '100%', '400px', 'auto') or a number, which will be coerced to a string and have 'px' appended.

expr

An expression that generates a vizdraws

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.