Aggregating Average Treatment Effects with Baggr

Rachael Meager, Witold Wiecek

2019-07-29

This vignette is - like the package itself - still under construction. We encourage your feedback.

baggr (pronounced “bagger” or “badger” and short for Bayesian Aggregator) is a package for aggregating evidence on causal effects measured in several separate and different instances. These instances may be different studies, groups, locations or “sites” however conceptualised. We refer to these separate pieces of evidence as “groups” for the remainder of this vignette When each group is a study, the model is that of meta-analysis, but aggregation of evidence is not limited to this case.

One of the most basic objects of interest is the average treatment effect, the difference in the mean outcome in treatment and control groups; for more information see work by Rubin (1974). In meta-analysis we are often interested in the average of this average effect across groups, estimated using all the evidence from all the groups. Consider the case where the evidence in each study or group is generated by comparing the outcomes of treatment and control samples in a randomized experiment. We will ignore any covariate information at the individual or group level for now.

Consider some outcome of interest \(y_{ik}\) such as consumption, income or health outcomes for a household or individual \(i = 1,2,...N_k\) in study group \(k = 1,2....K\). Let \(Y_k\) denote the \(N_k\)-length vector of observed outcomes from group \(k\). Denote the binary indicator of treatment status by \(T_{ik}\), and denote by \(T_k\) the \(N_k\)-length vector of all treatment status indicators from group \(k\).

Suppose that \(y_{ik}\) varies randomly around its mean \(\mu_k + \tau_k T_i\). In this setting \(\tau_k\) is the treatment effect in group \(k\). The random variation in \(y_{ik}\) may be the result of sampling variation or measurement error, as in the Rubin (1981) model, or it may be the result of unmodelled heterogeneity or uncertainty in outcomes for individuals within the group. Allow the variance of the outcome variable \(y_{ik}\) to vary across sites, so \(\sigma_{y_k}^2\) may differ across \(k\).

Data inputs: reported effects or full individual-level data sets

For average effects aggregation, baggr allows 3 types of data inputs. The user may supply, within a data frame environment, any of the following:

  1. A set of estimated treatment effects \(\{\hat{\tau_k}\}_{k=1}^{K}\) and their standard errors \(\{\hat{se_k}\}_{k=1}^{K}\) from each study. This should be formatted as two column vectors of length \(K\) within the data frame, where \(\hat{\tau_k}\) is the \(k\)-th entry of the treatment effect vector and \(\hat{se_k}\) is the \(k\)-th entry of the standard errors vector. Columns should be names “tau” and “se”.

  2. A set of control group means and estimated treatment effects \(\{\hat{\mu_k},\hat{\tau_k}\}_{k=1}^{K}\), as well as the standard errors for both \(\{\hat{se}_{\mu k}, \hat{se}_{\tau k}\}_{k=1}^{K}\), for each study site This should be formatted as four vectors of length \(K\) within the data frame, analogous to the above. Columns should be names “mu”, “tau”, “se.mu”, “se.tau”.

  3. The full data sets from all the original studies \(\{Y_k, T_k\}_{k=1}^{K}\). This should be formatted as three vectors of length \(\sum_{k=1}^K N_{k}\), which we recommend naming “outcome”, “treatment”, “group” (for site indicators), but the names can also be specified when calling baggr() function.

As an example of an individual-level data set we include in data frames microcredit and microcredit_simplified. The former contains all the microcredit outcome data used in Meager (2019), standardized to USD PPP in 2009 terms per two weeks (a time period is necessary as these are flow variables). It therefore contains NAs and other undesirable features, to allow the user to see how baggr handles these common data issues. The data set microcredit_simplified has these issues cleaned up and contains only one outcome of interest, consumer durables spending.

baggr also has a function that automatically produces summary data from full data sets, in case one wishes to run the comparatively faster summary-data models. The “prepare_ma()” function applied to a dataframe with columns named “group”, “outcome”, and “treatment” automatically estimates the control group means, treatment effects, and associated standard errors for each group using an Ordinary Least Squares regression. The resulting output is already formatted as a valid input to the baggr command itself:

colnames(microcredit_simplified) <- c("group", "outcome", "treatment")
prepare_ma(microcredit_simplified)
#>   group          mu       tau       se.mu     se.tau
#> 1     1    5.369612  1.074862   0.3226702   0.425339
#> 2     2 1156.243056 -6.503679 146.2217092 191.120776
#> 3     3   23.868992  4.440776   1.2379155   2.207257
#> 4     4    6.516936  1.377748   1.0043951   2.271460

ATE aggregation models in baggr

baggr currently contains two different models suitable for aggregating sets of average treatment effects. Consider first the evidence aggregation model from Rubin (1981), discussed extensively in Chapter 5 of Gelman et al. (2013); the model consists of a hierarchical likelihood as follows:

\[\begin{equation} \begin{aligned} \hat{\tau_k} &\sim N(\tau_k, \hat{se_k}^2) \; \forall \; k \\ \tau_k &\sim N(\tau, \sigma_{\tau}^2) \; \forall \; k . \end{aligned} \label{rubin model} \end{equation}\]

The motivation for this model structure is discussed in detail in the sources above and in Meager (2019). To complete the Bayesian model, we now need priors. baggr has a set of default priors for each model as well as allowing the user to specify her own priors if desired. In the Rubin model, baggr’s default priors on the hyper-parameters are as follows: for \(\tau\), the prior is Normal with mean 0 and variance 1000. This is a very weak prior which does little regularization as a default, centered at zero following the basic philosophical approach that causal effects should not be thought of as large unless data contains evidence to the contrary (a “hand-wavey” form of Occam’s Razor). For \(\sigma_{\tau}\) the prior is Uniform on an interval from zero to 10 times the simple or naive variance estimator of the vector \(\{\hat{\tau_k}\}_{k=1}^{K}\) generated by the R command var().

In case you also have data on the control groups’ mean outcomes and the uncertainty on those, it would make sense to augment the Rubin (1981) model to incorporate that information. Following Meager (2019), if one has access to the estimated control means \(\{\hat{\mu_k}\}^K_{k=1}\) and their standard errors \(\{\hat{se}_{\mu k}\}^K_{k=1}\), one can fit a jointly Normal model on the pairs \(\{\hat{\mu_k},\hat{\tau_k}\}_{k=1}^{K}\). baggr implements the model from Meager (2019) which it calls the “mutau” model, like so:

\[\begin{equation} \begin{aligned} \hat{\tau_k} &\sim N(\tau_k, \hat{se_{\tau k}}^2) \; \forall \; k \\ \hat{\mu_k} &\sim N(\mu_k, \hat{se_{\mu k}}^2) \; \forall \; k \\ \left( \begin{array}{c} \mu_{k}\\ \tau_{k} \end{array} \right) &\sim N\left( \left( \begin{array}{c} \mu\\ \tau \end{array} \right), V \right) \; \text{where} \;V = \left[ \begin{array}{cc} \sigma^2_{\mu} & \sigma_{\tau\mu} \\ \sigma_{\tau\mu} & \sigma_{\tau}^2 \end{array} \right]\forall \; k. \\ \end{aligned} \label{full data model} \end{equation}\]

If you have only few groups, the priors on \(V\) will need to be relatively strong to avoid overfitting. See Meager (2019) for more discussion of this issue in particular, or see the Stan Manual on hierarchical priors. Currently \(V\) is decomposed into a correlation matrix \(\Omega\), which receives an LKJCorr(3) prior regularizing it towards independence, and a scale parameter \(\theta\) which receives a Cauchy(0,10) prior. This will be something the user can change in later versions of baggr. The \(mu\) and \(\tau\) parameters have a joint gaussian prior which the user can specify, but which by default is centered at 0. The centering can be changed to any vector of length 2 by passing this vector to baggr labelled as “prior_tau_mean”). The default covariance matrix of this prior is independent with variance \(1000^2\), but the user can pass any prior covariance matrix to baggr labelled as “prior_tau_scale”.

Models, their inputs, likelihood and priors: a summary table

Model Data frame input columns Level-1 likelihood Level-2 likelihood Priors
“Rubin” tau and se \(\hat{\tau_k} \sim N(\tau_k, \hat{se_k}^2)\) \(\tau_k \sim N(\tau, \sigma_{\tau}^2)\) \(\tau \sim \mathcal{N}(0, \sigma^2)\), \(\sigma_{\tau} \sim \mathcal{U}(0, u)\)
\(\mu\) and \(\tau\) tau, mu, se.tau, se.mu \(\hat{\tau_k} \sim N(\tau_k, \hat{se_{\tau,k}}^2)\), \(\hat{\mu_k} \sim N(\mu_k, \hat{se_{\mu,k}}^2)\) \(\pmatrix{\mu_k \\ \tau_k} \sim N(\pmatrix{\mu \\ \tau}, V)\) \(V = \theta \Omega \theta'\) where \(\theta \sim Cauchy(0,10)\), \(\Omega \sim LKJCorr(3)\), \(\pmatrix{\mu \\ \tau} \sim N(0,\Xi )\)
Full data outcome, treatment, group Same as for “\(\mu\) and \(\tau\) Same as for “\(\mu\) and \(\tau\) Same as for “\(\mu\) and \(\tau\)
Quantiles outcome, treatment, group See Meager (2019) See Meager (2019) See Meager (2019)

Running the Rubin Model in baggr

To demonstrate the Rubin model in baggr, consider the 8 schools example from Rubin (1981). In this dataset, 8 schools in the United States performed similar randomized experiments to estimate the causal effect of an SAT tutoring program on learning outcomes. Reported treatment effects and their standard errors are included in baggr as a data frame:

schools
#>      group tau se
#> 1 School A  28 15
#> 2 School B   8 10
#> 3 School C  -3 16
#> 4 School D   7 11
#> 5 School E  -1  9
#> 6 School F   1 11
#> 7 School G  18 10
#> 8 School H  12 18

To fit the model in baggr (having followed the installation instructions and loaded the package):

baggr_schools <- baggr(schools, model = "rubin", pooling = "partial")

This creates a baggr class object, and you can access the underlying stanfit object by calling baggr_schools$fit. If you don’t change the default priors, then baggr will print a message informing you of the priors it has chosen.

Printing baggr_schools returns a summary of the posterior inference. First baggr records the model type and the pooling regime chosen by the user or implemented by default. Second, baggr returns inference on the aggregate treatment effect \(\tau\) by reporting its posterior mean and 95% credible interval, and similar inference on the hyper-variance \(\sigma^2_{\tau}\). Lastly it prints the “updated” inference on each of the groups’ treatment effects, displaying their new posterior means, standard deviations and pooling factors (see below).

print(baggr_schools)
#> Model type: Aggregate data (Rubin) 
#> Pooling of effects: partial 
#> 
#> Aggregate treatment effect:
#> Mean(tau) = 8.2 with 95% interval -2.1 to 20.0 
#> SD(tau) = 6.66 with 95% interval 0.24 to 20.55 
#> 
#> Treatment effects on mean:
#>          mean  sd pooling
#> School A 11.7 8.8    0.82
#> School B  8.1 6.3    0.72
#> School C  6.3 7.8    0.84
#> School D  7.7 6.5    0.74
#> School E  5.0 6.3    0.69
#> School F  6.3 6.8    0.74
#> School G 10.7 6.9    0.72
#> School H  8.5 7.7    0.86

This is quite similar to the output from the version of the model suggested in “How to use rstan” tutorial, the small difference probably arising from the different default priors.

As discussed above, it is possible for the user to override the default priors and specify her own priors. The first parameter you can change is the upper bound of the uniform prior on \(\sigma_{\tau}\), called "prior_upper_sigma_tau", the second is the mean of the prior on \(\tau\) itself called "prior_tau_mean", the third is the scale (standard deviation) of the prior on \(\tau\) itself called "prior_tau_scale". Here I have changed all three as an example (at this stage in baggr if you want to alter one you must provide the full vector):

baggr(schools, "rubin", prior = c("prior_upper_sigma_tau" = 10000, 
                                  "prior_tau_mean" = -10, 
                                  "prior_tau_scale" = 100))
baggr_schools

Currently, all our models specify Gaussian effects distributions across groups. This is generally appropriate as a first pass at the problem (see Rubin 1981, Gelman et al 2004 and McCollough and Nuehaus 2011 for more) except if the distribution is known to be asymmetric for scientific reasons. For example, if you are working with risk ratios or odds ratios these statistics cannot be negative and the chosen hyper-distribution should typically reflect that. However, in many cases it is possible and indeed standard to maintain the Gaussian assumption on a transform of the object: for example, you can safely fit the Rubin model to the logarithm of the risk ratios or odds ratios. While bearing in mind that log transforms obscure inherent dependencies between means and variances in the raw scale, this is still much better than applying a Gaussian to the raw object itself.

Understanding and criticising baggr model performance

Baggr models are run in Stan, and the fit and results need to be checked, understood and criticised as you would any stan model or indeed any MCMC model fitting exercise. You must pay attention to printed warnings about the Rhat criterion: if you see a warning that Rhat statistic exceeds 1.05 for any parameter, you MUST NOT use the results for inference. This warning means the MCMC chains have not converged, and it is exceedingly unlikely that the “posterior inference” printed out corresponds to anything close to the true posterior implied by your model and data. If you use results from which the Rhat statistic exceeds 1.05 YOUR INFERENCE WILL BE WRONG.

If you see this warning, try re-running the model with the option iter set to a large number such as 10,000, as below. It is also good practice to run many chains, such as 8 rather than the default 4, to have a greater chance to detect pathological MCMC behaviour. You do this by passing baggr the stan arguments iter = 10000 and chains = 8, like so:

baggr_schools <- baggr(schools, model = "rubin", pooling = "partial", iter = 10000, chains = 8)

Other warnings you may see involve “divergent transitions”. While not as serious as high Rhat, this can signal problems with the model. As the stan message that you will see suggests, try adjusting adapt_delta argument above 0.8, e.g. to 0.99. You cannot pass this parameter directly to stan and thus you cannot pass it directly to baggr, so instead you must pass the argument control = list(adapt_delta = 0.99).

Measuring “pooling”

It is often useful to measure the extent to which the hierarchical model is “pooling” or sharing information across the \(K\) groups in the process of aggregation. Baggr automatically computes such a metric, and as one can see above, printing a baggr object displays a column called “pooling”. This column contains the classical pooling metric that describes the extent to which each of the group effects is “shrunk” towards their common mean in the process of aggregating information across groups. While there are many different measures of pooling, and the appropriate metric depends on the specific research question, baggr computes by default the Gelman and Pardoe (2006) metric, which delivers the percentage of total variation in \(\hat{\tau_k}\) around \(\tau\) which is attributed to sampling variation within group \(k\): \[\begin{equation} \omega_{\tau_k} = \frac{\hat{se}^2_{k}}{\hat{se}^2_{k} + \sigma^2_{\tau}}. \end{equation}\] Baggr uses the posterior mean of \(\sigma^2_{\tau}\) to compute this metric (capacity to print bounds is coming soon).

One can interpret the metric as follows: if this pooling metric is large and approaching 1, the analyst gains a lot by pooling information across groups; if this is small and approaching 0, one gains little from the aggregated analysis relative to inference on each group separately (“no pooling”). For further discussion see Gelman and Pardoe (2006), Gelman and Pardoe (2006) or Meager (2019).

Plotting and model comparison in baggr

A fundamental step to understanding the model is to plot the posterior distributions. baggr has several automatic plot functions which you can access by calling baggr_plot(); these visuals are based on bayesplot package. Plotting functions always take baggr class object as their first argument. By default, means and 95% posterior intervals of the effects in each group are shown. Extra options are available, such as whether to order the results by effect size. For the 8 schools Rubin model we have

baggr_plot(baggr_schools, order = FALSE)

[Model comparison will be included in the next package release.]

The second step to understanding the model is to compare it to other models we could have fit: this can be done automatically in baggr using the command baggr_compare. The default Rubin model (which we have selected explicitly above) is that of partial pooling. When using baggr_compare without any extra arguments, full pooling, no pooling and partial pooling versions of the model will be fit:

baggr_compare(schools)

(We will show the output of this function below.) Different comparisons, e.g. of models using different priors, are also possible.

The baggr_compare command also produces an automatic comparison plot made by calling ggplot2 package. Because the output object of baggr_compare is a ggplot object you can edit it further yourself and built on it as you would any ggplot object. For example, the default title for the plot is just “mean”, so here I’ve changed it to be more descriptive:

my_baggr_plot <- baggr_compare(schools)
my_baggr_plot$plot + ggtitle("8 schools: model comparison")

Cross-validation in baggr

[Automated cross-validation will be included in the next package release. For this version only the “manual” method is available, as presented at the end of this section.]

Baggr has built-in, automated leave-one-out cross validation for its models, where the “one” always refers to one group. This naturally corresponds to the question of how much any one group has contributed to the overall inference. Therefore, if you have \(K\) groups, using the loocv() will run your model of choice \(K\) times. Be aware that this may take a while even for simple models. (You should see a progress bar in your terminal window.) The loocv() function takes in the same arguments as baggr(), plus an option (return_models) for whether to return all the models or just the summary statistics. For the 8 schools example we can do

loocv_res <- loocv(schools, return_models = FALSE, "rubin", pooling = "partial")
loocv_res
#> [1] "log predictive density =  63.51933"

The main output is \(-2\) times the log predictive density (lpd) summed over 8 models, which corresponds to the Watanabe-Akaike Information Criterion. A WAIC value closer to zero (i.e. a smaller number in magnitude) means a better fit.

More data are stored in loocv() output, and can be accessed via attributes(), e.g. the mean treatment effects, their variability and lpd for each model that are stored in the attribute df:

names(attributes(loocv_res))
#> [1] "names" "class"
attr(loocv_res, "df")
#> NULL

This data frame can then be used to examine or compute the variation in the inference on \(\tau\) in the absence of each group. If the user is interested in manually checking the consequences of excluding a particular group or set of groups, this is also possible in baggr using subsetting. For example, suppose that we want to run the Rubin model on school groups 1-7 and predict the effect in the 8th school. The code below shows how you can specify a subset of the dataframe as your “data” argument, and then designate another subset as the “testing” holdout set by assigning it to the argument “test_data” in the baggr command. Here we have done it for both partial and full pooling:

fit1 <- baggr(data = schools[1:7,], test_data = schools[8,], model = "rubin", pooling = "partial")
fit2 <- baggr(data = schools[1:7,], test_data = schools[8,], model = "rubin", pooling = "full")

We can compare the performance of the two models using the mean log predictive density. This itself is a density as the name suggests so we will compute the log expected value of this density: here, as before, a number closer to zero is better. In this case the full pooling model actually does slightly better:

fit1$mean_lpd
#> [1] 7.942566
fit2$mean_lpd
#> [1] 7.744134

References

Gelman, Andrew, John B. Carlin, Hal S. Stern, David B. Dunson, Aki Vehtari, and Donald B. Rubin. 2013. Bayesian Data Analysis. CRC Press.

Gelman, Andrew, and Iain Pardoe. 2006. “Bayesian Measures of Explained Variance and Pooling in Multilevel (Hierarchical) Models.” Technometrics 48 (2): 241–51. https://doi.org/10.1198/004017005000000517.

Meager, Rachael. 2019. “Aggregating Distributional Treatment Effects: A Bayesian Hierarchical Analysis of the Microcredit Literature.” https://doi.org/10.31222/osf.io/7tkvm.

Rubin, Donald B. 1974. “Estimating Causal Effects of Treatments in Randomized and Nonrandomized Studies.” Journal of Educational Psychology. https://doi.org/10.1037/h0037350.

———. 1981. “Estimation in Parallel Randomized Experiments.” Journal of Educational Statistics 6 (4): 377–401.