Skip to main content
NIHPA Author Manuscripts logoLink to NIHPA Author Manuscripts
. Author manuscript; available in PMC: 2026 Jan 1.
Published in final edited form as: Am Stat. 2024 May 24;79(1):40–49. doi: 10.1080/00031305.2024.2352010

The R2D2 prior for generalized linear mixed models

Eric Yanchenko 1, Howard D Bondell 2, Brian J Reich 3
PMCID: PMC12007809  NIHMSID: NIHMS2003261  PMID: 40256706

Abstract

In Bayesian analysis, the selection of a prior distribution is typically done by considering each parameter in the model. While this can be convenient, in many scenarios it may be desirable to place a prior on a summary measure of the model instead. In this work, we propose a prior on the model fit, as measured by a Bayesian coefficient of determination (R2), which then induces a prior on the individual parameters. We achieve this by placing a beta prior on R2 and then deriving the induced prior on the global variance parameter for generalized linear mixed models. We derive closed-form expressions in many scenarios and present several approximation strategies when an analytic form is not possible and/or to allow for easier computation. In these situations, we suggest approximating the prior by using a generalized beta prime distribution and provide a simple default prior construction scheme. This approach is quite flexible and can be easily implemented in standard Bayesian software. Lastly, we demonstrate the performance of the method on simulated and real-world data, where the method particularly shines in high-dimensional settings, as well as modeling random effects.

Keywords: Bayesian modeling, Coefficient of determination, Generalized beta prime distribution, Goodness-of-fit

1. Introduction

As computing power has increased and become more accessible, Bayesian inference has risen to prominence. Researchers are now free to consider complex models with many parameters. An advantage of the Bayesian approach is that it can incorporate prior domain knowledge about some parameters to reduce uncertainty. In the absence of such information, we might select vague prior distributions, i.e., prior distributions with large variance. This, however, can lead to some unintended consequences such as Lindley’s paradox (Lindley, 1957). Vague prior distributions can also lead to poor estimates when the number of parameters is large relative to the sample size. This has led to the recent development of shrinkage prior distributions (George and McCulloch, 1993; Ročková and George, 2018; Park and Casella, 2008; Hans, 2009; Carvalho et al., 2010; Bhadra et al., 2017; Bhattacharya et al., 2015; Zhang et al., 2022).

Typically, prior distributions are selected for individual parameters based on domain expertise and/or using a general paradigm, e.g., shrinkage priors. There are situations, however, where researchers may have meaningful prior information on the model in general as opposed to specific regression coefficients. For example, consider genetic association studies (e.g., Lewis and Knight, 2012) where scientists search for the genes that contribute to a specific disease. There may be good understanding of how much genes affect the disease, but little information about which genes are relevant. In this case, it may make more sense to pick a prior for the overall model fit that then induces prior distributions on the parameters. There has been some previous work towards this end. Hodges and Sargent (2001) use a flat prior distribution on the degrees of freedom in a Gaussian mixed effects model. Simpson et al. (2017) introduce a paradigm that penalizes the complexity of the model as measured by the Kullback-Liebler (KL) divergence between the null and fitted model. This method places a prior on this KL divergence, thus shrinking the entire model instead of the individual parameters. Fuglstad et al. (2020) present a user-friendly approach to prior construction by utilizing prior beliefs to apportion the overall variance between different random effect components. The authors construct a joint prior distribution which considers the entire model structure. For Gaussian linear regression, Zhang et al. (2022) place a prior on the model fit as measured by the coefficient of determination, R2. The authors first derive a Bayesian R2 and show that the prior R2Beta(a,b) yields a beta prime prior on the total variance of the regression parameters which is then distributed to each individual parameter through a Dirichlet Decomposition. For sparse high-dimensional regression problems, certain R2 prior choices and a Dirichlet decomposition give posterior consistency. This method is advantageous because R2 is an intuitive measure of model fit and it has excellent shrinkage properties.

In this work, we consider a prior on a summary of model fit by proposing a beta prior on Zhang et al. (2022)’s definition of R2 for generalized linear mixed models. This extends Zhang et al. (2022) beyond linear regression to allow for non-Gaussian responses and random effects. We derive closed-form expressions in multiple scenarios for the prior of the global variance parameter that induces a beta prior on R2. We also present several approximation strategies when an analytic prior distribution is not possible. The main approach we suggest approximates the prior by a generalized beta prime (GBP) distribution. This distribution is quite flexible as it can achieve boundedness at the origin as well as a heavy tail (Perez et al., 2017). The scaled beta prime distribution, a special case of the GBP, has also previously been used as a prior for the variance of the regression coefficients (Klein et al., 2021; Bai and Ghosh, 2021). Our method, like Zhang et al. (2022), differs from these previous approaches in that we place a GBP prior on the global variance which is then further decomposed in the hierarchy to the individual regression parameters. Our approach also provides an intuitive way to construct informative prior distributions as well as an automatic approach. The proposed methods can be applied using the r2d2glmm package available on GitHub at https://github.com/eyanchenko/r2d2glmm.

The remainder of the paper proceeds as follows. In Section 2, we describe the generalized linear mixed model framework and present several specific examples. In Section 3, we precisely define a Bayesian R2 and show how the model-level prior induces prior distributions for the individual model prior parameters. We also present the prior distributions for several specific regression models as well as approximation techniques when a closed-form solution cannot be found. Section 4 applies the proposed method to real-world data and Section 5 concludes with recommendations for default use and next steps.

2. Generalized linear mixed models

For notational simplicity, we follow Simpson et al. (2017) and specify our model for a generalized linear mixed model (GLMM), although the ideas presented here can generalize to other settings. For observations i{1,,n}, let Yi be the response, Xi=(Xi1,,Xip) be the explanatory variables and β=(β1,,βp)T be the corresponding fixed effects. We standardize the explanatory variables such that each column of X has mean zero and variance one. We also assume that there are q types of random effects, uk, k{1,,q} where uk=(uk1,,ukLk)T has Lk levels. We let gi=(gi1,,giq)T for i{1,,n} be membership vectors such that gik is the level of random effect k for observation i and where mixed-membership is excluded. The fixed and random effects prior distributions are assumed to be independent and are related to the response via the linear predictor

ηi=β0+Xiβ+k=1qukgik (1)

where β0 is the intercept. The responses are assumed to be conditionally independent given the linear predictor and follow density function Yiηi,θf(yηi,θ), where θ is an additional parameter in the likelihood function (see examples below).

The model for the fixed and random effects is βjϕj,WindepNormal(0,ϕjW) and ukϕp+k,WindepNormal(0,ϕp+kWILk) where W>0 controls the overall variance of the linear predictor (not the response) and ϕj0 satisfy j=1p+qϕj=1 and apportion the variance to the different model components. Thus, W may be interpreted as the total amount of variation in the fixed and random effects, or as a transformation of the total variation of the mean function. In the latter case, the interpretation depends on the link function. Moreover, large values of W encode a model with greater flexibility since large variance in the mean function means that the model can capture more trends in the data. In the limit as W0 conversely, we are reduced to the intercept-only model. This interpretation will be important later in this work when we treat the placement of a large prior mass on W near zero as “penalizing” towards the null (intercept-only) model. Additionally, notice that the fixed and random effects are modeled similarly, i.e., with a random variance. Even so, we maintain their differing interpretations. Specifically, if we are interested in effect estimates themselves, then we treat this effect as “fixed,” but if our interest lies in the underlying population of the effect, then it is treated as “random” (Searle et al., 2009). Following this interpretation, we are most interested in the estimates of β and ϕjW for j=p+1,,p+q .

The prior distribution of R2 relies on the distribution of ηi. For the majority of this work, we assume

ηiβ0,WNormal(β0,W). (2)

We derive this result in the Supplemental Materials whether Xi is treated as fixed or random. If we treat Xi as random, then ηi will be approximately normal for moderate p by the Central Limit Theorem. On the other hand, if we consider ηi conditional on Xi, then the distribution of ηi is exactly normal where the variance is different for each i but the average variance is W due to Xs standardization. For either case, we stress that the prior distribution of ηi is independent of the explanatory variables, resulting in a prior that does not depend on X, similar to the PC prior (Simpson et al., 2017). Alternative distributions are discussed in Sections 3.2.2 - 3.2.3 but the normality of ηi is assumed for all experiments.

2.1. Variance decomposition of the linear predictor

The variance parameters ϕ=(ϕ1,,ϕp+q) determine the relative variance of each component of the model and are restricted to sum to one. These parameters could be fixed, or given prior distributions to add flexibility to the variance decomposition. In the most general case we can assign these parameters a Dirichlet distribution, ϕDirichlet(ξ1,,ξp+q). Often times we will take ξ1==ξp+qξ0. The concentration parameter ξ0>0 controls the variation of the prior distribution with large ξ0 encouraging all the variance components to be roughly equal to 1(p+q), and small ξ0 reflecting prior uncertainty in the variance components. In some cases, the effects will be grouped and the variance across groups will be decomposed using a Dirichlet prior, e.g., all fixed effects assumed to have the same variance. These ideas are illustrated through examples below.

2.2. Examples

To help fix ideas, we present a few specific examples of this prior construction.

Example 1: Gaussian linear regression model:

In the linear regression setting with no random effects, the linear predictor is simply

ηi=β0+Xiβ

and we have Yiηi,σ2Normal(η,σ2) so that θ=σ2 is the error variance. We then take βjϕj,WNormal(0,ϕjW) for j=1,,p . Zhang et al. (2022) study the theoretical properties of this approach for various prior distributions on W and ϕ . In general, this is a global-local shrinkage prior which has been studied in various contexts (e.g., Carvalho et al., 2010; Polson and Scott, 2012; Polson et al., 2012; Bhattacharya et al., 2015; Zhang and Bondell, 2018).

Example 2: Poisson regression with two-way random effects:

For a mixed effects model with two-way (non-interacting) random effects, the linear predictor is

ηi=β0+Xiβ+u1gi1+u2gi2,

and YiηiPoisson{exp(ηi)}. The membership vectors gi1 and gi2 indicate the level assigned to observation i for random effects type one and two, respectively. The variance weights given to the fixed and random effects are determined by the Dirichlet parameter ϕ . For example, to allow each fixed effect to have a different variance, we might take ϕDirichlet(ξ1,,ξp+2) where ξk are fixed hyperparameters; on the other hand, for each fixed effect to have the same variance, we might take ϕDirichlet(ξ1,ξ2,ξ3) and then let βjϕ1,WNormal(0,1pϕ1W) for j=1,,p and ukNormal(0,ϕkWILk) for k=2,3 .

Example 3: Weibull model:

Survival analysis often uses a Weibull model. For simplicity, we consider uncensored data but this could be extended to censored data. Let there be a single random effect so that the linear predictor is

ηi=β0+Xiβ+ugi

for membership vector gi{1.,L}. If Yi is the survival time, then the model is Yiηi,θWeibull(eηi,θ) for shape parameter θ . If we assume that the fixed effects have equal variance, then βϕ1,WNormal(0,1pϕ1WIp) and uϕ2,WNormal(0,ϕ2WIL) where ϕDirichlet(ξ0,ξ0) .

Example 4: Generalized linear regression with spatial random effects:

Consider the scenario where we observe data from L spatial clusters (e.g., cities or villages) at spatial locations s1,,sL2. Then let Yi be the response from location sgi2 where gi{1,,L} is the cluster indicator. Spatial generalized linear models account for correlation between observations at nearby locations by adding spatially-correlated random effects (e.g., Diggle et al., 1998). Let ugi be the Gaussian random effect for cluster gi. The linear predictor is then ηi=β0+Xiβ+ugi. A stationary and isotropic model assumes E(ui)=0 and Var(ui)=σu2 for all i and Cor(ui,uj)=C(dij), where C is a spatial correlation function such as the exponential function C(d)=exp(dρ) and dij is the distance between locations si and sj. The covariance structure of the model is determined by the L×L correlation matrix C with (i,j) element C(dij). The spatial regression model is then in the form of (1) where uϕp+1,W,ρNormal(0,ϕp+1WC) and σu2=ϕp+1W. While the covariance matrix of the random effect is no longer diagonal, the derivation of (2) still holds as the different random effect levels have the same variance and the covariance terms do not appear in the derivation.

Example 5: Generalized additive model:

Non-linear regression models can also be written as (1). Assume that p explanatory variables, xi1,,xip, are allowed to have a non-linear relationship with the response variable. The generalized additive model (e.g., Hastie, 2017; Klein et al., 2021) is

ηi=β0+j=1pfj(xij)

for unknown functions f1,,fp. A common approach is to model the fjs using a basis expansion

fj(x)=l=1LjBjl(x)βl(k)

where Bjl,,BjLj are basis function, e.g., spline functions and β(k) are “grouped” fixed effects. This model then fits (1) with X=(X1,,Xp) where Xjn×Lj is such that (Xj)ik=Bjk(xij), and β=(β(1)T,,β(p)T)T. Then βk(j)Normal(0,1LjϕjW) for j{1,,p} and k{1,,Lj} such that ϕj determines the proportion of the variance allocated to the non-linear effect of xij.

3. Variance Decomposition R2 and the R2D2 prior

Gelman et al. (2019), Gelman and Hill (2006) and Zhang et al. (2022) propose measures of model complexity that we name the Variance Decomposition R2 (VaDeR). For the GLMM in Section 2, define E(Yiηi)=μ(ηi) and Var(Yiηi)=σ2(ηi) which relates the linear predictor to the response distribution. Gelman et al. (2019) use the empirical definition of R2, defined as

Rn2=V{μ(η1),,μ(ηn)X,g,β,u}V{μ(η1),,μ(ηn)X,g,β,u}+M{σ2(η1),,σ2(ηn)X,g,β,u} (3)

where M and V are the sample mean and variance operators, respectively.

In (3), V{μ(η1),,μ(ηn)X,g,β,u} is the variance of the expectation of future data and M{σ2(η1),,σ2(ηn)X,g,β,u} is the expected variance of future residuals, both conditioned on the explanatory variables, membership vectors and fixed and random effects. Because of this conditioning, Gelman et al. (2019) propose Rn2 as an a posteriori measure of model fit. In principle, however, if the values of Xi and gi are known but we had yet to observe the responses Yi, then the prior distributions of the fixed and random effects would induce a prior distribution on Rn2. Then Rn2 is the proportion of variance explained by the model for future data, conditioned on these variables and our prior information for β and uk.

While Rn2 is an intuitive measure of the fit of the model to a particular dataset, for the purpose of setting prior distributions we follow Zhang et al. (2022). We measure complexity at the population level and use the marginal version of R2 that averages over variation in both the explanatory variables and random effect levels (X and g) as well as parameters (β and uk). The marginal distribution does not depend on Xi or gi so the observations are exchangeable. We can then drop the subscript distinguishing them and consider the model for an arbitrary observation Y with E(Yη)=μ(η), Var(Yη)=σ2(η) and ηβ0,WNormal(β0,W) as in (2). Then R2 becomes

R2(β0,W)=Var{μ(η)}Var(Y)=Var{μ(η)}Var{μ(η)}+E{σ2(η)} (4)

where E{σ2(η)} and Var{μ(η)} are summaries of the distribution of η and thus depend on parameters β0 and W. For the sake of simplicity, we suppress the dependence on (β0,W) and write R2(β0,W)=R2 for the remainder of the paper. The Supplemental Materials discusses the relationship between Rn2 and R2 and shows that under general conditions, Rn2 will converge to R2 when both the sample size and number of effective parameters increase. We also include a brief discussion comparing R2 and Rn2 with other measures of model fit for GLMMs (e.g. Cox and Snell, 1989; McFadden, 1973). Moreover, we note that the coefficient of determination is not commonly used for GLMMs as a measure of model fit. This could be for several reasons, not least of which being that it is difficult to define and interpret a principled R2 for logistic regression, poisson regression, etc. A major advantage of R2 and Rn2 is that they can easily be extended to GLMMs, while also having intuitive interpretations.

As denoted in (4), the prior distribution of R2 is determined by the joint prior (β0,W). For Gaussian responses the distribution of R2 is invariant to β0, and so to reduce the problem to matching univariate distributions, we parameterize the prior for (β0,W) as the conditional prior for Wβ0 and marginal prior for β0π0. We then select a prior for Wβ0 so that R2Beta(a,b) . By construction, since R2Beta(a,b) conditioned on any β0, R2 also follows a Beta(a,b) marginally over the joint prior for (β0,W) for any marginal prior π0. Combined with the Dirichlet prior distribution on the variance proportions, this defines the R2 Dirichlet decomposition prior (R2D2).

The Beta(a,b) prior for R2 is our default choice, but in some cases the support of R2 can be restricted to a subspace of [0,1] and a modification is required. Typically, when W=0 we also have Var{μ(η)}=0 and thus R2=0 assuming the distribution of Yη is not degenerate, i.e., σ2(η)>0 . If, however, Var{μ(η)}>0 when W=0, then the lower bound of R2, Rmin2, is strictly greater than zero (e.g. Poisson regression with offsets in Supplemental Material). Conversely, for some link functions, R2<1 for all W (e.g., the zero-inflated Poisson model in Supplemental Materials). In general, the upper bound of R2, Rmax2, is 1 if and only if E{σ2(η)}=o(Var{μ(η)}) as W. In cases where Rmin2>0 and/or Rmax2<1, we use a Beta(a,b) prior distribution for the shifted and scaled R2, denoted R~2=(R2Rmin2)(Rmax2Rmin2). This is equivalent to using a four-parameter beta distribution for the prior where R2Beta(a,b,Rmin2,Rmax2) has density function

π(r2)=(r2Rmin2)a1(Rmax2r2)b1(Rmax2Rmin2)a+b1B(a,b),Rmin2r2Rmax2.

In most cases, Rmin2=0 and Rmax2=1 so unless otherwise noted we simply denote the prior as R2Beta(a,b).

3.1. Special cases with exact expressions

Below we derive the expressions for the prior distribution for W in several special cases where the exact prior distribution is available.

Location-scale models:

The location-scale model is Yi=ηi+σϵi, where the errors ϵi have mean zero and variance one. Then μ(η)=η and σ2(η)=σ2 and thus R2=W(W+σ2) . Assuming R2 follows a Beta(a,b) and σ=1 (or more generally that σ2 appears in the prior variance, βjσ2,ϕj,WNormal(0,σ2ϕjW)), Zhang et al. (2022) show that the induced prior on W is a Beta Prime distribution, denoted WBP(a,b) with density function

π(w)=1B(a,b)wa1(1+w)a+b,w0, (5)

where B(,) denotes the Beta function. In the left panel of Figure 1, we plot π(w) for various values of a and b, and we can see that the BP prior distribution for W has heavier tails when the expected R2 is large (a>b) versus small (a<b).

Figure 1:

Figure 1:

Plot of the prior distribution of W to induce R2Beta(a,b) with β0=0. The title of each panel corresponds to the response model. The normal case takes σ2=1.

For σ21, and not included in the prior variance, i.e., βjϕj,WNormal(0,ϕjW), the induced prior distribution for W is a Generalized Beta Prime (GBP) distribution, Wσ2GBP(a,b,1,σ2). The GBP distribution can be obtained via a transformation of a BP random variable, i.e., if VBP(a,b) then W=dV1cGBP(a,b,c,d) and has density function

π(w;a,b,c,d)=c(wd)ac1(1+(wd)c)abdB(a,b),w0 (6)

for a,b,c,d>0. The GBP reduces to the BP if c=d=1.

We note a few properties of the GBP distribution. The behavior at the origin is controlled by the value of ac, with

limw0π(w;a,b,c,d)={ac<1cB(a,v)dac=1.0ac>1}

The tail behaviour is controlled by bc with valid mean if only if bc>1. Also, for any model with WGBP(a,b,c,d) for the overall variance, then the standard deviation has prior distribution W12GBP(a,b,2c,d12). As another special case of the GBP, if a=12, b=ν2, c=2 and d=νσ2, then W is distributed as a half-t distribution with ν degrees of freedom and scale σ2. Specifically, if WGBP(12,12,1,σ2), then W follows a half-Cauchy distribution with scale σ as in Gelman (2006).

Poisson regression:

The Poisson regression model is YηPoisson(eη) and thus μ(η)=σ2(η)=eη. Since ηβ0,WNormal(β0,W), eηβ0,WLogNormal(β0,W), and thus

R2=eW1eW1+eβ012W. (7)

R2Beta(a,b) induces (see Supplemental Materials) the prior for W with density

π(wβ0;a,b)=1B(a,b)(ew1)a1eb(β0+w2)(3ew1)2(ew1+eβ0w2)a+b,w0. (8)

We plot this distribution in Figure 1 and show that shape of the prior looks very similar to that of the location-scale case. We do note, however, that the prior for W has exponential-decaying tails on the scale of E(Yη)=eη as seen in (8). But, on the scale of log{E(Yη)}=η, which is the same scale as β and u, the prior has polynomial-decaying tails. The value of the prior at 0 is if a<1, beβ0 if a=1 and 0 if a>1.

In the Supplemental Materials, we also include the exact prior distributions for: Poisson with offsets, negative binomial, zero-inflated Poisson, and the Weibull model.

3.2. Approximate Methods

In some cases, e.g., logistic regression, a closed-form expression for VaDeR is not available, so in this section we discuss alternatives.

3.2.1. Linear approximation

The two components we must compute for VaDeR are Var{μ(η)} and E{σ2(η)}. The simplest approach to approximate these is with a linear approximation. Applying a first-order Taylor series approximation of μ(η) and σ2(η) around β0 gives

Var{μ(η)}{μ(β0)}2WandE{σ2(η)}σ2(β0). (9)

Then denoting s2(β0)=σ2(β0){μ(β0)}2 we have

R2WW+s2(β0). (10)

If R2Beta(a,b) , the resulting prior for W is Wβ0GBP(a,b,1,s2(β0)). This result does not require any distributional assumptions about ηi other than a finite mean and variance after transformation by μ() and σ2() . Additionally, the computational burden is essentially zero.

3.2.2. Quasi-Monte Carlo (QMC)

As we will show, in many cases the linear approximation dose a poor job approximation the true R2 distribution. Therefore, we must turn to other methods. Since finding R2 reduces to computing complicated integrals, we can use integral approximation techniques, like quasi-Monte Carlo (QMC; e.g., Morokoff and Caflisch, 1995). In usual Monte Carlo integration, the integral of interest is approximated by summing over a randomly generated sample of points. QMC is similar except that the points are selected deterministically. To construct the R2D2 prior, we approximate

E{μ(η)m}μ~m(Wβ0)=1K1i=1K1μ(β0+ziW)m (11)

and

E{σ2(η)}σ~2(Wβ0)=1K1i=1K1σ2(β0+ziW) (12)

where zi is the iK quantile of a standard normal distribution and m=1,2 . This gives an approximation of R2 for a given β0 and W, which we denote by

R~2(Wβ0)μ~2(Wβ0)μ~12(Wβ0)μ~2(Wβ0)μ~12(Wβ0)+σ~2(Wβ0). (13)

Assuming R2Beta(a,b) , then the prior for W is

π(wβ0;a,b)=1B(a,b){R~2(wβ0)}a1{1R~2(wβ0)}b1dR~2(wβ0)dw,w0. (14)

Since this cannot be represented with elementary operations, in practice, we take a numerical derivative to evaluate the prior at a given value, and the entire calculation is completed virtually immediately.

The results in (11) and (12) make use of the normality of ηi from (2). The QMC procedure can be modified to account for non-normal ηi. Let ηF(ηβ0,W) for distribution function F(ηβ0,W) . Then we approximate

E{μ(η)m}μ~m(Wβ0)=1K1i=1K1μ{qi(β0,W)}m

where qi(β0,W) is the iK quantile of F(ηβ0,W) . A similar result holds for approximating E{σ2(η)} which then leads to an analogous result to (13). In practice, F(ηβ0,W) can be derived analytically if the distribution of Xi is known. A more general strategy is to average over the empirical distribution of X giving a mixture of normal distributions for F(ηβ0,W) .

3.2.3. Generalized beta prime approximation

The GBP distribution provides an exact solution for the location-scale model in Section 3.1, and an approximate solution for the linear approximation in Section 3.2.1. The prior WGBP(a,b,c,d) also induces the exact R2Beta(a,b) prior distribution for any model with link functions Var{μ(η)}=Wc and E{σ2(η)}=dc. The GBP will not give an exact solution in all cases, but it is a flexible four-parameter model which may often provide a reasonable approximation. Therefore, a general approximation strategy is to find the values of (a,b,c,d) so that the prior WGBP(a,b,c,d) gives an approximate Beta(a,b) distribution for R2.

The optimal values of (a,b,c,d) depend on μ() and σ2() as well as β0, a and b. For given link functions and parameters, let Wπ(w) be the distribution that gives exactly R2Beta(a,b) . The GBP parameters are then set to minimize the Pearson χ2-divergence (Rényi, 1961) between the true and approximated PDFs since this metric enforces a close fit at both the origin and in the tails. We found that minimizing this quantity alone, however, led to unstable solutions, i.e., the surface being maximized over is “flat.” This means that vastly different values of (a,b,c,d) may lead to GBP distributions that yield roughly the same approximation of π(w). Thus, we also add a regularization term to shrink the prior towards a GBP(a,b,1,1) distribution. We regularize toward this distribution because it gives the exact solution in the location-scale case and can be considered the baseline distribution. This results in the following optimization problem:

(a,b,c,d)=argminα,β,c,d0{fGBP(w;α,β,c,d)π(w)π(w)}2π(w)dw+λ{(αa)2+(βb)2+(c1)2+(d1)2}, (15)

where λ>0 is a tuning parameter. A larger value of λ yields a more stable solution but with a worse fit whereas a smaller value of λ yields a better fit but with more instability. We found that λ=14 gives a good balance between fit and stability. In practice, the integral is approximated by a sum and π(w) is approximated using QMC as in Section 3.2.2, if necessary. Since the GBP approximation may depend on the QMC procedure which can be modified to allow for non-normality in η, the GBP approach can similarly be adapted to allow for any distribution of η.

A major advantage of the GBP prior is that it can be easily implemented in standard Bayesian software such as JAGS (Plummer et al., 2016) or Stan (Carpenter et al., 2017). Because the exact prior distributions found in Section 3.1, as well as the resulting distributions from the QMC procedure in Section 3.2.2 do not easily allow for Gibbs sampling, these priors would be difficult for a practitioner to implement. By finding the GBP approximation, however, the R2D2 prior can be easily coded in JAGS and Stan. Example code is available as a vignette in our R package on GitHub. To specify the prior in these packages, we use the relationship that if R2Beta(a,b) and W=d{R2(1R2)}1c, then WGBP(a,b,c,d) . Because of these features, we recommend this method for general use even in cases when the exact expression is available, and will be the method we consider in the simulation studies.

Since the GBP approximation depends on β0 (and θ), this approximation should be updated with the unknown parameter β0. The calculation in (15) takes about half a second, however, so this would be overly time prohibitive to compute during every MCMC iteration. Instead, we find the GBP approximation once at the beginning of the analysis at β^0=g(i=1nYin) for link function g() . Thus, to induce R2Beta(a,b) , the first step is to find (a,b,c,d) as in (15) at β^0 (and θ^MLE, if necessary, the maximum likelihood estimate of the dispersion parameter). After determining (a,b,c,d), β0 (and θ) are treated as unknown parameters in the subsequent Bayesian analysis. In the Supplemental Materials, we report the GBP approximations for various values of (a,b) and different models. In most cases, the best fitting a and b values are not close to (a,b) which demonstrates the need for this approximation.

Figure 2 compares the linear and GBP approximations with the true distribution for the Poisson model (Section 3.1). The GBP is nearly a perfect match to the true distribution for each prior. The linear approximation is reasonable when a=1,b=4, but very poor when a=4,b=1. This example shows that the GBP is a very good approximation to the true prior distribution of W.

Figure 2:

Figure 2:

Comparison of different approximation methods for the Poisson regression model with β0=0. The title of each pane indicates the induced prior distribution on R2.

In the Supplemental Materials, we conduct a simulation study to compare the R2D2 prior with a standard vague prior, the Horseshoe prior (Carvalho et al., 2009), and the PC prior (Simpson et al., 2017) while also comparing different combinations of (a,b) . The proposed method performs favorably across all settings and particularly well in the high-dimensional regression setting. Indeed, we empirically find that prior distributions with large prior mass near R2=0 yield good shrinkage properties.

4. Real data analysis

The proposed method is now applied to two real-world data sets. The first analysis is focused on inference, while the second looks at prediction in the high-dimensional setting.

4.1. Malaria data

We now analyze the gambia data set (Thomson et al., 1999) from the geoR package (Ribeiro Jr et al., 2007) in R to demonstrate the use of the R2D2 prior in practice. We also consider PC and vague prior distributions. There are n=2035 children in this data set with binary response variable Yi which equals 1 if child i tested positive for malaria and 0 otherwise. There are p=5 explanatory variables including age, indicator of using a bed net, indicator of whether the bed net is treated, “greenness” of village and indicator of a health center in the area. These variables are standardized to have mean zero and variance one. There are also the L=65 villages where each child lived, along with the spatial location of each village.

We model the village effect as a spatial random effect. As in Example 4 from Section 2.2, the linear predictor is

logit{P(Yi=1ηi)}=ηi=β0+Xiβ+ugi (16)

where gi{1,,L} is the village of response i. We also assume that E(ui)=0 and Var(ui)=σu2 for all i and exponential spatial correlation Cij=Cor(ui,uj)=edijρ where dij is the distance between village i and j and ρ>0 is the spatial range parameter. Then the full prior specification for R2D2 is

β0Normal(μ0,τ02),βϕ1,WNormal(0,15ϕ1WI5),uϕ2,W,ρNormal(0,ϕ2WC),ρUniform(0,2r),WGBP(a,b,c,d),ϕDirichlet(ξ1,ξ2) (17)

for hyper-parameters set to μ0=0, τ02=3, ξ1=ξ2=1 and r is the maximum distance between pairs of villages. Note that σu2=ϕ2W in this model. We find β^0=0.59 and (a,b,c,d) are in Table 1 and the resulting prior distributions are plotted in Figure 3.

Table 1:

Generalized Beta Prime approximation parameters for Gambia data with β^0=0.59.

a b a b c d
1 4 1.15 2.08 0.91 2.09
0.5 0.5 0.57 0.29 0.90 1.54
1 1 1.47 0.65 0.79 1.67
4 4 7.45 2.72 0.73 1.63
4 1 7.77 0.71 0.68 1.45

Figure 3:

Figure 3:

Prior R2 and global variance parameter for R2D2 prior for Gambia data

For PC prior, the full prior specification is

β0Normal(μ0,τ02),βNormal(0,τ12I5),uσu2Normal(0,σu2C),ρUniform(0,2r),σuExp(λ0). (18)

where μ0=0,τ02=3,τ12=100 and λ0=log(0.01).968 . The vague prior has the same form as the PC prior except σu2InvGamma(0.5,0.0005) (Spiegelhalter et al., 2003).

We take 105,000 MCMC samples with the first 5,000 discarded as burn-in, where the analysis is performed in JAGS. The results are in Figure 4 and Table 2. We also present trace plots in the Supplemental Materials to check convergence of the MCMC chain, as well as the effective sample size and computation time. We can see that the posterior distributions of Rn2 are very similar across the different methods. The posterior of W, however, varies across the different R2D2 priors with the Beta(4,1) and Beta(4,4) having the greatest mean and Beta(0.5,0.5) and Beta(1,1) having the smallest mean. The posterior distributions of W and σu2 are almost identical for the R2D2 priors which means that the vast majority of the global variance mass is shifted on the random effect variance and away from the fixed effect variance. The posterior for σu2 has the smallest mean for the PC prior, which follows from the fact that this prior shrinks the spatial variance toward zero. Lastly, the posterior of ρ varies across the different priors with the PC prior also yielding the smallest posterior mean.

Figure 4:

Figure 4:

Posterior R2, global variance and random effect variance and ρ for vague (uninformative) prior distributions, PC and R2D2 for Gambia data with village spatial random effect.

Table 2:

Posterior mean and standard deviation for Rn2, global variance (W), random effect variance (σu2) and spatial range (ρ) for each method for Gambia data considering spatial random effect.

R2 W σu2 ρ
Method Mean St. Dev Mean St. Dev Mean St. Dev Mean St. Dev
Vague 0.176 0.016 2.389 1.397 0.851 0.500
PC 0.173 0.016 1.210 0.515 0.427 0.270
R2Beta(12,12) 0.171 0.015 1.538 0.827 1.511 0.824 0.549 0.388
R2Beta(1,1) 0.173 0.016 2.023 1.148 1.992 1.143 0.722 0.465
R2Beta(1,4) 0.171 0.016 1.540 0.796 1.513 0.792 0.556 0.382
R2Beta(4,1) 0.175 0.016 2.813 1.412 2.780 1.409 0.977 0.488
R2Beta(4,4) 0.174 0.016 2.675 1.237 2.637 1.227 0.981 0.479

4.2. Genomics data

For our second data analysis, we apply the proposed method to high-dimensional genomics data from human breast tumors (Perou et al., 2000) in the mixOmics R package (Rohart et al., 2017). This data was pre-processed in Pérez-Enciso and Tenenhaus (2003) such that the response, Yi, is 1 if tumor specimen i was analyzed before chemotherapy treatment, and 0 if it was analyzed after chemotherapy, for sample i{1,,n} where n=47. There are p=1000 gene expressions as predictor variables, so pn, and we imputed the appropriate column mean of X for any missing values. We consider the R2D2 prior with (a,b){(1,5),(1,10),(1,20),(1,30)}, and compare with the Horseshoe prior. We choose these hyper-parameter combinations because we hypothesize that prior distributions with large mass near R2=0 are useful in high-dimensional contexts.

Since our focus of this analysis is prediction, we randomly split the data into train and test sets, where 75% of the data is used for training, and 25% for testing. The model is fit on the training data, and we compute the Brier Score (BS) and binary cross entropy (BCE) loss on the hold-out test data. If Yi is the true response, and Y^i is the predicted response, then BS=1ni=1n(Y^iYi)2 and BCE=1ni=1n{YilogY^i+(1Yi)log(1Y^i)}. We compute Y^i=[1+exp{(β^0+Xiβ)}]1 where β^0 and β are the posterior means of β0 and β , respectively, and Xi are the predictor variables for the ith test data. The splitting procedure is repeated 50 times and we find the average of each metric. A good method will have small BS and BCE. The analysis was performed in Stan where we computed 10,000 MCMC samples with an additional 1000 for burn-in.

The results are in Table 3. In the Supplemental Materials, we also report the computation time, and average effective sample size for β and the global variance parameter. We can see that the R2D2 prior with (a,b)=(1,20) and Horseshoe perform the best, with smallest BCE and BS, respectively. Indeed, there is a clear trend that the R2D2 priors with more mass near R2=0 yield better predictions. However, there appears to be diminishing returns beyond R2Beta(1,10) .

Table 3:

Prediction results for genomics data with standard error in parentheses. BS is Brier Score, and BCE is the binary cross entropy loss. Best results are labeled in bold.

Method BS BCE
Horseshoe 0.23 (0.01) 0.79 (0.07)
R2Beta(1,5) 0.29 (0.01) 0.89 (0.06)
R2Beta(1,10) 0.26 (0.00) 0.71 (0.01)
R2Beta(1,20) 0.26 (0.00) 0.70 (0.01)
R2Beta(1,30) 0.26 (0.00) 0.71 (0.01)

5. Discussion

In this work, we proposed a novel method for choosing informative prior distributions in the generalized linear mixed model setting. The proposed prior is flexible and interpretable in terms of overall model fit as measured by a Bayesian R2. There are many cases where the prior R2 can be induced exactly as well as general approximation strategies when an exact form is not possible. The main approach that we suggest is approximating the global variance prior with a generalized beta prime distribution because of its flexibility and ability to be implemented in standard software. Combined with an initial estimate of the intercept via a method of moments estimator and the GBP approximation in the r2d2glmm package, we provide a simple and intuitive method for setting prior distributions in GLMMs.

If there is domain knowledge available on how well the model is expected to fit the data, then this could be used to inform prior choice for R2. In the absence of any prior information, we suggest R2Beta(1,1) as a reasonable default choice. This prior expresses a full range of model fits, but should not be confused with a flat prior for β . Choosing R2Beta(1,b) for large b, or another prior with large mass near 0, is also a good choice, especially when working in a high-dimensional setting. Indeed, substantial prior mass near R2=0 prevents the model from overfitting by shrinking towards the “base model” of β=0p.

The proposed approach naturally fits within the global-local shrinkage prior framework where W controls the global shrinkage, and ϕj the local shrinkage. Our approach does differ from, e.g., Hamura et al. (2022), who studies shrinkage priors for count data. Using the notation of our paper, Hamura et al. (2022) let YiλiPoisson(λieηi) where λiGamma(α,βνi), νiπ(), and ηi is some offset which may depend on covariates, i.e., ηi=β0+Xiβ. This paper is primarily interested in the prior distribution for the local component (νi) and estimating the rate parameter (λi). The R2D2 prior, on the other hand, is derived for the global component (W), and is focused on estimating the regression components (ηi).

A limitation of the proposed method is that the hierarchical framework only allows for random intercepts and not, for example, random slopes. Additionally, the finite mean and variance requirement precludes applications to some models, e.g., extreme value analysis (Coles et al., 2001). We have also not proven concentration or shrinkage properties which is an avenue for future work. We could also extend the method to allow for other survival analysis settings beyond the uncensored Weibull model and models that are not GLMMs such as Bayesian deep learning. Finally, at present, the method cannot easily be written in INLA (Lindgren and Rue, 2015), so we consider this an important next step.

Supplementary Material

Supp 1

Acknowledgements

The authors thank Brandon Feng for help with the derivation of the Weibull model. We also thank the National Institutes of Health (R01ES031651-01) and King Abdullah University of Science and Technology (3800.2) for financial support.

Footnotes

Supplemental Materials

In the Supplemental Materials, we provide: further discussion and comparison of the different coefficient of determination definitions, additional models and derivations for priors with closed-form expressions, a table showing different values of (a,b,c,d) for the GBP approximation, a simulation study, and additional results for the real-data analysis.

Disclosures

The authors report there are no competing interests to declare.

References

  1. Bai R and Ghosh M (2021). On the beta prime prior for scale parameters in high-dimensional bayesian regression models. Statistica Sinica 31(3), 1–23. [Google Scholar]
  2. Bhadra A, Datta J, Poison NG, and Willard B (2017). The horseshoe+ estimator of ultra-sparse signals. Bayesian Analysis 12(4), 1105–1131. [Google Scholar]
  3. Bhattacharya A, Pati D, Pillai NS, and Dunson DB (2015). Dirichlet-Laplace priors for optimal shrinkage. Journal of the American Statistical Association 110(512), 1479–1490. [DOI] [PMC free article] [PubMed] [Google Scholar]
  4. Carpenter B, Gelman A, Hoffman MD, Lee D, Goodrich B, Betancourt M, Brubaker M, Guo J, Li P, and Riddell A (2017). Stan: A probabilistic programming language. Journal of Statistical Software 76(1), 1–32. [DOI] [PMC free article] [PubMed] [Google Scholar]
  5. Carvalho CM, Poison NG, and Scott JG (2009). Handling sparsity via the horseshoe. In Artificial Intelligence and Statistics, pp. 73–80. PMLR. [Google Scholar]
  6. Carvalho CM, Polson NG, and Scott JG (2010, 04). The horseshoe estimator for sparse signals. Biometrika 97(2), 465–480. [Google Scholar]
  7. Coles S, Bawa J, Trenner L, and Dorazio P (2001). An introduction to statistical modeling of extreme values, Volume 208. Springer. [Google Scholar]
  8. Cox DR and Snell EJ (1989). Analysis of binary data. Chapman & Hall. [Google Scholar]
  9. Diggle PJ, Tawn JA, and Moyeed RA (1998). Model-based geostatistics. Journal of the Royal Statistical Society: Series C (Applied Statistics) 47(3), 299–350. [Google Scholar]
  10. Fuglstad G-A, Hem IG, Knight A, Rue H, and Riebler A (2020). Intuitive joint priors for variance parameters. Bayesian Analysis. [Google Scholar]
  11. Gelman A. (2006). Prior distributions for variance parameters in hierarchical models (comment on article by Browne and Draper). Bayesian Analysis 1(3), 515–534. [Google Scholar]
  12. Gelman A, Goodrich B, Gabry J, and Vehtari A (2019). R-squared for Bayesian regression models. The American Statistician 73(3), 307–309. [Google Scholar]
  13. Gelman A and Hill J (2006). Data analysis using regression and multilevel/hierarchical models. Cambridge University Press. [Google Scholar]
  14. George EI and McCulloch RE (1993). Variable selection via Gibbs sampling. Journal of the American Statistical Association 88(423), 881–889. [Google Scholar]
  15. Hamura Y, Irie K, and Sugasawa S (2022). On global-local shrinkage priors for count data. Bayesian Analysis 17(2), 545–564. [Google Scholar]
  16. Hans C. (2009). Bayesian lasso regression. Biometrika 96(4), 835–845. [Google Scholar]
  17. Hastie TJ (2017). Generalized Additive Models. Routledge. [Google Scholar]
  18. Hodges JS and Sargent DJ (2001). Counting degrees of freedom in hierarchical and other richly-parameterised models. Biometrika 88(2), 367–379. [Google Scholar]
  19. Klein N, Carlan M, Kneib T, Lang S, and Wagner H (2021). Bayesian effect selection in structured additive distributional regression models. Bayesian Analysis 16(2), 545–573. [Google Scholar]
  20. Lewis CM and Knight J (2012). Introduction to genetic association studies. Cold Spring Harbor Protocols 2012(3), pdb–top068163. [DOI] [PubMed] [Google Scholar]
  21. Lindgren F and Rue H (2015). Bayesian spatial modelling with R-INLA. Journal of statistical software 63(19). [Google Scholar]
  22. Lindley DV (1957). A statistical paradox. Biometrika 44(1/2), 187–192. [Google Scholar]
  23. McFadden D. (1973). Conditional logit analysis of qualitative choice behavior. [Google Scholar]
  24. Morokoff WJ and Caflisch RE (1995). Quasi-Monte Carlo integration. Journal of Computational Physics 122(2), 218–230. [Google Scholar]
  25. Park T and Casella G (2008). The Bayesian lasso. Journal of the American Statistical Association 103(482), 681–686. [Google Scholar]
  26. Perez M-E, Pericchi L, and Ramirez I (2017, 09). The scaled Beta2 distribution as a robust prior for scales. Bayesian Analysis 12, 615–637. [Google Scholar]
  27. Pérez-Enciso M and Tenenhaus M (2003). Prediction of clinical outcome with microarray data: a partial least squares discriminant analysis (pls-da) approach. Human genetics 112, 581–592. [DOI] [PubMed] [Google Scholar]
  28. Perou CM, Sørlie T, Eisen MB, Van De Rijn M, Jeffrey SS, Rees CA, Pollack JR, Ross DT, Johnsen H, Akslen LA, et al. (2000). Molecular portraits of human breast tumours. nature 406(6797), 747–752. [DOI] [PubMed] [Google Scholar]
  29. Plummer M, Stukalov A, Denwood M, and Plummer MM (2016). Package ‘rjags’ Vienna, Austria. [Google Scholar]
  30. Polson NG and Scott JG (2012). On the Half-Cauchy Prior for a Global Scale Parameter. Bayesian Analysis 7(4), 887–902. [Google Scholar]
  31. Polson NG, Scott JG, Clarke BS, and Severinski C (2012). Shrink globally, act locally Sparse bayesian regularization and prediction. [Google Scholar]
  32. Rényi A. (1961). On measures of entropy and information. In Proceedings of the Fourth Berkeley Symposium on Mathematical Statistics and Probability, Volume 1: Contributions to the Theory of Statistics, pp. 547–561. University of California Press. [Google Scholar]
  33. Ribeiro PJ Jr, Diggle PJ, Ribeiro MPJ Jr, and Suggests M (2007). The geoR package. R news 1(2), 14–18. [Google Scholar]
  34. Ročková V and George EI (2018). The spike-and-slab lasso. Journal of the American Statistical Association 113(521), 431–444. [Google Scholar]
  35. Rohart F, Gautier B, Singh A, and Lê Cao K-A (2017). mixomics: An r package for ‘omics feature selection and multiple data integration. PLoS computational biology 13(11), e1005752. [DOI] [PMC free article] [PubMed] [Google Scholar]
  36. Searle SR, Casella G, and McCulloch CE (2009). Variance Components. John Wiley & Sons. [Google Scholar]
  37. Simpson D, Rue H, Riebler A, Martins TG, Sørbye SH, et al. (2017). Penalising model component complexity: A principled, practical approach to constructing priors. Statistical science 32(1), 1–28. [Google Scholar]
  38. Spiegelhalter D, Thomas A, Best N, and Lunn D (2003). Winbugs user manual. [Google Scholar]
  39. Thomson MC, Connor SJ, D’Alessandro U, Rowlingson B, Diggle P, Cresswell M, and Greenwood B (1999). Predicting malaria infection in gambian children from satellite data and bed net use surveys: the importance of spatial correlation in the interpretation of results. The American Journal of Tropical Medicine and Hygiene 61(1), 2–8. [DOI] [PubMed] [Google Scholar]
  40. Zhang Y and Bondell HD (2018). Variable Selection via Penalized Credible Regions with Dirichlet-Laplace Global-Local Shrinkage Priors. Bayesian Analysis 13(3), 823–844. [Google Scholar]
  41. Zhang YD, Naughton BP, Bondell HD, and Reich BJ (2022). Bayesian regression using a prior on the model fit: The r2-d2 shrinkage prior. Journal of the American Statistical Association 117(538), 862–874. [Google Scholar]

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Supplementary Materials

Supp 1

RESOURCES