make_prior {makemyprior}R Documentation

Making a prior object

Description

Make a prior object with all necessary information about the prior and model. The object can either be sent to makemyprior_gui or used directly for inference with Stan (inference_stan) or INLA (inference_inla). eval_joint_prior can be used to evaluate the prior.

Usage

make_prior(
  formula,
  data,
  family = "gaussian",
  prior = list(),
  intercept_prior = c(),
  covariate_prior = list()
)

Arguments

formula

A formula object, using the function mc.

data

The data used in the model, as a data.frame or list. All elements must have the same length.

family

A string indicating the likelihood family. gaussian with identity link is the default. binomial with logit link and poisson with log link are also possible.

prior
tree

The tree structure as a string. A split is specified as s1 = (a,b), where (s1) represents a split node and can be any name except names of the input data in data and the reserved (eps), which is used for residuals for a Gaussian likelihood. Short names are recommended. Note that these split names are just used in the initial specification, and will not be used later as they are changed by the function automatically. The child nodes for each split are included in parentheses separated by commas, and each split is separated by semicolons. Singletons are included as (a).

V

A named list with information on the priors on each top node and singleton, i.e., all variances. The names in the list are the top node and singleton names from the tree argument. Syntax is V = list(s1 = list(prior = prior_name, param = parameter_vector)).

w

A named list with information on the priors on each split, i.e., all variance proportions. The names in the list are the split node names from the tree argument, and is specified in the same way as the variance priors in V.

Prior on residuals can be defined using eps in this list in the case of a Gaussian likelihood.

intercept_prior

Parameters for Gaussian prior on intercept, specified as a vector with mean and standard deviation. Default is (0, 1000).

covariate_prior

Parameters for Gaussian prior on coefficients of covariates, specified as named list, each element is a vector with mean and standard deviation. Default is (0, 1000).

Details

See makemyprior_models for details on available priors and likelihoods.

Value

Prior object.

Examples

## Not run: 

vignette("make_prior", package = "makemyprior")

## End(Not run)

p <- 10
m <- 10
n <- m*p

set.seed(1)
data <- list(a = rep(1:p, each = m),
             b = rep(1:m, times = p),
             x = runif(n))
data$y <- data$x + rnorm(p, 0, 0.5)[data$a] +
  rnorm(m, 0, 0.3)[data$b] + rnorm(n, 0, 1)

formula <- y ~ x + mc(a) + mc(b)

prior <- make_prior(formula, data, family = "gaussian",
                    intercept_prior = c(0, 1000),
                    covariate_prior = list(x = c(0, 100)))
prior
plot(prior)


[Package makemyprior version 1.2.1 Index]