Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

baggr_compare

(Run and) compare multiple baggr models


Description

Compare multiple baggr models by either providing multiple already existing models as (named) arguments or passing parameters necessary to run a baggr model.

Usage

baggr_compare(..., what = "pooling", compare = "groups", transform = NULL)

Arguments

...

Either some (at least 1) objects of class baggr (you should name your objects, see the example below) or the same arguments you'd pass to baggr. In the latter case you must specify what to compare.

what

One of "pooling" (comparison between no, partial and full pooling) or "prior" (comparison between prior and posterior predictive). If pre-existing baggr models are passed to ..., this argument is ignored.

compare

When plotting, choose between comparison of "groups" (default) or (hyper-) "effects". The former is not available when what = "prior".

transform

a function (e.g. exp(), log()) to apply to the values of group (and hyper, if hyper=TRUE) effects before plotting; when working with effects that are on log scale, exponent transform is used automatically, you can plot on log scale by setting transform = identity

Details

If you pass parameters to the function you must specify what kind of comparison you want, either "pooling" which will run fully/partially/un-pooled models and compare them or "prior" which will generate estimates without the data and compare them to the model with the full data. For more details see baggr, specifically the PPD argument.

Value

an object of class baggr_compare

Author(s)

Witold Wiecek, Brice Green

See Also

plot.baggr_compare and print.baggr_compare for working with results of this function

Examples

# Most basic comparison between no, partial and full pooling
# (This will run the models)

# run model with just prior and then full data for comparison
# with the same arguments that are passed to baggr
prior_comparison <-
    baggr_compare(schools,
                  model = 'rubin',
                  prior_hypermean = normal(0, 3),
                  prior_hypersd = normal(0,2),
                  prior_hypercor = lkj(2),
                  what = "prior")

# print the aggregated treatment effects
prior_comparison

# plot the comparison of the two distributions
plot(prior_comparison)

# Now compare different types of pooling for the same model
pooling_comparison <-
   baggr_compare(schools,
                 model = 'rubin',
                 prior_hypermean = normal(0, 3),
                 prior_hypersd = normal(0,2),
                 prior_hypercor = lkj(2),
                 what = "pooling")

# plot this comparison
plot(pooling_comparison)

# Compare existing models:
bg1 <- baggr(schools, pooling = "partial")
bg2 <- baggr(schools, pooling = "full")
baggr_compare("Partial pooling model" = bg1, "Full pooling" = bg2,
              arrange = "grid")

#' ...or simply draw prior predictive dist (note ppd=T)
bg1 <- baggr(schools, ppd=T)
bg2 <- baggr(schools, prior_hypermean = normal(0, 5), ppd=T)
baggr_compare("Prior A, p.p.d."=bg1,
              "Prior B p.p.d."=bg2,
              compare = "effects")

# Compare posterior effects as a function of priors (note ppd=F)
bg1 <- baggr(schools, prior_hypersd = uniform(0, 20))
bg2 <- baggr(schools, prior_hypersd = normal(0, 5))
baggr_compare("Uniform prior on SD"=bg1,
              "Normal prior on SD"=bg2,
              compare = "effects")
# You can also compare different subsets of input data
bg1_small <- baggr(schools[1:6,], pooling = "partial")
baggr_compare("8 schools model" = bg1, "First 6 schools" = bg1_small)

baggr

Bayesian Aggregate Treatment Effects

v0.4.0
GPL (>= 3)
Authors
Witold Wiecek [cre, aut], Rachael Meager [aut], Brice Green [ctb] (predict(), loo_compare, many visuals), Trustees of Columbia University [cph] (tools/make_cc.R)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.