Plot either the distribution or trace of a subset of parameters split out by their dimension

plot_param(libbi_model = NULL, param = NULL, prior_params = NULL,
  log_scale = FALSE, sqrt_scale = FALSE, plot_type = "dist",
  plot_data = TRUE, burn_in = 0, scales = "free")

Arguments

libbi_model

LiBBi model object

param

A character vector containing the complete names of the variables to plot.

prior_params

A prior parameter set as generated by fit_model. Alternatively a libbi model can be passed.

log_scale

Logical, defaults to TRUE. Should the x axis be plotted on a log scale?

sqrt_scale

Logical, defaults to TRUE. Should the x axis be plotted on a square root scale?

plot_type

A character string indicating the type of plot to show. "dist" plots a density and rug plot, whilst "trace" plots a trace plot.

plot_data

Logical, defaults to TRUE. Should the summarised data be plotted.

burn_in

Numeric, defaults to 0. The number of samples to remove as burn in.

scales

Character string, defaulting to "free". What scales to use for graph faceting.

Value

A plot of the specified parameters.

Examples

##Show function code plot_param
#> function(libbi_model = NULL, param = NULL, #> prior_params = NULL, log_scale = FALSE, sqrt_scale = FALSE, #> plot_type = "dist", plot_data = TRUE, burn_in = 0, scales = "free") { #> #> #> data <- bi_read(libbi_model, type = c("param")) %>% #> map_dfr(~mutate(., distribution = "Posterior"), .id = "parameter") #> #> if (!is.null(param)) { #> data <- data %>% #> filter(parameter %in% param) #> } #> #> if (!is.null(prior_params)) { #> #> if (class(prior_params) != "libbi") { #> prior <- prior_params %>% #> mutate(distribution = "Prior") #> }else { #> prior <- bi_read(prior_params, type = c("param")) %>% #> map_dfr(~mutate(., distribution = "Prior"), .id = "parameter") #> } #> #> if (!is.null(param)) { #> prior <- prior %>% #> filter(parameter %in% param) #> } #> #> data <- suppressWarnings(data %>% #> bind_rows(prior)) #> } #> #> data <- data %>% #> group_by(np, distribution, parameter) %>% #> mutate(length = 1:n()) %>% #> rename(Distribution = distribution) %>% #> ungroup %>% #> filter(any(np > burn_in, Distribution %in% "Prior")) #> #> if (plot_data) { #> if (plot_type == "dist") { #> plot <- ggplot(data, aes(x = value, col = Distribution, fill = Distribution)) + #> geom_density(alpha = 0.4) + #> geom_rug(alpha = 0.1) + #> labs(x = "Value", y = "Density") #> }else if (plot_type =="trace") { #> plot <- ggplot(data, aes(x = np, y = value, col = Distribution)) + #> geom_line(alpha = 0.8) + #> labs(x = "Time", y = "Value") #> } #> #> plot <- plot + #> facet_wrap(c("parameter", "length"), scales = scales) + #> theme_minimal() + #> theme(legend.position = "top") #> #> if (log_scale) { #> plot <- plot + #> scale_x_log10(labels = comma) #> } #> #> if (sqrt_scale) { #> plot <- plot + #> scale_x_sqrt(labels = comma) #> } #> }else{ #> plot <- data #> } #> #> return(plot) #> } #> <environment: namespace:ModelTBBCGEngland>