Description Usage Arguments Value Examples
Compute highest density intervals
1 2 3 4 5 6 |
object |
an object describing a posterior distribution |
prob |
the desired mass of the HDI region. |
pars |
a vector of parameter names |
regex_pars |
a regular expression for selecting parameter names |
... |
additional arguments (ignored for now) |
a data frame with 1 row per paramter and variables
lo
lower end of hdi
hi
higher end of hdi
prob
is the total probability
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # Determining HDI of a beta(30,12) distribution
# Create a grid
Grid <-
expand.grid(x = seq(0, 1, length.out = 201)) %>%
mutate(posterior = dbeta(x, 30, 12))
hdi_from_grid(Grid, "x", prob = 0.9)
Grid %>% dplyr::slice_sample(n = 1E4, weight_by = posterior, replace = TRUE) %>%
pull(x) %>%
hdi(prob = 0.9)
x <- rnorm(25, 3, 2) # some random data
Grid <-
expand.grid(
mean = seq(0, 10, length.out = 101),
sd = seq(0, 10, length.out = 101)
) %>%
mutate(
prior = 1,
loglik =
purrr::map2_dbl(mean, sd, ~ sum(dnorm(x, .x, .y, log = TRUE)), x = x),
likelihood = exp(loglik),
posterior = prior * likelihood
)
hdi_from_grid(Grid, pars = c("mean", "sd"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.