set_user_prior: Set a user-defined prior

View source: R/set_and_check_prior.R

set_user_priorR Documentation

Set a user-defined prior

Description

Constructs a user-defined prior distribution for use as the argument prior in hef or hanova1.

Usage

set_user_prior(
  prior,
  ...,
  model = c("beta_binom", "gamma_pois", "anova1"),
  anova_d = 2
)

Arguments

prior

An R function returning the log of the prior density for of (perhaps a subset of) the hyperparameter vector \phi.

...

Further arguments giving the names and values of any parameters involved in the function prior.

model

A character string. Abbreviated name of the model: "beta_binom" for beta-binomial and "gamma_pois" for gamma-Poisson (see hef), "anova1" for 1-way ANOVA (see hanova1).

anova_d

An integer scalar. Only relevant if model = anova1. If anova_d = 2 then prior must return the log-prior density for the standard deviations (\sigma_\alpha, \sigma) and a normal prior with mean mu0 and standard deviation sigma0 is used for \mu. The values of mu0 = 0 and sigma0 = Inf are set in the call to hanova1, with default values mu0 = 0 and sigma0 = Inf. If anova_d = 3 then prior must return the log-prior density for (\mu, \sigma_\alpha, \sigma).

Details

For details of the hyperparameters in \phi see the Details section of hef for the models beta_binom and gamma_pois and of hanova1 for the model anova1.

Value

A list of class "bang_prior". Will contain the component prior, the user-supplied function to evaluate the log of the prior, and any arguments supplied in ....

See Also

hef for hierarchical exponential family models.

hanova1 for hierarchical one-way analysis of variance (ANOVA).

Examples

# User-defined prior, passing parameters
# (equivalent to prior = "gamma" with hpars = c(1, 0.01, 1, 0.01))
user_prior <- function(x, hpars) {
  return(dexp(x[1], hpars[1], log = TRUE) + dexp(x[2], hpars[2], log = TRUE))
}
user_prior_fn <- set_user_prior(user_prior, hpars = c(0.01, 0.01))

paulnorthrop/bang documentation built on Dec. 11, 2023, 11:10 p.m.