stan-dev / stan-dev/rstanarm

Feature: Allow different priors for each predictor, and MVN priors across predictors

Open
#127 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
R
Stars
401
Forks
136
PR merge metrics
No merged PRs in 30d

Description

Summary:

I would like to see more flexibility in the specification of priors

Description:

The current specifications allowed for priors in, e.g., stan_glm(), are overly restrictive. The user can only enter one prior for each of the regression coefficients, and all the priors are assumed independent. I would like to see the ability to:

  1. Specify different priors for each regression coefficient
  2. Specify a prior across multiple regression coefficients, e.g. a multivariate normal prior

Neither of these seem like they would be very difficult to implement, and it would greatly increase the flexibility of prior specification. Here are my suggested solutions:

Enhancement 1: different priors for different regression coefficients

The priors argument of stan_glm() would accept a named list of priors, where each prior is named according to the term that it applies to. For example:

fit <- stan_glm(y ~ x1 + x2, data = dat, priors = list(x1 = normal(0, 1), x2 = student_t(1, 1))

If a single prior is entered for the priors argument, then this prior would be applied to all regression coefficients, ensuring backwards compatibility with the current version of the function. The rest just comes down to parsing the prior inputs. This may be tedious, but certainly not impossible.

Enhancement 2: priors across multiple regression terms

In order to allow for correlated priors, the formula interface would have to allow for matrices to be entered in the regression formula. For example, suppose X is an N x p matrix of predictors for which you want a multivariate normal prior, and Z is a matrix (or vector) for which you want independent priors. The interface would be something like:

fit <- stan_glm(y ~ X + Z, data = dat, priors = list(X = multi_normal(0, D), Z = normal(0,1))

where D is a known covariance matrix. Bonus points if you allow for multi_normal_prec and/or multi_normal_cholesky priors.


Maybe I'm overly optimistic, but neither of these changes seems impossible to implement. The first one, in particular, seems relatively easy. The second one might be more work, but it would be a huge enhancement. It would allow, for example, for autoregressive priors across coefficients, which would make it possible to fit GAMs, allow for functional regression, etc.

If the parsing of the prior information is difficult to do in Stan, one possibility is to do all of it in R itself, and to create the Stan code dynamically, when the user calls stan_glm. The disadvantage of this is that you can't pre-compile the C code, but I think this is a small price to pay for the additional functionality.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the stan_glm() entry point and review how its priors argument and formula interface currently parse regression terms. Define how named per-coefficient priors and multivariate normal priors would be represented, including any Stan code generation implications; done means both requested enhancements work while a single prior remains backward-compatible.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.