# NOT RUN {
library(dplyr)
# parse dist can operate on strings directly...
parse_dist(c("normal(0,1)", "student_t(3,0,1)"))
# ... or on columns of a data frame, where it adds the
# parsed specs back on as columns
data.frame(prior = c("normal(0,1)", "student_t(3,0,1)")) %>%
parse_dist(prior)
if (
require("brms", quietly = TRUE)
) {
# parse_dist is particularly useful with brms prior specifications,
# which follow the same format...
# get priors for a brms model
priors = get_prior(mpg ~ log(hp), data = mtcars, family = lognormal)
# The `prior` column output by `get_prior()` is a character vector
# of distribution specifications. We can parse this directly...
parse_dist(priors$prior)
# ... or we can parse it and have it added back onto the original data frame
# (this form is likely more useful for plotting, since the other columns
# are retained)
parse_dist(priors, prior)
}
# }
Run the code above in your browser using DataLab