Learn R Programming

metaBMA (version 0.3.9)

prior: Prior Distributions

Description

Returns prior density function, e.g., for mean effect size \(d\) and heterogeneity of effect sizes \(\tau\)

Usage

prior(family, param, label = "d", lower = -Inf, upper = Inf)

Arguments

family

a character value defining the distribution family

param

numeric parameters for the distribution

label

parameter label

lower

only for family = "custom": lower bound for prior density

upper

only for family = "custom": upper bound for prior density

Value

an object of the class prior: a density function with the arguments x (parameter values) and log (whether to return density or log-density)

Details

  • "norm": Normal distribution with param = c(mean, sd) (see dnorm)

  • "halfnorm": Half-normal distribution (positive) with param = c(mean, sd) (see dhalfnorm)

  • "truncnorm": Truncated normal distribution with param = c(min, max, mean, sd) (see dtruncnorm)

  • "scaledt": Scaled Student-t with param = c(mean, sigma, nu) (see dst)

  • "halft": Half-normal Student-t with param = c(scale, df) (see dhalft)

  • "cauchy": Cauchy distribution with param = scale (see dcauchy)

  • "halfcauchy": Half-Cauchy distribution (positive) with param = scale (see dhalfcauchy)

  • "triangular": Triangular distribution with param = c(min, peak, max) (see dtriangular)

  • "beta": Beta distribution with param = c(alpha, beta) (see dbeta)

  • "custom": User-specified prior density function defined by param (see examples; the density must be nonnegative and vectorized, but is normalized internally). Integration is performed from (-Inf, Inf), which requires that the function returns zeros (and not NAs) for values not in the support of the distribution.

Examples

Run this code
# NOT RUN {
### Half-Normal Distribution
p1 <- prior("halfnorm", c(mean=0, sd=.3), "d")
p1
p1(c(-1,1,3))
plot(p1, -.1, 1)

### Half-Cauchy Distribution
p2 <- prior("halfcauchy", c(scale=.3))
plot(p2, -.5, 3)

### Custom Prior Distribution
p3 <- prior("custom", function(x) x^2, "d", 0, 1)
plot(p3, -.1, 1.2)
# }

Run the code above in your browser using DataLab