#> 1 HMC 1.75 0.460
#> 2 Laplace 1.74 0.455
#> 3 ADVI 1.77 0.420
#> 4 Pathfinder 1.74 0.456
```
More comprehensively, the estimated posterior distributions are shown in Figure \@ref(fig:posterior).
Click to expand for code to create posterior distribution plot
``` r
p_posterior <- draws |>
ggplot(aes(x = value, col = method)) +
stat_slabinterval(density = "histogram", breaks = 30, alpha = 0.8) +
scale_colour_manual(values = c("#56B4E9", "#009E73", "#E69F00", "#CC79A7")) +
facet_grid(method ~ parameter, scales = "free_x") +
theme_minimal() +
guides(fill = "none") +
labs(x = "", y = "", col = "Method") +
theme(legend.position = "bottom")
```
(ref:posterior) Estimated posterior distributions for the `mu` and `sigma` parameters using each inference method, shown using `tidybayes::stat_slabinterval()`.
``` r
p_posterior
```
## Comparison of resulting delay distributions
Figure \@ref(fig:delay-pdf) shows how the different `mu` and `sigma` posterior mean estimates from each inference method alter an estimated delay distribution.
Click to expand for code to create delay PDF plot
``` r
p_delay_pdf <- pmap_df(
filter(pars), ~ tibble(
x = seq(0, 25, by = 0.1),
method = ..1, density = dlnorm(x, ..2, ..3)
)
) |>
ggplot(aes(x = x, y = density, col = method)) +
geom_line(linewidth = 1) +
scale_color_manual(values = c("#56B4E9", "#009E73", "#E69F00", "#CC79A7")) +
theme_minimal() +
labs(x = "", y = "", col = "Method") +
theme(legend.position = "bottom")
```
(ref:delay-pdf) Delay probability density functions obtained based on the posterior mean estimated `mu` and `sigma` parameters.
``` r
p_delay_pdf
```
## Comparison of time taken
In this example, HMC took a longer time to run than the other methods and Pathfinder was the fastest running method.
That said, even for HMC the computation time in this case is unlikely to be prohibitive.
``` r
times <- list(
HMC = time_hmc,
Laplace = time_laplace,
ADVI = time_advi,
Pathfinder = time_pathfinder
)
times
#> $HMC
#> user system elapsed
#> 12.551 0.206 12.771
#>
#> $Laplace
#> user system elapsed
#> 1.296 0.110 1.502
#>
#> $ADVI
#> user system elapsed
#> 1.029 0.082 1.122
#>
#> $Pathfinder
#> user system elapsed
#> 0.396 0.083 0.528
```
# Conclusion
The range of alternative approximation algorithms available, and their ease of use, is an attractive feature of `brms`.
We found that these algorithms do produce reasonable approximations in far less time than HMC.
Of course, this vignette only includes one example, so results may differ for other models and datasets.
## References {-}