Learn R Programming

see (version 0.2.1)

data_plot: Prepare objects for plotting or plot objects

Description

data_plot() attempts to extract and tranform an object to be further plotted, while plot() tries to visualize results of functions from different packages of the easystats-project.

Usage

data_plot(x, data = NULL, ...)

# S3 method for see_bayesfactor_models plot(x, n_pies = c("one", "many"), value = c("none", "BF", "probability"), log = FALSE, prior_odds = NULL, ...)

# S3 method for see_bayesfactor_parameters plot(x, point_size = 2, rope_color = "#0171D3", rope_alpha = 0.2, show_intercept = FALSE, ...)

# S3 method for see_check_distribution plot(x, point_size = 2, panel = TRUE, ...)

# S3 method for see_check_normality plot(x, type = c("density", "qq", "pp"), data = NULL, ...)

# S3 method for see_check_outliers plot(x, text_size = 3.5, ...)

# S3 method for see_equivalence_test plot(x, rope_color = "#0171D3", rope_alpha = 0.2, show_intercept = FALSE, ...)

# S3 method for see_estimate_density plot(x, stack = TRUE, show_intercept = FALSE, ...)

# S3 method for see_parameters_model plot(x, show_intercept = FALSE, dot_size = 0.8, ...)

# S3 method for see_parameters_sem plot(x, data = NULL, type = c("regression", "correlation", "loading"), threshold_coefficient = NULL, threshold_p = NULL, ci = TRUE, ...)

# S3 method for see_point_estimate plot(x, data = NULL, point_size = 2, text_size = 3.5, panel = TRUE, show_labels = TRUE, show_intercept = FALSE, ...)

# S3 method for see_rope plot(x, data = NULL, rope_alpha = 0.5, rope_color = "cadetblue", show_intercept = FALSE, ...)

Arguments

x

An object.

data

The original data used to create this object. Can be a statistical model or such.

...

Arguments passed to or from other methods.

n_pies

Number of pies.

value

What value to display.

log

Show log-transformed Bayes factors.

prior_odds

optional vector of prior odds for the models. See BayesFactor::priorOdds. As the size of the pizza slices corresponds to posterior probability (which is a function of prior probability and the BF), custom prior_odds will change the slices' size.

point_size

Size of point-geoms.

rope_color

Color of ROPE ribbon.

rope_alpha

Transparency level of ROPE ribbon.

show_intercept

Logical, if TRUE, the intercept-parameter is included in the plot. By default, it is hidden because in many cases the intercept-parameter has a posterior distribution on a very different location, so density curves of posterior distributions for other parameters are hardly visible.

panel

Logical, if TRUE, plots are arranged as panels; else, single plots are returned.

type

Character vector, indicating the type of plot (for check_normality or parameters::model_parameters.lavaan).

text_size

Size of text labels.

stack

Logical, if TRUE, densities are plotted as stacked lines. Else, densities are plotted for each parameter among each other.

dot_size

Size of point geoms.

threshold_coefficient

Numeric, threshold at which value coefficients will be displayed.

threshold_p

Numeric, threshold at which value p-values will be displayed.

ci

Logical, whether confidence intervals should be added to the plot.

show_labels

Logical, if TRUE, the text labels for the point estimates (i.e. "Mean", "Median" and/or "MAP") are shown. You may set show_labels = FALSE in case of overlapping labels, and add your own legend or footnote to the plot.

Details

data_plot() is in most situation not needed when the purpose is plotting, since most plot()-functions in see internally call data_plot() to prepare the data for plotting.

Many plot()-functions have a data-argument that is needed when the data or model for plotting can't be retrieved via data_plot(). In such cases, plot() gives an error and asks for providing data or models.

Most plot()-functions work out-of-the-box, i.e. you don't need to do much more than calling plot(<object>) (see 'Examples'). Some plot-functions allow to specify arguments to modify the transparancy or color of geoms, these are shown in the 'Usage' section.

Plot-functions are available for objects from following functions (note that functions from packages might be listed here that are currently still in development and probably not yet available):

  • bayestestR::bayesfactor_models()

  • bayestestR::bayesfactor_parameters()

  • bayestestR::bayesfactor_savagedickey()

  • bayestestR::ci()

  • bayestestR::equivalence_test()

  • bayestestR::estimate_density()

  • bayestestR::eti()

  • bayestestR::hdi()

  • bayestestR::map_estimate()

  • bayestestR::p_direction()

  • bayestestR::point_estimate()

  • bayestestR::rope()

  • estimate::estimate_contrasts()

  • parameters::model_parameters()

  • performance::binned_residuals()

  • performance::check_collinearity()

  • performance::check_distribution()

  • performance::check_heteroscedasticity()

  • performance::check_homogeneity()

  • performance::check_model()

  • performance::check_normality()

  • performance::check_outliers()

  • performance::performance_roc()

See Also

Package-Vignettes

Examples

Run this code
# NOT RUN {
library(bayestestR)
library(rstanarm)

model <- stan_glm(
  Sepal.Length ~ Petal.Width * Species,
  data = iris,
  chains = 2, iter = 200
)

x <- rope(model)
plot(x)

x <- hdi(model)
plot(x) + theme_modern()

data <- rnorm(1000, 1)
x <- p_direction(data)
plot(x)

x <- p_direction(model)
plot(x)

model <- stan_glm(
  mpg ~ wt + gear + cyl + disp,
  chains = 2,
  iter = 200,
  data = mtcars
)
x <- equivalence_test(model)
plot(x)
# }
# NOT RUN {
library(bayestestR)
library(see)

lm0 <- lm(qsec ~ 1, data = mtcars)
lm1 <- lm(qsec ~ drat, data = mtcars)
lm2 <- lm(qsec ~ wt, data = mtcars)
lm3 <- lm(qsec ~ drat + wt, data = mtcars)

result <- bayesfactor_models(lm1, lm2, lm3, denominator = lm0)

plot(result, n_pies = "one", value = "probability") + theme_modern() +
  scale_fill_pizza(reverse = TRUE)

# }

Run the code above in your browser using DataLab