Learn R Programming

psborrow2 (version 0.0.4.0)

plot: Plot Prior Objects

Description

Plot prior distributions as densities. Continuous distributions are plotted as curves and discrete distributions as bar plots.

Usage

# S4 method for Prior,missing
plot(
  x,
  y,
  default_limits,
  dist_type = c("continuous", "discrete"),
  density_fun,
  add,
  ...
)

# S4 method for PriorNormal,missing plot(x, y, add = FALSE, ...)

# S4 method for PriorExponential,missing plot(x, y, add = FALSE, ...)

# S4 method for PriorHalfCauchy,missing plot(x, y, add = FALSE, ...)

# S4 method for PriorBernoulli,missing plot(x, y, add = FALSE, ...)

# S4 method for PriorBeta,missing plot(x, y, add = FALSE, ...)

# S4 method for PriorCauchy,missing plot(x, y, add = FALSE, ...)

# S4 method for PriorGamma,missing plot(x, y, add = FALSE, ...)

# S4 method for PriorHalfNormal,missing plot(x, y, add = FALSE, ...)

# S4 method for PriorPoisson,missing plot(x, y, add = FALSE, ...)

# S4 method for UniformPrior,missing plot(x, y, add = FALSE, ...)

Value

No return value, this function generates a plot in the current graphics device.

Arguments

x

Object inheriting from Prior

y

Not used.

default_limits

Numeric range to plot distribution over.

dist_type

Plot a continuous or discrete distribution.

density_fun

Function which takes a vector of values and returns a vector of density values.

add

logical. Add density to existing plot.

...

Optional arguments for plotting.

Details

Plot ranges are selected by default to show 99% of the density for unbounded distributions. The limits can be changed by specifying xlim = c(lower, upper).

Colors, line types, and other typical par() parameters can be used.

Examples

Run this code
plot(prior_normal(1, 2))
plot(prior_exponential(0.1))
plot(prior_half_cauchy(0, 1), xlim = c(-20, 20))
plot(prior_half_cauchy(0, 2), xlim = c(-20, 20), col = 2, add = TRUE)
plot(prior_bernoulli(0.4), xlim = c(0, 15))
plot(prior_beta(2, 2))
plot(prior_cauchy(0, 1), xlim = c(-20, 20))
plot(prior_cauchy(0, 2), xlim = c(-20, 20), col = 2, add = TRUE)
plot(prior_gamma(0.1, 0.1))
plot(prior_half_normal(0, 1), xlim = c(-20, 20))
plot(prior_half_normal(0, 2), xlim = c(-20, 20), col = 2, add = TRUE)
plot(prior_poisson(5), xlim = c(0, 15))
plot(uniform_prior(1, 2), xlim = c(0, 3))

Run the code above in your browser using DataLab