├── .Rbuildignore ├── .Rprofile ├── .gitignore ├── CITATION.cff ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── R ├── SBC-deprecated.R ├── backend-brms.R ├── backend-cmdstanr.R ├── backend-mock.R ├── backend-rjags.R ├── backend-rstan.R ├── backend-stan-shared.R ├── backends.R ├── brms-helpers.R ├── calculate.R ├── datasets.R ├── derived-quantities.R ├── example.R ├── generator-brms.R ├── onLoad.R ├── plot.R ├── results.R └── util.R ├── README.md ├── SBC.Rproj ├── _pkgdown.yml ├── docs ├── 404.html ├── LICENSE-text.html ├── LICENSE.html ├── articles │ ├── SBC.html │ ├── SBC_files │ │ └── figure-html │ │ │ ├── ecdf-1.png │ │ │ ├── ecdf_diff-1.png │ │ │ └── rank_hist-1.png │ ├── bad_parametrization.html │ ├── bad_parametrization_files │ │ └── figure-html │ │ │ ├── results1_ecdf_diff-1.png │ │ │ ├── results1_other-1.png │ │ │ ├── results2_plots-1.png │ │ │ └── results2_plots-2.png │ ├── brms.html │ ├── brms_files │ │ └── figure-html │ │ │ ├── results_func2_fullrank_plots-1.png │ │ │ ├── results_func2_fullrank_plots-2.png │ │ │ ├── results_func2_meanfield_plots-1.png │ │ │ ├── results_func2_meanfield_plots-2.png │ │ │ ├── results_func2_plots-1.png │ │ │ ├── results_func2_plots-2.png │ │ │ ├── results_func_plots-1.png │ │ │ ├── results_func_plots-2.png │ │ │ ├── results_plots-1.png │ │ │ └── results_plots-2.png │ ├── computational_algorithm1.html │ ├── computational_algorithm1_files │ │ └── figure-html │ │ │ ├── ecdf_rank_poisson-1.png │ │ │ ├── ecdf_rank_poisson-2.png │ │ │ ├── ecdf_rank_poisson_100-1.png │ │ │ ├── ecdf_rank_poisson_100-2.png │ │ │ ├── ecdf_rank_poisson_optimizing-1.png │ │ │ ├── ecdf_rank_poisson_optimizing-2.png │ │ │ ├── ecdf_rank_poisson_optimizing_100-1.png │ │ │ ├── ecdf_rank_poisson_optimizing_100-2.png │ │ │ ├── hmm_2_coverage-1.png │ │ │ ├── hmm_2_ecdf_ranks-1.png │ │ │ ├── hmm_2_ecdf_ranks-2.png │ │ │ ├── hmm_coverage-1.png │ │ │ ├── hmm_coverage-2.png │ │ │ ├── hmm_ecdf_ranks-1.png │ │ │ ├── hmm_ecdf_ranks-2.png │ │ │ ├── hmm_fullrank_coverage-1.png │ │ │ ├── hmm_fullrank_ecdf_ranks-1.png │ │ │ ├── hmm_fullrank_ecdf_ranks-2.png │ │ │ ├── hmm_lowtol_coverage-1.png │ │ │ ├── hmm_lowtol_ecdf_ranks-1.png │ │ │ ├── hmm_lowtol_ecdf_ranks-2.png │ │ │ ├── hmm_optimizing_ecdf_ranks-1.png │ │ │ ├── hmm_optimizing_ecdf_ranks-2.png │ │ │ ├── hmm_ordered_ecdf_ranks-1.png │ │ │ ├── hmm_ordered_ecdf_ranks-2.png │ │ │ ├── hmm_ordered_fullrank_ecdf_ranks-1.png │ │ │ ├── hmm_ordered_fullrank_ecdf_ranks-2.png │ │ │ ├── hmm_ordered_optimizing_ecdf_ranks-1.png │ │ │ ├── hmm_ordered_optimizing_ecdf_ranks-2.png │ │ │ ├── hmm_sample_ecdf_ranks-1.png │ │ │ ├── hmm_sample_ecdf_ranks-2.png │ │ │ └── hmm_time-1.png │ ├── discrete_vars.html │ ├── discrete_vars_files │ │ └── figure-html │ │ │ ├── ranks_jags-1.png │ │ │ ├── ranks_jags-2.png │ │ │ ├── ranks_jags_marginalized-1.png │ │ │ ├── ranks_jags_marginalized-2.png │ │ │ ├── results1_plots-1.png │ │ │ ├── results1_plots-2.png │ │ │ ├── results_2_all_plots-1.png │ │ │ ├── results_2_all_plots-2.png │ │ │ ├── results_2_plots-1.png │ │ │ └── results_2_plots-2.png │ ├── implementing_backends.html │ ├── implementing_backends_files │ │ └── figure-html │ │ │ ├── indo_complex_narrow_ranks-1.png │ │ │ ├── indo_complex_narrow_ranks-2.png │ │ │ ├── indo_complex_ranks-1.png │ │ │ ├── indo_complex_ranks-2.png │ │ │ ├── indo_sim_coverage-1.png │ │ │ ├── indo_simple_narrow_ranks-1.png │ │ │ ├── indo_simple_narrow_ranks-2.png │ │ │ ├── indo_simple_ranks-1.png │ │ │ ├── indo_simple_ranks-2.png │ │ │ ├── indo_simple_sim_est-1.png │ │ │ ├── indo_simple_sim_est_ugly-1.png │ │ │ ├── poisson_ranks-1.png │ │ │ ├── poisson_ranks-2.png │ │ │ └── poisson_sim_estimated-1.png │ ├── index.html │ ├── indexing.html │ ├── indexing_files │ │ └── figure-html │ │ │ ├── plots_regression1-1.png │ │ │ ├── plots_regression1-2.png │ │ │ ├── plots_regression2-1.png │ │ │ ├── plots_regression2-2.png │ │ │ ├── plots_regression3-1.png │ │ │ └── plots_regression3-2.png │ ├── limits_of_SBC.html │ ├── limits_of_SBC_files │ │ └── figure-html │ │ │ ├── dens_compare-1.png │ │ │ ├── log_dens_compare-1.png │ │ │ ├── results_corr-1.png │ │ │ ├── results_corr-2.png │ │ │ ├── results_corr_dq-1.png │ │ │ ├── results_corr_dq-2.png │ │ │ ├── results_minor_100_plots-1.png │ │ │ ├── results_minor_100_plots-2.png │ │ │ ├── results_minor_10_plots-1.png │ │ │ ├── results_minor_10_plots-2.png │ │ │ ├── results_minor_200_coverage-1.png │ │ │ ├── results_minor_200_plots-1.png │ │ │ ├── results_minor_200_plots-2.png │ │ │ ├── results_minor_200_sim_estimated-1.png │ │ │ ├── results_missing_2_contraction-1.png │ │ │ ├── results_missing_2_plots-1.png │ │ │ ├── results_missing_2_plots-2.png │ │ │ ├── results_missing_2_sim_estimated-1.png │ │ │ ├── results_missing_contraction-1.png │ │ │ ├── results_missing_dq_plots-1.png │ │ │ ├── results_missing_dq_plots-2.png │ │ │ ├── results_missing_plots-1.png │ │ │ ├── results_missing_plots-2.png │ │ │ └── results_missing_sim_estimated-1.png │ ├── overview_wide.png │ ├── rank_visualizations.html │ ├── rank_visualizations_files │ │ └── figure-html │ │ │ ├── coverage_50-1.png │ │ │ ├── coverage_diff_50-1.png │ │ │ ├── densities-1.png │ │ │ ├── ecdf_1000-1.png │ │ │ ├── ecdf_50-1.png │ │ │ ├── ecdf_diff_1000-1.png │ │ │ ├── ecdf_diff_50-1.png │ │ │ ├── rank_hist_1000-1.png │ │ │ ├── rank_hist_50_100-1.png │ │ │ ├── rank_hist_50_17-1.png │ │ │ ├── rank_hist_50_default-1.png │ │ │ ├── side_by_side_1000_exact_match-1.png │ │ │ ├── side_by_side_50_exact_match-1.png │ │ │ ├── side_by_side_50_overest-1.png │ │ │ ├── side_by_side_50_too_certain-1.png │ │ │ ├── side_by_side_50_too_uncertain-1.png │ │ │ └── side_by_side_50_underest-1.png │ ├── rejection_sampling.html │ ├── rejection_sampling_files │ │ └── figure-html │ │ │ ├── reject_unobserved_plots-1.png │ │ │ ├── reject_unobserved_plots-2.png │ │ │ ├── reject_y_plot-1.png │ │ │ ├── reject_y_plot-2.png │ │ │ ├── results1_plots-1.png │ │ │ └── results1_plots-2.png │ ├── small_model_workflow.html │ └── small_model_workflow_files │ │ └── figure-html │ │ ├── beta_first_10_pairs-1.png │ │ ├── beta_first_10_pairs_subset-1.png │ │ ├── beta_first_10_pairs_subset-2.png │ │ ├── beta_first_10_pairs_subset-3.png │ │ ├── beta_first_10_pairs_subset-4.png │ │ ├── beta_first_10_pairs_subset-5.png │ │ ├── beta_first_results-1.png │ │ ├── beta_first_results-2.png │ │ ├── combined_fanos-1.png │ │ ├── combined_reject_coverage-1.png │ │ ├── combined_reject_plots-1.png │ │ ├── combined_reject_plots-2.png │ │ ├── fanos_divergent-1.png │ │ ├── mixture_first_convergence-1.png │ │ ├── mixture_fixed_log_mix_pairs-1.png │ │ ├── mixture_fixed_log_mix_rhat-1.png │ │ ├── mixture_fixed_ordered_pairs-1.png │ │ ├── mixture_fixed_ordered_subset_coverage-1.png │ │ ├── mixture_fixed_ordered_subset_results-1.png │ │ ├── mixture_fixed_ordered_subset_results-2.png │ │ ├── results_beta_precision_100_plots-1.png │ │ ├── results_beta_precision_100_plots-2.png │ │ ├── results_beta_precision_10_plots-1.png │ │ ├── results_beta_precision_10_plots-2.png │ │ ├── results_beta_precision_fixed_prior_200_coverage-1.png │ │ ├── results_beta_precision_fixed_prior_200_plots-1.png │ │ ├── results_beta_precision_fixed_prior_200_plots-2.png │ │ ├── results_beta_precision_fixed_prior_plots-1.png │ │ ├── results_beta_precision_fixed_prior_plots-2.png │ │ ├── results_combined_plots-1.png │ │ ├── results_combined_plots-2.png │ │ ├── results_combined_reject_more_coverage-1.png │ │ ├── results_combined_reject_more_plots-1.png │ │ ├── results_combined_reject_more_plots-2.png │ │ ├── results_fixed_ordered_combined_results-1.png │ │ ├── results_fixed_ordered_combined_results-2.png │ │ ├── results_fixed_ordered_combined_results_coverage-1.png │ │ └── sim_estimated_final-1.png ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── index.html ├── link.svg ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── ECDF-plots.html │ ├── Rplot001.png │ ├── SBC-deprecated.html │ ├── SBC_backend_brms.html │ ├── SBC_backend_brms_from_generator.html │ ├── SBC_backend_cmdstan_sample.html │ ├── SBC_backend_cmdstan_variational.html │ ├── SBC_backend_default_thin_ranks.default.html │ ├── SBC_backend_default_thin_ranks.html │ ├── SBC_backend_hash_for_cache.html │ ├── SBC_backend_iid_draws.default.html │ ├── SBC_backend_iid_draws.html │ ├── SBC_backend_mock.html │ ├── SBC_backend_rjags.html │ ├── SBC_backend_rstan_optimizing.html │ ├── SBC_backend_rstan_sample.html │ ├── SBC_datasets.html │ ├── SBC_example_backend.html │ ├── SBC_example_generator.html │ ├── SBC_example_results.html │ ├── SBC_fit.html │ ├── SBC_fit_to_diagnostics.html │ ├── SBC_fit_to_draws_matrix.default.html │ ├── SBC_fit_to_draws_matrix.html │ ├── SBC_generator_brms.html │ ├── SBC_generator_custom.html │ ├── SBC_generator_function.html │ ├── SBC_print_example_model.html │ ├── SBC_results.html │ ├── SBC_statistics_from_single_fit.html │ ├── bind_datasets.html │ ├── bind_derived_quantities.html │ ├── bind_generated_quantities-deprecated.html │ ├── bind_generated_quantities.html │ ├── bind_globals.html │ ├── bind_results.html │ ├── brms_full_ppred.html │ ├── brms_response_sequence.html │ ├── calculate_prior_sd.html │ ├── calculate_ranks_draws_matrix.html │ ├── check_all_SBC_diagnostics.SBC_results.html │ ├── check_all_SBC_diagnostics.default.html │ ├── check_all_SBC_diagnostics.html │ ├── combine-functions.html │ ├── combine_args.html │ ├── combine_array_elements.html │ ├── compute_SBC.html │ ├── compute_dquants.html │ ├── compute_gen_quants-deprecated.html │ ├── compute_gen_quants.html │ ├── compute_results-deprecated.html │ ├── compute_results.html │ ├── data_for_ecdf_plots.html │ ├── default_chunk_size.html │ ├── default_cores_per_fit.html │ ├── derived_quantities.html │ ├── empirical_coverage.html │ ├── generate_datasets.html │ ├── generated_quantities-deprecated.html │ ├── generated_quantities.html │ ├── get_diagnostic_messages.default.html │ ├── get_diagnostic_messages.html │ ├── guess_rank_hist_bins.html │ ├── index.html │ ├── plot_contraction.html │ ├── plot_coverage.html │ ├── plot_coverage_diff.html │ ├── plot_ecdf_diff.html │ ├── plot_rank_hist.html │ ├── plot_sim_estimated.html │ ├── rdunif.html │ ├── recompute_SBC_statistics.html │ ├── recompute_statistics-deprecated.html │ ├── recompute_statistics.html │ ├── sub-.SBC_datasets.html │ ├── sub-.SBC_results.html │ ├── validate_derived_quantities.html │ └── validate_generated_quantities.html └── sitemap.xml ├── inst ├── CITATION ├── normal_bad.jags ├── normal_bad.stan ├── normal_sd.jags └── normal_sd.stan ├── man ├── ECDF-plots.Rd ├── SBC-deprecated.Rd ├── SBC_backend_brms.Rd ├── SBC_backend_brms_from_generator.Rd ├── SBC_backend_cmdstan_sample.Rd ├── SBC_backend_cmdstan_variational.Rd ├── SBC_backend_default_thin_ranks.Rd ├── SBC_backend_hash_for_cache.Rd ├── SBC_backend_iid_draws.Rd ├── SBC_backend_mock.Rd ├── SBC_backend_rjags.Rd ├── SBC_backend_rstan_optimizing.Rd ├── SBC_backend_rstan_sample.Rd ├── SBC_datasets.Rd ├── SBC_example_backend.Rd ├── SBC_example_generator.Rd ├── SBC_example_results.Rd ├── SBC_fit.Rd ├── SBC_fit_to_diagnostics.Rd ├── SBC_fit_to_draws_matrix.Rd ├── SBC_generator_brms.Rd ├── SBC_generator_custom.Rd ├── SBC_generator_function.Rd ├── SBC_print_example_model.Rd ├── SBC_results.Rd ├── SBC_statistics_from_single_fit.Rd ├── bind_datasets.Rd ├── bind_derived_quantities.Rd ├── bind_generated_quantities-deprecated.Rd ├── bind_globals.Rd ├── bind_results.Rd ├── brms_full_ppred.Rd ├── brms_response_sequence.Rd ├── calculate_prior_sd.Rd ├── calculate_ranks_draws_matrix.Rd ├── check_all_SBC_diagnostics.Rd ├── combine-functions.Rd ├── combine_args.Rd ├── compute_SBC.Rd ├── compute_dquants.Rd ├── compute_gen_quants-deprecated.Rd ├── compute_results-deprecated.Rd ├── data_for_ecdf_plots.Rd ├── default_chunk_size.Rd ├── default_cores_per_fit.Rd ├── derived_quantities.Rd ├── empirical_coverage.Rd ├── generate_datasets.Rd ├── generated_quantities-deprecated.Rd ├── get_diagnostic_messages.Rd ├── guess_rank_hist_bins.Rd ├── plot_contraction.Rd ├── plot_coverage.Rd ├── plot_rank_hist.Rd ├── plot_sim_estimated.Rd ├── rdunif.Rd ├── recompute_SBC_statistics.Rd ├── recompute_statistics-deprecated.Rd ├── sub-.SBC_datasets.Rd ├── sub-.SBC_results.Rd └── validate_derived_quantities.Rd ├── pkgdown └── templates │ └── in-header.html ├── tests └── testthat │ ├── test-backends.R │ ├── test-brms.R │ ├── test-datasets.R │ ├── test-empirical-coverage.R │ ├── test-integration.R │ ├── test-plot-helpers.R │ ├── test-results.R │ └── test-utils.R └── vignettes ├── SBC.Rmd ├── bad_parametrization.Rmd ├── brms.Rmd ├── computational_algorithm1.Rmd ├── discrete_vars.Rmd ├── implementing_backends.Rmd ├── indexing.Rmd ├── limits_of_SBC.Rmd ├── other_models ├── changepoint.jags └── changepoint_marginalized.jags ├── overview.graphml ├── overview.png ├── overview_wide.graphml ├── overview_wide.png ├── rank_visualizations.Rmd ├── rejection_sampling.Rmd ├── small_model_workflow.Rmd ├── small_model_workflow ├── .gitignore ├── beta_first.stan ├── beta_precision.stan ├── beta_precision_fixed_prior.stan ├── combined_first.stan ├── mixture_first.stan ├── mixture_fixed_log_mix.stan └── mixture_fixed_ordered.stan └── stan ├── .gitignore ├── bad_parametrization1.stan ├── bad_parametrization2.stan ├── discrete_vars1.stan ├── hmm_poisson.stan ├── hmm_poisson_ordered.stan ├── minor_discrepancy.stan ├── missing_likelihood.stan ├── partially_missing_likelihood.stan ├── poisson.stan ├── regression1.stan ├── regression2.stan ├── regression3.stan └── rejection_sampling.stan /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^SBC\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^doc$ 5 | ^Meta$ 6 | ^_pkgdown\.yml$ 7 | ^docs$ 8 | ^pkgdown$ 9 | _SBC_cache$ 10 | ^vignettes/stan/.*\.rds$ 11 | -------------------------------------------------------------------------------- /.Rprofile: -------------------------------------------------------------------------------- 1 | source("~/.Rprofile") 2 | # Allows to change how all vignettes are run at once (especially to test rstan) 3 | options("SBC.vignettes_cmdstanr" = TRUE) 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .Rproj.user 3 | .Rhistory 4 | .RData 5 | Meta 6 | 7 | *.nb.html 8 | *.exe 9 | 10 | *_SBC_cache 11 | vignettes/stan/*.rds 12 | vignettes/small_model_workflow/*.rds 13 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use this software, please preferably cite the underlying paper, but citing the package itself is also great." 3 | title: "SBC: Simulation Based Calibration for rstan/cmdstanr models" 4 | repository-code: "https://github.com/hyunjimoon/SBC/" 5 | authors: 6 | - family-names: "Modrák" 7 | given-names: "Martin" 8 | orcid: "https://orcid.org/0000-0002-8886-7797" 9 | - family-names: "Kim" 10 | given-names: "Shinyoung" 11 | - family-names: "Moon" 12 | given-names: "Angie H." 13 | - family-names: "Säilynoja" 14 | given-names: "Teemu" 15 | orcid: "https://orcid.org/0000-0002-5249-348X" 16 | preferred-citation: 17 | authors: 18 | - family-names: "Modrák" 19 | given-names: "Martin" 20 | orcid: "https://orcid.org/0000-0002-8886-7797" 21 | - family-names: "Moon" 22 | given-names: "Angie H." 23 | - family-names: "Kim" 24 | given-names: "Shinyoung" 25 | - family-names: "Bürkner" 26 | given-names: "Paul" 27 | orcid: "https://orcid.org/0000-0001-5765-8995" 28 | - family-names: "Huurre" 29 | given-names: "Niko" 30 | - family-names: "Faltejsková" 31 | given-names: "Kateřina" 32 | - family-names: "Gelman" 33 | given-names: "Andrew" 34 | orcid: "https://orcid.org/0000-0002-6975-2601" 35 | - family-names: "Vehtari" 36 | given-names: "Aki" 37 | orcid: "https://orcid.org/0000-0003-2164-9469" 38 | title: "Simulation-Based Calibration Checking for Bayesian Computation: The Choice of Test Quantities Shapes Sensitivity" 39 | type: article 40 | doi: 10.1214/23-BA1404 41 | year: 2023 42 | journal: "Bayesian Analysis" 43 | volume: "Advance publication" 44 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: SBC 2 | Title: Simulation Based Calibration for Bayesian models 3 | Version: 0.3.0.9000 4 | Authors@R: 5 | c(person(given = "Shinyoung", 6 | family = "Kim", 7 | role = c("aut"), 8 | email = "tttllshin@gmail.com", 9 | comment = c()), 10 | person(given = "Angie.H", 11 | family = "Moon", 12 | role = c("aut", "cre"), 13 | email = "amoon@mit.edu", 14 | comment = c()), 15 | person(given = "Martin", 16 | family = "Modrák", 17 | role = c("aut"), 18 | email = "martin.modrak@biomed.cas.cz", 19 | comment = c(ORCID= "0000-0002-8886-7797")), 20 | person(given = "Teemu", 21 | family = "Säilynoja", 22 | role = "aut"), 23 | person(given = "Luna", 24 | family = "Fazio", 25 | role = "ctb"), 26 | person(given = "Timo", 27 | family = "Stenz", 28 | role = "ctb") 29 | ) 30 | Description: SBC helps perform Simulation Based Calibration on Bayesian models. 31 | SBC lets you check for bugs in your model code and/or algorithm that fits 32 | the model. SBC focuses on models built with 'Stan' , 33 | but can support other modelling languages as well. 34 | License: MIT + file LICENSE 35 | URL: https://hyunjimoon.github.io/SBC/, https://github.com/hyunjimoon/SBC/ 36 | BugReports: https://github.com/hyunjimoon/SBC/issues 37 | Encoding: UTF-8 38 | LazyData: true 39 | Roxygen: list(markdown = TRUE) 40 | RoxygenNote: 7.3.2 41 | Imports: 42 | R6, 43 | posterior (>= 1.0.0), 44 | ggplot2, 45 | stats, 46 | stringi, 47 | abind, 48 | future.apply, 49 | dplyr, 50 | tidyr, 51 | tidyselect, 52 | purrr, 53 | memoise 54 | Suggests: 55 | testthat, 56 | cmdstanr (>= 0.4.0), 57 | rstan, 58 | knitr, 59 | rmarkdown, 60 | brms, 61 | MCMCpack, 62 | medicaldata, 63 | formula.tools, 64 | MASS, 65 | mvtnorm, 66 | patchwork, 67 | bayesplot 68 | VignetteBuilder: knitr 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2020 2 | COPYRIGHT HOLDER: Shinyoung Kim,Hyunji Moon 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2020 Shinyoung Kim,Hyunji Moon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method("[",SBC_datasets) 4 | S3method("[",SBC_results) 5 | S3method(SBC_backend_default_thin_ranks,SBC_backend_brms) 6 | S3method(SBC_backend_default_thin_ranks,default) 7 | S3method(SBC_backend_hash_for_cache,SBC_backend_brms) 8 | S3method(SBC_backend_hash_for_cache,SBC_backend_cmdstan_sample) 9 | S3method(SBC_backend_hash_for_cache,SBC_backend_cmdstan_variational) 10 | S3method(SBC_backend_hash_for_cache,SBC_backend_rjags) 11 | S3method(SBC_backend_hash_for_cache,SBC_backend_rstan_optimizing) 12 | S3method(SBC_backend_hash_for_cache,SBC_backend_rstan_sample) 13 | S3method(SBC_backend_hash_for_cache,default) 14 | S3method(SBC_backend_iid_draws,SBC_backend_brms) 15 | S3method(SBC_backend_iid_draws,SBC_backend_cmdstan_variational) 16 | S3method(SBC_backend_iid_draws,SBC_backend_mock_rng) 17 | S3method(SBC_backend_iid_draws,SBC_backend_rstan_optimizing) 18 | S3method(SBC_backend_iid_draws,default) 19 | S3method(SBC_fit,SBC_backend_brms) 20 | S3method(SBC_fit,SBC_backend_cmdstan_sample) 21 | S3method(SBC_fit,SBC_backend_cmdstan_variational) 22 | S3method(SBC_fit,SBC_backend_mock) 23 | S3method(SBC_fit,SBC_backend_mock_rng) 24 | S3method(SBC_fit,SBC_backend_rjags) 25 | S3method(SBC_fit,SBC_backend_rstan_optimizing) 26 | S3method(SBC_fit,SBC_backend_rstan_sample) 27 | S3method(SBC_fit_to_diagnostics,CmdStanMCMC) 28 | S3method(SBC_fit_to_diagnostics,CmdStanVB) 29 | S3method(SBC_fit_to_diagnostics,RStanOptimizingFit) 30 | S3method(SBC_fit_to_diagnostics,brmsfit) 31 | S3method(SBC_fit_to_diagnostics,default) 32 | S3method(SBC_fit_to_diagnostics,stanfit) 33 | S3method(SBC_fit_to_draws_matrix,CmdStanMCMC) 34 | S3method(SBC_fit_to_draws_matrix,CmdStanVB) 35 | S3method(SBC_fit_to_draws_matrix,RStanOptimizingFit) 36 | S3method(SBC_fit_to_draws_matrix,SBC_rjags_fit) 37 | S3method(SBC_fit_to_draws_matrix,brmsfit) 38 | S3method(SBC_fit_to_draws_matrix,default) 39 | S3method(brms_response_sequence,bform) 40 | S3method(brms_response_sequence,brmsfit) 41 | S3method(brms_response_sequence,brmsterms) 42 | S3method(brms_response_sequence,btl) 43 | S3method(brms_response_sequence,mvbrmsterms) 44 | S3method(check_all_SBC_diagnostics,SBC_results) 45 | S3method(check_all_SBC_diagnostics,default) 46 | S3method(data_for_ecdf_plots,SBC_results) 47 | S3method(data_for_ecdf_plots,data.frame) 48 | S3method(data_for_ecdf_plots,matrix) 49 | S3method(generate_datasets,SBC_generator_brms) 50 | S3method(generate_datasets,SBC_generator_custom) 51 | S3method(generate_datasets,SBC_generator_function) 52 | S3method(get_diagnostic_messages,SBC_ADVI_diagnostics) 53 | S3method(get_diagnostic_messages,SBC_ADVI_diagnostics_summary) 54 | S3method(get_diagnostic_messages,SBC_RStanOptimizing_diagnostics) 55 | S3method(get_diagnostic_messages,SBC_RStanOptimizing_diagnostics_summary) 56 | S3method(get_diagnostic_messages,SBC_nuts_diagnostics_summary) 57 | S3method(get_diagnostic_messages,SBC_results) 58 | S3method(get_diagnostic_messages,SBC_results_summary) 59 | S3method(get_diagnostic_messages,default) 60 | S3method(length,SBC_datasets) 61 | S3method(length,SBC_results) 62 | S3method(plot_contraction,SBC_results) 63 | S3method(plot_contraction,data.frame) 64 | S3method(plot_coverage,SBC_results) 65 | S3method(plot_coverage,data.frame) 66 | S3method(plot_coverage_diff,SBC_results) 67 | S3method(plot_coverage_diff,data.frame) 68 | S3method(plot_rank_hist,SBC_results) 69 | S3method(plot_rank_hist,data.frame) 70 | S3method(plot_sim_estimated,SBC_results) 71 | S3method(plot_sim_estimated,data.frame) 72 | S3method(print,SBC_diagnostic_messages) 73 | S3method(print,SBC_nuts_diagnostics_summary) 74 | S3method(print,SBC_results_summary) 75 | S3method(summary,SBC_ADVI_diagnostics) 76 | S3method(summary,SBC_RStanOptimizing_diagnostics) 77 | S3method(summary,SBC_nuts_diagnostics) 78 | S3method(summary,SBC_results) 79 | export(SBC_backend_brms) 80 | export(SBC_backend_brms_from_generator) 81 | export(SBC_backend_cmdstan_sample) 82 | export(SBC_backend_cmdstan_variational) 83 | export(SBC_backend_default_thin_ranks) 84 | export(SBC_backend_hash_for_cache) 85 | export(SBC_backend_iid_draws) 86 | export(SBC_backend_mock) 87 | export(SBC_backend_mock_rng) 88 | export(SBC_backend_rjags) 89 | export(SBC_backend_rstan_optimizing) 90 | export(SBC_backend_rstan_sample) 91 | export(SBC_datasets) 92 | export(SBC_diagnostic_messages) 93 | export(SBC_example_backend) 94 | export(SBC_example_generator) 95 | export(SBC_example_results) 96 | export(SBC_fit) 97 | export(SBC_fit_to_diagnostics) 98 | export(SBC_fit_to_draws_matrix) 99 | export(SBC_generator_brms) 100 | export(SBC_generator_custom) 101 | export(SBC_generator_function) 102 | export(SBC_print_example_model) 103 | export(SBC_results) 104 | export(SBC_statistics_from_single_fit) 105 | export(bind_datasets) 106 | export(bind_derived_quantities) 107 | export(bind_generated_quantities) 108 | export(bind_results) 109 | export(calculate_prior_sd) 110 | export(calculate_ranks_draws_matrix) 111 | export(calculate_sds_draws_matrix) 112 | export(check_all_SBC_diagnostics) 113 | export(combine_all_variables) 114 | export(combine_array_elements) 115 | export(compute_SBC) 116 | export(compute_dquants) 117 | export(compute_gen_quants) 118 | export(compute_results) 119 | export(data_for_ecdf_plots) 120 | export(default_chunk_size) 121 | export(default_cores_per_fit) 122 | export(derived_quantities) 123 | export(draws_rvars_to_standata) 124 | export(draws_rvars_to_standata_single) 125 | export(empirical_coverage) 126 | export(generate_datasets) 127 | export(generated_quantities) 128 | export(get_diagnostic_messages) 129 | export(plot_contraction) 130 | export(plot_coverage) 131 | export(plot_coverage_diff) 132 | export(plot_ecdf) 133 | export(plot_ecdf_diff) 134 | export(plot_rank_hist) 135 | export(plot_sim_estimated) 136 | export(recompute_SBC_statistics) 137 | export(recompute_statistics) 138 | export(validate_SBC_datasets) 139 | export(validate_SBC_results) 140 | export(validate_derived_quantities) 141 | export(validate_generated_quantities) 142 | import(ggplot2) 143 | -------------------------------------------------------------------------------- /R/SBC-deprecated.R: -------------------------------------------------------------------------------- 1 | #' @title Deprecated functions in package \pkg{SBC}. 2 | #' @description The functions listed below are deprecated and will be defunct in 3 | #' the near future. When possible, alternative functions with similar 4 | #' functionality are also mentioned. Help pages for deprecated functions are 5 | #' available at \code{help("-deprecated")}. 6 | #' @name SBC-deprecated 7 | #' @keywords internal 8 | NULL 9 | -------------------------------------------------------------------------------- /R/backend-brms.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | # For internal use, creates brms backend. 4 | new_SBC_backend_brms <- function(compiled_model, 5 | args 6 | ) { 7 | require_brms_version("brms backend") 8 | 9 | if(is.null(args$algorithm) || args$algorithm == "sampling") { 10 | arg_names_for_stan <- c("chains", "inits", "init", "iter", "warmup", "thin") 11 | } else if(args$algorithm %in% c("meanfield", "fullrank")) { 12 | arg_names_for_stan <- c("inits", "init") # possibly more valid args 13 | } 14 | args_for_stan <- args[intersect(names(args), arg_names_for_stan)] 15 | 16 | args_for_stan_renames <- c("inits" = "init") 17 | for(i in 1:length(args_for_stan_renames)) { 18 | orig <- names(args_for_stan_renames)[i] 19 | new <- args_for_stan_renames[i] 20 | if(!is.null(args_for_stan[[orig]])) { 21 | args_for_stan[[new]] <- args_for_stan[[orig]] 22 | args_for_stan[[orig]] <- NULL 23 | } 24 | } 25 | if(is.null(args$algorithm) || args$algorithm == "sampling") { 26 | stan_backend <- sampling_backend_from_stanmodel(compiled_model, args_for_stan) 27 | } else if(args$algorithm %in% c("meanfield", "fullrank")) { 28 | args_for_stan$algorithm <- args$algorithm 29 | stan_backend <- variational_backend_from_stanmodel(compiled_model, args_for_stan) 30 | } 31 | 32 | structure(list(stan_backend = stan_backend, args = args), class = "SBC_backend_brms") 33 | } 34 | 35 | validate_SBC_backend_brms_args <- function(args) { 36 | if(!is.null(args$algorithm) && !(args$algorithm %in% c("sampling", "meanfield", "fullrank"))) { 37 | stop("Algorithms other than sampling, meanfield and fullrank not supported yet. Comment on https://github.com/hyunjimoon/SBC/issues/91 to express your interest.") 38 | } 39 | 40 | if(!is.null(args$algorithm) && args$algorithm %in% c("meanfield", "fullrank")) { 41 | backend <- args$backend 42 | if(is.null(backend)) { 43 | backend <- getOption("brms.backend", "rstan") 44 | } 45 | if(backend != "cmdstanr") { 46 | stop("algorithm = 'meanfield' or 'fullrank' is currently supported only when using cmdstanr as brms backend. Comment on https://github.com/hyunjimoon/SBC/issues/91 to express your interest.") 47 | } 48 | } 49 | 50 | unacceptable_params <- c("data", "cores", "empty") 51 | if(any(names(args) %in% unacceptable_params)) { 52 | stop(paste0("Parameters ", paste0("'", unacceptable_params, "'", collapse = ", "), 53 | " cannot be provided when defining a backend as they need to be set ", 54 | "by the SBC package")) 55 | } 56 | } 57 | 58 | #' Build a backend based on the `brms` package. 59 | #' 60 | #' @param ... arguments passed to `brm`. 61 | #' @param template_data a representative value for the `data` argument in `brm` 62 | #' that can be used to generate code. 63 | #' @param template_dataset DEPRECATED. Use `template_data` 64 | #' @param out_stan_file A filename for the generated Stan code. Useful for 65 | #' debugging and for avoiding unnecessary recompilations. 66 | #' @export 67 | SBC_backend_brms <- function(..., template_data, out_stan_file = NULL, template_dataset = NULL) { 68 | if(!is.null(template_dataset)) { 69 | warning("Argument 'template_dataset' is deprecated, use 'template_data' instead") 70 | if(missing(template_data)) { 71 | template_data <- template_dataset 72 | } 73 | } 74 | args = list(...) 75 | validate_SBC_backend_brms_args(args) 76 | 77 | stanmodel <- stanmodel_for_brms(data = template_data, out_stan_file = out_stan_file, ...) 78 | 79 | new_SBC_backend_brms(stanmodel, args) 80 | } 81 | 82 | #' Build a brms backend, reusing the compiled model from a previously created `SBC_generator_brms` 83 | #' object. 84 | #' 85 | #' @export 86 | SBC_backend_brms_from_generator <- function(generator, ...) { 87 | stopifnot(inherits(generator, "SBC_generator_brms")) 88 | validate_SBC_backend_brms_args(list(...)) 89 | 90 | args <- combine_args(generator$args, list(...)) 91 | args$data <- NULL 92 | args$cores <- NULL 93 | args$empty <- NULL 94 | 95 | validate_SBC_backend_brms_args(args) 96 | 97 | 98 | new_SBC_backend_brms(generator$compiled_model, args) 99 | } 100 | 101 | #' @export 102 | SBC_fit.SBC_backend_brms <- function(backend, generated, cores) { 103 | args_with_data <- backend$args 104 | args_with_data$data <- generated 105 | 106 | standata <- do.call(brms::make_standata, args_with_data) 107 | class(standata) <- NULL 108 | stanfit <- SBC_fit(backend$stan_backend, standata, cores) 109 | 110 | 111 | brmsfit <- brmsfit_from_stanfit(stanfit, args_with_data) 112 | brmsfit 113 | } 114 | 115 | #' @export 116 | SBC_fit_to_draws_matrix.brmsfit <- function(fit) { 117 | posterior::as_draws_matrix(fit$fit) 118 | } 119 | 120 | #' @export 121 | SBC_fit_to_diagnostics.brmsfit <- function(fit, fit_output, fit_messages, fit_warnings) { 122 | if(!is.null(fit$vb_fit)) { 123 | SBC_fit_to_diagnostics(fit$vb_fit, fit_output, fit_messages, fit_warnings) 124 | } else { 125 | SBC_fit_to_diagnostics(fit$fit, fit_output, fit_messages, fit_warnings) 126 | } 127 | } 128 | 129 | #' @export 130 | SBC_backend_iid_draws.SBC_backend_brms <- function(backend) { 131 | SBC_backend_iid_draws(backend$stan_backend) 132 | } 133 | 134 | #' @export 135 | SBC_backend_default_thin_ranks.SBC_backend_brms <- function(backend) { 136 | SBC_backend_default_thin_ranks(backend$stan_backend) 137 | } 138 | 139 | 140 | #' @export 141 | SBC_backend_hash_for_cache.SBC_backend_brms <- function(backend) { 142 | object_for_hash <- list(args = backend$args, 143 | model_hash = 144 | SBC_backend_hash_for_cache(backend$stan_backend)) 145 | rlang::hash(object_for_hash) 146 | } 147 | 148 | -------------------------------------------------------------------------------- /R/backend-mock.R: -------------------------------------------------------------------------------- 1 | #' A mock backend. 2 | #' 3 | #' Mock backend is useful for testing the package. 4 | #' It will ignore all data passed to it and always 5 | #' provide `result` as the draws generated by the backend. 6 | #' 7 | #' @param result a `draws_matrix` that will be returned regardless of the data 8 | #' @export 9 | SBC_backend_mock <- function(result = posterior::draws_matrix(a = rnorm(100)), 10 | output = NULL, message = NULL, 11 | warning = NULL, error = NULL) { 12 | if(!posterior::is_draws_matrix(result)) { 13 | stop("Mock backend requires result to be draws_matrix") 14 | } 15 | 16 | structure(list(result = result, 17 | output = output, 18 | message = message, 19 | warning = warning, 20 | error = error), class = "SBC_backend_mock") 21 | } 22 | 23 | #' @export 24 | SBC_fit.SBC_backend_mock <- function(backend, generated, cores) { 25 | if(!is.null(backend$output)) { 26 | cat(backend$output) 27 | } 28 | if(!is.null(backend$message)) { 29 | message(backend$message) 30 | } 31 | if(!is.null(backend$warning)) { 32 | warning(backend$warning) 33 | } 34 | if(!is.null(backend$error)) { 35 | stop(backend$error) 36 | } 37 | 38 | backend$result 39 | } 40 | 41 | #' @export 42 | SBC_backend_mock_rng <- function(..., n_draws = 1000) { 43 | var_to_rng <- list(...) 44 | if(is.null(names(var_to_rng)) || 45 | length(unique(names(var_to_rng))) != length(var_to_rng) || 46 | any(names(var_to_rng) == "") 47 | ) { 48 | stop("All arguments must have a unique name") 49 | } 50 | var_to_rng <- purrr::map(var_to_rng, purrr::as_mapper) 51 | 52 | purrr::iwalk(var_to_rng, function(rng, name) { 53 | tryCatch({ 54 | res <- rng(13) 55 | }, error = function(e) { 56 | message(e) 57 | stop("Test invocation for argument '", name, "' failed.\n", 58 | "All arguments must be convertible to a function that takes the number of draws as input and returns a 1D array of draws.") 59 | }) 60 | if(!is.numeric(res) || length(res) != 13) { 61 | stop("Test invocation for argument '", name, "' returned unexpected result.\n", 62 | "All arguments must be convertible to a function that takes the number of draws as input and returns a 1D array of draws.") 63 | } 64 | }) 65 | 66 | structure(list(var_to_rng = var_to_rng, n_draws = n_draws), class = "SBC_backend_mock_rng") 67 | } 68 | 69 | #' @export 70 | SBC_fit.SBC_backend_mock_rng <- function(backend, generated, cores) { 71 | draws_list <- purrr::map(backend$var_to_rng, ~ .x(backend$n_draws)) 72 | 73 | do.call(posterior::draws_matrix, draws_list) 74 | } 75 | 76 | #' @export 77 | SBC_backend_iid_draws.SBC_backend_mock_rng <- function(backend) { 78 | TRUE 79 | } 80 | -------------------------------------------------------------------------------- /R/backend-rjags.R: -------------------------------------------------------------------------------- 1 | #' Create a JAGS backend using `rjags` 2 | #' 3 | #' @param file model file or connection to model code (passed to [rjags::jags.model()]) 4 | #' @param n.iter number of iterations for sampling (passed to [rjags::coda.samples()) 5 | #' @param n.burnin number of iterations used for burnin 6 | #' @param variable.names names of variables to monitor (passed to [rjags::coda.samples()]) 7 | #' @param thin thinning (passed to [rjags::coda.samples()]) 8 | #' @param na.rm whether to omit variables containing NA (passed to [rjags::coda.samples()]) 9 | #' @param ... additional optional arguments passed to [rjags::jags.model()] 10 | #' - most notably `n.chains`, `n.adapt` and `inits`. 11 | #' @export 12 | SBC_backend_rjags <- function(file, n.iter, n.burnin, variable.names, thin = 1, na.rm = TRUE, ...) { 13 | args = list(...) 14 | if(any(names(args) == "data")) { 15 | stop(paste0("Argument 'data' cannot be provided when defining a backend", 16 | " as it needs to be set by the SBC package")) 17 | } 18 | 19 | structure(list(file = file, 20 | n.iter = n.iter, 21 | variable.names = variable.names, 22 | n.burnin = n.burnin, 23 | thin = thin, 24 | na.rm = na.rm, 25 | args = args), class = "SBC_backend_rjags") 26 | } 27 | 28 | 29 | #' @export 30 | SBC_fit.SBC_backend_rjags <- function(backend, generated, cores) { 31 | args_all <- c(list(file = backend$file, data = generated), backend$args) 32 | 33 | model <- do.call(rjags::jags.model, args_all) 34 | if(backend$n.burnin > 0) { 35 | stats::update(model, n.iter = backend$n.burnin, progress.bar = "none") 36 | } 37 | samples <- rjags::coda.samples(model, 38 | variable.names = backend$variable.names, 39 | n.iter = backend$n.iter, 40 | thin = backend$thin, 41 | na.rm = backend$na.rm, 42 | progress.bar = "none") 43 | 44 | structure(list(model = model, samples = samples), 45 | class = "SBC_rjags_fit") 46 | } 47 | 48 | 49 | #' @export 50 | SBC_fit_to_draws_matrix.SBC_rjags_fit <- function(fit) { 51 | posterior::as_draws_matrix(fit$samples) 52 | } 53 | 54 | #' @export 55 | SBC_backend_hash_for_cache.SBC_backend_rjags <- function(backend) { 56 | model_code <- readLines(backend$file) 57 | 58 | backend_for_cache <- backend 59 | backend_for_cache$file <- NULL 60 | backend_for_cache$model_code <- model_code 61 | rlang::hash(backend_for_cache) 62 | } 63 | -------------------------------------------------------------------------------- /R/backends.R: -------------------------------------------------------------------------------- 1 | #' S3 generic using backend to fit a model to data. 2 | #' 3 | #' Needs to be implemented by all backends. 4 | #' All implementations have to return an object for which you can safely 5 | #' call [SBC_fit_to_draws_matrix()] and get some draws. 6 | #' If that's not possible an error should be raised. 7 | #' @export 8 | SBC_fit <- function(backend, generated, cores) { 9 | UseMethod("SBC_fit") 10 | } 11 | 12 | #' S3 generic converting a fitted model to a `draws_matrix` object. 13 | #' 14 | #' Needs to be implemented for all types of objects the backend can 15 | #' return from [SBC_fit()]. Default implementation just calls, 16 | #' [posterior::as_draws_matrix()], so if the fit object already supports 17 | #' this, it will work out of the box. 18 | #' @export 19 | SBC_fit_to_draws_matrix <- function(fit) { 20 | UseMethod("SBC_fit_to_draws_matrix") 21 | } 22 | 23 | #' @rdname SBC_fit_to_draws_matrix 24 | #' @export 25 | SBC_fit_to_draws_matrix.default <- function(fit) { 26 | posterior::as_draws_matrix(fit) 27 | } 28 | 29 | #' S3 generic to get backend-specific diagnostics. 30 | #' 31 | #' The diagnostics object has to be a `data.frame` but may 32 | #' inherit additional classes - in particular it may be useful 33 | #' for the returning object to implement [get_diagnostic_messages()]. 34 | #' 35 | #' @param fit The fit returned by `SBC_fit` 36 | #' @param fit_output a character string capturing what the backend wrote to stdout 37 | #' @param fit_messages a character vector of messages the backend raised 38 | #' @param fit_warnings a character vector of warnings the backend raised 39 | #' @return an single row `data.frame` that includes diagnostics or NULL, if no diagnostics available. 40 | #' @export 41 | SBC_fit_to_diagnostics <- function(fit, fit_output, fit_messages, fit_warnings) { 42 | UseMethod("SBC_fit_to_diagnostics") 43 | } 44 | 45 | #' @export 46 | SBC_fit_to_diagnostics.default <- function(fit, fit_output, fit_messages, fit_warnings) { 47 | NULL 48 | } 49 | 50 | #' Get hash used to identify cached results. 51 | #' 52 | #' S3 generic that allows backends to override how a hash is computed. By default `rlang::hash()` 53 | #' is used. 54 | #' 55 | #' @export 56 | SBC_backend_hash_for_cache <- function(backend) { 57 | UseMethod("SBC_backend_hash_for_cache") 58 | } 59 | 60 | #' @export 61 | SBC_backend_hash_for_cache.default <- function(backend) { 62 | rlang::hash(backend) 63 | } 64 | 65 | #' S3 generic to let backends signal that they produced independent draws. 66 | #' 67 | #' Most backends (e.g. those based on variatns of MCMC) don't produce 68 | #' independent draws and thus diagnostics like Rhat and ESS are important 69 | #' and draws may need thinning. Backends that already produce independent 70 | #' draws (e.g. ADVI/optimizing) can implement this method to return `TRUE` 71 | #' to signal this is the case. If this method returns `TRUE`, ESS and Rhat will 72 | #' always attain their best possible values and [SBC_backend_default_thin_ranks()] 73 | #' will return `1`. 74 | #' The default implementation returns `FALSE`. 75 | #' @param backend to check 76 | #' @export 77 | SBC_backend_iid_draws <- function(backend) { 78 | UseMethod("SBC_backend_iid_draws") 79 | } 80 | 81 | #' @rdname SBC_backend_iid_draws 82 | #' @export 83 | SBC_backend_iid_draws.default <- function(backend) { 84 | FALSE 85 | } 86 | 87 | #' S3 generic to get backend-specific default thinning for rank computation. 88 | #' 89 | #' The default implementation plays it relatively safe and returns 10, unless 90 | #' [SBC_backend_iid_draws()] returns `TRUE` in which case it returns 1. 91 | #' 92 | #' @export 93 | SBC_backend_default_thin_ranks <- function(backend) { 94 | UseMethod("SBC_backend_default_thin_ranks") 95 | } 96 | 97 | #' @rdname SBC_backend_default_thin_ranks 98 | #' @export 99 | SBC_backend_default_thin_ranks.default <- function(backend) { 100 | if(SBC_backend_iid_draws(backend)) { 101 | 1 102 | } else { 103 | 10 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /R/brms-helpers.R: -------------------------------------------------------------------------------- 1 | stanmodel_for_brms <- function(..., out_stan_file = NULL) { 2 | model_code <- brms::make_stancode(...) 3 | 4 | args <- list(...) 5 | if(!is.null(args$sample_prior)) { 6 | stop("Do not specify `sample_prior`") 7 | } 8 | if(!is.null(args$empty)) { 9 | stop("Do not specify `empty`") 10 | } 11 | backend <- args$backend 12 | if(is.null(backend)) { 13 | backend <- getOption("brms.backend", "rstan") 14 | } 15 | if(backend == "cmdstanr") { 16 | if(is.null(out_stan_file)) { 17 | out_stan_file <- cmdstanr::write_stan_file(model_code) 18 | } else { 19 | write_stan_file_simple(out_stan_file, model_code) 20 | } 21 | compiled_model <- cmdstanr::cmdstan_model(out_stan_file) 22 | } else if(backend == "rstan") { 23 | if(is.null(out_stan_file)) { 24 | compiled_model <- rstan::stan_model(model_code = model_code) 25 | } else { 26 | write_stan_file_simple(out_stan_file, model_code) 27 | compiled_model <- rstan::stan_model(file = out_stan_file) 28 | } 29 | } else { 30 | stop("Unsupported backend: ", backend) 31 | 32 | } 33 | 34 | compiled_model 35 | } 36 | 37 | # write code to file, not touching the file if the code matches 38 | write_stan_file_simple <- function(file, code) { 39 | overwrite <- TRUE 40 | if(file.exists(file)) { 41 | collapsed_code <- paste0(code, collapse = "\n") 42 | tryCatch({ 43 | file_contents <- paste0(readLines(file), collapse = "\n") 44 | if (gsub("(\r|\n)+", "\n", file_contents) == gsub("(\r|\n)+", "\n", collapsed_code)) { 45 | overwrite <- FALSE 46 | } 47 | }, 48 | error = function(e) { 49 | warning("Error when checking old file contents", e) 50 | }) 51 | } 52 | 53 | if(overwrite) { 54 | cat(code, file = file, sep = "\n") 55 | } 56 | } 57 | 58 | translate_rstan_args_to_cmdstan <- function(args, include_unrecognized = TRUE) { 59 | ignored_args <- c("cores", "data") 60 | recognized_but_unchanged <- c("thin", "refresh") 61 | translated_args <- list() 62 | for(old in names(args)) { 63 | if(old == "control") { 64 | if(!is.null(args$control$adapt_delta)) { 65 | translated_args$adapt_delta = args$control$adapt_delta 66 | } 67 | if(!is.null(args$control$max_treedepth)) { 68 | translated_args$max_depth = args$control$max_treedepth 69 | } 70 | } else if(old == "iter") { 71 | if(is.null(args$warmup)) { 72 | translated_args$iter_warmup = args$iter / 2 73 | translated_args$iter_sampling = args$iter/ 2 74 | } else { 75 | translated_args$iter_warmup = args$warmup 76 | translated_args$iter_sampling = args$iter - args$warmup 77 | } 78 | } else if(old == "warmup") { 79 | if(is.null(args$iter)) { 80 | translated_args$iter_warmup = args$warmup 81 | } #If iter is present, warmup will be handled when handling iter 82 | } else if(!(old %in% ignored_args)) { 83 | if(include_unrecognized || old %in% recognized_but_unchanged) { 84 | translated_args[[old]] = args[[old]] 85 | } 86 | } 87 | } 88 | translated_args 89 | } 90 | 91 | sampling_backend_from_stanmodel <- function(stanmodel, args) { 92 | 93 | if(inherits(stanmodel, "CmdStanModel")) { 94 | translated_args <- translate_rstan_args_to_cmdstan(args) 95 | 96 | do.call(SBC_backend_cmdstan_sample, combine_args(translated_args, list(model = stanmodel))) 97 | } else if(inherits(stanmodel, "stanmodel")) { 98 | do.call(SBC_backend_rstan_sample, combine_args(args,list(model = stanmodel))) 99 | } else { 100 | stop("stanmodel does not inherit from `stanmodel` or `CmdStanModel`") 101 | } 102 | } 103 | 104 | variational_backend_from_stanmodel <- function(stanmodel, args) { 105 | 106 | if(inherits(stanmodel, "CmdStanModel")) { 107 | translated_args <- translate_rstan_args_to_cmdstan(args) 108 | 109 | do.call(SBC_backend_cmdstan_variational, combine_args(translated_args, list(model = stanmodel))) 110 | } else if(inherits(stanmodel, "stanmodel")) { 111 | do.call(SBC_backend_rstan_variational, combine_args(args,list(model = stanmodel))) 112 | } else { 113 | stop("stanmodel does not inherit from `stanmodel` or `CmdStanModel`") 114 | } 115 | } 116 | 117 | brmsfit_from_stanfit <- function(fit, brmsargs) { 118 | fit_brms <- do.call(brms::brm, combine_args(brmsargs, list(empty = TRUE))) 119 | if(inherits(fit, "CmdStanFit")) { 120 | fit_brms$fit <- brms::read_csv_as_stanfit(fit$output_files()) 121 | if(inherits(fit, "CmdStanVB")) { 122 | fit_brms$vb_fit <- fit 123 | } 124 | } else { 125 | fit_brms$fit <- fit 126 | } 127 | fit_brms <- brms::rename_pars(fit_brms) 128 | 129 | fit_brms 130 | } 131 | -------------------------------------------------------------------------------- /R/derived-quantities.R: -------------------------------------------------------------------------------- 1 | #' Create a definition of derived quantities evaluated in R. 2 | #' 3 | #' When the expression contains non-library functions/objects, and parallel processing 4 | #' is enabled, those must be 5 | #' named in the `.globals` parameter (hopefully we'll be able to detect those 6 | #' automatically in the future). Note that [recompute_SBC_statistics()] currently 7 | #' does not use parallel processing, so `.globals` don't need to be set. 8 | #' 9 | #' @param ... named expressions representing the quantitites 10 | #' @param .globals A list of names of objects that are defined 11 | #' in the global environment and need to present for the gen. quants. to evaluate. 12 | #' It is added to the `globals` argument to [future::future()], to make those 13 | #' objects available on all workers. 14 | #' @examples 15 | #'# Derived quantity computing the total log likelihood of a normal distribution 16 | #'# with known sd = 1 17 | #'normal_lpdf <- function(y, mu, sigma) { 18 | #' sum(dnorm(y, mean = mu, sd = sigma, log = TRUE)) 19 | #'} 20 | #' 21 | #'# Note the use of .globals to make the normal_lpdf function available 22 | #'# within the expression 23 | #'log_lik_dq <- derived_quantities(log_lik = normal_lpdf(y, mu, 1), 24 | #' .globals = "normal_lpdf" ) 25 | #' 26 | #' @export 27 | derived_quantities <- function(..., .globals = list()) { 28 | structure(rlang::enquos(..., .named = TRUE), 29 | class = "SBC_derived_quantities", 30 | globals = .globals 31 | ) 32 | } 33 | 34 | #' @title Validate a definition of derived quantities evaluated in R. 35 | #' @export 36 | validate_derived_quantities <- function(x) { 37 | # Backwards compatibility 38 | if(inherits(x, "SBC_generated_quantities")) { 39 | class(x) <- "SBC_derived_quantities" 40 | } 41 | stopifnot(inherits(x, "SBC_derived_quantities")) 42 | invisible(x) 43 | } 44 | 45 | #' @title Combine two lists of derived quantities 46 | #' @export 47 | bind_derived_quantities <- function(dq1, dq2) { 48 | validate_derived_quantities(dq1) 49 | validate_derived_quantities(dq2) 50 | structure(c(dq1, dq2), 51 | class = "SBC_derived_quantities", 52 | globals = bind_globals(attr(dq1, "globals"), attr(dq2, "globals"))) 53 | } 54 | 55 | #'@title Compute derived quantities based on given data and posterior draws. 56 | #'@param gen_quants Deprecated, use `dquants` 57 | #'@export 58 | compute_dquants <- function(draws, generated, dquants, gen_quants = NULL) { 59 | if(!is.null(gen_quants)) { 60 | warning("gen_quants argument is deprecated, use dquants") 61 | if(rlang::is_missing(dquants)) { 62 | dquants <- gen_quants 63 | } 64 | } 65 | dquants <- validate_derived_quantities(dquants) 66 | draws_rv <- posterior::as_draws_rvars(draws) 67 | 68 | draws_env <- list2env(draws_rv) 69 | if(!is.null(generated)) { 70 | if(!is.list(generated)) { 71 | stop("compute_dquants assumes that generated is a list, but this is not the case") 72 | } 73 | generated_env <- list2env(generated, parent = draws_env) 74 | 75 | data_mask <- rlang::new_data_mask(bottom = generated_env, top = draws_env) 76 | } else { 77 | data_mask <- rlang::new_data_mask(bottom = draws_env) 78 | } 79 | 80 | eval_func <- function(dq) { 81 | # Wrap the expression in `rdo` which will mostly do what we need 82 | # all the tricks are just to have the correct environment when we need it 83 | wrapped_dq <- rlang::new_quosure(rlang::expr(posterior::rdo(!!rlang::get_expr(dq))), rlang::get_env(dq)) 84 | rlang::eval_tidy(wrapped_dq, data = data_mask) 85 | } 86 | rvars <- lapply(dquants, FUN = eval_func) 87 | do.call(posterior::draws_rvars, rvars) 88 | } 89 | 90 | 91 | 92 | #' @title Create a definition of derived quantities evaluated in R. 93 | #' @description Delegates directly to `derived_quantities()`. 94 | #' 95 | #' @name generated_quantities-deprecated 96 | #' @seealso \code{\link{SBC-deprecated}} 97 | #' @keywords internal 98 | NULL 99 | 100 | #' @rdname SBC-deprecated 101 | #' @section \code{generated_quantities}: 102 | #' Instead of \code{generated_quantities}, use \code{\link{derived_quantities}}. 103 | #' 104 | #' @export 105 | generated_quantities <- function(...) { 106 | warning("generated_quantities() is deprecated, use derived_quantities instead.") 107 | derived_quantities(...) 108 | } 109 | 110 | #' @title Validate a definition of derived quantities evaluated in R. 111 | #' @description Delegates directly to `validate_derived_quantities()`. 112 | #' 113 | #' @name generated_quantities-deprecated 114 | #' @seealso \code{\link{SBC-deprecated}} 115 | #' @keywords internal 116 | NULL 117 | 118 | #' @rdname SBC-deprecated 119 | #' @section \code{validate_generated_quantities}: 120 | #' Instead of \code{validate_generated_quantities}, use \code{\link{validate_derived_quantities}}. 121 | #' 122 | #' @export 123 | validate_generated_quantities <- function(...) { 124 | warning("generated_quantities() is deprecated, use validate_derived_quantities instead.") 125 | validate_derived_quantities(...) 126 | } 127 | 128 | #' @title Combine two lists of derived quantities 129 | #' @description Delegates directly to `bind_derived_quantities()`. 130 | #' 131 | #' @name bind_generated_quantities-deprecated 132 | #' @seealso \code{\link{SBC-deprecated}} 133 | #' @keywords internal 134 | NULL 135 | 136 | #' @rdname SBC-deprecated 137 | #' @section \code{bind_generated_quantities}: 138 | #' Instead of \code{bind_generated_quantities}, use \code{\link{bind_derived_quantities}}. 139 | #' 140 | #' @export 141 | bind_generated_quantities <- function(...) { 142 | warning("bind_generated_quantities() is deprecated, use bind_derived_quantities instead.") 143 | bind_derived_quantities(...) 144 | } 145 | 146 | #'@title Compute derived quantities based on given data and posterior draws. 147 | #' @description Delegates directly to `compute_dquants()`. 148 | #' 149 | #' @name compute_gen_quants-deprecated 150 | #' @seealso \code{\link{SBC-deprecated}} 151 | #' @keywords internal 152 | NULL 153 | 154 | #' @rdname SBC-deprecated 155 | #' @section \code{compute_gen_quants}: 156 | #' Instead of \code{compute_gen_quants}, use \code{\link{compute_dquants}}. 157 | #' 158 | #' @export 159 | compute_gen_quants <- function(...) { 160 | warning("compute_gen_quants() is deprecated, use compute_dquants() instead.") 161 | compute_dquants(...) 162 | } 163 | -------------------------------------------------------------------------------- /R/onLoad.R: -------------------------------------------------------------------------------- 1 | .onLoad <- function(libname, pkgname) { 2 | adjust_gamma <<- memoise::memoise(adjust_gamma, cache = cachem::cache_mem(max_size = 1024 * 32)) 3 | } 4 | -------------------------------------------------------------------------------- /R/util.R: -------------------------------------------------------------------------------- 1 | 2 | #' Combine two named lists and overwrite elements with the same name 3 | #' using the value from args2 4 | combine_args <- function(args1, args2) { 5 | if(is.null(names(args1)) || is.null(names(args2))) { 6 | c(args1, args2) 7 | } else { 8 | shared <- intersect(names(args1), names(args2)) 9 | shared <- setdiff(shared, "") 10 | for(s in shared) { 11 | args1[[s]] <- args2[[s]] 12 | } 13 | c(args1, args2[!(names(args2) %in% shared)]) 14 | } 15 | } 16 | 17 | 18 | SBC_error <- function(subclass, message, call = sys.call(-1), ...) { 19 | structure( 20 | class = c(subclass, "SBC_error", "error", "condition"), 21 | list(message = message, call = call), 22 | ... 23 | ) 24 | } 25 | 26 | 27 | require_package_version <- function(package, version, purpose) { 28 | if(!requireNamespace(package, quietly = TRUE)) { 29 | stop(paste0("Using ", purpose, " requires the '", package, "' package")) 30 | } 31 | # Cannot use `versionCheck` of `requireNamespace` as that doesn't work when 32 | # the package is already loaded. Note that `packageVersion` and `package_version` 33 | # are completely different methods 34 | if(packageVersion(package) < package_version(version)) { 35 | stop(paste0("SBC requires ", package, " version >= ", version, ", please update to use SBC.")) 36 | } 37 | } 38 | 39 | require_brms_version <- function(purpose) { 40 | require_package_version("brms", "2.21.0", purpose) 41 | } 42 | 43 | require_cmdstanr_version <- function(purpose) { 44 | require_package_version("cmdstanr", "0.4.0", purpose) 45 | } 46 | -------------------------------------------------------------------------------- /SBC.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: b108152d-9d8f-49b0-99a1-3ae87744434c 3 | 4 | RestoreWorkspace: No 5 | SaveWorkspace: No 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | AutoAppendNewline: Yes 17 | StripTrailingWhitespace: Yes 18 | 19 | BuildType: Package 20 | PackageUseDevtools: Yes 21 | PackageInstallArgs: --no-multiarch --with-keep.source 22 | PackageRoxygenize: rd,collate,namespace 23 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://hyunjimoon.github.io/SBC/ 2 | 3 | template: 4 | params: 5 | bootswatch: cosmo 6 | 7 | navbar: 8 | title: "SBC" 9 | left: 10 | - text: "Get Started" 11 | href: articles/SBC.html 12 | - text: "Vignettes" 13 | href: articles/index.html 14 | - text: "Functions" 15 | href: reference/index.html 16 | - text: "Other Packages" 17 | menu: 18 | - text: "rstan" 19 | href: http://mc-stan.org/rstan 20 | - text: "cmdstanr" 21 | href: https://mc-stan.org/cmdstanr 22 | - text: "brms" 23 | href: http://paul-buerkner.github.io/brms/ 24 | - text: "rstanarm" 25 | href: http://mc-stan.org/rstanarm 26 | - text: "bayesplot" 27 | href: http://mc-stan.org/bayesplot 28 | - text: "shinystan" 29 | href: http://mc-stan.org/shinystan 30 | - text: "loo" 31 | href: http://mc-stan.org/loo 32 | - text: "projpred" 33 | href: http://mc-stan.org/projpred 34 | - text: "rstantools" 35 | href: http://mc-stan.org/rstantools 36 | - text: "posterior" 37 | href: https://mc-stan.org/posterior 38 | - text: "Stan" 39 | href: http://mc-stan.org 40 | right: 41 | - icon: fa-twitter 42 | href: https://twitter.com/mcmc_stan 43 | - icon: fa-github 44 | href: https://github.com/hyunjimoon/SBC 45 | - icon: fa-users 46 | href: http://discourse.mc-stan.org/ 47 | 48 | home: 49 | links: 50 | - text: Ask a question 51 | href: http://discourse.mc-stan.org/ 52 | 53 | articles: 54 | - title: "Getting started" 55 | desc: > 56 | Understanding the basic usage and philosophy of the package 57 | contents: 58 | - SBC 59 | - rank_visualizations 60 | - title: "Using SBC for debugging/validating Stan models" 61 | desc: > 62 | Case studies showing how problems in a Stan model can be discovered with SBC. 63 | contents: 64 | - bad_parametrization 65 | - indexing 66 | - small_model_workflow 67 | - title: "Additional use cases and advanced topics" 68 | contents: 69 | - limits_of_SBC 70 | - computational_algorithm1 71 | - implementing_backends 72 | - brms 73 | - discrete_vars 74 | - rejection_sampling 75 | 76 | reference: 77 | - title: Datasets 78 | desc: Generating datasets ready for use with SBC and working with them. 79 | - contents: 80 | - contains("dataset") 81 | - starts_with("SBC_generator_") 82 | - calculate_prior_sd 83 | - title: Backends 84 | desc: Represent various inference engines you can use with SBC. 85 | - contents: 86 | - starts_with("SBC_backend") 87 | - starts_with("SBC_fit") 88 | - title: Computation & results 89 | desc: Functions related to running the SBC computation and handling the results. 90 | - contents: 91 | - compute_SBC 92 | - contains("SBC_results") 93 | - contains("derived_quantities") 94 | - contains("dquants") 95 | - bind_globals 96 | - SBC_statistics_from_single_fit 97 | - recompute_SBC_statistics 98 | - bind_results 99 | - calculate_ranks_draws_matrix 100 | - contains("diagnostic") 101 | - default_chunk_size 102 | - default_cores_per_fit 103 | - title: Plotting & Summarising 104 | desc: Plotting and summarising results 105 | - contents: 106 | - contains("plot") 107 | - guess_rank_hist_bins 108 | - empirical_coverage 109 | - starts_with("combine_") 110 | - title: Examples 111 | desc: Functions to let you easily test the pacakge 112 | - contents: 113 | - contains("example") 114 | - title: Miscellaneous 115 | - contents: 116 | - combine_args 117 | 118 | footer: 119 | structure: 120 | left: [developed_by, break, built_with] 121 | right: analytics 122 | components: 123 | break : "\n\n" 124 | analytics: | 125 | This site uses [Plausible.io](https://plausible.io) for privacy-friendly web analytics (no cookies, no tracking). 126 | 127 | Our stats are public at: https://plausible.io/hyunjimoon.github.io 128 | -------------------------------------------------------------------------------- /docs/articles/SBC_files/figure-html/ecdf-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/SBC_files/figure-html/ecdf-1.png -------------------------------------------------------------------------------- /docs/articles/SBC_files/figure-html/ecdf_diff-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/SBC_files/figure-html/ecdf_diff-1.png -------------------------------------------------------------------------------- /docs/articles/SBC_files/figure-html/rank_hist-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/SBC_files/figure-html/rank_hist-1.png -------------------------------------------------------------------------------- /docs/articles/bad_parametrization_files/figure-html/results1_ecdf_diff-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/bad_parametrization_files/figure-html/results1_ecdf_diff-1.png -------------------------------------------------------------------------------- /docs/articles/bad_parametrization_files/figure-html/results1_other-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/bad_parametrization_files/figure-html/results1_other-1.png -------------------------------------------------------------------------------- /docs/articles/bad_parametrization_files/figure-html/results2_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/bad_parametrization_files/figure-html/results2_plots-1.png -------------------------------------------------------------------------------- /docs/articles/bad_parametrization_files/figure-html/results2_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/bad_parametrization_files/figure-html/results2_plots-2.png -------------------------------------------------------------------------------- /docs/articles/brms_files/figure-html/results_func2_fullrank_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/brms_files/figure-html/results_func2_fullrank_plots-1.png -------------------------------------------------------------------------------- /docs/articles/brms_files/figure-html/results_func2_fullrank_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/brms_files/figure-html/results_func2_fullrank_plots-2.png -------------------------------------------------------------------------------- /docs/articles/brms_files/figure-html/results_func2_meanfield_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/brms_files/figure-html/results_func2_meanfield_plots-1.png -------------------------------------------------------------------------------- /docs/articles/brms_files/figure-html/results_func2_meanfield_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/brms_files/figure-html/results_func2_meanfield_plots-2.png -------------------------------------------------------------------------------- /docs/articles/brms_files/figure-html/results_func2_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/brms_files/figure-html/results_func2_plots-1.png -------------------------------------------------------------------------------- /docs/articles/brms_files/figure-html/results_func2_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/brms_files/figure-html/results_func2_plots-2.png -------------------------------------------------------------------------------- /docs/articles/brms_files/figure-html/results_func_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/brms_files/figure-html/results_func_plots-1.png -------------------------------------------------------------------------------- /docs/articles/brms_files/figure-html/results_func_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/brms_files/figure-html/results_func_plots-2.png -------------------------------------------------------------------------------- /docs/articles/brms_files/figure-html/results_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/brms_files/figure-html/results_plots-1.png -------------------------------------------------------------------------------- /docs/articles/brms_files/figure-html/results_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/brms_files/figure-html/results_plots-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_100-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_100-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_100-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_100-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_optimizing-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_optimizing-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_optimizing-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_optimizing-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_optimizing_100-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_optimizing_100-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_optimizing_100-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/ecdf_rank_poisson_optimizing_100-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_2_coverage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_2_coverage-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_2_ecdf_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_2_ecdf_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_2_ecdf_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_2_ecdf_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_coverage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_coverage-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_coverage-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_coverage-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_ecdf_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_ecdf_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_ecdf_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_ecdf_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_fullrank_coverage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_fullrank_coverage-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_fullrank_ecdf_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_fullrank_ecdf_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_fullrank_ecdf_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_fullrank_ecdf_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_lowtol_coverage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_lowtol_coverage-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_lowtol_ecdf_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_lowtol_ecdf_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_lowtol_ecdf_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_lowtol_ecdf_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_optimizing_ecdf_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_optimizing_ecdf_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_optimizing_ecdf_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_optimizing_ecdf_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_ecdf_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_ecdf_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_ecdf_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_ecdf_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_fullrank_ecdf_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_fullrank_ecdf_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_fullrank_ecdf_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_fullrank_ecdf_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_optimizing_ecdf_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_optimizing_ecdf_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_optimizing_ecdf_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_ordered_optimizing_ecdf_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_sample_ecdf_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_sample_ecdf_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_sample_ecdf_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_sample_ecdf_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/computational_algorithm1_files/figure-html/hmm_time-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/computational_algorithm1_files/figure-html/hmm_time-1.png -------------------------------------------------------------------------------- /docs/articles/discrete_vars_files/figure-html/ranks_jags-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/discrete_vars_files/figure-html/ranks_jags-1.png -------------------------------------------------------------------------------- /docs/articles/discrete_vars_files/figure-html/ranks_jags-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/discrete_vars_files/figure-html/ranks_jags-2.png -------------------------------------------------------------------------------- /docs/articles/discrete_vars_files/figure-html/ranks_jags_marginalized-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/discrete_vars_files/figure-html/ranks_jags_marginalized-1.png -------------------------------------------------------------------------------- /docs/articles/discrete_vars_files/figure-html/ranks_jags_marginalized-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/discrete_vars_files/figure-html/ranks_jags_marginalized-2.png -------------------------------------------------------------------------------- /docs/articles/discrete_vars_files/figure-html/results1_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/discrete_vars_files/figure-html/results1_plots-1.png -------------------------------------------------------------------------------- /docs/articles/discrete_vars_files/figure-html/results1_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/discrete_vars_files/figure-html/results1_plots-2.png -------------------------------------------------------------------------------- /docs/articles/discrete_vars_files/figure-html/results_2_all_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/discrete_vars_files/figure-html/results_2_all_plots-1.png -------------------------------------------------------------------------------- /docs/articles/discrete_vars_files/figure-html/results_2_all_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/discrete_vars_files/figure-html/results_2_all_plots-2.png -------------------------------------------------------------------------------- /docs/articles/discrete_vars_files/figure-html/results_2_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/discrete_vars_files/figure-html/results_2_plots-1.png -------------------------------------------------------------------------------- /docs/articles/discrete_vars_files/figure-html/results_2_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/discrete_vars_files/figure-html/results_2_plots-2.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/indo_complex_narrow_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/indo_complex_narrow_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/indo_complex_narrow_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/indo_complex_narrow_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/indo_complex_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/indo_complex_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/indo_complex_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/indo_complex_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/indo_sim_coverage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/indo_sim_coverage-1.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/indo_simple_narrow_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/indo_simple_narrow_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/indo_simple_narrow_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/indo_simple_narrow_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/indo_simple_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/indo_simple_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/indo_simple_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/indo_simple_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/indo_simple_sim_est-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/indo_simple_sim_est-1.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/indo_simple_sim_est_ugly-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/indo_simple_sim_est_ugly-1.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/poisson_ranks-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/poisson_ranks-1.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/poisson_ranks-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/poisson_ranks-2.png -------------------------------------------------------------------------------- /docs/articles/implementing_backends_files/figure-html/poisson_sim_estimated-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/implementing_backends_files/figure-html/poisson_sim_estimated-1.png -------------------------------------------------------------------------------- /docs/articles/indexing_files/figure-html/plots_regression1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/indexing_files/figure-html/plots_regression1-1.png -------------------------------------------------------------------------------- /docs/articles/indexing_files/figure-html/plots_regression1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/indexing_files/figure-html/plots_regression1-2.png -------------------------------------------------------------------------------- /docs/articles/indexing_files/figure-html/plots_regression2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/indexing_files/figure-html/plots_regression2-1.png -------------------------------------------------------------------------------- /docs/articles/indexing_files/figure-html/plots_regression2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/indexing_files/figure-html/plots_regression2-2.png -------------------------------------------------------------------------------- /docs/articles/indexing_files/figure-html/plots_regression3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/indexing_files/figure-html/plots_regression3-1.png -------------------------------------------------------------------------------- /docs/articles/indexing_files/figure-html/plots_regression3-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/indexing_files/figure-html/plots_regression3-2.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/dens_compare-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/dens_compare-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/log_dens_compare-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/log_dens_compare-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_corr-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_corr-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_corr-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_corr-2.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_corr_dq-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_corr_dq-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_corr_dq-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_corr_dq-2.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_minor_100_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_minor_100_plots-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_minor_100_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_minor_100_plots-2.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_minor_10_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_minor_10_plots-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_minor_10_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_minor_10_plots-2.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_minor_200_coverage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_minor_200_coverage-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_minor_200_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_minor_200_plots-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_minor_200_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_minor_200_plots-2.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_minor_200_sim_estimated-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_minor_200_sim_estimated-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_missing_2_contraction-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_missing_2_contraction-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_missing_2_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_missing_2_plots-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_missing_2_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_missing_2_plots-2.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_missing_2_sim_estimated-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_missing_2_sim_estimated-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_missing_contraction-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_missing_contraction-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_missing_dq_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_missing_dq_plots-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_missing_dq_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_missing_dq_plots-2.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_missing_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_missing_plots-1.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_missing_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_missing_plots-2.png -------------------------------------------------------------------------------- /docs/articles/limits_of_SBC_files/figure-html/results_missing_sim_estimated-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/limits_of_SBC_files/figure-html/results_missing_sim_estimated-1.png -------------------------------------------------------------------------------- /docs/articles/overview_wide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/overview_wide.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/coverage_50-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/coverage_50-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/coverage_diff_50-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/coverage_diff_50-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/densities-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/densities-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/ecdf_1000-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/ecdf_1000-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/ecdf_50-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/ecdf_50-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/ecdf_diff_1000-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/ecdf_diff_1000-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/ecdf_diff_50-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/ecdf_diff_50-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/rank_hist_1000-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/rank_hist_1000-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/rank_hist_50_100-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/rank_hist_50_100-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/rank_hist_50_17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/rank_hist_50_17-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/rank_hist_50_default-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/rank_hist_50_default-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/side_by_side_1000_exact_match-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/side_by_side_1000_exact_match-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/side_by_side_50_exact_match-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/side_by_side_50_exact_match-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/side_by_side_50_overest-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/side_by_side_50_overest-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/side_by_side_50_too_certain-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/side_by_side_50_too_certain-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/side_by_side_50_too_uncertain-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/side_by_side_50_too_uncertain-1.png -------------------------------------------------------------------------------- /docs/articles/rank_visualizations_files/figure-html/side_by_side_50_underest-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rank_visualizations_files/figure-html/side_by_side_50_underest-1.png -------------------------------------------------------------------------------- /docs/articles/rejection_sampling_files/figure-html/reject_unobserved_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rejection_sampling_files/figure-html/reject_unobserved_plots-1.png -------------------------------------------------------------------------------- /docs/articles/rejection_sampling_files/figure-html/reject_unobserved_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rejection_sampling_files/figure-html/reject_unobserved_plots-2.png -------------------------------------------------------------------------------- /docs/articles/rejection_sampling_files/figure-html/reject_y_plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rejection_sampling_files/figure-html/reject_y_plot-1.png -------------------------------------------------------------------------------- /docs/articles/rejection_sampling_files/figure-html/reject_y_plot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rejection_sampling_files/figure-html/reject_y_plot-2.png -------------------------------------------------------------------------------- /docs/articles/rejection_sampling_files/figure-html/results1_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rejection_sampling_files/figure-html/results1_plots-1.png -------------------------------------------------------------------------------- /docs/articles/rejection_sampling_files/figure-html/results1_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/rejection_sampling_files/figure-html/results1_plots-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs_subset-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs_subset-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs_subset-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs_subset-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs_subset-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs_subset-3.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs_subset-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs_subset-4.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs_subset-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/beta_first_10_pairs_subset-5.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/beta_first_results-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/beta_first_results-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/beta_first_results-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/beta_first_results-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/combined_fanos-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/combined_fanos-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/combined_reject_coverage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/combined_reject_coverage-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/combined_reject_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/combined_reject_plots-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/combined_reject_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/combined_reject_plots-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/fanos_divergent-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/fanos_divergent-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/mixture_first_convergence-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/mixture_first_convergence-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/mixture_fixed_log_mix_pairs-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/mixture_fixed_log_mix_pairs-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/mixture_fixed_log_mix_rhat-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/mixture_fixed_log_mix_rhat-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/mixture_fixed_ordered_pairs-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/mixture_fixed_ordered_pairs-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/mixture_fixed_ordered_subset_coverage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/mixture_fixed_ordered_subset_coverage-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/mixture_fixed_ordered_subset_results-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/mixture_fixed_ordered_subset_results-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/mixture_fixed_ordered_subset_results-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/mixture_fixed_ordered_subset_results-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_beta_precision_100_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_beta_precision_100_plots-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_beta_precision_100_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_beta_precision_100_plots-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_beta_precision_10_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_beta_precision_10_plots-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_beta_precision_10_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_beta_precision_10_plots-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_beta_precision_fixed_prior_200_coverage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_beta_precision_fixed_prior_200_coverage-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_beta_precision_fixed_prior_200_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_beta_precision_fixed_prior_200_plots-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_beta_precision_fixed_prior_200_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_beta_precision_fixed_prior_200_plots-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_beta_precision_fixed_prior_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_beta_precision_fixed_prior_plots-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_beta_precision_fixed_prior_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_beta_precision_fixed_prior_plots-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_combined_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_combined_plots-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_combined_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_combined_plots-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_combined_reject_more_coverage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_combined_reject_more_coverage-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_combined_reject_more_plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_combined_reject_more_plots-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_combined_reject_more_plots-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_combined_reject_more_plots-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_fixed_ordered_combined_results-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_fixed_ordered_combined_results-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_fixed_ordered_combined_results-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_fixed_ordered_combined_results-2.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/results_fixed_ordered_combined_results_coverage-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/results_fixed_ordered_combined_results_coverage-1.png -------------------------------------------------------------------------------- /docs/articles/small_model_workflow_files/figure-html/sim_estimated_final-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/articles/small_model_workflow_files/figure-html/sim_estimated_final-1.png -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: '3.2' 2 | pkgdown: 2.1.1 3 | pkgdown_sha: ~ 4 | articles: 5 | bad_parametrization: bad_parametrization.html 6 | brms: brms.html 7 | computational_algorithm1: computational_algorithm1.html 8 | discrete_vars: discrete_vars.html 9 | implementing_backends: implementing_backends.html 10 | indexing: indexing.html 11 | limits_of_SBC: limits_of_SBC.html 12 | rank_visualizations: rank_visualizations.html 13 | rejection_sampling: rejection_sampling.html 14 | SBC: SBC.html 15 | small_model_workflow: small_model_workflow.html 16 | last_built: 2025-02-14T20:42Z 17 | urls: 18 | reference: https://hyunjimoon.github.io/SBC/reference 19 | article: https://hyunjimoon.github.io/SBC/articles 20 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/SBC_backend_default_thin_ranks.default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/SBC_backend_iid_draws.default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/SBC_fit_to_draws_matrix.default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/bind_generated_quantities.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/check_all_SBC_diagnostics.SBC_results.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/check_all_SBC_diagnostics.default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/combine_array_elements.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/compute_gen_quants.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/compute_results.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/generated_quantities.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/get_diagnostic_messages.default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/plot_coverage_diff.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/plot_ecdf_diff.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/recompute_statistics.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/validate_generated_quantities.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry(bibtype = "Article", 2 | title = "Simulation-based calibration checking for Bayesian computation: The choice of test quantities shapes sensitivity", 3 | author = c(person("Martin", "Modrák"), 4 | person("Angie H.", "Moon"), 5 | person("Shinyoung", "Kim"), 6 | person("Paul", "Bürkner"), 7 | person("Niko", "Huurre"), 8 | person("Kateřina", "Faltejsková"), 9 | person( "Andrew", "Gelman"), 10 | person("Aki", "Vehtari")), 11 | year = "2023", 12 | journal = "Bayesian Analysis", 13 | volume = "Advance publication", 14 | doi = "10.1214/23-BA1404", 15 | textVersion = paste("Modrák, M., Moon, A. H., Kim, S., Bürkner, P., Huurre, N., Faltejsková, K., Gelman, A., & Vehtari, A. (2023).", 16 | "Simulation-based calibration checking for Bayesian computation: The choice of test quantities shapes sensitivity.", 17 | "Bayesian Analysis, Advance publication.") 18 | ) 19 | -------------------------------------------------------------------------------- /inst/normal_bad.jags: -------------------------------------------------------------------------------- 1 | model { 2 | for(i in 1:N) { 3 | y[i] ~ dnorm(mu, sigma); 4 | } 5 | mu ~ dnorm(0, 1); 6 | sigma ~ dnorm(0, 1) T(0,); 7 | } 8 | -------------------------------------------------------------------------------- /inst/normal_bad.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; 3 | vector[N] y; 4 | } 5 | 6 | parameters { 7 | real mu; 8 | real sigma; 9 | } 10 | 11 | model { 12 | y ~ normal(mu, 1/sigma^2); 13 | mu ~ normal(0, 1); 14 | sigma ~ normal(0, 1); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /inst/normal_sd.jags: -------------------------------------------------------------------------------- 1 | model { 2 | for(i in 1:N) { 3 | y[i] ~ dnorm(mu, 1/sigma^2); 4 | } 5 | mu ~ dnorm(0, 1); 6 | sigma ~ dnorm(0, 1) T(0,); 7 | } 8 | -------------------------------------------------------------------------------- /inst/normal_sd.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; 3 | vector[N] y; 4 | } 5 | 6 | parameters { 7 | real mu; 8 | real sigma; 9 | } 10 | 11 | model { 12 | y ~ normal(mu, sigma); 13 | mu ~ normal(0, 1); 14 | sigma ~ normal(0, 1); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /man/ECDF-plots.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{plot_ecdf} 4 | \alias{plot_ecdf} 5 | \alias{plot_ecdf_diff} 6 | \title{Plot the ECDF-based plots.} 7 | \usage{ 8 | plot_ecdf( 9 | x, 10 | variables = NULL, 11 | K = NULL, 12 | gamma = NULL, 13 | prob = 0.95, 14 | size = 1, 15 | alpha = 0.33, 16 | combine_variables = NULL, 17 | ecdf_alpha = NULL, 18 | ..., 19 | parameters = NULL 20 | ) 21 | 22 | plot_ecdf_diff( 23 | x, 24 | variables = NULL, 25 | K = NULL, 26 | gamma = NULL, 27 | prob = 0.95, 28 | size = 1, 29 | alpha = 0.33, 30 | combine_variables = NULL, 31 | ecdf_alpha = NULL, 32 | ..., 33 | parameters = NULL 34 | ) 35 | } 36 | \arguments{ 37 | \item{x}{object supporting the \code{\link[=data_for_ecdf_plots]{data_for_ecdf_plots()}} method.} 38 | 39 | \item{variables}{optional subset of variables to show in the plot} 40 | 41 | \item{K}{number of uniformly spaced evaluation points for the ECDF or ECDFs. Affects 42 | the granularity of the plot and can significantly speed up the computation 43 | of the simultaneous confidence bands. Default value is chosen heuristically. 44 | You can also use \code{"max"} to represent 45 | the number of ranks or \code{"min"} to choose a lower but still sensible value.} 46 | 47 | \item{gamma}{TODO} 48 | 49 | \item{prob}{the width of the plotted confidence interval for the ECDF.} 50 | 51 | \item{size}{size passed to \code{\link[ggplot2:geom_ribbon]{ggplot2::geom_ribbon()}} for the confidence band} 52 | 53 | \item{alpha}{alpha level of the confidence band} 54 | 55 | \item{combine_variables}{optionally specify a named list where each entry is a character 56 | vectors which specifies a group of variables that will be displayed in the 57 | same panel. Panel title will be the name of the list element. 58 | A function that takes a character vector as an input and produces a list 59 | can also be specified (see \link{combine-functions}).} 60 | 61 | \item{ecdf_alpha}{the alpha level of the empirical CDF. Can be either a single number or 62 | a function taking the number of variables that were combined (when \code{combine_variables} 63 | is specified) and returns a number. By default, plots showing many 64 | ECDFs will have reduced alpha.} 65 | 66 | \item{...}{additional arguments passed to \code{\link[=data_for_ecdf_plots]{data_for_ecdf_plots()}}. 67 | Most notably, if \code{x} is matrix, a \code{max_rank} parameter needs to be given.} 68 | 69 | \item{parameters}{DEPRECATED, use \code{variables} instead.} 70 | } 71 | \description{ 72 | See \code{vignette("rank_visualizations")} for 73 | more details. 74 | See the methods for \code{\link[=data_for_ecdf_plots]{data_for_ecdf_plots()}} for available data formats. 75 | } 76 | \details{ 77 | \href{https://arxiv.org/abs/1903.08008}{arxiv::1903.08008} by A. Vehtari et al. 78 | } 79 | \seealso{ 80 | \code{\link[=plot_coverage]{plot_coverage()}} 81 | } 82 | -------------------------------------------------------------------------------- /man/SBC-deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SBC-deprecated.R, R/derived-quantities.R, 3 | % R/results.R 4 | \name{SBC-deprecated} 5 | \alias{SBC-deprecated} 6 | \alias{generated_quantities} 7 | \alias{validate_generated_quantities} 8 | \alias{bind_generated_quantities} 9 | \alias{compute_gen_quants} 10 | \alias{compute_results} 11 | \alias{recompute_statistics} 12 | \title{Deprecated functions in package \pkg{SBC}.} 13 | \usage{ 14 | generated_quantities(...) 15 | 16 | validate_generated_quantities(...) 17 | 18 | bind_generated_quantities(...) 19 | 20 | compute_gen_quants(...) 21 | 22 | compute_results(...) 23 | 24 | recompute_statistics(...) 25 | } 26 | \description{ 27 | The functions listed below are deprecated and will be defunct in 28 | the near future. When possible, alternative functions with similar 29 | functionality are also mentioned. Help pages for deprecated functions are 30 | available at \code{help("-deprecated")}. 31 | } 32 | \section{\code{generated_quantities}}{ 33 | 34 | Instead of \code{generated_quantities}, use \code{\link{derived_quantities}}. 35 | } 36 | 37 | \section{\code{validate_generated_quantities}}{ 38 | 39 | Instead of \code{validate_generated_quantities}, use \code{\link{validate_derived_quantities}}. 40 | } 41 | 42 | \section{\code{bind_generated_quantities}}{ 43 | 44 | Instead of \code{bind_generated_quantities}, use \code{\link{bind_derived_quantities}}. 45 | } 46 | 47 | \section{\code{compute_gen_quants}}{ 48 | 49 | Instead of \code{compute_gen_quants}, use \code{\link{compute_dquants}}. 50 | } 51 | 52 | \section{\code{compute_results}}{ 53 | 54 | Instead of \code{compute_results}, use \code{\link{compute_SBC}}. 55 | } 56 | 57 | \section{\code{recompute_statistics}}{ 58 | 59 | Instead of \code{recompute_statistics}, use \code{\link{recompute_SBC_statistics}}. 60 | } 61 | 62 | \keyword{internal} 63 | -------------------------------------------------------------------------------- /man/SBC_backend_brms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backend-brms.R 3 | \name{SBC_backend_brms} 4 | \alias{SBC_backend_brms} 5 | \title{Build a backend based on the \code{brms} package.} 6 | \usage{ 7 | SBC_backend_brms( 8 | ..., 9 | template_data, 10 | out_stan_file = NULL, 11 | template_dataset = NULL 12 | ) 13 | } 14 | \arguments{ 15 | \item{...}{arguments passed to \code{brm}.} 16 | 17 | \item{template_data}{a representative value for the \code{data} argument in \code{brm} 18 | that can be used to generate code.} 19 | 20 | \item{out_stan_file}{A filename for the generated Stan code. Useful for 21 | debugging and for avoiding unnecessary recompilations.} 22 | 23 | \item{template_dataset}{DEPRECATED. Use \code{template_data}} 24 | } 25 | \description{ 26 | Build a backend based on the \code{brms} package. 27 | } 28 | -------------------------------------------------------------------------------- /man/SBC_backend_brms_from_generator.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backend-brms.R 3 | \name{SBC_backend_brms_from_generator} 4 | \alias{SBC_backend_brms_from_generator} 5 | \title{Build a brms backend, reusing the compiled model from a previously created \code{SBC_generator_brms} 6 | object.} 7 | \usage{ 8 | SBC_backend_brms_from_generator(generator, ...) 9 | } 10 | \description{ 11 | Build a brms backend, reusing the compiled model from a previously created \code{SBC_generator_brms} 12 | object. 13 | } 14 | -------------------------------------------------------------------------------- /man/SBC_backend_cmdstan_sample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backend-cmdstanr.R 3 | \name{SBC_backend_cmdstan_sample} 4 | \alias{SBC_backend_cmdstan_sample} 5 | \title{Backend based on sampling via \code{cmdstanr}.} 6 | \usage{ 7 | SBC_backend_cmdstan_sample(model, ..., init_factory = NULL) 8 | } 9 | \arguments{ 10 | \item{model}{an object of class \code{CmdStanModel} (as created by \code{cmdstanr::cmdstan_model})} 11 | 12 | \item{...}{other arguments passed to the \verb{$sample()} method of the model. The \code{data} and 13 | \code{parallel_chains} arguments cannot be set this way as they need to be controlled by the SBC 14 | package.} 15 | 16 | \item{init_factory}{an optional function that takes in a dataset and returns a value that 17 | can be passed to the \code{init} argument of \verb{$sample()}. This allows for data-dependent inits. 18 | The caching mechanism in \code{\link[=compute_SBC]{compute_SBC()}} ignores the environment of the function, i.e. 19 | if the init factory takes values from its environment and those values change between 20 | runs, this will not by itself cause cached results to be recomputed.} 21 | } 22 | \description{ 23 | Backend based on sampling via \code{cmdstanr}. 24 | } 25 | -------------------------------------------------------------------------------- /man/SBC_backend_cmdstan_variational.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backend-cmdstanr.R 3 | \name{SBC_backend_cmdstan_variational} 4 | \alias{SBC_backend_cmdstan_variational} 5 | \title{Backend based on variational approximation via \code{cmdstanr}.} 6 | \usage{ 7 | SBC_backend_cmdstan_variational(model, ..., n_retries_init = 1) 8 | } 9 | \arguments{ 10 | \item{model}{an object of class \code{CmdStanModel} (as created by \code{cmdstanr::cmdstan_model})} 11 | 12 | \item{...}{other arguments passed to the \verb{$variational()} method of the model. 13 | The \code{data} argument cannot be set this way as they need to be controlled by the SBC 14 | package.} 15 | 16 | \item{n_retries_init}{number of times to retry the variational fit if the algorithm 17 | has trouble initializing (e.g. too many dropped evaluations 18 | (see https://discourse.mc-stan.org/t/advi-too-many-dropped-evaluations-even-for-well-behaved-models/24338), 19 | or "cannot compute ELBO using the initial variational distribution")} 20 | } 21 | \description{ 22 | Backend based on variational approximation via \code{cmdstanr}. 23 | } 24 | -------------------------------------------------------------------------------- /man/SBC_backend_default_thin_ranks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backends.R 3 | \name{SBC_backend_default_thin_ranks} 4 | \alias{SBC_backend_default_thin_ranks} 5 | \alias{SBC_backend_default_thin_ranks.default} 6 | \title{S3 generic to get backend-specific default thinning for rank computation.} 7 | \usage{ 8 | SBC_backend_default_thin_ranks(backend) 9 | 10 | \method{SBC_backend_default_thin_ranks}{default}(backend) 11 | } 12 | \description{ 13 | The default implementation plays it relatively safe and returns 10, unless 14 | \code{\link[=SBC_backend_iid_draws]{SBC_backend_iid_draws()}} returns \code{TRUE} in which case it returns 1. 15 | } 16 | -------------------------------------------------------------------------------- /man/SBC_backend_hash_for_cache.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backends.R 3 | \name{SBC_backend_hash_for_cache} 4 | \alias{SBC_backend_hash_for_cache} 5 | \title{Get hash used to identify cached results.} 6 | \usage{ 7 | SBC_backend_hash_for_cache(backend) 8 | } 9 | \description{ 10 | S3 generic that allows backends to override how a hash is computed. By default \code{rlang::hash()} 11 | is used. 12 | } 13 | -------------------------------------------------------------------------------- /man/SBC_backend_iid_draws.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backends.R 3 | \name{SBC_backend_iid_draws} 4 | \alias{SBC_backend_iid_draws} 5 | \alias{SBC_backend_iid_draws.default} 6 | \title{S3 generic to let backends signal that they produced independent draws.} 7 | \usage{ 8 | SBC_backend_iid_draws(backend) 9 | 10 | \method{SBC_backend_iid_draws}{default}(backend) 11 | } 12 | \arguments{ 13 | \item{backend}{to check} 14 | } 15 | \description{ 16 | Most backends (e.g. those based on variatns of MCMC) don't produce 17 | independent draws and thus diagnostics like Rhat and ESS are important 18 | and draws may need thinning. Backends that already produce independent 19 | draws (e.g. ADVI/optimizing) can implement this method to return \code{TRUE} 20 | to signal this is the case. If this method returns \code{TRUE}, ESS and Rhat will 21 | always attain their best possible values and \code{\link[=SBC_backend_default_thin_ranks]{SBC_backend_default_thin_ranks()}} 22 | will return \code{1}. 23 | The default implementation returns \code{FALSE}. 24 | } 25 | -------------------------------------------------------------------------------- /man/SBC_backend_mock.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backend-mock.R 3 | \name{SBC_backend_mock} 4 | \alias{SBC_backend_mock} 5 | \title{A mock backend.} 6 | \usage{ 7 | SBC_backend_mock( 8 | result = posterior::draws_matrix(a = rnorm(100)), 9 | output = NULL, 10 | message = NULL, 11 | warning = NULL, 12 | error = NULL 13 | ) 14 | } 15 | \arguments{ 16 | \item{result}{a \code{draws_matrix} that will be returned regardless of the data} 17 | } 18 | \description{ 19 | Mock backend is useful for testing the package. 20 | It will ignore all data passed to it and always 21 | provide \code{result} as the draws generated by the backend. 22 | } 23 | -------------------------------------------------------------------------------- /man/SBC_backend_rjags.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backend-rjags.R 3 | \name{SBC_backend_rjags} 4 | \alias{SBC_backend_rjags} 5 | \title{Create a JAGS backend using \code{rjags}} 6 | \usage{ 7 | SBC_backend_rjags( 8 | file, 9 | n.iter, 10 | n.burnin, 11 | variable.names, 12 | thin = 1, 13 | na.rm = TRUE, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{file}{model file or connection to model code (passed to \code{\link[rjags:jags.model]{rjags::jags.model()}})} 19 | 20 | \item{n.iter}{number of iterations for sampling (passed to [rjags::coda.samples())} 21 | 22 | \item{n.burnin}{number of iterations used for burnin} 23 | 24 | \item{variable.names}{names of variables to monitor (passed to \code{\link[rjags:coda.samples]{rjags::coda.samples()}})} 25 | 26 | \item{thin}{thinning (passed to \code{\link[rjags:coda.samples]{rjags::coda.samples()}})} 27 | 28 | \item{na.rm}{whether to omit variables containing NA (passed to \code{\link[rjags:coda.samples]{rjags::coda.samples()}})} 29 | 30 | \item{...}{additional optional arguments passed to \code{\link[rjags:jags.model]{rjags::jags.model()}} 31 | \itemize{ 32 | \item most notably \code{n.chains}, \code{n.adapt} and \code{inits}. 33 | }} 34 | } 35 | \description{ 36 | Create a JAGS backend using \code{rjags} 37 | } 38 | -------------------------------------------------------------------------------- /man/SBC_backend_rstan_optimizing.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backend-rstan.R 3 | \name{SBC_backend_rstan_optimizing} 4 | \alias{SBC_backend_rstan_optimizing} 5 | \title{SBC backend using the \code{optimizing} method from \code{rstan}.} 6 | \usage{ 7 | SBC_backend_rstan_optimizing(model, ..., n_retries_hessian = 1) 8 | } 9 | \arguments{ 10 | \item{model}{a \code{stanmodel} object (created via \code{rstan::stan_model})} 11 | 12 | \item{...}{other arguments passed to \code{optimizing} (number of iterations, ...). 13 | Argument \code{data} cannot be set this way as they need to be 14 | controlled by the package.} 15 | 16 | \item{n_retries_hessian}{the number of times the backend is allow to retry optimization 17 | (with different seeed) to produce a usable Hessian that can produce draws. In some cases, 18 | the Hessian may be numerically unstable and not be positive definite.} 19 | } 20 | \description{ 21 | SBC backend using the \code{optimizing} method from \code{rstan}. 22 | } 23 | -------------------------------------------------------------------------------- /man/SBC_backend_rstan_sample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backend-rstan.R 3 | \name{SBC_backend_rstan_sample} 4 | \alias{SBC_backend_rstan_sample} 5 | \title{SBC backend using the \code{sampling} method from \code{rstan}.} 6 | \usage{ 7 | SBC_backend_rstan_sample(model, ...) 8 | } 9 | \arguments{ 10 | \item{model}{a \code{stanmodel} object (created via \code{rstan::stan_model})} 11 | 12 | \item{...}{other arguments passed to \code{sampling} (number of iterations, ...). 13 | Arguments \code{data} and \code{cores} cannot be set this way as they need to be 14 | controlled by the package.} 15 | } 16 | \description{ 17 | SBC backend using the \code{sampling} method from \code{rstan}. 18 | } 19 | -------------------------------------------------------------------------------- /man/SBC_datasets.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/datasets.R 3 | \name{SBC_datasets} 4 | \alias{SBC_datasets} 5 | \title{Create new \code{SBC_datasets} object.} 6 | \usage{ 7 | SBC_datasets(variables, generated, parameters = NULL) 8 | } 9 | \arguments{ 10 | \item{variables}{draws of "true" values of unobserved parameters or other derived variables. 11 | An object of class \code{draws_matrix} (from the \code{posterior} package)} 12 | 13 | \item{generated}{a list of objects that can be passed as data to the backend you plan to use. 14 | (e.g. list of values for Stan-based backends, a data frame for \code{SBC_backend_brms})} 15 | 16 | \item{parameters}{DEPRECATED. Use variables instead.} 17 | } 18 | \description{ 19 | In most cases, you may want to use \code{generate_datasets} to build the object, but 20 | for full control, you can also create datasets directly via this function. 21 | } 22 | -------------------------------------------------------------------------------- /man/SBC_example_backend.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/example.R 3 | \name{SBC_example_backend} 4 | \alias{SBC_example_backend} 5 | \title{Construct a backend to be used in the examples.} 6 | \usage{ 7 | SBC_example_backend( 8 | example = c("normal_sd", "normal_bad"), 9 | interface = c("rstan", "cmdstanr", "rjags") 10 | ) 11 | } 12 | \arguments{ 13 | \item{example}{name of the example model. \code{normal_sd} is a simple model fitting 14 | a normal distribution parametrized as mean and standard deviation. 15 | \code{normal_bad} is a model that \emph{tries} to implement the \code{normal_sd} model, 16 | but assumes an incorrect parametrization of the normal distribution. 17 | For Stan-based backends, the model is written as if Stan parametrized 18 | normal distribution with precision (while Stan uses sd), for JAGS-based 19 | backends the model is written as if JAGS parametrized normal distribution 20 | with sd (while JAGS uses precision).} 21 | 22 | \item{interface}{name of the interface to be used to fit the model} 23 | } 24 | \description{ 25 | Note that this will involve compiling a Stan model and may take a while. 26 | } 27 | -------------------------------------------------------------------------------- /man/SBC_example_generator.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/example.R 3 | \name{SBC_example_generator} 4 | \alias{SBC_example_generator} 5 | \title{Construct a generator used in the examples.} 6 | \usage{ 7 | SBC_example_generator(example = c("normal"), N = 100) 8 | } 9 | \arguments{ 10 | \item{example}{name of example} 11 | 12 | \item{N}{size of the dataset the generator should simulate} 13 | } 14 | \value{ 15 | an object that can be passed to \code{\link[=generate_datasets]{generate_datasets()}} 16 | } 17 | \description{ 18 | Construct a generator used in the examples. 19 | } 20 | -------------------------------------------------------------------------------- /man/SBC_example_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/example.R 3 | \name{SBC_example_results} 4 | \alias{SBC_example_results} 5 | \title{Combine an example backend with an example generator to provide full 6 | results that can be used to test other functions in the package.} 7 | \usage{ 8 | SBC_example_results( 9 | example = c("normal_ok", "normal_bad", "visualizations"), 10 | interface = c("rstan", "cmdstanr", "rjags"), 11 | N = 100, 12 | n_sims = 50 13 | ) 14 | } 15 | \arguments{ 16 | \item{example}{\itemize{ 17 | \item name of the example. \code{normal_ok} is an example 18 | where the generator matches the model 19 | (using the \code{normal} generator and \code{normal_sd} backend), while 20 | \code{normal_bad} is an example with a mismatch between the generator and backend 21 | that manifests in SBC (\code{normal_bad} combines the \code{normal} generator with 22 | \code{normal_bad} backend). \code{visualizations} creates a purely artificial results 23 | that are meant to showcase the built-in plots (the \code{interface} parameter will 24 | be ignored). 25 | }} 26 | 27 | \item{interface}{name of the interface to be used for the backend} 28 | 29 | \item{N}{number of datapoints to simulate from the generator for each simulation} 30 | 31 | \item{n_sims}{number of simulations to perform} 32 | } 33 | \description{ 34 | Except for \code{example = "visualizations"}, all examples will actually 35 | compile and fit Stan models and thus may take a while to complete. 36 | } 37 | -------------------------------------------------------------------------------- /man/SBC_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backends.R 3 | \name{SBC_fit} 4 | \alias{SBC_fit} 5 | \title{S3 generic using backend to fit a model to data.} 6 | \usage{ 7 | SBC_fit(backend, generated, cores) 8 | } 9 | \description{ 10 | Needs to be implemented by all backends. 11 | All implementations have to return an object for which you can safely 12 | call \code{\link[=SBC_fit_to_draws_matrix]{SBC_fit_to_draws_matrix()}} and get some draws. 13 | If that's not possible an error should be raised. 14 | } 15 | -------------------------------------------------------------------------------- /man/SBC_fit_to_diagnostics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backends.R 3 | \name{SBC_fit_to_diagnostics} 4 | \alias{SBC_fit_to_diagnostics} 5 | \title{S3 generic to get backend-specific diagnostics.} 6 | \usage{ 7 | SBC_fit_to_diagnostics(fit, fit_output, fit_messages, fit_warnings) 8 | } 9 | \arguments{ 10 | \item{fit}{The fit returned by \code{SBC_fit}} 11 | 12 | \item{fit_output}{a character string capturing what the backend wrote to stdout} 13 | 14 | \item{fit_messages}{a character vector of messages the backend raised} 15 | 16 | \item{fit_warnings}{a character vector of warnings the backend raised} 17 | } 18 | \value{ 19 | an single row \code{data.frame} that includes diagnostics or NULL, if no diagnostics available. 20 | } 21 | \description{ 22 | The diagnostics object has to be a \code{data.frame} but may 23 | inherit additional classes - in particular it may be useful 24 | for the returning object to implement \code{\link[=get_diagnostic_messages]{get_diagnostic_messages()}}. 25 | } 26 | -------------------------------------------------------------------------------- /man/SBC_fit_to_draws_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/backends.R 3 | \name{SBC_fit_to_draws_matrix} 4 | \alias{SBC_fit_to_draws_matrix} 5 | \alias{SBC_fit_to_draws_matrix.default} 6 | \title{S3 generic converting a fitted model to a \code{draws_matrix} object.} 7 | \usage{ 8 | SBC_fit_to_draws_matrix(fit) 9 | 10 | \method{SBC_fit_to_draws_matrix}{default}(fit) 11 | } 12 | \description{ 13 | Needs to be implemented for all types of objects the backend can 14 | return from \code{\link[=SBC_fit]{SBC_fit()}}. Default implementation just calls, 15 | \code{\link[posterior:draws_matrix]{posterior::as_draws_matrix()}}, so if the fit object already supports 16 | this, it will work out of the box. 17 | } 18 | -------------------------------------------------------------------------------- /man/SBC_generator_brms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generator-brms.R 3 | \name{SBC_generator_brms} 4 | \alias{SBC_generator_brms} 5 | \title{Create a brms generator.} 6 | \usage{ 7 | SBC_generator_brms( 8 | formula, 9 | data, 10 | ..., 11 | generate_lp = TRUE, 12 | generate_lp_chunksize = 5000/nrow(data), 13 | out_stan_file = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{formula, data, ...}{arguments passed to \code{brms::brm}} 18 | 19 | \item{generate_lp}{whether to compute the overall log-likelihood of the model 20 | as an additional variable. This can be somewhat computationally expensive, 21 | but improves sensitivity of the SBC process.} 22 | 23 | \item{generate_lp_chunksize}{Will determine whether 24 | the chunk size used with \code{\link[future.apply:future_mapply]{future.apply::future_mapply()}}. Set quite high 25 | by default as the parallelism only benefits for large individual datasets/number of 26 | simulations.} 27 | 28 | \item{out_stan_file}{A filename for the generated Stan code. Useful for 29 | debugging and for avoiding unnecessary recompilations.} 30 | } 31 | \description{ 32 | Brms generator uses a brms model with \code{sample_prior = "only"} to generate 33 | new datasets. 34 | } 35 | -------------------------------------------------------------------------------- /man/SBC_generator_custom.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/datasets.R 3 | \name{SBC_generator_custom} 4 | \alias{SBC_generator_custom} 5 | \title{Wrap a function the creates a complete dataset.} 6 | \usage{ 7 | SBC_generator_custom(f, ...) 8 | } 9 | \arguments{ 10 | \item{f}{function accepting at least an \code{n_sims} argument and returning 11 | and \code{SBC_datasets} object} 12 | 13 | \item{...}{Additional arguments passed to \code{f}} 14 | } 15 | \description{ 16 | This creates a very thin wrapper around the function and can store additional 17 | arguments, but does not do anything more.. 18 | } 19 | \details{ 20 | Running: 21 | 22 | \if{html}{\out{
    }}\preformatted{gen <- SBC_generator_custom(f, <>) 23 | datasets <- generate_datasets(gen, n_sims = my_n_sims) 24 | }\if{html}{\out{
    }} 25 | 26 | is equivalent to just running 27 | 28 | \if{html}{\out{
    }}\preformatted{datasets <- f(<>, n_sims = my_n_sims) 29 | }\if{html}{\out{
    }} 30 | 31 | So whenever you control the code calling \code{generate_datasets}, 32 | it usually makes more sense to just create an \code{SBC_datasets} 33 | object directly and avoid using \code{SBC_generator_custom} and \code{generate_datasets} at all. 34 | \code{SBC_generator_custom} can however be useful, when a code you 35 | do not control calls \code{generate_datasets} for you and the 36 | built-in generators do not provide you with enough flexibility. 37 | } 38 | -------------------------------------------------------------------------------- /man/SBC_generator_function.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/datasets.R 3 | \name{SBC_generator_function} 4 | \alias{SBC_generator_function} 5 | \title{Generate datasets via a function that creates a single dataset.} 6 | \usage{ 7 | SBC_generator_function(f, ...) 8 | } 9 | \arguments{ 10 | \item{f}{function returning a list with elements \code{variables} 11 | (prior draws, a list or anything that can be converted to \code{draws_rvars}) and 12 | \code{generated} (observed dataset, ready to be passed to backend)} 13 | 14 | \item{...}{Additional arguments passed to \code{f}} 15 | } 16 | \description{ 17 | Generate datasets via a function that creates a single dataset. 18 | } 19 | -------------------------------------------------------------------------------- /man/SBC_print_example_model.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/example.R 3 | \name{SBC_print_example_model} 4 | \alias{SBC_print_example_model} 5 | \title{Print the Stan code of a model used in the examples.} 6 | \usage{ 7 | SBC_print_example_model( 8 | example = c("normal_sd", "normal_bad"), 9 | interface = c("rstan", "cmdstanr", "rjags") 10 | ) 11 | } 12 | \arguments{ 13 | \item{example}{name of the example model.} 14 | } 15 | \description{ 16 | Print the Stan code of a model used in the examples. 17 | } 18 | -------------------------------------------------------------------------------- /man/SBC_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{SBC_results} 4 | \alias{SBC_results} 5 | \title{Create an \code{SBC_results} object} 6 | \usage{ 7 | SBC_results( 8 | stats, 9 | fits, 10 | backend_diagnostics, 11 | default_diagnostics, 12 | outputs, 13 | messages, 14 | warnings, 15 | errors 16 | ) 17 | } 18 | \description{ 19 | This will build and validate an \code{SBC_results} object from its constituents. 20 | } 21 | \details{ 22 | The \code{SBC_results} contains the following fields: 23 | \itemize{ 24 | \item \verb{$stats} statistics for all variables and fits (one row per variable-fit combination) 25 | \item \verb{$fits} the raw fits (unless \code{keep_fits = FALSE}) or \code{NULL} if the fit failed 26 | \item \verb{$errors} error messages that caused fit failures 27 | \item \verb{$outputs}, \verb{$messages}, \verb{$warnings} the outputs/messages/warnings written by fits 28 | \item \verb{$default_diagnostics} a data frame of default convergence/correctness diagnostics (one row per fit) 29 | \item \verb{$backend_diagnostics} a data frame of backend-specific diagnostics (one row per fit) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /man/SBC_statistics_from_single_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{SBC_statistics_from_single_fit} 4 | \alias{SBC_statistics_from_single_fit} 5 | \title{Recompute SBC statistics given a single fit.} 6 | \usage{ 7 | SBC_statistics_from_single_fit( 8 | fit, 9 | variables, 10 | generated, 11 | thin_ranks, 12 | ensure_num_ranks_divisor, 13 | dquants, 14 | backend, 15 | gen_quants = NULL 16 | ) 17 | } 18 | \arguments{ 19 | \item{thin_ranks}{how much thinning should be applied to posterior draws before computing 20 | ranks for SBC. Should be large enough to avoid any noticeable autocorrelation of the 21 | thinned draws See details below.} 22 | 23 | \item{ensure_num_ranks_divisor}{Potentially drop some posterior samples to 24 | ensure that this number divides the total number of SBC ranks (see Details).} 25 | 26 | \item{dquants}{Derived quantities to include in SBC. Use \code{\link[=derived_quantities]{derived_quantities()}} to construct them.} 27 | 28 | \item{backend}{the model + sampling algorithm. The built-in backends can be constructed 29 | using \code{\link[=SBC_backend_cmdstan_sample]{SBC_backend_cmdstan_sample()}}, \code{\link[=SBC_backend_cmdstan_variational]{SBC_backend_cmdstan_variational()}}, 30 | \code{\link[=SBC_backend_rstan_sample]{SBC_backend_rstan_sample()}}, \code{\link[=SBC_backend_rstan_optimizing]{SBC_backend_rstan_optimizing()}} and \code{\link[=SBC_backend_brms]{SBC_backend_brms()}}. 31 | (more to come: issue 31, 38, 39). The backend is an S3 class supporting at least the \code{\link[=SBC_fit]{SBC_fit()}}, 32 | \code{\link[=SBC_fit_to_draws_matrix]{SBC_fit_to_draws_matrix()}} methods.} 33 | 34 | \item{gen_quants}{Deprecated, use dquants instead} 35 | } 36 | \description{ 37 | Potentially useful for doing some advanced stuff, but should not 38 | be used in regular workflow. Use \code{\link[=recompute_SBC_statistics]{recompute_SBC_statistics()}} to update 39 | an \verb{[SBC_results]} objects with different \code{thin_ranks} or other settings. 40 | } 41 | \seealso{ 42 | \code{\link[=recompute_SBC_statistics]{recompute_SBC_statistics()}} 43 | } 44 | -------------------------------------------------------------------------------- /man/bind_datasets.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/datasets.R 3 | \name{bind_datasets} 4 | \alias{bind_datasets} 5 | \title{Combine multiple datasets together.} 6 | \usage{ 7 | bind_datasets(...) 8 | } 9 | \arguments{ 10 | \item{...}{datasets to bind} 11 | } 12 | \description{ 13 | Combine multiple datasets together. 14 | } 15 | -------------------------------------------------------------------------------- /man/bind_derived_quantities.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/derived-quantities.R 3 | \name{bind_derived_quantities} 4 | \alias{bind_derived_quantities} 5 | \title{Combine two lists of derived quantities} 6 | \usage{ 7 | bind_derived_quantities(dq1, dq2) 8 | } 9 | \description{ 10 | Combine two lists of derived quantities 11 | } 12 | -------------------------------------------------------------------------------- /man/bind_generated_quantities-deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/derived-quantities.R 3 | \name{bind_generated_quantities-deprecated} 4 | \alias{bind_generated_quantities-deprecated} 5 | \title{Combine two lists of derived quantities} 6 | \description{ 7 | Delegates directly to \code{bind_derived_quantities()}. 8 | } 9 | \seealso{ 10 | \code{\link{SBC-deprecated}} 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/bind_globals.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{bind_globals} 4 | \alias{bind_globals} 5 | \title{Combine two sets globals for use in derived quantities or backend} 6 | \usage{ 7 | bind_globals(globals1, globals2) 8 | } 9 | \description{ 10 | Combine two sets globals for use in derived quantities or backend 11 | } 12 | \seealso{ 13 | \code{\link[=compute_SBC]{compute_SBC()}}, \code{\link[=derived_quantities]{derived_quantities()}} 14 | } 15 | -------------------------------------------------------------------------------- /man/bind_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{bind_results} 4 | \alias{bind_results} 5 | \title{Combine multiple SBC results together.} 6 | \usage{ 7 | bind_results(...) 8 | } 9 | \arguments{ 10 | \item{...}{objects of type \code{SBC_results} to be combined.} 11 | } 12 | \description{ 13 | Primarily useful for iteratively adding more simulations to your SBC check. 14 | } 15 | \details{ 16 | An example usage can be found in the \code{small_model_workflow} vignette. 17 | } 18 | -------------------------------------------------------------------------------- /man/brms_full_ppred.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generator-brms.R 3 | \name{brms_full_ppred} 4 | \alias{brms_full_ppred} 5 | \title{Full forward sampling of a the response of brms fit, including multivariate models.} 6 | \usage{ 7 | brms_full_ppred(fit, newdata = NULL, draws = NULL, validate_all = FALSE) 8 | } 9 | \arguments{ 10 | \item{fit}{An object of class \code{brmsfit}} 11 | 12 | \item{newdata}{An optional data.frame for which to evaluate predictions. If NULL (default), the original data of the model is used.} 13 | 14 | \item{draws}{An integer vector specifying the posterior draws to be used. If NULL (the default), all draws are used.} 15 | 16 | \item{validate_all}{if TRUE, validation of input data will be done in all iterations, otherwise only once} 17 | } 18 | \value{ 19 | A list of data.frames containing the draws. 20 | } 21 | \description{ 22 | Full forward sampling of a the response of brms fit, including multivariate models. 23 | } 24 | \examples{ 25 | # Pending 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/brms_response_sequence.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generator-brms.R 3 | \name{brms_response_sequence} 4 | \alias{brms_response_sequence} 5 | \title{Determine the response sequence of brms model} 6 | \usage{ 7 | brms_response_sequence(x) 8 | } 9 | \description{ 10 | Determine the response sequence of brms model 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/calculate_prior_sd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/datasets.R 3 | \name{calculate_prior_sd} 4 | \alias{calculate_prior_sd} 5 | \title{Calculate prior standard deviation of a dataset} 6 | \usage{ 7 | calculate_prior_sd(datasets) 8 | } 9 | \value{ 10 | a named vector of prior SDs 11 | } 12 | \description{ 13 | Calculate prior standard deviation of a dataset 14 | } 15 | -------------------------------------------------------------------------------- /man/calculate_ranks_draws_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{calculate_ranks_draws_matrix} 4 | \alias{calculate_ranks_draws_matrix} 5 | \title{Calculate ranks given variable values within a posterior distribution.} 6 | \usage{ 7 | calculate_ranks_draws_matrix(variables, dm, params = NULL) 8 | } 9 | \arguments{ 10 | \item{variables}{a vector of values to check} 11 | 12 | \item{dm}{draws_matrix of the fit (assumed to be already thinned if that was necessary)} 13 | 14 | \item{params}{DEPRECATED. Use \code{variables} instead.} 15 | } 16 | \description{ 17 | When there are ties (e.g. for discrete variables), the rank is currently drawn stochastically 18 | among the ties. NA is assumed to be potentially equal to any value (Issue #78) 19 | } 20 | -------------------------------------------------------------------------------- /man/check_all_SBC_diagnostics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{check_all_SBC_diagnostics} 4 | \alias{check_all_SBC_diagnostics} 5 | \alias{check_all_SBC_diagnostics.default} 6 | \alias{check_all_SBC_diagnostics.SBC_results} 7 | \title{Check diagnostics and issue warnings when those fail.} 8 | \usage{ 9 | check_all_SBC_diagnostics(x) 10 | 11 | \method{check_all_SBC_diagnostics}{default}(x) 12 | 13 | \method{check_all_SBC_diagnostics}{SBC_results}(x) 14 | } 15 | \value{ 16 | TRUE if all checks are OK, FALSE otherwise. 17 | } 18 | \description{ 19 | Check diagnostics and issue warnings when those fail. 20 | } 21 | -------------------------------------------------------------------------------- /man/combine-functions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{combine_all_variables} 4 | \alias{combine_all_variables} 5 | \alias{combine_array_elements} 6 | \title{Helper functions to be passed to \link{ECDF-plots} to combine variables in a single 7 | panel.} 8 | \usage{ 9 | combine_all_variables(x) 10 | 11 | combine_array_elements(x) 12 | } 13 | \arguments{ 14 | \item{x}{parameter names} 15 | } 16 | \description{ 17 | \code{combine_all_variables} will merge all variables in a single plot, while 18 | \code{combine_array_elements} will merge all elements of any array into a single 19 | panel of the plot 20 | } 21 | -------------------------------------------------------------------------------- /man/combine_args.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/util.R 3 | \name{combine_args} 4 | \alias{combine_args} 5 | \title{Combine two named lists and overwrite elements with the same name 6 | using the value from args2} 7 | \usage{ 8 | combine_args(args1, args2) 9 | } 10 | \description{ 11 | Combine two named lists and overwrite elements with the same name 12 | using the value from args2 13 | } 14 | -------------------------------------------------------------------------------- /man/compute_dquants.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/derived-quantities.R 3 | \name{compute_dquants} 4 | \alias{compute_dquants} 5 | \title{Compute derived quantities based on given data and posterior draws.} 6 | \usage{ 7 | compute_dquants(draws, generated, dquants, gen_quants = NULL) 8 | } 9 | \arguments{ 10 | \item{gen_quants}{Deprecated, use \code{dquants}} 11 | } 12 | \description{ 13 | Compute derived quantities based on given data and posterior draws. 14 | } 15 | -------------------------------------------------------------------------------- /man/compute_gen_quants-deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/derived-quantities.R 3 | \name{compute_gen_quants-deprecated} 4 | \alias{compute_gen_quants-deprecated} 5 | \title{Compute derived quantities based on given data and posterior draws.} 6 | \description{ 7 | Delegates directly to \code{compute_dquants()}. 8 | } 9 | \seealso{ 10 | \code{\link{SBC-deprecated}} 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/compute_results-deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{compute_results-deprecated} 4 | \alias{compute_results-deprecated} 5 | \title{Compute SBC results} 6 | \description{ 7 | Delegates directly to \code{compute_SBC()}. 8 | } 9 | \seealso{ 10 | \code{\link{SBC-deprecated}} 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/data_for_ecdf_plots.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{data_for_ecdf_plots} 4 | \alias{data_for_ecdf_plots} 5 | \title{Maybe not export in the end? Useful for debugging} 6 | \usage{ 7 | data_for_ecdf_plots(x, ..., prob = 0.95, gamma = NULL, K = NULL) 8 | } 9 | \description{ 10 | Maybe not export in the end? Useful for debugging 11 | } 12 | -------------------------------------------------------------------------------- /man/default_chunk_size.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{default_chunk_size} 4 | \alias{default_chunk_size} 5 | \title{Determines the default chunk size.} 6 | \usage{ 7 | default_chunk_size(n_fits, n_workers = future::nbrOfWorkers()) 8 | } 9 | \description{ 10 | By default will make every worker process a single chunk. 11 | You can set the \code{options(SBC.min_chunk_size = value)} to enforce a minimum 12 | chunk size globally (chunk size can still be larger if you have substantially more 13 | fits to run than workers. 14 | } 15 | -------------------------------------------------------------------------------- /man/default_cores_per_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{default_cores_per_fit} 4 | \alias{default_cores_per_fit} 5 | \title{Determines the default cores per single fit.} 6 | \usage{ 7 | default_cores_per_fit( 8 | n_fits, 9 | total_cores = future::availableCores(), 10 | chunk_size = default_chunk_size(n_fits) 11 | ) 12 | } 13 | \description{ 14 | When parallel processing is disabled, this just returns the number of available 15 | cores. Otherwise, it chooses the largest integer that keeps 16 | \code{cores_per_fit * (n_fits / chunk_size) <= total_cores}, i.e. it avoids 17 | running so many chains in parallel that there will be more chains than cores. 18 | } 19 | -------------------------------------------------------------------------------- /man/derived_quantities.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/derived-quantities.R 3 | \name{derived_quantities} 4 | \alias{derived_quantities} 5 | \title{Create a definition of derived quantities evaluated in R.} 6 | \usage{ 7 | derived_quantities(..., .globals = list()) 8 | } 9 | \arguments{ 10 | \item{...}{named expressions representing the quantitites} 11 | 12 | \item{.globals}{A list of names of objects that are defined 13 | in the global environment and need to present for the gen. quants. to evaluate. 14 | It is added to the \code{globals} argument to \code{\link[future:future]{future::future()}}, to make those 15 | objects available on all workers.} 16 | } 17 | \description{ 18 | When the expression contains non-library functions/objects, and parallel processing 19 | is enabled, those must be 20 | named in the \code{.globals} parameter (hopefully we'll be able to detect those 21 | automatically in the future). Note that \code{\link[=recompute_SBC_statistics]{recompute_SBC_statistics()}} currently 22 | does not use parallel processing, so \code{.globals} don't need to be set. 23 | } 24 | \examples{ 25 | # Derived quantity computing the total log likelihood of a normal distribution 26 | # with known sd = 1 27 | normal_lpdf <- function(y, mu, sigma) { 28 | sum(dnorm(y, mean = mu, sd = sigma, log = TRUE)) 29 | } 30 | 31 | # Note the use of .globals to make the normal_lpdf function available 32 | # within the expression 33 | log_lik_dq <- derived_quantities(log_lik = normal_lpdf(y, mu, 1), 34 | .globals = "normal_lpdf" ) 35 | 36 | } 37 | -------------------------------------------------------------------------------- /man/empirical_coverage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/calculate.R 3 | \name{empirical_coverage} 4 | \alias{empirical_coverage} 5 | \title{Compute observed coverage of posterior credible intervals.} 6 | \usage{ 7 | empirical_coverage(stats, width, prob = 0.95, interval_type = "central") 8 | } 9 | \arguments{ 10 | \item{stats}{a data.frame of rank statistics (e.g. as returned in the \verb{$stats} component of \link{SBC_results}), 11 | at minimum should have at least \code{variable}, \code{rank} and \code{max_rank} columns)} 12 | 13 | \item{width}{a vector of values between 0 and 1 representing widths of credible intervals for 14 | which we compute coverage.} 15 | 16 | \item{prob}{determines width of the uncertainty interval around the observed coverage} 17 | 18 | \item{inteval_type}{\code{"central"} to show coverage of central credible intervals 19 | or \code{"leftmost"} to show coverage of leftmost credible intervals (i.e. the observed CDF).} 20 | } 21 | \value{ 22 | A \code{data.frame} with columns \code{variable}, \code{width} (width of the interval as given 23 | in the \code{width} parameter), \code{width_represented} the closest width that can be represented by 24 | the ranks in the input (any discrepancy needs to be judged against this rather than \code{width}), 25 | \code{estimate} - observed coverage for the interval, \code{ci_low}, \code{ci_high} the uncertainty 26 | interval around \code{estimate} (width of the interval is given by the \code{prob} argument). 27 | } 28 | \description{ 29 | Uses ranks to compute coverage and surrounding uncertainty of posterior credible intervals. 30 | The uncertainty is only approximate (treating coverage for each interval as a set of independent 31 | Bernoulli trials, while in fact they are not independent), so for making claims on presence/ 32 | absence of detectable discrepancies we strongly recommend using \code{\link[=plot_ecdf]{plot_ecdf()}} or \code{\link[=plot_ecdf_diff]{plot_ecdf_diff()}}. 33 | The uncertainty about the coverage can however be useful for guiding decisions on whether 34 | more SBC steps should be performed (i.e. whether we can rule out that the coverage of 35 | the given backend differs too much for our purposes from the optimal value). 36 | } 37 | \details{ 38 | Note that while coverage of central posterior intervals (with the default \code{type = "central"}) 39 | is often of the biggest practical interest, perfect calibration of central intervals 40 | still leaves space for substantial problems with the model (e.g. if the posterior 25\% - 50\% intervals 41 | contain 50\% of the true values and the posterior 50\% - 75\% interval never contains the true value, 42 | the central 50\% interval still has the ideal 50\% coverage), so investigating central 43 | intervals should always be accompanied by checks with \code{\link[=plot_ecdf]{plot_ecdf()}} or \code{\link[=plot_ecdf_diff]{plot_ecdf_diff()}} 44 | or by using \code{type = "leftmost"}, because if all leftmost credible intervals are well calibrated, 45 | then all intervals are well calibrated. 46 | } 47 | \seealso{ 48 | \code{\link[=plot_coverage]{plot_coverage()}} 49 | } 50 | -------------------------------------------------------------------------------- /man/generate_datasets.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/datasets.R 3 | \name{generate_datasets} 4 | \alias{generate_datasets} 5 | \title{Generate datasets.} 6 | \usage{ 7 | generate_datasets(generator, n_sims, n_datasets = NULL) 8 | } 9 | \arguments{ 10 | \item{generator}{a generator object - build e.g. via \code{SBC_generator_function} or 11 | \code{SBC_generator_brms}.} 12 | 13 | \item{n_sims}{the number of simulated datasets to use} 14 | 15 | \item{n_datasets}{DEPRECATED, use \code{n_sims} instead.} 16 | } 17 | \value{ 18 | object of class \code{SBC_datasets} 19 | TODO: seed 20 | } 21 | \description{ 22 | Generate datasets. 23 | } 24 | -------------------------------------------------------------------------------- /man/generated_quantities-deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/derived-quantities.R 3 | \name{generated_quantities-deprecated} 4 | \alias{generated_quantities-deprecated} 5 | \title{Create a definition of derived quantities evaluated in R.} 6 | \description{ 7 | Delegates directly to \code{derived_quantities()}. 8 | 9 | Delegates directly to \code{validate_derived_quantities()}. 10 | } 11 | \seealso{ 12 | \code{\link{SBC-deprecated}} 13 | 14 | \code{\link{SBC-deprecated}} 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/get_diagnostic_messages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{get_diagnostic_messages} 4 | \alias{get_diagnostic_messages} 5 | \alias{get_diagnostic_messages.default} 6 | \title{Get diagnostic messages for \code{SBC_results} or other objects.} 7 | \usage{ 8 | get_diagnostic_messages(x) 9 | 10 | \method{get_diagnostic_messages}{default}(x) 11 | } 12 | \value{ 13 | An object of class \code{SBC_diagnostic_messages}, inheriting a data.frame. 14 | } 15 | \description{ 16 | Get diagnostic messages for \code{SBC_results} or other objects. 17 | } 18 | -------------------------------------------------------------------------------- /man/guess_rank_hist_bins.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{guess_rank_hist_bins} 4 | \alias{guess_rank_hist_bins} 5 | \title{Guess the number of bins for \code{\link[=plot_rank_hist]{plot_rank_hist()}}.} 6 | \usage{ 7 | guess_rank_hist_bins(max_rank, N) 8 | } 9 | \arguments{ 10 | \item{max_rank}{the maximum rank observed} 11 | 12 | \item{N}{the number of ranks observed} 13 | } 14 | \description{ 15 | Guess the number of bins for \code{\link[=plot_rank_hist]{plot_rank_hist()}}. 16 | } 17 | -------------------------------------------------------------------------------- /man/plot_contraction.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{plot_contraction} 4 | \alias{plot_contraction} 5 | \title{Prior/posterior contraction plot.} 6 | \usage{ 7 | plot_contraction( 8 | x, 9 | prior_sd, 10 | variables = NULL, 11 | scale = "sd", 12 | alpha = 0.8, 13 | parameters = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{object containing results (a data.frame or \code{\link[=SBC_results]{SBC_results()}} object).} 18 | 19 | \item{prior_sd}{a named vector of prior standard deviations for your variables. 20 | Either pass in analytically obtained values or use \code{\link[=calculate_prior_sd]{calculate_prior_sd()}} to get an empirical estimate from 21 | an \code{SBC_datasets} object.} 22 | 23 | \item{variables}{variables to show in the plot or \code{NULL} to show all 24 | must correspond a field already computed in the results (most likely \code{"mean"} and \code{"median"}).} 25 | 26 | \item{scale}{which scale of variability you want to see - either \code{"sd"} for standard deviation 27 | or \code{"var"} for variance.} 28 | 29 | \item{alpha}{the alpha for the points} 30 | 31 | \item{parameters}{DEPRECATED, use \code{variables} instead.} 32 | } 33 | \value{ 34 | a ggplot2 plot object 35 | } 36 | \description{ 37 | The rationale for this plot and its interpretation is explained in 38 | Mike Betancourt's 39 | \href{https://betanalpha.github.io/assets/case_studies/principled_bayesian_workflow.html#132_A_Bayesian_Eye_Chart}{Towards A Principled Bayesian Workflow}. 40 | } 41 | -------------------------------------------------------------------------------- /man/plot_coverage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{plot_coverage} 4 | \alias{plot_coverage} 5 | \alias{plot_coverage_diff} 6 | \title{Plot the observed coverage and its uncertainty.} 7 | \usage{ 8 | plot_coverage( 9 | x, 10 | variables = NULL, 11 | prob = 0.95, 12 | interval_type = "central", 13 | parameters = NULL, 14 | max_points = NULL 15 | ) 16 | 17 | plot_coverage_diff( 18 | x, 19 | variables = NULL, 20 | prob = 0.95, 21 | interval_type = "central", 22 | parameters = NULL, 23 | max_points = NULL 24 | ) 25 | } 26 | \arguments{ 27 | \item{x}{object containing results (a data.frame or \code{\link[=SBC_results]{SBC_results()}} object).} 28 | 29 | \item{variables}{variables to show in the plot or \code{NULL} to show all} 30 | 31 | \item{prob}{the with of the uncertainty interval to be shown} 32 | 33 | \item{parameters}{DEPRECATED. Use \code{variables} instead.} 34 | 35 | \item{max_points}{maximum number of points where to evaluate the coverage. 36 | If set to \code{NULL}, coverage is evaluated across the whole range of ranks. 37 | Setting to some smaller number may reduce memory footprint and increase speed.} 38 | } 39 | \value{ 40 | a ggplot2 plot object 41 | } 42 | \description{ 43 | \code{plot_coverage} will plot the observed coverage, 44 | while \code{plot_coverage_diff} will show the difference between observed 45 | and expected coverage. 46 | Please refer to \code{\link[=empirical_coverage]{empirical_coverage()}} for details on computation 47 | and limitations of this plot as well as details on the arguments. 48 | See \code{vignette("rank_visualizations")} for 49 | more details. 50 | } 51 | \seealso{ 52 | empirical_coverage 53 | } 54 | -------------------------------------------------------------------------------- /man/plot_rank_hist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{plot_rank_hist} 4 | \alias{plot_rank_hist} 5 | \title{Plot rank histogram of an SBC results.} 6 | \usage{ 7 | plot_rank_hist( 8 | x, 9 | variables = NULL, 10 | bins = NULL, 11 | prob = 0.95, 12 | ..., 13 | parameters = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{Object supporting the plotting method.} 18 | 19 | \item{variables}{Names of variables to show} 20 | 21 | \item{bins}{number of bins to be used in the histogram, if left unspecified, 22 | it is determined by \code{\link[=guess_rank_hist_bins]{guess_rank_hist_bins()}}.} 23 | 24 | \item{prob}{The width of the approximate confidence interval shown.} 25 | } 26 | \description{ 27 | The expected uniform distribution and an approximate confidence interval 28 | is also shown. The confidence interval cannot be taken too seriously 29 | as it is derived assuming the bins are independent (which they are not). 30 | The \code{\link[=plot_ecdf]{plot_ecdf()}} and \code{\link[=plot_ecdf_diff]{plot_ecdf_diff()}} plots provide better confidence interval 31 | but are somewhat less interpretable. See \code{vignette("rank_visualizations")} for 32 | more details. 33 | } 34 | \details{ 35 | By default the support is for \code{SBC_results} objects and data frames in the same 36 | format as the \verb{$stats} element of \code{SBC_results}. 37 | } 38 | -------------------------------------------------------------------------------- /man/plot_sim_estimated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{plot_sim_estimated} 4 | \alias{plot_sim_estimated} 5 | \title{Plot the simulated "true" values versus posterior estimates} 6 | \usage{ 7 | plot_sim_estimated( 8 | x, 9 | variables = NULL, 10 | estimate = "mean", 11 | uncertainty = c("q5", "q95"), 12 | alpha = NULL, 13 | parameters = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{object containing results (a data.frame or \code{\link[=SBC_results]{SBC_results()}} object).} 18 | 19 | \item{variables}{variables to show in the plot or \code{NULL} to show all} 20 | 21 | \item{estimate}{which estimate to use for the central tendency, 22 | must correspond a field already computed in the results (most likely \code{"mean"} and \code{"median"}).} 23 | 24 | \item{uncertainty}{which estimates to use for uncertainty (a character vector of length 2) 25 | must correspond a field already computed in the results. Pass \code{NULL} to avoid showing uncertainty at all.} 26 | 27 | \item{alpha}{the alpha for the points and uncertainty intervals} 28 | 29 | \item{parameters}{DEPRECATED, use \code{variables} instead} 30 | } 31 | \value{ 32 | a ggplot2 plot object 33 | } 34 | \description{ 35 | Plot the simulated "true" values versus posterior estimates 36 | } 37 | -------------------------------------------------------------------------------- /man/rdunif.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{rdunif} 4 | \alias{rdunif} 5 | \title{Discrete uniform distribution allowing for varying lower and upper bounds.} 6 | \usage{ 7 | rdunif(n, a, b) 8 | } 9 | \description{ 10 | Internal, should not be exported. 11 | Based on https://stats.stackexchange.com/a/3939/73129 12 | } 13 | \keyword{internal} 14 | -------------------------------------------------------------------------------- /man/recompute_SBC_statistics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{recompute_SBC_statistics} 4 | \alias{recompute_SBC_statistics} 5 | \title{Recompute SBC statistics without refitting models.} 6 | \usage{ 7 | recompute_SBC_statistics( 8 | old_results, 9 | datasets, 10 | backend, 11 | thin_ranks = SBC_backend_default_thin_ranks(backend), 12 | ensure_num_ranks_divisor = 2, 13 | dquants = NULL, 14 | gen_quants = NULL 15 | ) 16 | } 17 | \arguments{ 18 | \item{datasets}{an object of class \code{SBC_datasets}} 19 | 20 | \item{backend}{backend used to fit the results. Used to pull various defaults 21 | and other setting influencing the computation of statistics.} 22 | 23 | \item{thin_ranks}{how much thinning should be applied to posterior draws before computing 24 | ranks for SBC. Should be large enough to avoid any noticeable autocorrelation of the 25 | thinned draws See details below.} 26 | 27 | \item{ensure_num_ranks_divisor}{Potentially drop some posterior samples to 28 | ensure that this number divides the total number of SBC ranks (see Details).} 29 | 30 | \item{dquants}{Derived quantities to include in SBC. Use \code{\link[=derived_quantities]{derived_quantities()}} to construct them.} 31 | 32 | \item{gen_quants}{Deprecated, use dquants instead} 33 | } 34 | \value{ 35 | An S3 object of class \code{SBC_results} with updated \verb{$stats} and \verb{$default_diagnostics} fields. 36 | } 37 | \description{ 38 | Useful for example to recompute SBC ranks with a different choice of \code{thin_ranks} 39 | or added derived quantities. 40 | } 41 | -------------------------------------------------------------------------------- /man/recompute_statistics-deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{recompute_statistics-deprecated} 4 | \alias{recompute_statistics-deprecated} 5 | \title{Recompute SBC statistics without refitting models.} 6 | \description{ 7 | Delegates directly to \code{recompute_SBC_statistics()}. 8 | } 9 | \seealso{ 10 | \code{\link{SBC-deprecated}} 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/sub-.SBC_datasets.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/datasets.R 3 | \name{[.SBC_datasets} 4 | \alias{[.SBC_datasets} 5 | \title{Subset an \code{SBC_datasets} object.} 6 | \usage{ 7 | \method{[}{SBC_datasets}(x, indices) 8 | } 9 | \description{ 10 | Subset an \code{SBC_datasets} object. 11 | } 12 | -------------------------------------------------------------------------------- /man/sub-.SBC_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/results.R 3 | \name{[.SBC_results} 4 | \alias{[.SBC_results} 5 | \title{Subset the results.} 6 | \usage{ 7 | \method{[}{SBC_results}(x, indices) 8 | } 9 | \arguments{ 10 | \item{indices}{integer indices or a binary vector of the same length as the number fits, 11 | selecting which fits to keep.} 12 | } 13 | \description{ 14 | Subset the results. 15 | } 16 | -------------------------------------------------------------------------------- /man/validate_derived_quantities.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/derived-quantities.R 3 | \name{validate_derived_quantities} 4 | \alias{validate_derived_quantities} 5 | \title{Validate a definition of derived quantities evaluated in R.} 6 | \usage{ 7 | validate_derived_quantities(x) 8 | } 9 | \description{ 10 | Validate a definition of derived quantities evaluated in R. 11 | } 12 | -------------------------------------------------------------------------------- /pkgdown/templates/in-header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/testthat/test-backends.R: -------------------------------------------------------------------------------- 1 | test_that("draws_rvars_to_standata converts properly", { 2 | 3 | scalar_var <- 1 4 | vector_var <- array(1:10, 10) 5 | matrix_var <- array(1:12, c(3,4)) 6 | 7 | list_val <- list(scalar_var = scalar_var, 8 | vector_var = vector_var, 9 | matrix_var = matrix_var) 10 | 11 | rvar_val <- posterior::draws_rvars(scalar_var = posterior::rvar(scalar_var), 12 | vector_var = posterior::rvar(array(vector_var, dim = c(1, dim(vector_var))), dim = dim(vector_var)), 13 | matrix_var = posterior::rvar(array(matrix_var, dim = c(1, dim(matrix_var))), dim = dim(matrix_var))) 14 | 15 | expect_equal(draws_rvars_to_standata_single(rvar_val), list_val) 16 | }) 17 | 18 | -------------------------------------------------------------------------------- /tests/testthat/test-brms.R: -------------------------------------------------------------------------------- 1 | test_that("Response sequences for univariate and multivariate models", { 2 | # TODO: the order within each list element shouldn't matter, 3 | # but now tests are sensitive to change in that order. 4 | # Keep that in mind when investigating test failures 5 | 6 | expect_equal(brms_response_sequence( 7 | brms::bf(y ~ x)), 8 | list("y")) 9 | 10 | expect_equal(brms_response_sequence( 11 | brms::bf(y ~ x) + brms::bf(y2 ~ x) + brms::set_rescor(FALSE)), 12 | list(c("y", "y2"))) 13 | 14 | expect_equal(brms_response_sequence( 15 | brms::bf(z ~ y) + brms::bf(y ~ x) + brms::set_rescor(FALSE)), 16 | list("y", "z")) 17 | 18 | expect_equal(brms_response_sequence( 19 | brms::bf(q ~ y, shape ~ z, family = "negbinomial") + brms::bf(z ~ y + r) + brms::bf(y ~ x) + brms::bf(r ~ x) + brms::set_rescor(FALSE)), 20 | list(c("y", "r"), "z", "q")) 21 | 22 | expect_equal(brms_response_sequence( 23 | brms::bf(q ~ y, shape ~ x, family = "negbinomial") + brms::bf(z ~ y + r) + brms::bf(y ~ x) + brms::bf(r ~ x) + brms::set_rescor(FALSE)), 24 | list(c("y", "r"), c("q", "z"))) 25 | }) 26 | -------------------------------------------------------------------------------- /tests/testthat/test-datasets.R: -------------------------------------------------------------------------------- 1 | test_that("Generating datasets via functions", { 2 | list_function <- function(N) { 3 | mu <- rnorm(1) 4 | sigma <- abs(rnorm(1)) 5 | beta <- matrix(1:6, nrow = 3, ncol = 2) 6 | gamma <- array(1:12, dim = c(2,3,2)) 7 | delta <- rnorm(3) 8 | names(delta) <- LETTERS[1:3] 9 | y1 <- rnorm(N, mu, sigma) 10 | y2 <- rnorm(2 * N, mu + 5, sigma) 11 | list(variables = list(mu = mu, sigma = sigma, beta = beta, gamma = gamma, delta = delta), 12 | generated = list(y1 = y1, y2 = y2)) 13 | } 14 | 15 | res <- generate_datasets( 16 | SBC_generator_function(list_function, N = 10), 17 | n_sims = 7) 18 | 19 | expect_true(length(res) == 7) 20 | 21 | beta_vars <- paste0("beta[", rep(1:3, times = 2), ",", rep(1:2, each = 3), "]") 22 | gamma_vars <- paste0("gamma[", rep(1:2, times = 6), ",", rep(rep(1:3, each = 2), times = 2), 23 | ",", rep(1:2, each = 6), "]") 24 | delta_vars <- paste0("delta[",LETTERS[1:3],"]") 25 | expect_identical(posterior::variables(res$variables), c("mu", "sigma", beta_vars, gamma_vars, delta_vars)) 26 | expect_identical(names(res$generated[[1]]), c("y1", "y2")) 27 | 28 | expect_equal(posterior::ndraws(res$variables), 7) 29 | 30 | direct_func <- function(n_sims, base_indices = 1:length(res)) { 31 | res[base_indices[rep(1:length(base_indices), length.out = n_sims)]] 32 | } 33 | 34 | res_direct1 <- generate_datasets(SBC_generator_custom(direct_func), n_sims = 7) 35 | 36 | expect_equal(res, res_direct1, check.attributes = FALSE) 37 | 38 | res_direct2 <- generate_datasets(SBC_generator_custom(direct_func, base_indices = 1:3), 39 | n_sims = 5) 40 | 41 | expect_identical(res[c(1,2,3,1,2)], res_direct2) 42 | 43 | }) 44 | 45 | test_that("Generating datasets via functions - exceptions", { 46 | missing_gen_function <- function() { 47 | list(variables = list(mu = 1), 48 | not_generated = 1) 49 | } 50 | 51 | expect_error(generate_datasets( 52 | SBC_generator_function(missing_gen_function), 53 | n_sims = 1), class = "SBC_datasets_error") 54 | 55 | missing_par_function <- function() { 56 | list(not_variables = list(mu = 1), 57 | generated = 1) 58 | } 59 | 60 | expect_error(generate_datasets( 61 | SBC_generator_function(missing_par_function), 62 | n_sims = 1), class = "SBC_datasets_error") 63 | 64 | 65 | missing_names_function <- function() { 66 | list(variables = list(mu = 1, 5), 67 | generated = 1) 68 | } 69 | 70 | expect_error(generate_datasets( 71 | SBC_generator_function(missing_names_function), 72 | n_sims = 1), class = "SBC_datasets_error") 73 | }) 74 | 75 | test_that("subsetting datasets", { 76 | list_function <- function(N) { 77 | mu <- rnorm(1) 78 | sigma <- abs(rnorm(1)) 79 | y1 <- rnorm(N, mu, sigma) 80 | y2 <- rnorm(2 * N, mu + 5, sigma) 81 | list(variables = list(mu = mu, sigma = sigma), 82 | generated = list(y1 = y1, y2 = y2)) 83 | } 84 | 85 | res <- generate_datasets( 86 | SBC_generator_function(list_function, N = 10), 87 | n_sims = 7) 88 | 89 | res_subs <- res[3:5] 90 | 91 | expect_identical(res_subs$variables, posterior::subset_draws(res$variables, draw = 3:5)) 92 | expect_identical(res_subs$generated[[1]], res$generated[[3]]) 93 | expect_identical(res_subs$generated[[2]], res$generated[[4]]) 94 | expect_identical(res_subs$generated[[3]], res$generated[[5]]) 95 | expect_equal(length(res_subs$generated), 3) 96 | 97 | }) 98 | -------------------------------------------------------------------------------- /tests/testthat/test-empirical-coverage.R: -------------------------------------------------------------------------------- 1 | test_that("empirical coverage and merging", { 2 | stats_rnd <- tidyr::crossing(variable = LETTERS[1:5], max_rank = 100, sim_id = 1:100) 3 | stats_rnd <- dplyr::mutate(stats_rnd, rank = sample(0:100, size = dplyr::n(), replace = TRUE, prob = c(1:50,seq(200, 40, length.out = 51)))) 4 | #widths_to_test <- c(0.3,0.6,0.9) 5 | widths_to_test <- c(0.3) 6 | per_var <- empirical_coverage(stats_rnd, width = widths_to_test) 7 | stats_merged <- dplyr::mutate(stats_rnd, variable = "Merged") 8 | merged <- empirical_coverage(stats_merged, width = widths_to_test) 9 | 10 | per_var_merged <- dplyr::summarise( 11 | dplyr::group_by(per_var, width), 12 | estimate_mean = mean(estimate), 13 | min_ci_low = min(ci_low), 14 | max_ci_high = max(ci_high) 15 | ) 16 | 17 | expect_equal(merged$estimate, per_var_merged$estimate_mean) 18 | for(i in length(widths_to_test)) { 19 | expect_gt(merged$ci_low[i], per_var_merged$min_ci_low[i]) 20 | expect_lt(merged$ci_high[i], per_var_merged$max_ci_high[i]) 21 | } 22 | }) 23 | -------------------------------------------------------------------------------- /tests/testthat/test-plot-helpers.R: -------------------------------------------------------------------------------- 1 | test_that("combine_XXX functions work", { 2 | var_names_to_test <- c("A", "B[1]", "B[2]", "C[1,1]", "C[2,2]", "C[3,3]") 3 | expect_identical(combine_all_variables(var_names_to_test), 4 | list(all = var_names_to_test)) 5 | 6 | expect_identical(combine_array_elements(var_names_to_test), 7 | list(A = "A", "B[]" = c("B[1]", "B[2]"), "C[]" = c("C[1,1]", "C[2,2]", "C[3,3]"))) 8 | 9 | }) 10 | -------------------------------------------------------------------------------- /tests/testthat/test-utils.R: -------------------------------------------------------------------------------- 1 | test_that("combine_args", { 2 | expect_identical(combine_args(list(a = 1, b = 2, c = 3), 3 | list(b = "no", d = 4)), 4 | list(a = 1, b = "no", c = 3, d = 4)) 5 | 6 | expect_identical(combine_args(list(1, 2), 7 | list(c = 3, d = 4)), 8 | list(1, 2, c = 3, d = 4)) 9 | 10 | expect_identical(combine_args(list(1, b = 2), 11 | list(c = 3, d = 4)), 12 | list(1, b = 2, c = 3, d = 4)) 13 | 14 | expect_identical(combine_args(list(1, b = 2, c = 3), 15 | list(13, b = "ugh", e = 5)), 16 | list(1, b = "ugh", c = 3, 13, e = 5)) 17 | 18 | expect_identical(combine_args(list(a = 1, b = 2, c = 3), 19 | list(c = "ugh", a = "no")), 20 | list(a = "no", b = 2, c = "ugh")) 21 | 22 | }) 23 | -------------------------------------------------------------------------------- /vignettes/bad_parametrization.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Discovering bad parametrization with SBC" 3 | author: "Martin Modrák" 4 | date: "`r Sys.Date()`" 5 | output: 6 | rmarkdown::html_vignette: 7 | toc: yes 8 | vignette: > 9 | %\VignetteIndexEntry{Discovering bad parametrization with SBC} 10 | %\VignetteEngine{knitr::rmarkdown} 11 | \usepackage[utf8]{inputenc} 12 | --- 13 | 14 | 15 | This vignette provides the example used as Exercise 2 of the [SBC tutorial](https://www.martinmodrak.cz/post/2021-sbc_tutorial/) 16 | presented at SBC StanConnect. Feel free to head to the tutorial website to get an interactive version and solve the problems yourself. 17 | 18 | Let's setup the environment: 19 | 20 | ```{r setup, message=FALSE,warning=FALSE, results="hide"} 21 | library(SBC) 22 | library(ggplot2) 23 | use_cmdstanr <- getOption("SBC.vignettes_cmdstanr", TRUE) # Set to false to use rstan instead 24 | 25 | if(use_cmdstanr) { 26 | library(cmdstanr) 27 | } else { 28 | library(rstan) 29 | rstan_options(auto_write = TRUE) 30 | } 31 | 32 | options(mc.cores = parallel::detectCores()) 33 | 34 | # Uncomment below to have the fits evaluated in parallel 35 | # However, as this example evaluates just a few fits, it 36 | # is usually not worth the overhead. 37 | 38 | # library(future) 39 | # plan(multisession) 40 | 41 | 42 | # Setup caching of results 43 | if(use_cmdstanr) { 44 | cache_dir <- "./_bad_parametrization_SBC_cache" 45 | } else { 46 | cache_dir <- "./_bad_parametrization_rstan_SBC_cache" 47 | } 48 | if(!dir.exists(cache_dir)) { 49 | dir.create(cache_dir) 50 | } 51 | 52 | theme_set(theme_minimal()) 53 | ``` 54 | 55 | Premise: we mistakenly assume that Stan does parametrize the Gamma distribution 56 | via shape and scale, when in fact Stan uses the shape and rate parametrization 57 | (see [Gamma distribution](https://en.wikipedia.org/wiki/Gamma_distribution) on Wikipedia 58 | for details on the parametrizations. 59 | 60 | ```{r, comment = ""} 61 | cat(readLines("stan/bad_parametrization1.stan"), sep = "\n") 62 | ``` 63 | 64 | ```{r} 65 | iter_warmup <- 1000 66 | iter_sampling <- 1000 67 | 68 | if(use_cmdstanr) { 69 | model_gamma <- cmdstan_model("stan/bad_parametrization1.stan") 70 | 71 | backend_gamma <- SBC_backend_cmdstan_sample( 72 | model_gamma, iter_warmup = iter_warmup, iter_sampling = iter_sampling, chains = 2) 73 | } else { 74 | model_gamma <- stan_model("stan/bad_parametrization1.stan") 75 | 76 | backend_gamma <- SBC_backend_rstan_sample( 77 | model_gamma, iter = iter_sampling + iter_warmup, warmup = iter_warmup, chains = 2) 78 | } 79 | 80 | ``` 81 | 82 | Build a generator to create simulated datasets. 83 | 84 | ```{r} 85 | set.seed(21448857) 86 | n_sims <- 10 87 | 88 | single_sim_gamma <- function(N) { 89 | shape <- rlnorm(n = 1, meanlog = 0, sdlog = 1) 90 | scale <- rlnorm(n = 1, meanlog = 0, sdlog = 1.5) 91 | 92 | y <- rgamma(N, shape = shape, scale = scale) 93 | 94 | list( 95 | variables = list( 96 | shape = shape, 97 | scale = scale), 98 | generated = list( 99 | N = N, 100 | y = y) 101 | ) 102 | } 103 | 104 | 105 | generator_gamma <- SBC_generator_function(single_sim_gamma, N = 40) 106 | datasets_gamma <- generate_datasets( 107 | generator_gamma, 108 | n_sims) 109 | 110 | ``` 111 | 112 | 113 | ```{r} 114 | results_gamma <- compute_SBC(datasets_gamma, backend_gamma, 115 | cache_mode = "results", 116 | cache_location = file.path(cache_dir, "model1")) 117 | ``` 118 | 119 | Here we also use the caching feature to avoid recomputing the fits when recompiling this vignette. 120 | In practice, caching is not necessary but is often useful. 121 | 122 | 10 simulations are enough to see something is wrong with the model. The problem is best seen on an `ecdf` plot - we even see the issue is primarily with the `scale` variable! 123 | 124 | ```{r results1_ecdf_diff} 125 | plot_ecdf(results_gamma) 126 | ``` 127 | 128 | However, we can use the rank histogram (with suitable number of bins) to show a different visualisation of the same problem. The rank histogram often tends to be intuitively more understandable than the `ecdf` plots, but tweaking the number of bins is often necessary and the confidence interval is only approximate and has decreased sensitivity. 129 | 130 | ```{r results1_other} 131 | plot_rank_hist(results_gamma, bins = 10) 132 | ``` 133 | 134 | 135 | So we see that the simulation does not match the model. In practice, the problem may lie with the simulation, with the model or both. Here, we'll assume that the simulation is correct - we really wanted to work with scale and fix the model to match. I.e. we still represent scale in our model, but invert it to get rate before using Stan's `gamma` distribution: 136 | 137 | 138 | ```{r, comment = ""} 139 | cat(readLines("stan/bad_parametrization2.stan"), sep = "\n") 140 | ``` 141 | 142 | ```{r} 143 | if(use_cmdstanr) { 144 | model_gamma_2 <- cmdstan_model("stan/bad_parametrization2.stan") 145 | 146 | backend_gamma_2 <- SBC_backend_cmdstan_sample( 147 | model_gamma_2, iter_warmup = iter_warmup, iter_sampling = iter_sampling, chains = 2) 148 | } else { 149 | model_gamma_2 <- stan_model("stan/bad_parametrization2.stan") 150 | 151 | backend_gamma_2 <- SBC_backend_rstan_sample( 152 | model_gamma_2, iter = iter_sampling + iter_warmup, warmup = iter_warmup, chains = 2) 153 | } 154 | 155 | 156 | ``` 157 | 158 | 159 | ```{r} 160 | results_gamma2 <- compute_SBC(datasets_gamma, backend_gamma_2, 161 | cache_mode = "results", 162 | cache_location = file.path(cache_dir, "model2")) 163 | ``` 164 | 165 | No obvious problems here, but if we wanted to be sure, we should have ran a lot more simulations. 166 | 167 | ```{r results2_plots} 168 | plot_ecdf(results_gamma2) 169 | plot_rank_hist(results_gamma2, bins = 10) 170 | ``` 171 | 172 | 173 | -------------------------------------------------------------------------------- /vignettes/other_models/changepoint.jags: -------------------------------------------------------------------------------- 1 | data { 2 | for(i in 1:T) { 3 | prior_s[i] = 1.0/T 4 | } 5 | } 6 | 7 | model { 8 | e ~ dexp(r_e); 9 | l ~ dexp(r_l); 10 | s ~ dcat(prior_s) 11 | for(i in 1:T) { 12 | y[i] ~ dpois(ifelse(i < s, e, l)) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vignettes/other_models/changepoint_marginalized.jags: -------------------------------------------------------------------------------- 1 | data { 2 | for(i in 1:T) { 3 | prior_unif[i] = -log(T) 4 | } 5 | 6 | # Using the zeroes crossing trick to compute the likelihood 7 | # See e.g. https://667-per-cm.net/2014/02/17/the-zero-crossings-trick-for-jags-finding-roots-stochastically/ 8 | z = 0 9 | } 10 | 11 | model { 12 | e ~ dexp(r_e); 13 | l ~ dexp(r_l); 14 | 15 | # Prepare the zero trick 16 | z ~ dpois(z_mean) 17 | 18 | # Compute the likelihood 19 | # The lp is a matrix to avoid having to redefine nodes 20 | lp[1, 1:T] = prior_unif 21 | for (s in 1:T) { 22 | for (t in 1:T) { 23 | lp[1 + t, s] = lp[t, s] + log(ifelse(t < s, e, l)) * y[t] - ifelse(t < s, e, l) 24 | } 25 | p[s] = exp(lp[T + 1, s]) 26 | } 27 | 28 | # log-sum-exp to compute the log likelihood in a numerically stable way 29 | m = max(lp[T + 1, ]) 30 | sum_exp_rest[1] = 0 31 | for(t in 1:T) { 32 | sum_exp_rest[1 + t] = sum_exp_rest[t] + exp(lp[T + 1, s] - m) 33 | } 34 | lp_total = m + log(sum_exp_rest[T + 1]) 35 | 36 | # We have the likelihood now add it to z_mean for the zeros trick 37 | z_mean = -lp_total + 10000 38 | 39 | s ~ dcat(p) 40 | } 41 | -------------------------------------------------------------------------------- /vignettes/overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/vignettes/overview.png -------------------------------------------------------------------------------- /vignettes/overview_wide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyunjimoon/SBC/4eb14edec865bb041100984582b4d601a137f889/vignettes/overview_wide.png -------------------------------------------------------------------------------- /vignettes/small_model_workflow/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !*.* 3 | !*/ 4 | *.rds 5 | -------------------------------------------------------------------------------- /vignettes/small_model_workflow/beta_first.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N_obs; 3 | vector[N_obs] y; 4 | 5 | int N_predictors; 6 | matrix[N_predictors, N_obs] x; 7 | } 8 | 9 | parameters { 10 | matrix[2, N_predictors] beta; 11 | } 12 | 13 | model { 14 | matrix[2, N_obs] linpred = beta * x; 15 | target += beta_lpdf(y | exp(linpred[1,]), exp(linpred[2,])); 16 | target += normal_lpdf(to_vector(beta) | 0, 1); 17 | } 18 | -------------------------------------------------------------------------------- /vignettes/small_model_workflow/beta_precision.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N_obs; 3 | vector[N_obs] y; 4 | 5 | int N_predictors; 6 | matrix[N_predictors, N_obs] x; 7 | } 8 | 9 | parameters { 10 | vector[N_predictors] beta; 11 | real phi; 12 | } 13 | 14 | model { 15 | vector[N_obs] mu = inv_logit(transpose(x) * beta); 16 | 17 | target += beta_lpdf(y | mu * phi, (1 - mu) * phi); 18 | target += normal_lpdf(beta | 0, 1); 19 | } 20 | -------------------------------------------------------------------------------- /vignettes/small_model_workflow/beta_precision_fixed_prior.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N_obs; 3 | vector[N_obs] y; 4 | 5 | int N_predictors; 6 | matrix[N_predictors, N_obs] x; 7 | } 8 | 9 | parameters { 10 | vector[N_predictors] beta; 11 | real phi; 12 | } 13 | 14 | model { 15 | vector[N_obs] mu = inv_logit(transpose(x) * beta); 16 | 17 | target += beta_lpdf(y | mu * phi, (1 - mu) * phi); 18 | target += normal_lpdf(beta | 0, 1); 19 | target += lognormal_lpdf(phi | 3, 1); 20 | } 21 | -------------------------------------------------------------------------------- /vignettes/small_model_workflow/combined_first.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N_obs; 3 | array[N_obs] int y; 4 | 5 | int N_predictors; 6 | matrix[N_predictors, N_obs] x; 7 | } 8 | 9 | parameters { 10 | ordered[2] mu; 11 | 12 | vector[N_predictors] beta; 13 | } 14 | 15 | model { 16 | vector[N_obs] theta = inv_logit(transpose(x) * beta); 17 | 18 | 19 | for(n in 1:N_obs) { 20 | target += log_mix(theta[n], 21 | poisson_log_lpmf(y[n] | mu[1]), 22 | poisson_log_lpmf(y[n] | mu[2])); 23 | } 24 | target += normal_lpdf(mu | 3, 1); 25 | target += normal_lpdf(beta | 0, 1); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /vignettes/small_model_workflow/mixture_first.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; 3 | array[N] int y; 4 | } 5 | 6 | parameters { 7 | real mu1; 8 | real mu2; 9 | real theta; 10 | } 11 | 12 | model { 13 | target += log_mix(theta, poisson_log_lpmf(y | mu1), poisson_log_lpmf(y | mu2)); 14 | target += normal_lpdf(mu1 | 3, 1); 15 | target += normal_lpdf(mu2 | 3, 1); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /vignettes/small_model_workflow/mixture_fixed_log_mix.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; 3 | array[N] int y; 4 | } 5 | 6 | parameters { 7 | real mu1; 8 | real mu2; 9 | real theta; 10 | } 11 | 12 | model { 13 | for(n in 1:N) { 14 | target += log_mix(theta, 15 | poisson_log_lpmf(y[n] | mu1), 16 | poisson_log_lpmf(y[n] | mu2)); 17 | } 18 | target += normal_lpdf(mu1 | 3, 1); 19 | target += normal_lpdf(mu2 | 3, 1); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /vignettes/small_model_workflow/mixture_fixed_ordered.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; 3 | array[N] int y; 4 | } 5 | 6 | parameters { 7 | ordered[2] mu; 8 | real theta; 9 | } 10 | 11 | model { 12 | for(n in 1:N) { 13 | target += log_mix(theta, 14 | poisson_log_lpmf(y[n] | mu[1]), 15 | poisson_log_lpmf(y[n] | mu[2])); 16 | } 17 | target += normal_lpdf(mu | 3, 1); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /vignettes/stan/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !*.* 3 | !*/ 4 | *.rds 5 | -------------------------------------------------------------------------------- /vignettes/stan/bad_parametrization1.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; 3 | vector[N] y; 4 | } 5 | 6 | parameters { 7 | real shape; 8 | real scale; 9 | } 10 | 11 | model { 12 | y ~ gamma(shape, scale); 13 | shape ~ lognormal(0, 1); 14 | scale ~ lognormal(0, 1.5); 15 | } 16 | -------------------------------------------------------------------------------- /vignettes/stan/bad_parametrization2.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; 3 | vector[N] y; 4 | } 5 | 6 | parameters { 7 | real shape; 8 | real scale; 9 | } 10 | 11 | model { 12 | y ~ gamma(shape, inv(scale)); 13 | shape ~ lognormal(0, 1); 14 | scale ~ lognormal(0, 1.5); 15 | } 16 | -------------------------------------------------------------------------------- /vignettes/stan/discrete_vars1.stan: -------------------------------------------------------------------------------- 1 | data { 2 | real r_e; 3 | real r_l; 4 | 5 | int T; 6 | array[T] int y; 7 | } 8 | transformed data { 9 | real log_unif; 10 | log_unif = -log(T); 11 | } 12 | parameters { 13 | real e; 14 | real l; 15 | } 16 | transformed parameters { 17 | vector[T] lp; 18 | lp = rep_vector(log_unif, T); 19 | for (s in 1:T) 20 | for (t in 1:T) 21 | lp[s] = lp[s] + poisson_lpmf(y[t] | t < s ? e : l); 22 | } 23 | model { 24 | e ~ exponential(r_e); 25 | l ~ exponential(r_l); 26 | target += log_sum_exp(lp); 27 | } 28 | 29 | generated quantities { 30 | int s; 31 | s = categorical_logit_rng(lp); 32 | } 33 | -------------------------------------------------------------------------------- /vignettes/stan/hmm_poisson.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; // Number of observations 3 | array[N] int y; 4 | } 5 | parameters { 6 | // Parameters of measurement model 7 | real mu_background; 8 | real mu_signal; 9 | 10 | // Initial state 11 | simplex[2] rho; 12 | 13 | // Rows of the transition matrix 14 | simplex[2] t1; 15 | simplex[2] t2; 16 | } 17 | 18 | model { 19 | 20 | matrix[2, 2] Gamma; 21 | matrix[2, N] log_omega; 22 | 23 | // Build the transition matrix 24 | Gamma[1, : ] = t1'; 25 | Gamma[2, : ] = t2'; 26 | 27 | // Compute the log likelihoods in each possible state 28 | for (n in 1 : N) { 29 | // The observation model could change with n, or vary in a number of 30 | // different ways (which is why log_omega is passed in as an argument) 31 | log_omega[1, n] = poisson_lpmf(y[n] | mu_background); 32 | log_omega[2, n] = poisson_lpmf(y[n] | mu_background + mu_signal); 33 | } 34 | 35 | mu_background ~ lognormal(-2, 1); 36 | mu_signal ~ lognormal(2, 1); 37 | 38 | // Initial state - we're quite sure we started with the source working 39 | rho ~ dirichlet([1, 10]); 40 | 41 | t1 ~ dirichlet([3, 3]); 42 | t2 ~ dirichlet([3, 3]); 43 | 44 | target += hmm_marginal(log_omega, Gamma, rho); 45 | } 46 | -------------------------------------------------------------------------------- /vignettes/stan/hmm_poisson_ordered.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; // Number of observations 3 | array[N] int y; 4 | } 5 | parameters { 6 | // Parameters of measurement model 7 | ordered[2] log_mu; 8 | 9 | // Initial state 10 | simplex[2] rho; 11 | 12 | // Rows of the transition matrix 13 | simplex[2] t1; 14 | simplex[2] t2; 15 | } 16 | 17 | model { 18 | 19 | matrix[2, 2] Gamma; 20 | matrix[2, N] log_omega; 21 | 22 | // Build the transition matrix 23 | Gamma[1, : ] = t1'; 24 | Gamma[2, : ] = t2'; 25 | 26 | // Compute the log likelihoods in each possible state 27 | for (n in 1 : N) { 28 | // The observation model could change with n, or vary in a number of 29 | // different ways (which is why log_omega is passed in as an argument) 30 | log_omega[1, n] = poisson_log_lpmf(y[n] | log_mu[1]); 31 | log_omega[2, n] = poisson_log_lpmf(y[n] | log_mu[2]); 32 | } 33 | 34 | log_mu[1] ~ normal(-2, 1); 35 | log_mu[2] ~ normal(2, 1); 36 | 37 | // Initial state - we're quite sure we started with the source working 38 | rho ~ dirichlet([1, 10]); 39 | 40 | t1 ~ dirichlet([3, 3]); 41 | t2 ~ dirichlet([3, 3]); 42 | 43 | target += hmm_marginal(log_omega, Gamma, rho); 44 | } 45 | 46 | 47 | generated quantities { 48 | positive_ordered[2] mu = exp(log_mu); 49 | } 50 | -------------------------------------------------------------------------------- /vignettes/stan/minor_discrepancy.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; 3 | vector[N] y; 4 | } 5 | 6 | parameters { 7 | real mu; 8 | real sigma; 9 | } 10 | 11 | model { 12 | target += normal_lpdf(mu | 0, 1); 13 | target += normal_lpdf(sigma | 0, 1); 14 | target += normal_lpdf(y | mu, sigma); 15 | } 16 | -------------------------------------------------------------------------------- /vignettes/stan/missing_likelihood.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; 3 | vector[N] y; 4 | } 5 | 6 | parameters { 7 | real mu; 8 | } 9 | 10 | model { 11 | target += normal_lpdf(mu | 0, 1); 12 | } 13 | -------------------------------------------------------------------------------- /vignettes/stan/partially_missing_likelihood.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; 3 | vector[N] y; 4 | } 5 | 6 | transformed data { 7 | int N2 = N %/% 2 + 1; 8 | } 9 | 10 | parameters { 11 | real mu; 12 | } 13 | 14 | model { 15 | target += normal_lpdf(mu | 0, 1); 16 | for(n in 1:N2) { 17 | target += normal_lpdf(y[n] | mu, 1); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /vignettes/stan/poisson.stan: -------------------------------------------------------------------------------- 1 | data{ 2 | int N; 3 | array[N] int y; 4 | } 5 | parameters{ 6 | real lambda; 7 | } 8 | model{ 9 | lambda ~ gamma(15, 5); 10 | y ~ poisson(lambda); 11 | } 12 | -------------------------------------------------------------------------------- /vignettes/stan/regression1.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; // number of data items 3 | int K; // number of predictors 4 | matrix[N, K] x; // predictor matrix 5 | vector[N] y; // outcome vector 6 | } 7 | parameters { 8 | real alpha; // intercept 9 | vector[K] beta; // coefficients for predictors 10 | real sigma; // error scale 11 | } 12 | model { 13 | vector[N] mu = rep_vector(alpha, N); 14 | for(i in 1:K) { 15 | for(j in 1:N) { 16 | mu[j] += beta[i] * x[j, i]; 17 | } 18 | } 19 | y ~ normal(mu, sigma); // likelihood 20 | alpha ~ normal(0, 5); 21 | beta ~ normal(0, 1); 22 | sigma ~ normal(0, 2); 23 | } 24 | -------------------------------------------------------------------------------- /vignettes/stan/regression2.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; // number of data items 3 | int K; // number of predictors 4 | matrix[N, K] x; // predictor matrix 5 | vector[N] y; // outcome vector 6 | } 7 | parameters { 8 | real alpha; // intercept 9 | vector[K] beta; // coefficients for predictors 10 | real sigma; // error scale 11 | } 12 | model { 13 | vector[N] mu; 14 | for(i in 1:N) { 15 | mu[i] = alpha; 16 | for(j in 1:K) { 17 | mu[i] += beta[j] * x[j, j]; 18 | } 19 | } 20 | y ~ normal(mu, sigma); // likelihood 21 | alpha ~ normal(0, 5); 22 | beta ~ normal(0, 1); 23 | sigma ~ normal(0, 2); 24 | } 25 | -------------------------------------------------------------------------------- /vignettes/stan/regression3.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; // number of data items 3 | int K; // number of predictors 4 | matrix[N, K] x; // predictor matrix 5 | vector[N] y; // outcome vector 6 | } 7 | parameters { 8 | real alpha; // intercept 9 | vector[K] beta; // coefficients for predictors 10 | real sigma; // error scale 11 | } 12 | model { 13 | y ~ normal(transpose(beta) * transpose(x) + alpha, sigma); // likelihood 14 | alpha ~ normal(0, 5); 15 | beta ~ normal(0, 1); 16 | sigma ~ normal(0, 2); 17 | } 18 | -------------------------------------------------------------------------------- /vignettes/stan/rejection_sampling.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int N; 3 | array[N] real y; 4 | } 5 | 6 | parameters { 7 | real mu; 8 | } 9 | 10 | model { 11 | mu ~ normal(0, 2); 12 | y ~ normal(mu, 1); 13 | } 14 | --------------------------------------------------------------------------------