Priors for compositions

opts_chunk$set(message = FALSE, warning=FALSE, fig.width = 5.5)
build = "cran"
if(build=="cran") {
  iter = 3
} else {
  iter = 10

Let's load the necessary packages:


This vignette is designed to illustrate how to build priors for the estimated compositions, $\textbf{p}$. When covariates are included in the design matrix, all elements of $\textbf{p}$ in the Dirichlet regression (both intercepts and slopes or offsets) are assigned $\sim N(0,1)$ priors. This approach is similar to the improper priors used in brms::brm(). These priors may be weakly informative, and the user may wish to change the standard deviation -- which can be done with the prior_sd argument in fit_zoid().

fit <- fit_zoid(data, prior_sd = 2)

Dirichlet priors

A more familiar approach may be to work with Dirichlet priors. We can adjust the standard deviation in our Normal priors to match the Dirichlet. The helper function for this uses optim to minimize the RMSPE between the observed and target values. For example, if we had 8 bins and wanted to find the Dirichlet prior that would correspond to hyperparamters $(\alpha)=1$, we could call the fit_prior function.

sd = fit_prior(n_bins = 8, n_draws = draws, target = 1, iterations=iter)

The sd object is a list that contains (1) the estimated standard deviation, (2) the value of the objective function at convergence, and (3) whether or not convergence occurred (anything other than 0 is problematic). The value of the standard deviation here in sd$sd is 1.200453.

So in this case, a standard deviation of ~ 1.20 yields a prior equivalent to a $\sim Dirichlet(1)$ prior. This new value can then be entered into our model with the prior_sd argument,

fit <- fit_zoid(data, prior_sd = 1.2)

Try the zoid package in your browser

Any scripts or data that you put into this service are public.

zoid documentation built on May 29, 2024, 2 a.m.