BuildPrior | R Documentation |
BuildPrior
sets up a joint distribution of the prior. Each model
parameter is assigned one probability distribution.
p0
and p1
refer to the first and second parameters.
I use the convention of the 0-based index to work with the C++ and the
Python sister package, 'pydmc' (coming soon). p0
must comes with
parameter names.
BuildPrior(
p0,
p1,
lower = rep(NA, length(p0)),
upper = rep(NA, length(p0)),
dists = rep("norm", length(p0)),
log_p = rep(TRUE, length(p0)),
types = c("tnorm", "beta", "gamma", "lnorm", "cauchy", "unif", "norm")
)
p0 |
the first parameter of a distribution (e.g., mean, shape1, etc.). |
p1 |
the second parameter of a distribution (e.g., sd, shape2, etc.). |
lower |
lower support (boundary). Default is |
upper |
upper support (boundary). Default is |
dists |
a vector of character strings specifying the distribution type
for each parameter. Valid types are: |
log_p |
logical; if |
types |
available distribution types. |
Seven distributions are implemented:
Truncated normal distribution, where: p0 = mean
, p1 = sd
.
When the lower and upper bounds are not provided, they are set
to -Inf
and Inf
, rendering a normal distribution
(see tnorm). Type name is "tnorm"
.
Beta distribution, where: p0 = shape1
and p1 = shape2
(see pbeta). Note the uniform distribution is a special case
of the beta with p0 = 1
and p1 = 1
. Type name is
"beta"
.
Gamma distribution, where p0 = shape
and p1 = scale
(see pgamma). Note p1
is scale, not rate. Type name is
"gamma"
.
Log-normal, where p0 = meanlog
and p1 = sdlog
(see plnorm). Type name is "lnorm"
.
Cauchy distribution, where p0 = location
and p1 = scale
(see pcauchy). Type name is "cauchy"
.
Uniform distribution, where p0 = lower
and p1 = upper
(see punif). Type name is "unif"
.
Normal distribution, where p0 = mean
and p1 = sd
(see pnorm). Type name is "norm"
.
a list of lists, where each sub-list contains the parameter for its prior definition. Each sub-list includes:
p0
: The first parameter of the distribution.
p1
: The second parameter of the distribution.
lower
: The lower bound of the distribution.
upper
: The upper bound of the distribution.
dist
: A numeric code representing the distribution
type.
log_p
: Logical indicating whether probabilities
are logged.
# Using dbeta to represent a uniform distribution of bounds(0, 1)
x <- seq(-.1, 1.1, .001)
plot(x, dbeta(x, 1, 1),
type = "l", ylab = "Density", xlab = "x",
lwd = 2, cex.lab = 1.5, cex.axis = 2
)
## Create an S4 prior object
p_prior <- BuildPrior(
p0 = c(A = 0.15, B = 0.45, mean_v = 2.25, sd_v = 0.15, t0 = 0.2),
p1 = rep(0.1, 5),
lower = rep(NA, 5),
upper = rep(NA, 5),
dist = rep("tnorm", 5),
log_p = rep(NA, 5)
)
print_prior(p_prior)
# Use the beta distribution to create uniform densities
# lower and upper set the bounds. If lower is NA, it will be set to 0.
# If upper is NA, it will be set to 1.
p_prior <- BuildPrior(
p0 = c(A = 1, B = 1, mean_v = 1, sd_v = 1, t0 = 1),
p1 = rep(1, 5),
lower = rep(0, 5),
upper = rep(5, 5),
dist = rep("beta", 5),
log_p = rep(FALSE, 5)
)
p0 <- plot_prior(p_prior, font_size = 3.5, cex = 3.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.