Learn R Programming

baggr (version 0.2.0)

baggr_compare: (Run and) compare multiple baggr models

Description

(Run and) compare multiple baggr models

Usage

baggr_compare(..., what = "pooling", compare = "groups",
  style = "areas", arrange = "single")

Arguments

...

Either a number (at least 1) of objects of class baggr (you should name your objects, see the example below) or the same arguments you'd pass to baggr(), in which you must case 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".

style

What kind of plot to display (if arrange = "grid"), passed to the style argument in baggr_plot.

arrange

If "single" (default), generate a single comparison plot; if "grid", display multiple plots side-by-side.

Value

a ggplot is rendered and/or returned

Examples

Run this code
# NOT RUN {
# Most basic comparison between no, partial and full pooling
# (This will run the models)
baggr_compare(schools)

# Compare prior vs posterior
baggr_compare(schools, what = "prior")


# 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)
# }

Run the code above in your browser using DataLab