Turns posterior draws of a taxon-level quantity (one row per draw and
taxon, as from tidybayes::add_epred_draws() and a contrast computed from
it) into one row per taxon: a point estimate, a credible interval and,
with threshold, the posterior probability of being above it. This is
the shape gtdb_tree_plot() takes.
Usage
gtdb_summarise_draws(
draws,
value,
taxon = "accession",
by = NULL,
width = 0.95,
point = c("median", "mean"),
threshold = NULL
)Arguments
- draws
A data frame of draws, one row per draw and taxon.
- value
Column of
drawsholding the drawn values.- taxon
Column of
drawsidentifying the taxon, matching the tree's tips. Defaults to"accession".- by
Optional other columns to summarise within, e.g.
"donor_id".- width
Width of the central credible interval. Defaults to 0.95.
- point
"median"(the default) or"mean".- threshold
Optional value: adds
prob_above, the proportion of draws above it (and so1 - prob_abovebelow it).
Value
A tibble with one row per taxon (and by group): the taxon and
by columns, estimate, .lower, .upper, .width, n_draws, and
with threshold, prob_above.
Details
Draws are summarised over every row of a taxon, so if draws holds
several values per draw and taxon (e.g. predictions over a grid of
abundances, or per donor), the summary pools them. To keep them apart,
name the columns in by; to average them first, summarise draws
before calling this function.
Examples
draws <- read.csv(gtdb_example("draws"))
head(draws)
#> .draw accession effect
#> 1 1 GCF_037023725.1 0.0241
#> 2 2 GCF_037023725.1 -0.0185
#> 3 3 GCF_037023725.1 0.0844
#> 4 4 GCF_037023725.1 -0.0753
#> 5 5 GCF_037023725.1 -0.0106
#> 6 6 GCF_037023725.1 -0.0752
estimates <- gtdb_summarise_draws(draws, value = "effect",
threshold = 0)
estimates
#> # A tibble: 560 × 7
#> accession estimate .lower .upper .width n_draws prob_above
#> <chr> <dbl> <dbl> <dbl> <dbl> <int> <dbl>
#> 1 GCF_025567095.1 0.423 0.361 0.503 0.95 100 1
#> 2 GCA_018369015.1 0.345 0.303 0.375 0.95 100 1
#> 3 GCF_004216775.1 0.331 0.269 0.384 0.95 100 1
#> 4 GCF_005845215.1 0.330 0.255 0.375 0.95 100 1
#> 5 GCF_003024715.1 0.303 0.272 0.346 0.95 100 1
#> 6 GCF_040545455.1 0.292 0.240 0.345 0.95 100 1
#> 7 GCF_000466485.1 0.268 0.230 0.302 0.95 100 1
#> 8 GCF_003477885.1 0.267 0.248 0.287 0.95 100 1
#> 9 GCA_944383765.1 0.254 0.160 0.343 0.95 100 1
#> 10 GCF_032490495.1 0.237 0.162 0.336 0.95 100 1
#> # ℹ 550 more rows