prior_viz: Plot the prior distribution for a simmr run

View source: R/prior_viz.simmr_output.R

prior_vizR Documentation

Plot the prior distribution for a simmr run

Description

This function takes the output from simmr_mcmc or simmr_ffvb and plots the prior distribution to enable visual inspection. This can be used by itself or together with posterior_predictive to visually evaluate the influence of the prior on the posterior distribution.

Usage

prior_viz(
  simmr_out,
  group = 1,
  plot = TRUE,
  include_posterior = TRUE,
  n_sims = 10000,
  scales = "free"
)

Arguments

simmr_out

A run of the simmr model from simmr_mcmc or simmr_ffvb

group

Which group to run it for (currently only numeric rather than group names)

plot

Whether to create a density plot of the prior or not. The simulated prior values are returned as part of the object

include_posterior

Whether to include the posterior distribution on top of the priors. Defaults to TRUE

n_sims

The number of simulations from the prior distribution

scales

The type of scale from facet_wrap allowing for fixed, free, free_x, free_y

Value

A list containing plot: the ggplot object (useful if requires customisation), and sim: the simulated prior values which can be compared with the posterior densities

Examples


data(geese_data_day1)
simmr_1 <- with(
  geese_data_day1,
  simmr_load(
    mixtures = mixtures,
    source_names = source_names,
    source_means = source_means,
    source_sds = source_sds,
    correction_means = correction_means,
    correction_sds = correction_sds,
    concentration_means = concentration_means
  )
)

# Plot
plot(simmr_1)

# Print
simmr_1

# MCMC run
simmr_1_out <- simmr_mcmc(simmr_1)

# Prior predictive
prior <- prior_viz(simmr_1_out)
head(prior$p_prior_sim)
summary(prior$p_prior_sim)


andrewcparnell/simmr documentation built on April 12, 2024, 6:33 p.m.