Title: | Visualize Draws from the Prior and Posterior Distributions |
Version: | 2.0.0 |
Date: | 2024-01-10 |
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. |
License: | GPL-3 |
Encoding: | UTF-8 |
URL: | https://github.com/ignacio82/vizdraws/ https://vizdraws.martinez.fyi/, https://github.com/ignacio82/vizdraws |
Imports: | dplyr, htmlwidgets, magrittr, stats, stringr |
Suggests: | glue, knitr, rmarkdown |
RoxygenNote: | 7.2.3 |
VignetteBuilder: | knitr |
BugReports: | https://github.com/ignacio82/vizdraws/issues |
NeedsCompilation: | no |
Packaged: | 2024-01-11 02:36:48 UTC; ignacio |
Author: | Ignacio Martinez [aut, cre], Linus Marco [aut], Dan Thal [aut] |
Maintainer: | Ignacio Martinez <ignacio@protonmail.com> |
Repository: | CRAN |
Date/Publication: | 2024-01-11 03:50:02 UTC |
Pipe operator
Description
See magrittr::%>%
for details.
Usage
lhs %>% rhs
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 |
logoSize |
Logo size. Defaults to |
logoLocation |
Logo location. |
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 |
tense |
Either "future" or "past." This is the tense used in the description if quantity is set to TRUE. |
backgroundColor |
Defaults to |
backgroundOpacity |
Defaults to |
xlab |
Defaults to |
breaks |
Defaults to |
break_names |
Defaults to |
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 |
font_scale |
Defaults to |
display_mode_name |
Defaults to |
title |
Defaults to |
stop_trans |
Defaults to |
percentage |
Defaults to |
elementId |
Use an explicit element ID for the widget (rather than an automatically generated one). elementID for shiny. |
logoPath |
Logo path. Defaults to |
logoSize |
Logo size. Defaults to |
logoLocation |
Logo location. |
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 |
expr |
An expression that generates a vizdraws |
env |
The environment in which to evaluate |
quoted |
Is |