visualize_predictions: Visualize hypotheses' predictions for a Bayesian two-group...

View source: R/Visualizations.R

visualize_predictionsR Documentation

Visualize hypotheses' predictions for a Bayesian two-group t-test

Description

Visualizes the predictions of the null and an alternative hypothesis. By specifying an observed effect (observed t-value), an illustration of the ratio of the marginal likelihoods, i.e., an illustration of the Bayes factor is displayed.

Usage

visualize_predictions(alternative = function(x) dcauchy(x, scale =
  sqrt(2)/2), n1, n2, from = -6, to = 6, lwd = 3,
  col = c("#005A31", "red", "black", "orange"), observed_t = NULL,
  frame.plot = FALSE, xlab = "t-value", BFx = from + 0.1,
  BFy = 0.1, BF10 = TRUE, legend_placement = "topleft",
  legend_content = c("Null", "Alternative", "Observed"), ...)

Arguments

alternative

A function object. The default is a Cauchy prior with scaling parameter 'sqrt(2) / 2' as is the default in package 'BayesFactor' (Morey & Rouder, 2015). This argument can also be a scalar number, in which case it is assumed that the alternative is a point hypothesis on Cohen's d (with Cohen's d = 'prior'). If 'alternative' is NULL, only the null hypothesis predictions are drawn.

n1

The sample size in group 1

n2

The sample size in group 2

from

the left margin of the x-axis

to

the right margin of the x-axis

col

Specify the coloring of the plot. col[1] specifies the color for the null hypothesis; col[2] specifies the color for the alternative hypothesis; col[3] specifies the color for the line the illustrates the observed effect (only has an effect if an observed effect size is specified via argument 'observed_t'); col[4] specifies the color of the points at the intersection of the observed effect and the curves for the hypotheses (only has an effect if an observed effect size is specified via argument 'observed_t')

observed_t

An observed t-value. Does not need to be specified and defaults to NULL. If this argument is passed, the marginal likelihoods of the null and the alternative hypothesis are drawn and a Bayes factor is displayed.

frame.plot

Should a frame be drawn?

xlab

The label of the x-axis

BFx

The x coordinate where the Bayes factor is displayed in the plot. Only has an effect if an 'observed_t' is passed.

BFy

The y coordinate where the Bayes factor is displayed in the plot. Only has an effect if an 'observed_t' is passed.

BF10

Boolean; defaults to TRUE. Should a Bayes factor be displayed quantifying the evidence in favor of the alternative hypothesis? The BF01 is displayed if 'BF10' is 'FALSE'. Only has an effect if an 'observed_t' is passed.

legend_placement

A keyword passed to 'legend' to indicate where the legend has to be placed. Defaults to "topleft". Only has an effect if an 'observed_t' is passed.

legend_content

Specify the content of the legend. legend_content[1] refers to the label for the null hypothesis; legend_content[2] refers to the label for the alternative hypothesis; legend_content[3] refers to the label for the observed effect; (only has an effect if an observed effect size is specified via argument 'observed_t');

...

additional parameters passed to 'curve'

References

Morey, R. D., & Rouder, J. N. (2015). BayesFactor: Computation of Bayes factors for common designs. Retrieved from https://CRAN.R-project.org/package=BayesFactor

Rouder, J. N., Speckman, P. L., Sun, D., Morey, R. D., & Iverson, G. (2009). Bayesian t tests for accepting and rejecting the null hypothesis. Psychonomic Bulletin & Review, 16(2), 225–237.

Examples

## Using the default cauchy prior
visualize_predictions(n1 = 100, n2 = 100, observed_t = 3)
## Using a wide Cauchy prior
visualize_predictions(function(x) dcauchy(x, scale = 1), 
n1 = 100, n2 = 100, observed_t = 3)
## Using a normal prior (M = 0, SD = 0.4)
visualize_predictions(function(x) dnorm(x, 0, 0.4), 
n1 = 100, n2 = 100, observed_t = 3, lty = c(1, 1, 2))


m-Py/bayesEd documentation built on Feb. 25, 2023, 5:35 p.m.