├── .Rbuildignore ├── .gitattributes ├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── .lintr ├── DESCRIPTION ├── NAMESPACE ├── R ├── deprecated.R ├── global_variables.R ├── linpred_draws.R ├── predicted_draws.R ├── tidy_draws.R └── util.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── docs ├── 404.html ├── apple-touch-icon-120x120.png ├── apple-touch-icon-152x152.png ├── apple-touch-icon-180x180.png ├── apple-touch-icon-60x60.png ├── apple-touch-icon-76x76.png ├── apple-touch-icon.png ├── articles │ ├── index.html │ ├── slabinterval_family.png │ ├── tidy-rethinking.html │ └── tidy-rethinking_files │ │ ├── figure-html │ │ ├── unnamed-chunk-16-1.png │ │ ├── unnamed-chunk-17-1.png │ │ ├── unnamed-chunk-18-1.png │ │ ├── unnamed-chunk-19-1.png │ │ ├── unnamed-chunk-20-1.png │ │ ├── unnamed-chunk-21-1.png │ │ ├── unnamed-chunk-26-1.png │ │ ├── unnamed-chunk-27-1.png │ │ ├── unnamed-chunk-28-1.png │ │ ├── unnamed-chunk-29-1.png │ │ ├── unnamed-chunk-30-1.png │ │ ├── unnamed-chunk-31-1.png │ │ ├── unnamed-chunk-33-1.png │ │ ├── unnamed-chunk-34-1.png │ │ ├── unnamed-chunk-35-1.gif │ │ ├── unnamed-chunk-36-1.png │ │ ├── unnamed-chunk-37-1.png │ │ ├── unnamed-chunk-38-1.png │ │ ├── unnamed-chunk-39-1.png │ │ ├── unnamed-chunk-4-1.png │ │ ├── unnamed-chunk-40-1.png │ │ ├── unnamed-chunk-44-1.png │ │ ├── unnamed-chunk-45-1.gif │ │ ├── unnamed-chunk-46-1.png │ │ ├── unnamed-chunk-47-1.png │ │ ├── unnamed-chunk-48-1.png │ │ └── unnamed-chunk-49-1.png │ │ └── header-attrs-2.10 │ │ └── header-attrs.js ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── extra.css ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── index.html ├── link.svg ├── logo.svg ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── Rplot001.png │ ├── figures │ │ └── logo.svg │ ├── index.html │ ├── linpred_draws.ulam.html │ ├── predicted_draws.ulam.html │ ├── tidy_draws.map.html │ └── tidybayes.rethinking-deprecated.html └── sitemap.xml ├── figures-source ├── github-preview.pdf ├── github-preview.png └── logo.pdf ├── inst └── CITATION ├── man ├── figures │ └── logo.svg ├── linpred_draws.ulam.Rd ├── predicted_draws.ulam.Rd ├── tidy_draws.map.Rd └── tidybayes.rethinking-deprecated.Rd ├── pkgdown ├── extra.css └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── tests ├── testthat.R └── testthat │ └── test.fitted_draws.R └── vignettes ├── slabinterval_family.png └── tidy-rethinking.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^TODO$ 4 | ^.*\.md$ 5 | ^.*~$ 6 | ^\.gitignore$ 7 | ^\.gitattributes$ 8 | ^\.git$ 9 | ^\.github$ 10 | ^\.travis\.yml$ 11 | ^README.Rmd$ 12 | ^README_files$ 13 | ^.lintr$ 14 | ^figures-source$ 15 | ^vignettes/.*_cache$ 16 | ^_pkgdown\.yml$ 17 | ^docs$ 18 | ^pkgdown$ 19 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - '*' 5 | pull_request: 6 | branches: 7 | - master 8 | - dev 9 | 10 | name: R-CMD-check 11 | 12 | jobs: 13 | R-CMD-check: 14 | runs-on: ${{ matrix.config.os }} 15 | 16 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) ${{ matrix.config.suffix }} 17 | 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | config: 22 | # - {os: windows-latest, r: 'release', suffix: 'quick', not_cran: 'false', vignettes: '"--no-build-vignettes"'} 23 | - {os: windows-latest, r: 'release', suffix: '', not_cran: 'true', vignettes: 'NULL'} 24 | # - {os: macOS-latest, r: 'release', suffix: '', not_cran: 'true', vignettes: 'NULL'} 25 | # - {os: macOS-latest, r: 'devel', suffix: '', not_cran: 'true', vignettes: 'NULL'} 26 | # - {os: ubuntu-16.04, r: 'release', suffix: '', not_cran: 'true', vignettes: 'NULL', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} 27 | 28 | env: 29 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 30 | RSPM: ${{ matrix.config.rspm }} 31 | 32 | steps: 33 | - uses: actions/checkout@v2 34 | 35 | - uses: r-lib/actions/setup-r@master 36 | with: 37 | r-version: ${{ matrix.config.r }} 38 | 39 | - uses: r-lib/actions/setup-pandoc@master 40 | 41 | - name: Query dependencies 42 | run: | 43 | install.packages('remotes') 44 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 45 | shell: Rscript {0} 46 | 47 | - name: Cache R packages 48 | if: runner.os != 'Windows' 49 | uses: actions/cache@v1 50 | with: 51 | path: ${{ env.R_LIBS_USER }} 52 | key: ${{ runner.os }}-r-${{ matrix.config.r }}-1-${{ hashFiles('.github/depends.Rds') }} 53 | restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-1- 54 | 55 | - name: Install system dependencies 56 | if: runner.os == 'Linux' 57 | env: 58 | RHUB_PLATFORM: linux-x86_64-ubuntu-gcc 59 | run: | 60 | Rscript -e "remotes::install_github('r-hub/sysreqs')" 61 | sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))") 62 | sudo -s eval "$sysreqs" 63 | 64 | - name: Install dependencies 65 | run: | 66 | remotes::install_deps(dependencies = TRUE) 67 | remotes::install_cran("rcmdcheck") 68 | shell: Rscript {0} 69 | 70 | - name: Check 71 | env: 72 | _R_CHECK_CRAN_INCOMING_REMOTE_: false 73 | NOT_CRAN: ${{ matrix.config.not_cran }} 74 | run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran", ${{ matrix.config.vignettes }}), error_on = "warning", check_dir = "check") 75 | shell: Rscript {0} 76 | 77 | - name: Upload check results 78 | if: failure() 79 | uses: actions/upload-artifact@master 80 | with: 81 | name: ${{ runner.os }}-r${{ matrix.config.r }}-results 82 | path: check 83 | 84 | # - name: Test coverage 85 | # if: matrix.config.r == 'release' && runner.os == 'Windows' && matrix.config.suffix == 'quick' 86 | # run: covr::codecov() 87 | # shell: Rscript {0} 88 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .project 3 | .settings 4 | .Rhistory 5 | .RData 6 | .Rproj* 7 | *.Rproj 8 | vignettes/*_cache/ 9 | .Rproj.user 10 | -------------------------------------------------------------------------------- /.lintr: -------------------------------------------------------------------------------- 1 | linters: with_defaults( 2 | assignment_linter = NULL, 3 | line_length_linter(120), 4 | open_curly_linter(allow_single_line = TRUE), 5 | closed_curly_linter(allow_single_line = TRUE), 6 | object_name_linter = NULL, 7 | object_length_linter = NULL 8 | ) 9 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: tidybayes.rethinking 2 | Title: Tidy Data for Rethinking 3 | Version: 3.0.0 4 | Date: 2020-06-01 5 | Authors@R: c(person("Matthew", "Kay", role = c("aut", "cre"), 6 | email = "mjskay@northwestern.edu")) 7 | Maintainer: Matthew Kay 8 | Description: Extends tidybayes to support composing data for and gathering draws from 9 | models fit using Richard McElreath's rethinking package in a tidy data format. 10 | Depends: 11 | R (>= 2.10) 12 | Imports: 13 | dplyr, 14 | tibble, 15 | rlang, 16 | MASS, 17 | tidybayes (>= 3.0.0), 18 | rethinking, 19 | rstan 20 | Suggests: 21 | ggplot2, 22 | magrittr, 23 | tidyr, 24 | knitr, 25 | testthat, 26 | rmarkdown 27 | Remotes: 28 | rmcelreath/rethinking 29 | License: GPL (>= 3) 30 | BugReports: https://github.com/mjskay/tidybayes.rethinking/issues/new 31 | URL: http://mjskay.github.io/tidybayes.rethinking, https://github.com/mjskay/tidybayes.rethinking 32 | VignetteBuilder: knitr 33 | RoxygenNote: 7.3.1 34 | LazyData: true 35 | Encoding: UTF-8 36 | Roxygen: list(markdown = TRUE) 37 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(fitted_draws,ulam) 4 | S3method(linpred_draws,map) 5 | S3method(linpred_draws,map2stan) 6 | S3method(linpred_draws,quap) 7 | S3method(linpred_draws,ulam) 8 | S3method(predicted_draws,map) 9 | S3method(predicted_draws,map2stan) 10 | S3method(predicted_draws,quap) 11 | S3method(predicted_draws,ulam) 12 | S3method(tidy_draws,map) 13 | S3method(tidy_draws,map2stan) 14 | S3method(tidy_draws,quap) 15 | S3method(tidy_draws,ulam) 16 | export(tidy_link) 17 | export(tidy_sim) 18 | importFrom(MASS,mvrnorm) 19 | importFrom(dplyr,bind_cols) 20 | importFrom(rethinking,extract.samples) 21 | importFrom(rlang,"%||%") 22 | importFrom(rlang,is_empty) 23 | importFrom(rlang,is_false) 24 | importFrom(rlang,is_true) 25 | importFrom(tibble,as_tibble) 26 | importFrom(tibble,tibble) 27 | importFrom(tidybayes,add_draws) 28 | importFrom(tidybayes,fitted_draws) 29 | importFrom(tidybayes,linpred_draws) 30 | importFrom(tidybayes,predicted_draws) 31 | importFrom(tidybayes,sample_draws) 32 | importFrom(tidybayes,tidy_draws) 33 | -------------------------------------------------------------------------------- /R/deprecated.R: -------------------------------------------------------------------------------- 1 | # Deprecated functions 2 | # 3 | # Author: mjskay 4 | ############################################################################### 5 | 6 | 7 | #' Deprecated functions, arguments, and column names in tidybayes 8 | #' 9 | #' Deprecated functions, arguments, and column names and their alternatives are listed below. 10 | #' 11 | #' @section Deprecated Functions: 12 | #' 13 | #' When `tidybayes.rethinking` was originally created, `tidybayes` did not have good 14 | #' analogs for `tidy_link()` or `tidy_sim()`. However, `tidybayes` now has a mature API 15 | #' analogous to these functions, so they have been deprecated: 16 | #' 17 | #' - `tidy_link()` has been replaced with `add_linpred_draws()` / `linpred_draws()`. See 18 | #' `linpred_draws.ulam()` for information on rethinking-specific arguments, or 19 | #' `tidybayes::linpred_draws()` for information on the general function. 20 | #' 21 | #' - `tidy_sim()` has been replaced with `add_predicted_draws()` / `predicted_draws()`. See 22 | #' `predicted_draws.ulam()` for information on rethinking-specific arguments, or 23 | #' `tidybayes::predicted_draws()` for information on the general function. 24 | #' 25 | #' @format NULL 26 | #' @usage NULL 27 | #' @author Matthew Kay 28 | #' @name tidybayes.rethinking-deprecated 29 | NULL 30 | -------------------------------------------------------------------------------- /R/global_variables.R: -------------------------------------------------------------------------------- 1 | # Names that should be suppressed from global variable check by codetools 2 | # Names used broadly should be put here; Names used in specific files should 3 | # be put at the top of the corresponding file. 4 | # 5 | # Author: mjskay 6 | ############################################################################### 7 | 8 | # names used in dlpyr functions 9 | globalVariables(c(".")) 10 | -------------------------------------------------------------------------------- /R/linpred_draws.R: -------------------------------------------------------------------------------- 1 | # linpred_draws 2 | # 3 | # Author: mjskay 4 | ############################################################################### 5 | 6 | 7 | # deprecated names for linpred_draws ------------------------------- 8 | 9 | #' @rdname tidybayes.rethinking-deprecated 10 | #' @format NULL 11 | #' @usage NULL 12 | #' @importFrom tidybayes linpred_draws 13 | #' @export 14 | tidy_link = function(data, fit, ...) { 15 | .Deprecated("add_linpred_draws", "tidybayes.rethinking") 16 | 17 | linpred_draws(object = fit, newdata = data, ...) 18 | } 19 | 20 | #' @importFrom tidybayes fitted_draws 21 | #' @export 22 | fitted_draws.ulam = function(model, newdata, ..., value = ".value", n = NULL) { 23 | .Deprecated("linpred_draws", "tidybayes", paste0( 24 | "`fitted_draws` and `add_fitted_draws` are deprecated as their names were confusing.\n", 25 | "Use [add_]linpred_draws() to get the distribution of the linear predictor." 26 | )) 27 | 28 | linpred_draws(object = model, newdata = newdata, ..., value = value, ndraws = n) 29 | } 30 | #' @export 31 | linpred_draws.quap = fitted_draws.ulam 32 | #' @export 33 | linpred_draws.map = fitted_draws.ulam 34 | #' @export 35 | linpred_draws.map2stan = fitted_draws.ulam 36 | 37 | 38 | # linpred_draws ------------------------------------------------------------ 39 | 40 | #' Add draws from the posterior link-level predictor of a rethinking model to a data frame 41 | #' 42 | #' Adds draws from the posterior link-level predictor of a rethinking model to a data frame. 43 | #' Provides support for [tidybayes::linpred_draws()] / [tidybayes::add_linpred_draws()] / 44 | #' for models from the `rethinking` package. 45 | #' 46 | #' @inheritParams tidybayes::linpred_draws 47 | #' @param object A model fit using `rethinking::quap()`, `rethinking::ulam()`, 48 | #' `rethinking::map()`, or `rethinking::map2stan()`. 49 | #' @param ... Optional parameters passed on to `rethinking::link()`. The most pertinent are: 50 | #' - `replace`: Optional named list of samples to replace inside posterior samples. See examples in `rethinking::link()`. 51 | #' @param post Optional samples from posterior. When missing, `linpred_draws()` extracts these in advance, 52 | #' bypassing `rethinking::link()`'s normal process (`rethinking::link()` uses `rstan::extract()`, which 53 | #' unfortunately permutes samples, breaking the ability of the `.draw` column to be meaningfully joined 54 | #' with output from other methods, like `spread_draws()`). 55 | #' @param ndraws The number of draws per fit to return. When `NULL` (the default), `rethinking::ulam()` and 56 | #' `rethinking::map2stan()` models return all draws; `rethinking::quap()` and `rethinking::map()` models 57 | #' return 5000 draws. 58 | #' @param dpar Should distributional regression 59 | #' parameters be included in the output? In rethinking models, these correspond to the linear submodels 60 | #' returned by `rethinking::link()`. If `TRUE`, distributional regression 61 | #' parameters are included in the output as additional columns named after each parameter 62 | #' (alternative names can be provided using a list or named vector, e.g. `c(sigma.hat = "sigma")` 63 | #' would output the `"sigma"` parameter from a model as a column named `"sigma.hat"`). 64 | #' If `FALSE` (the default), distributional regression parameters are not included; instead, 65 | #' just the first linear submodel returned by `rethinking::link()` is used. 66 | #' @param re_formula,category Not used with this model type. 67 | #' @importFrom rlang is_true is_false is_empty 68 | #' @importFrom tidybayes linpred_draws add_draws sample_draws 69 | #' @importFrom rethinking extract.samples 70 | #' @export 71 | linpred_draws.ulam = function(object, newdata, value = ".value", ..., post = NULL, ndraws = NULL, seed = NULL, 72 | dpar = FALSE, re_formula = NULL, category = ".category" 73 | ) { 74 | if (!is.null(re_formula)) { 75 | warning("The re_formula parameter is not supported by rethinking models; ignored.") 76 | } 77 | if (category != ".category") { 78 | warning("The category parameter is not supported by rethinking models; ignored.") 79 | } 80 | 81 | set.seed(seed) 82 | 83 | # map and quap models need to specify the number of draws (since they are generated) 84 | unpermute_samples = FALSE 85 | if (inherits(object, "map") || inherits(object, "quap")){ 86 | if (is.null(ndraws)) { 87 | ndraws = 5000 88 | } 89 | if (is.null(post)) { 90 | post = extract.samples(object, n = ndraws) 91 | } 92 | } else if (hasName(attributes(object), "stanfit") && is.null(post)) { 93 | # have to do this manually because rethinking::link with rstan under the hood 94 | # uses permuted samples (!!) and can't use unpermuted samples because when 95 | # permuted = FALSE the format of the returned samples changes (!!!!) 96 | # see the statement guarded by unpermute_samples below 97 | unpermute_samples = TRUE 98 | post = rethinking::extract.samples(object, permuted = TRUE) 99 | } 100 | 101 | # get the draws from the link-level predictors 102 | draws_list = if (is.null(post)) { 103 | rethinking::link(object, newdata, n = ndraws, flatten = FALSE, ...) 104 | } else { 105 | rethinking::link(object, newdata, n = ndraws, post = post, flatten = FALSE, ...) 106 | } 107 | draws = add_draws(newdata, draws_list[[1]], value = value) 108 | 109 | # get the names of distributional regression parameters to include 110 | dpars = if (is_true(dpar)) { 111 | names(draws_list) 112 | } else if (is_false(dpar)) { 113 | NULL 114 | } else { 115 | dpar 116 | } 117 | if (is_empty(dpars)) { 118 | # the above conditions might return an empty vector, which does not play well with the code below 119 | # (if there are no dpars, it is expected that dpars is NULL) 120 | dpars = NULL 121 | } 122 | 123 | # missing names default to the same name used for the parameter in the model 124 | if (is.null(names(dpars))) { 125 | names(dpars) = dpars 126 | } else { 127 | missing_names = is.na(names(dpars)) | names(dpars) == "" 128 | names(dpars)[missing_names] = dpars[missing_names] 129 | } 130 | 131 | for (i in seq_along(dpars)) { 132 | varname = names(dpars)[[i]] 133 | dpar_linpred_draws = add_draws(newdata, draws_list[[dpars[[i]]]], value = ".value") 134 | draws[[varname]] = dpar_linpred_draws[[".value"]] 135 | } 136 | 137 | if (unpermute_samples) { 138 | # unpermute the samples 139 | # TODO: this is an awful hack! 140 | perm = stanfit_permutation(object@stanfit) 141 | draws$.draw = perm[draws$.draw] 142 | } 143 | 144 | # ulam and map2stan models seem to ignore n 145 | if ((inherits(object, "map2stan") || inherits(object, "ulam")) && !is.null(ndraws)) { 146 | draws = sample_draws(draws, ndraws) 147 | } 148 | 149 | draws 150 | } 151 | 152 | #' @rdname linpred_draws.ulam 153 | #' @export 154 | linpred_draws.quap = linpred_draws.ulam 155 | 156 | #' @rdname linpred_draws.ulam 157 | #' @export 158 | linpred_draws.map = linpred_draws.ulam 159 | 160 | #' @rdname linpred_draws.ulam 161 | #' @export 162 | linpred_draws.map2stan = linpred_draws.ulam 163 | 164 | 165 | # helpers ----------------------------------------------------------------- 166 | 167 | stanfit_permutation = function(stanfit) { 168 | # the draw order permutation in a stanfit used with rstan::extract() 169 | chain_perm = stanfit@sim$permutation 170 | n_per_chain = length(chain_perm[[1]]) 171 | unlist(lapply(seq_along(chain_perm), function(chain) { 172 | perm = chain_perm[[chain]] 173 | (chain - 1)*n_per_chain + perm 174 | })) 175 | } 176 | -------------------------------------------------------------------------------- /R/predicted_draws.R: -------------------------------------------------------------------------------- 1 | # predicted_draws 2 | # 3 | # Author: mjskay 4 | ############################################################################### 5 | 6 | 7 | # deprecated names for predicted_draws ------------------------------- 8 | 9 | #' @rdname tidybayes.rethinking-deprecated 10 | #' @format NULL 11 | #' @usage NULL 12 | #' @importFrom tidybayes predicted_draws 13 | #' @export 14 | tidy_sim = function(data, fit, ...) { 15 | .Deprecated("add_predicted_draws", "tidybayes.rethinking") 16 | 17 | fitted_draws(object = fit, newdata = data, ...) 18 | } 19 | 20 | 21 | # predicted_draws ------------------------------------------------------------ 22 | 23 | #' Add draws from the posterior predictive of a rethinking model to a data frame 24 | #' 25 | #' Adds draws from the posterior predictive distribution of a rethinking model to a data frame. 26 | #' Provides support for [tidybayes::predicted_draws()] / [tidybayes::add_predicted_draws()] for 27 | #' models from the `rethinking` package. 28 | #' 29 | #' @inheritParams tidybayes::predicted_draws 30 | #' @param object A model fit using `rethinking::quap()`, `rethinking::ulam()`, 31 | #' `rethinking::map()`, or `rethinking::map2stan()`. 32 | #' @param ... Optional parameters passed on to `rethinking::sim()`. The most pertinent are: 33 | #' - `post`: Optional samples from posterior. If missing, simulates samples using `ndraws`. 34 | #' @param ndraws The number of draws per prediction to return. When `NULL` (the default), `rethinking::ulam()` and 35 | #' `rethinking::map2stan()` models return all draws; `rethinking::quap()` and `rethinking::map()` models 36 | #' return 5000 draws. 37 | #' @param re_formula,category Not used with this model type. 38 | #' @importFrom rlang is_true is_false is_empty 39 | #' @importFrom tidybayes predicted_draws add_draws sample_draws 40 | #' @export 41 | predicted_draws.ulam = function(object, newdata, value = ".prediction", ..., ndraws = NULL, seed = NULL, 42 | re_formula = NULL, category = ".category" 43 | ) { 44 | if (!is.null(re_formula)) { 45 | warning("The re_formula parameter is not supported by rethinking models; ignored.") 46 | } 47 | if (category != ".category") { 48 | warning("The category parameter is not supported by rethinking models; ignored.") 49 | } 50 | 51 | # map and quap models need to specify the number of draws (since they are generated) 52 | if ((inherits(object, "map") || inherits(object, "quap")) && is.null(ndraws)) { 53 | ndraws = 5000 54 | } 55 | 56 | # get the draws from the posterior predictive 57 | set.seed(seed) 58 | sims = rethinking::sim(object, newdata, n = ndraws, ...) 59 | draws = add_draws(newdata, sims, value = value) 60 | 61 | # ulam and map2stan models seem to ignore n 62 | if ((inherits(object, "map2stan") || inherits(object, "ulam")) && !is.null(ndraws)) { 63 | draws = sample_draws(draws, ndraws) 64 | } 65 | 66 | draws 67 | } 68 | 69 | #' @rdname predicted_draws.ulam 70 | #' @export 71 | predicted_draws.quap = predicted_draws.ulam 72 | 73 | #' @rdname predicted_draws.ulam 74 | #' @export 75 | predicted_draws.map = predicted_draws.ulam 76 | 77 | #' @rdname predicted_draws.ulam 78 | #' @export 79 | predicted_draws.map2stan = predicted_draws.ulam 80 | -------------------------------------------------------------------------------- /R/tidy_draws.R: -------------------------------------------------------------------------------- 1 | # tidy_draws 2 | # 3 | # Author: mjskay 4 | ############################################################################### 5 | 6 | 7 | #' Get a sample of posterior draws from quap and map models as a tibble 8 | #' 9 | #' Implementation of [tidybayes::tidy_draws()] for [rethinking::map()] and [rethinking::quap()] 10 | #' models. Extract draws from a Bayesian fit into a wide-format data frame with a 11 | #' `.chain`, `.iteration`, and `.draw` column, as well as all variables as columns. 12 | #' While this function can be useful for quick glances at models (especially 13 | #' combined with [gather_variables()] and [median_qi()]), it is 14 | #' generally speaking not as useful as [spread_draws()] or 15 | #' [gather_draws()] for most applications, and is mainly used internally. 16 | #' 17 | #' @param model A model fit using `rethinking::map()`, `rethinking::quap()`, 18 | #' `rethinking::map2stan()`, or `rethinking::ulam()` 19 | #' @param n For `map` and `quap` models, the number of draws to generate (defaults to 5000). 20 | #' Ignored for `map2stan` and `ulam` models. 21 | #' @param ... Further arguments passed to other methods (mostly unused). 22 | #' @details 23 | #' 24 | #' The main additional functionality compared to [tidybayes::tidy_draws()] when used on 25 | #' other models is that since draws must be generated on-the-fly, 26 | #' an argument (`n`) is provided to indicate how many draws to take. The `.chain` and 27 | #' `.iteration` columns are also always `NA`, since they have no meaning for these model 28 | #' types (use the `.draw` column if you need to index draws). Otherwise, the result of 29 | #' this function follows the same format as [tidybayes::tidy_draws()]; see that 30 | #' documentation for more information. 31 | #' 32 | #' @examples 33 | #' 34 | #' library(rethinking) 35 | #' library(tidybayes) 36 | #' library(dplyr) 37 | #' 38 | #' m = quap(alist( 39 | #' mpg ~ dlnorm(mu, sigma), 40 | #' mu <- a + b*wt, 41 | #' c(a,b) ~ dnorm(0, 10), 42 | #' sigma ~ dexp(1) 43 | #' ), 44 | #' data = mtcars, 45 | #' start = list(a = 4, b = -1, sigma = 1) 46 | #' ) 47 | #' 48 | #' m %>% 49 | #' tidy_draws() %>% 50 | #' gather_variables() %>% 51 | #' median_qi() 52 | #' 53 | #' @importFrom tidybayes tidy_draws 54 | #' @importFrom MASS mvrnorm 55 | #' @importFrom dplyr bind_cols 56 | #' @importFrom tibble tibble as_tibble 57 | #' @export 58 | tidy_draws.map = function(model, n = 5000, ...) { 59 | mu = rethinking::coef(model) 60 | draws = as_tibble(mvrnorm(n = n, mu = mu, Sigma = rethinking::vcov(model))) 61 | 62 | #map models have no chains 63 | draws = bind_cols(tibble( 64 | .chain = NA_integer_, 65 | .iteration = NA_integer_, 66 | .draw = 1:nrow(draws) 67 | ), 68 | draws 69 | ) 70 | 71 | attr(draws, "tidybayes_constructors") = attr(model, "tidybayes_constructors") 72 | draws 73 | } 74 | 75 | #' @rdname tidy_draws.map 76 | #' @export 77 | tidy_draws.quap = tidy_draws.map 78 | 79 | #' @rdname tidy_draws.map 80 | #' @importFrom rlang %||% 81 | #' @export 82 | tidy_draws.map2stan = function(model, ...) { 83 | stan_model = attr(model, "stanfit") %||% attr(model, "cstanfit") 84 | draws = tidy_draws(stan_model, ...) 85 | 86 | attr(draws, "tidybayes_constructors") = attr(model, "tidybayes_constructors") 87 | draws 88 | } 89 | 90 | #' @rdname tidy_draws.map 91 | #' @export 92 | tidy_draws.ulam = tidy_draws.map2stan 93 | -------------------------------------------------------------------------------- /R/util.R: -------------------------------------------------------------------------------- 1 | # Utility functions for tidybayes 2 | # 3 | # Author: mjskay 4 | ############################################################################### 5 | 6 | 7 | # deparse that is guaranteed to return a single string (instead of 8 | # a list of strings if the expression goes to multiple lines) 9 | deparse0 = function(expr, width.cutoff = 500, ...) { 10 | paste0(deparse(expr, width.cutoff = width.cutoff, ...), collapse = "") 11 | } 12 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | # tidybayes.rethinking: Extend tidybayes to work with the rethinking package 6 | 7 | [![R build status](https://github.com/mjskay/tidybayes.rethinking/workflows/R-CMD-check/badge.svg)](https://github.com/mjskay/tidybayes.rethinking/actions) 8 | 9 | _Matthew Kay, Northwestern University, _ 10 | 11 | This package extends the [tidybayes](https://mjskay.github.io/tidybayes/) R package to support models from Richard McElreath's [rethinking](https://github.com/rmcelreath/rethinking) package. 12 | 13 | 14 | ## Installation 15 | 16 | `tidybayes.rethinking` is separate from the core `tidybayes` package because `rethinking` is not currently available on CRAN. Thus, `tidybayes.rethinking` is also not available on CRAN. 17 | 18 | You can install `tidybayes.rethinking` from Github: 19 | 20 | ```{r, eval = FALSE} 21 | install.packages("devtools") # only necessary if you don't have devtools already 22 | devtools::install_github("mjskay/tidybayes.rethinking") 23 | ``` 24 | 25 | 26 | ## Examples 27 | 28 | See the [tidy-rethinking](https://mjskay.github.io/tidybayes.rethinking/articles/tidy-rethinking.html) vignette for `rethinking`-specific examples, or check out the [tidybayes](https://mjskay.github.io/tidybayes/) documentation for more general examples of `tidybayes` usage. 29 | 30 | 31 | ## Feedback and issues 32 | 33 | I welcome feedback, suggestions, and issues! If you have found a bug in the rethinking-specific version of functions, please file it on 34 | [the tidybayes.rethinking github](https://github.com/mjskay/tidybayes.rethinking/issues/new) with minimal code to reproduce the issue. For general `tidybayes` issues, please file bugs on [the tidybayes github](https://github.com/mjskay/tidybayes/issues/new). If you're not sure which it falls under, file it on one or the other and I will redirect the issue if necessary. 35 | 36 | 37 | ## Citing `tidybayes` 38 | 39 | Matthew Kay (`r format(Sys.Date(), "%Y")`). _tidybayes: Tidy Data and Geoms for Bayesian Models_. R package version `r getNamespaceVersion("tidybayes")`, . 40 | DOI: [10.5281/zenodo.1308151](https://doi.org/10.5281/zenodo.1308151). 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # tidybayes.rethinking: Extend tidybayes to work with the rethinking package 3 | 4 | [![R build 5 | status](https://github.com/mjskay/tidybayes.rethinking/workflows/R-CMD-check/badge.svg)](https://github.com/mjskay/tidybayes.rethinking/actions) 6 | 7 | *Matthew Kay, Northwestern University, * 8 | 9 | This package extends the 10 | [tidybayes](https://mjskay.github.io/tidybayes/) R package to support 11 | models from Richard McElreath’s 12 | [rethinking](https://github.com/rmcelreath/rethinking) package. 13 | 14 | ## Installation 15 | 16 | `tidybayes.rethinking` is separate from the core `tidybayes` package 17 | because `rethinking` is not currently available on CRAN. Thus, 18 | `tidybayes.rethinking` is also not available on CRAN. 19 | 20 | You can install `tidybayes.rethinking` from Github: 21 | 22 | ``` r 23 | install.packages("devtools") # only necessary if you don't have devtools already 24 | devtools::install_github("mjskay/tidybayes.rethinking") 25 | ``` 26 | 27 | ## Examples 28 | 29 | See the 30 | [tidy-rethinking](https://mjskay.github.io/tidybayes.rethinking/articles/tidy-rethinking.html) 31 | vignette for `rethinking`-specific examples, or check out the 32 | [tidybayes](https://mjskay.github.io/tidybayes/) documentation for more 33 | general examples of `tidybayes` usage. 34 | 35 | ## Feedback and issues 36 | 37 | I welcome feedback, suggestions, and issues! If you have found a bug in 38 | the rethinking-specific version of functions, please file it on [the 39 | tidybayes.rethinking 40 | github](https://github.com/mjskay/tidybayes.rethinking/issues/new) with 41 | minimal code to reproduce the issue. For general `tidybayes` issues, 42 | please file bugs on [the tidybayes 43 | github](https://github.com/mjskay/tidybayes/issues/new). If you’re not 44 | sure which it falls under, file it on one or the other and I will 45 | redirect the issue if necessary. 46 | 47 | ## Citing `tidybayes` 48 | 49 | Matthew Kay (2021). *tidybayes: Tidy Data and Geoms for Bayesian 50 | Models*. R package version 3.0.0, . 51 | DOI: [10.5281/zenodo.1308151](https://doi.org/10.5281/zenodo.1308151). 52 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: http://mjskay.github.io/tidybayes.rethinking 2 | 3 | 4 | template: 5 | params: 6 | bootswatch: paper 7 | ganalytics: UA-93322-5 8 | 9 | 10 | authors: 11 | Matthew Kay: 12 | href: http://www.mjskay.com 13 | 14 | 15 | reference: 16 | - title: Extracting posteriors 17 | desc: Get tidy draws of posterior distributions from models 18 | contents: 19 | - tidy_draws.map 20 | 21 | - title: Extracting fits and predictions 22 | desc: Get tidy draws from transformed linear predictors ("fits") or posterior predictions 23 | contents: 24 | - linpred_draws.ulam 25 | - predicted_draws.ulam 26 | 27 | - title: Deprecated functions 28 | desc: Deprecated functions 29 | contents: 30 | - tidybayes.rethinking-deprecated 31 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • tidybayes.rethinking 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 65 | 66 | 67 | 68 | 69 | 76 | 77 | 78 | 79 | 80 | 81 |
82 |
83 | 134 | 135 | 136 | 137 |
138 | 139 |
140 |
141 | 144 | 145 | Content not found. Please use links in the navbar. 146 | 147 |
148 | 149 | 154 | 155 |
156 | 157 | 158 | 159 |
160 | 163 | 164 |
165 |

Site built with pkgdown 1.6.1.

166 |
167 | 168 |
169 |
170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /docs/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /docs/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • tidybayes.rethinking 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 65 | 66 | 67 | 68 | 69 | 76 | 77 | 78 | 79 | 80 | 81 |
82 |
83 | 134 | 135 | 136 | 137 |
138 | 139 |
140 |
141 | 144 | 145 |
146 |

All vignettes

147 |

148 | 149 |
150 |
Extracting and visualizing tidy draws from rethinking models
151 |
152 |
153 |
154 |
155 |
156 | 157 | 158 |
159 | 162 | 163 |
164 |

Site built with pkgdown 1.6.1.

165 |
166 | 167 |
168 |
169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /docs/articles/slabinterval_family.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/slabinterval_family.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-16-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-16-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-17-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-20-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-20-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-21-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-21-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-26-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-26-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-27-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-27-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-28-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-28-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-29-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-29-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-30-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-30-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-31-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-31-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-33-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-33-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-34-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-34-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-35-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-35-1.gif -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-36-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-36-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-37-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-37-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-38-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-38-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-39-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-39-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-40-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-40-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-44-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-44-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-45-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-45-1.gif -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-46-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-46-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-47-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-47-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-48-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-48-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-49-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/articles/tidy-rethinking_files/figure-html/unnamed-chunk-49-1.png -------------------------------------------------------------------------------- /docs/articles/tidy-rethinking_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Citation and Authors • tidybayes.rethinking 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 65 | 66 | 67 | 68 | 69 | 76 | 77 | 78 | 79 | 80 | 81 |
82 |
83 | 134 | 135 | 136 | 137 |
138 | 139 |
140 |
141 | 145 | 146 |

Kay M (2021). 147 | tidybayes: Tidy Data and Geoms for Bayesian Models. 148 | doi: 10.5281/zenodo.1308151, R package version 3.0.0, http://mjskay.github.io/tidybayes/. 149 |

150 |
@Manual{,
151 |   title = {{tidybayes}: Tidy Data and Geoms for {Bayesian} Models},
152 |   author = {Matthew Kay},
153 |   year = {2021},
154 |   note = {R package version 3.0.0},
155 |   url = {http://mjskay.github.io/tidybayes/},
156 |   doi = {10.5281/zenodo.1308151},
157 | }
158 | 159 | 162 | 163 |
    164 |
  • 165 |

    Matthew Kay. Author, maintainer. 166 |

    167 |
  • 168 |
169 | 170 |
171 | 172 |
173 | 174 | 175 | 176 |
177 | 180 | 181 |
182 |

Site built with pkgdown 1.6.1.

183 |
184 | 185 |
186 |
187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /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.css: -------------------------------------------------------------------------------- 1 | /* Docsearch -------------------------------------------------------------- */ 2 | /* 3 | Source: https://github.com/algolia/docsearch/ 4 | License: MIT 5 | */ 6 | 7 | .algolia-autocomplete { 8 | display: block; 9 | -webkit-box-flex: 1; 10 | -ms-flex: 1; 11 | flex: 1 12 | } 13 | 14 | .algolia-autocomplete .ds-dropdown-menu { 15 | width: 100%; 16 | min-width: none; 17 | max-width: none; 18 | padding: .75rem 0; 19 | background-color: #fff; 20 | background-clip: padding-box; 21 | border: 1px solid rgba(0, 0, 0, .1); 22 | box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); 23 | } 24 | 25 | @media (min-width:768px) { 26 | .algolia-autocomplete .ds-dropdown-menu { 27 | width: 175% 28 | } 29 | } 30 | 31 | .algolia-autocomplete .ds-dropdown-menu::before { 32 | display: none 33 | } 34 | 35 | .algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { 36 | padding: 0; 37 | background-color: rgb(255,255,255); 38 | border: 0; 39 | max-height: 80vh; 40 | } 41 | 42 | .algolia-autocomplete .ds-dropdown-menu .ds-suggestions { 43 | margin-top: 0 44 | } 45 | 46 | .algolia-autocomplete .algolia-docsearch-suggestion { 47 | padding: 0; 48 | overflow: visible 49 | } 50 | 51 | .algolia-autocomplete .algolia-docsearch-suggestion--category-header { 52 | padding: .125rem 1rem; 53 | margin-top: 0; 54 | font-size: 1.3em; 55 | font-weight: 500; 56 | color: #00008B; 57 | border-bottom: 0 58 | } 59 | 60 | .algolia-autocomplete .algolia-docsearch-suggestion--wrapper { 61 | float: none; 62 | padding-top: 0 63 | } 64 | 65 | .algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { 66 | float: none; 67 | width: auto; 68 | padding: 0; 69 | text-align: left 70 | } 71 | 72 | .algolia-autocomplete .algolia-docsearch-suggestion--content { 73 | float: none; 74 | width: auto; 75 | padding: 0 76 | } 77 | 78 | .algolia-autocomplete .algolia-docsearch-suggestion--content::before { 79 | display: none 80 | } 81 | 82 | .algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { 83 | padding-top: .75rem; 84 | margin-top: .75rem; 85 | border-top: 1px solid rgba(0, 0, 0, .1) 86 | } 87 | 88 | .algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { 89 | display: block; 90 | padding: .1rem 1rem; 91 | margin-bottom: 0.1; 92 | font-size: 1.0em; 93 | font-weight: 400 94 | /* display: none */ 95 | } 96 | 97 | .algolia-autocomplete .algolia-docsearch-suggestion--title { 98 | display: block; 99 | padding: .25rem 1rem; 100 | margin-bottom: 0; 101 | font-size: 0.9em; 102 | font-weight: 400 103 | } 104 | 105 | .algolia-autocomplete .algolia-docsearch-suggestion--text { 106 | padding: 0 1rem .5rem; 107 | margin-top: -.25rem; 108 | font-size: 0.8em; 109 | font-weight: 400; 110 | line-height: 1.25 111 | } 112 | 113 | .algolia-autocomplete .algolia-docsearch-footer { 114 | width: 110px; 115 | height: 20px; 116 | z-index: 3; 117 | margin-top: 10.66667px; 118 | float: right; 119 | font-size: 0; 120 | line-height: 0; 121 | } 122 | 123 | .algolia-autocomplete .algolia-docsearch-footer--logo { 124 | background-image: url("data:image/svg+xml;utf8,"); 125 | background-repeat: no-repeat; 126 | background-position: 50%; 127 | background-size: 100%; 128 | overflow: hidden; 129 | text-indent: -9000px; 130 | width: 100%; 131 | height: 100%; 132 | display: block; 133 | transform: translate(-8px); 134 | } 135 | 136 | .algolia-autocomplete .algolia-docsearch-suggestion--highlight { 137 | color: #FF8C00; 138 | background: rgba(232, 189, 54, 0.1) 139 | } 140 | 141 | 142 | .algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { 143 | box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) 144 | } 145 | 146 | .algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { 147 | background-color: rgba(192, 192, 192, .15) 148 | } 149 | -------------------------------------------------------------------------------- /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/extra.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-size: 15.5px; 3 | } 4 | 5 | .navbar-brand { 6 | font-size: 16px; 7 | font-weight: bold; 8 | } 9 | 10 | .navbar-default .navbar-nav>li>a:hover, 11 | .navbar-default .navbar-nav>li>a:focus { 12 | background-color: #eee; 13 | } 14 | 15 | p.caption { 16 | display: none; 17 | } 18 | 19 | h1, .h1 { 20 | font-size: 32px; 21 | font-weight: bold; 22 | } 23 | 24 | h1 small, .h1 small { 25 | font-size: 70%; 26 | text-transform: uppercase; 27 | letter-spacing: 0.5px; 28 | } 29 | 30 | img#tidybayes_logo { 31 | width: 80px; 32 | margin-top: -48px; 33 | margin-right: -60px; 34 | } 35 | 36 | .page-header h1 { 37 | padding-right: 60px; 38 | } 39 | 40 | @media (max-width: 1200px) { 41 | img#tidybayes_logo { 42 | display: none; 43 | } 44 | .page-header h1 { 45 | padding-right: 0; 46 | } 47 | } 48 | 49 | h2, .h2 { 50 | font-size: 28px; 51 | font-weight: bold; 52 | } 53 | 54 | h3, .h3 { 55 | font-size: 20px; 56 | font-weight: bold; 57 | } 58 | 59 | h4, .h4 { 60 | font-size: 20px; 61 | font-weight: normal; 62 | } 63 | 64 | .contents h1, .contents h2, .contents h3, .contents h4 { 65 | margin-bottom: 20px; 66 | } 67 | 68 | .contents .page-header h1 { 69 | margin-top: 25px; 70 | } 71 | 72 | .contents h3, .contents h4 { 73 | margin-top: -55px; 74 | } 75 | 76 | h4.date, h4.author { 77 | font-size: 1em; 78 | color: #bbb; 79 | display: inline; 80 | padding-right: 0.5em; 81 | } 82 | 83 | pre code { 84 | font-size: 13.5px; 85 | white-space: pre; 86 | } 87 | -------------------------------------------------------------------------------- /docs/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/favicon-16x16.png -------------------------------------------------------------------------------- /docs/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/favicon-32x32.png -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/favicon.ico -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Tidy Data for Rethinking • tidybayes.rethinking 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 35 | 36 | 37 |
    38 |
    90 | 91 | 92 | 93 | 94 |
    95 |
    96 |
    97 | 100 | 101 |

    Matthew Kay, Northwestern University,

    102 |

    This package extends the tidybayes R package to support models from Richard McElreath’s rethinking package.

    103 |
    104 |

    105 | Installation

    106 |

    tidybayes.rethinking is separate from the core tidybayes package because rethinking is not currently available on CRAN. Thus, tidybayes.rethinking is also not available on CRAN.

    107 |

    You can install tidybayes.rethinking from Github:

    108 |
    109 | install.packages("devtools")     # only necessary if you don't have devtools already
    110 | devtools::install_github("mjskay/tidybayes.rethinking")
    111 |
    112 |
    113 |

    114 | Examples

    115 |

    See the tidy-rethinking vignette for rethinking-specific examples, or check out the tidybayes documentation for more general examples of tidybayes usage.

    116 |
    117 |
    118 |

    119 | Feedback and issues

    120 |

    I welcome feedback, suggestions, and issues! If you have found a bug in the rethinking-specific version of functions, please file it on the tidybayes.rethinking github with minimal code to reproduce the issue. For general tidybayes issues, please file bugs on the tidybayes github. If you’re not sure which it falls under, file it on one or the other and I will redirect the issue if necessary.

    121 |
    122 |
    123 |

    124 | Citing tidybayes 125 |

    126 |

    Matthew Kay (2021). tidybayes: Tidy Data and Geoms for Bayesian Models. R package version 3.0.0, https://mjskay.github.io/tidybayes/. DOI: 10.5281/zenodo.1308151.

    127 |
    128 |
    129 |
    130 | 131 | 168 |
    169 | 170 | 171 |
    174 | 175 |
    176 |

    Site built with pkgdown 1.6.1.

    177 |
    178 | 179 |
    180 |
    181 | 182 | 183 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 47 | 49 | 53 | 55 | 57 | 58 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 71 | 72 | 73 | 74 | 75 | 77 | 79 | 80 | 82 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | img { 60 | max-width: 100%; 61 | } 62 | 63 | /* Fix bug in bootstrap (only seen in firefox) */ 64 | summary { 65 | display: list-item; 66 | } 67 | 68 | /* Typographic tweaking ---------------------------------*/ 69 | 70 | .contents .page-header { 71 | margin-top: calc(-60px + 1em); 72 | } 73 | 74 | dd { 75 | margin-left: 3em; 76 | } 77 | 78 | /* Section anchors ---------------------------------*/ 79 | 80 | a.anchor { 81 | margin-left: -30px; 82 | display:inline-block; 83 | width: 30px; 84 | height: 30px; 85 | visibility: hidden; 86 | 87 | background-image: url(./link.svg); 88 | background-repeat: no-repeat; 89 | background-size: 20px 20px; 90 | background-position: center center; 91 | } 92 | 93 | .hasAnchor:hover a.anchor { 94 | visibility: visible; 95 | } 96 | 97 | @media (max-width: 767px) { 98 | .hasAnchor:hover a.anchor { 99 | visibility: hidden; 100 | } 101 | } 102 | 103 | 104 | /* Fixes for fixed navbar --------------------------*/ 105 | 106 | .contents h1, .contents h2, .contents h3, .contents h4 { 107 | padding-top: 60px; 108 | margin-top: -40px; 109 | } 110 | 111 | /* Navbar submenu --------------------------*/ 112 | 113 | .dropdown-submenu { 114 | position: relative; 115 | } 116 | 117 | .dropdown-submenu>.dropdown-menu { 118 | top: 0; 119 | left: 100%; 120 | margin-top: -6px; 121 | margin-left: -1px; 122 | border-radius: 0 6px 6px 6px; 123 | } 124 | 125 | .dropdown-submenu:hover>.dropdown-menu { 126 | display: block; 127 | } 128 | 129 | .dropdown-submenu>a:after { 130 | display: block; 131 | content: " "; 132 | float: right; 133 | width: 0; 134 | height: 0; 135 | border-color: transparent; 136 | border-style: solid; 137 | border-width: 5px 0 5px 5px; 138 | border-left-color: #cccccc; 139 | margin-top: 5px; 140 | margin-right: -10px; 141 | } 142 | 143 | .dropdown-submenu:hover>a:after { 144 | border-left-color: #ffffff; 145 | } 146 | 147 | .dropdown-submenu.pull-left { 148 | float: none; 149 | } 150 | 151 | .dropdown-submenu.pull-left>.dropdown-menu { 152 | left: -100%; 153 | margin-left: 10px; 154 | border-radius: 6px 0 6px 6px; 155 | } 156 | 157 | /* Sidebar --------------------------*/ 158 | 159 | #pkgdown-sidebar { 160 | margin-top: 30px; 161 | position: -webkit-sticky; 162 | position: sticky; 163 | top: 70px; 164 | } 165 | 166 | #pkgdown-sidebar h2 { 167 | font-size: 1.5em; 168 | margin-top: 1em; 169 | } 170 | 171 | #pkgdown-sidebar h2:first-child { 172 | margin-top: 0; 173 | } 174 | 175 | #pkgdown-sidebar .list-unstyled li { 176 | margin-bottom: 0.5em; 177 | } 178 | 179 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 180 | 181 | /* All levels of nav */ 182 | 183 | nav[data-toggle='toc'] .nav > li > a { 184 | padding: 4px 20px 4px 6px; 185 | font-size: 1.5rem; 186 | font-weight: 400; 187 | color: inherit; 188 | } 189 | 190 | nav[data-toggle='toc'] .nav > li > a:hover, 191 | nav[data-toggle='toc'] .nav > li > a:focus { 192 | padding-left: 5px; 193 | color: inherit; 194 | border-left: 1px solid #878787; 195 | } 196 | 197 | nav[data-toggle='toc'] .nav > .active > a, 198 | nav[data-toggle='toc'] .nav > .active:hover > a, 199 | nav[data-toggle='toc'] .nav > .active:focus > a { 200 | padding-left: 5px; 201 | font-size: 1.5rem; 202 | font-weight: 400; 203 | color: inherit; 204 | border-left: 2px solid #878787; 205 | } 206 | 207 | /* Nav: second level (shown on .active) */ 208 | 209 | nav[data-toggle='toc'] .nav .nav { 210 | display: none; /* Hide by default, but at >768px, show it */ 211 | padding-bottom: 10px; 212 | } 213 | 214 | nav[data-toggle='toc'] .nav .nav > li > a { 215 | padding-left: 16px; 216 | font-size: 1.35rem; 217 | } 218 | 219 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 220 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 221 | padding-left: 15px; 222 | } 223 | 224 | nav[data-toggle='toc'] .nav .nav > .active > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 226 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 227 | padding-left: 15px; 228 | font-weight: 500; 229 | font-size: 1.35rem; 230 | } 231 | 232 | /* orcid ------------------------------------------------------------------- */ 233 | 234 | .orcid { 235 | font-size: 16px; 236 | color: #A6CE39; 237 | /* margins are required by official ORCID trademark and display guidelines */ 238 | margin-left:4px; 239 | margin-right:4px; 240 | vertical-align: middle; 241 | } 242 | 243 | /* Reference index & topics ----------------------------------------------- */ 244 | 245 | .ref-index th {font-weight: normal;} 246 | 247 | .ref-index td {vertical-align: top; min-width: 100px} 248 | .ref-index .icon {width: 40px;} 249 | .ref-index .alias {width: 40%;} 250 | .ref-index-icons .alias {width: calc(40% - 40px);} 251 | .ref-index .title {width: 60%;} 252 | 253 | .ref-arguments th {text-align: right; padding-right: 10px;} 254 | .ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} 255 | .ref-arguments .name {width: 20%;} 256 | .ref-arguments .desc {width: 80%;} 257 | 258 | /* Nice scrolling for wide elements --------------------------------------- */ 259 | 260 | table { 261 | display: block; 262 | overflow: auto; 263 | } 264 | 265 | /* Syntax highlighting ---------------------------------------------------- */ 266 | 267 | pre { 268 | word-wrap: normal; 269 | word-break: normal; 270 | border: 1px solid #eee; 271 | } 272 | 273 | pre, code { 274 | background-color: #f8f8f8; 275 | color: #333; 276 | } 277 | 278 | pre code { 279 | overflow: auto; 280 | word-wrap: normal; 281 | white-space: pre; 282 | } 283 | 284 | pre .img { 285 | margin: 5px 0; 286 | } 287 | 288 | pre .img img { 289 | background-color: #fff; 290 | display: block; 291 | height: auto; 292 | } 293 | 294 | code a, pre a { 295 | color: #375f84; 296 | } 297 | 298 | a.sourceLine:hover { 299 | text-decoration: none; 300 | } 301 | 302 | .fl {color: #1514b5;} 303 | .fu {color: #000000;} /* function */ 304 | .ch,.st {color: #036a07;} /* string */ 305 | .kw {color: #264D66;} /* keyword */ 306 | .co {color: #888888;} /* comment */ 307 | 308 | .message { color: black; font-weight: bolder;} 309 | .error { color: orange; font-weight: bolder;} 310 | .warning { color: #6A0366; font-weight: bolder;} 311 | 312 | /* Clipboard --------------------------*/ 313 | 314 | .hasCopyButton { 315 | position: relative; 316 | } 317 | 318 | .btn-copy-ex { 319 | position: absolute; 320 | right: 0; 321 | top: 0; 322 | visibility: hidden; 323 | } 324 | 325 | .hasCopyButton:hover button.btn-copy-ex { 326 | visibility: visible; 327 | } 328 | 329 | /* headroom.js ------------------------ */ 330 | 331 | .headroom { 332 | will-change: transform; 333 | transition: transform 200ms linear; 334 | } 335 | .headroom--pinned { 336 | transform: translateY(0%); 337 | } 338 | .headroom--unpinned { 339 | transform: translateY(-100%); 340 | } 341 | 342 | /* mark.js ----------------------------*/ 343 | 344 | mark { 345 | background-color: rgba(255, 255, 51, 0.5); 346 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 347 | padding: 1px; 348 | } 349 | 350 | /* vertical spacing after htmlwidgets */ 351 | .html-widget { 352 | margin-bottom: 10px; 353 | } 354 | 355 | /* fontawesome ------------------------ */ 356 | 357 | .fab { 358 | font-family: "Font Awesome 5 Brands" !important; 359 | } 360 | 361 | /* don't display links in code chunks when printing */ 362 | /* source: https://stackoverflow.com/a/10781533 */ 363 | @media print { 364 | code a:link:after, code a:visited:after { 365 | content: ""; 366 | } 367 | } 368 | -------------------------------------------------------------------------------- /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 | $(".examples, 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; 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: 2.14.0.3 2 | pkgdown: 1.6.1 3 | pkgdown_sha: ~ 4 | articles: 5 | tidy-rethinking: tidy-rethinking.html 6 | last_built: 2021-08-19T01:51Z 7 | urls: 8 | reference: http://mjskay.github.io/tidybayes.rethinking/reference 9 | article: http://mjskay.github.io/tidybayes.rethinking/articles 10 | 11 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/figures/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 47 | 49 | 53 | 55 | 57 | 58 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 71 | 72 | 73 | 74 | 75 | 77 | 79 | 80 | 82 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Function reference • tidybayes.rethinking 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 65 | 66 | 67 | 68 | 69 | 76 | 77 | 78 | 79 | 80 | 81 |
    82 |
    83 | 134 | 135 | 136 | 137 |
    138 | 139 |
    140 |
    141 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 170 | 171 | 172 | 173 | 174 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 189 | 190 | 191 | 192 | 195 | 196 | 197 | 198 | 199 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 214 | 215 | 216 | 217 |
    156 |

    Extracting posteriors

    157 |

    Get tidy draws of posterior distributions from models

    158 |
    168 |

    tidy_draws(<map>) tidy_draws(<quap>) tidy_draws(<map2stan>) tidy_draws(<ulam>)

    169 |

    Get a sample of posterior draws from quap and map models as a tibble

    175 |

    Extracting fits and predictions

    176 |

    Get tidy draws from transformed linear predictors (“fits”) or posterior predictions

    177 |
    187 |

    linpred_draws(<ulam>) linpred_draws(<quap>) linpred_draws(<map>) linpred_draws(<map2stan>)

    188 |

    Add draws from the posterior link-level predictor of a rethinking model to a data frame

    193 |

    predicted_draws(<ulam>) predicted_draws(<quap>) predicted_draws(<map>) predicted_draws(<map2stan>)

    194 |

    Add draws from the posterior predictive of a rethinking model to a data frame

    200 |

    Deprecated functions

    201 |

    Deprecated functions

    202 |
    212 |

    tidybayes.rethinking-deprecated

    213 |

    Deprecated functions, arguments, and column names in tidybayes

    218 |
    219 | 220 | 225 |
    226 | 227 | 228 |
    229 | 232 | 233 |
    234 |

    Site built with pkgdown 1.6.1.

    235 |
    236 | 237 |
    238 |
    239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | -------------------------------------------------------------------------------- /docs/reference/linpred_draws.ulam.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Add draws from the posterior link-level predictor of a rethinking model to a data frame — linpred_draws.ulam • tidybayes.rethinking 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 68 | 69 | 70 | 71 | 72 | 79 | 80 | 81 | 82 | 83 | 84 |
    85 |
    86 | 137 | 138 | 139 | 140 |
    141 | 142 |
    143 |
    144 | 149 | 150 |
    151 |

    Adds draws from the posterior link-level predictor of a rethinking model to a data frame. 152 | Provides support for tidybayes::linpred_draws() / tidybayes::add_linpred_draws() / 153 | for models from the rethinking package.

    154 |
    155 | 156 |
    # S3 method for ulam
    157 | linpred_draws(
    158 |   object,
    159 |   newdata,
    160 |   value = ".value",
    161 |   ...,
    162 |   post = NULL,
    163 |   ndraws = NULL,
    164 |   seed = NULL,
    165 |   dpar = FALSE,
    166 |   re_formula = NULL,
    167 |   category = ".category"
    168 | )
    169 | 
    170 | # S3 method for quap
    171 | linpred_draws(
    172 |   object,
    173 |   newdata,
    174 |   value = ".value",
    175 |   ...,
    176 |   post = NULL,
    177 |   ndraws = NULL,
    178 |   seed = NULL,
    179 |   dpar = FALSE,
    180 |   re_formula = NULL,
    181 |   category = ".category"
    182 | )
    183 | 
    184 | # S3 method for map
    185 | linpred_draws(
    186 |   object,
    187 |   newdata,
    188 |   value = ".value",
    189 |   ...,
    190 |   post = NULL,
    191 |   ndraws = NULL,
    192 |   seed = NULL,
    193 |   dpar = FALSE,
    194 |   re_formula = NULL,
    195 |   category = ".category"
    196 | )
    197 | 
    198 | # S3 method for map2stan
    199 | linpred_draws(
    200 |   object,
    201 |   newdata,
    202 |   value = ".value",
    203 |   ...,
    204 |   post = NULL,
    205 |   ndraws = NULL,
    206 |   seed = NULL,
    207 |   dpar = FALSE,
    208 |   re_formula = NULL,
    209 |   category = ".category"
    210 | )
    211 | 212 |

    Arguments

    213 | 214 | 215 | 216 | 217 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 232 | 233 | 234 | 235 | 238 | 239 | 240 | 241 | 245 | 246 | 247 | 248 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 266 | 267 | 268 | 269 | 270 | 271 |
    object

    A model fit using rethinking::quap(), rethinking::ulam(), 218 | rethinking::map(), or rethinking::map2stan().

    newdata

    Data frame to generate predictions from.

    value

    The name of the output column:

      227 |
    • for [add_]epred_draws(), defaults to ".epred".

    • 228 |
    • for [add_]predicted_draws(), defaults to ".prediction".

    • 229 |
    • for [add_]linpred_draws(), defaults to ".linpred".

    • 230 |
    • for [add_]residual_draws(), defaults to ".residual"

    • 231 |
    ...

    Optional parameters passed on to rethinking::link(). The most pertinent are:

      236 |
    • replace: Optional named list of samples to replace inside posterior samples. See examples in rethinking::link().

    • 237 |
    post

    Optional samples from posterior. When missing, linpred_draws() extracts these in advance, 242 | bypassing rethinking::link()'s normal process (rethinking::link() uses rstan::extract(), which 243 | unfortunately permutes samples, breaking the ability of the .draw column to be meaningfully joined 244 | with output from other methods, like spread_draws()).

    ndraws

    The number of draws per fit to return. When NULL (the default), rethinking::ulam() and 249 | rethinking::map2stan() models return all draws; rethinking::quap() and rethinking::map() models 250 | return 5000 draws.

    seed

    A seed to use when subsampling draws (i.e. when ndraws is not NULL).

    dpar

    Should distributional regression 259 | parameters be included in the output? In rethinking models, these correspond to the linear submodels 260 | returned by rethinking::link(). If TRUE, distributional regression 261 | parameters are included in the output as additional columns named after each parameter 262 | (alternative names can be provided using a list or named vector, e.g. c(sigma.hat = "sigma") 263 | would output the "sigma" parameter from a model as a column named "sigma.hat"). 264 | If FALSE (the default), distributional regression parameters are not included; instead, 265 | just the first linear submodel returned by rethinking::link() is used.

    re_formula, category

    Not used with this model type.

    272 | 273 | 274 |
    275 | 280 |
    281 | 282 | 283 |
    284 | 287 | 288 |
    289 |

    Site built with pkgdown 1.6.1.

    290 |
    291 | 292 |
    293 |
    294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | -------------------------------------------------------------------------------- /docs/reference/predicted_draws.ulam.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Add draws from the posterior predictive of a rethinking model to a data frame — predicted_draws.ulam • tidybayes.rethinking 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 68 | 69 | 70 | 71 | 72 | 79 | 80 | 81 | 82 | 83 | 84 |
    85 |
    86 | 137 | 138 | 139 | 140 |
    141 | 142 |
    143 |
    144 | 149 | 150 |
    151 |

    Adds draws from the posterior predictive distribution of a rethinking model to a data frame. 152 | Provides support for tidybayes::predicted_draws() / tidybayes::add_predicted_draws() for 153 | models from the rethinking package.

    154 |
    155 | 156 |
    # S3 method for ulam
    157 | predicted_draws(
    158 |   object,
    159 |   newdata,
    160 |   value = ".prediction",
    161 |   ...,
    162 |   ndraws = NULL,
    163 |   seed = NULL,
    164 |   re_formula = NULL,
    165 |   category = ".category"
    166 | )
    167 | 
    168 | # S3 method for quap
    169 | predicted_draws(
    170 |   object,
    171 |   newdata,
    172 |   value = ".prediction",
    173 |   ...,
    174 |   ndraws = NULL,
    175 |   seed = NULL,
    176 |   re_formula = NULL,
    177 |   category = ".category"
    178 | )
    179 | 
    180 | # S3 method for map
    181 | predicted_draws(
    182 |   object,
    183 |   newdata,
    184 |   value = ".prediction",
    185 |   ...,
    186 |   ndraws = NULL,
    187 |   seed = NULL,
    188 |   re_formula = NULL,
    189 |   category = ".category"
    190 | )
    191 | 
    192 | # S3 method for map2stan
    193 | predicted_draws(
    194 |   object,
    195 |   newdata,
    196 |   value = ".prediction",
    197 |   ...,
    198 |   ndraws = NULL,
    199 |   seed = NULL,
    200 |   re_formula = NULL,
    201 |   category = ".category"
    202 | )
    203 | 204 |

    Arguments

    205 | 206 | 207 | 208 | 209 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 224 | 225 | 226 | 227 | 230 | 231 | 232 | 233 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 |
    object

    A model fit using rethinking::quap(), rethinking::ulam(), 210 | rethinking::map(), or rethinking::map2stan().

    newdata

    Data frame to generate predictions from.

    value

    The name of the output column:

      219 |
    • for [add_]epred_draws(), defaults to ".epred".

    • 220 |
    • for [add_]predicted_draws(), defaults to ".prediction".

    • 221 |
    • for [add_]linpred_draws(), defaults to ".linpred".

    • 222 |
    • for [add_]residual_draws(), defaults to ".residual"

    • 223 |
    ...

    Optional parameters passed on to rethinking::sim(). The most pertinent are:

      228 |
    • post: Optional samples from posterior. If missing, simulates samples using ndraws.

    • 229 |
    ndraws

    The number of draws per prediction to return. When NULL (the default), rethinking::ulam() and 234 | rethinking::map2stan() models return all draws; rethinking::quap() and rethinking::map() models 235 | return 5000 draws.

    seed

    A seed to use when subsampling draws (i.e. when ndraws is not NULL).

    re_formula, category

    Not used with this model type.

    246 | 247 | 248 |
    249 | 254 |
    255 | 256 | 257 |
    258 | 261 | 262 |
    263 |

    Site built with pkgdown 1.6.1.

    264 |
    265 | 266 |
    267 |
    268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | -------------------------------------------------------------------------------- /docs/reference/tidy_draws.map.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Get a sample of posterior draws from quap and map models as a tibble — tidy_draws.map • tidybayes.rethinking 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 72 | 73 | 74 | 75 | 76 | 83 | 84 | 85 | 86 | 87 | 88 |
    89 |
    90 | 141 | 142 | 143 | 144 |
    145 | 146 |
    147 |
    148 | 153 | 154 |
    155 |

    Implementation of tidybayes::tidy_draws() for rethinking::map() and rethinking::quap() 156 | models. Extract draws from a Bayesian fit into a wide-format data frame with a 157 | .chain, .iteration, and .draw column, as well as all variables as columns. 158 | While this function can be useful for quick glances at models (especially 159 | combined with gather_variables() and median_qi()), it is 160 | generally speaking not as useful as spread_draws() or 161 | gather_draws() for most applications, and is mainly used internally.

    162 |
    163 | 164 |
    # S3 method for map
    165 | tidy_draws(model, n = 5000, ...)
    166 | 
    167 | # S3 method for quap
    168 | tidy_draws(model, n = 5000, ...)
    169 | 
    170 | # S3 method for map2stan
    171 | tidy_draws(model, ...)
    172 | 
    173 | # S3 method for ulam
    174 | tidy_draws(model, ...)
    175 | 176 |

    Arguments

    177 | 178 | 179 | 180 | 181 | 183 | 184 | 185 | 186 | 188 | 189 | 190 | 191 | 192 | 193 |
    model

    A model fit using rethinking::map(), rethinking::quap(), 182 | rethinking::map2stan(), or rethinking::ulam()

    n

    For map and quap models, the number of draws to generate (defaults to 5000). 187 | Ignored for map2stan and ulam models.

    ...

    Further arguments passed to other methods (mostly unused).

    194 | 195 |

    Details

    196 | 197 |

    The main additional functionality compared to tidybayes::tidy_draws() when used on 198 | other models is that since draws must be generated on-the-fly, 199 | an argument (n) is provided to indicate how many draws to take. The .chain and 200 | .iteration columns are also always NA, since they have no meaning for these model 201 | types (use the .draw column if you need to index draws). Otherwise, the result of 202 | this function follows the same format as tidybayes::tidy_draws(); see that 203 | documentation for more information.

    204 | 205 |

    Examples

    206 |
    207 | library(rethinking) 208 |
    #> Loading required package: rstan
    #> Loading required package: StanHeaders
    #> 209 | #> rstan version 2.26.2 (Stan version 2.26.1)
    #> For execution on a local, multicore CPU with excess RAM we recommend calling 210 | #> options(mc.cores = parallel::detectCores()). 211 | #> To avoid recompilation of unchanged Stan programs, we recommend calling 212 | #> rstan_options(auto_write = TRUE) 213 | #> For within-chain threading using `reduce_sum()` or `map_rect()` Stan functions, 214 | #> change `threads_per_chain` option: 215 | #> rstan_options(threads_per_chain = 1)
    #> Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file
    #> Loading required package: parallel
    #> rethinking (Version 2.13)
    #> 216 | #> Attaching package: 'rethinking'
    #> The following object is masked from 'package:stats': 217 | #> 218 | #> rstudent
    #> 221 | #> Attaching package: 'dplyr'
    #> The following objects are masked from 'package:stats': 222 | #> 223 | #> filter, lag
    #> The following objects are masked from 'package:base': 224 | #> 225 | #> intersect, setdiff, setequal, union
    226 | m = quap(alist( 227 | mpg ~ dlnorm(mu, sigma), 228 | mu <- a + b*wt, 229 | c(a,b) ~ dnorm(0, 10), 230 | sigma ~ dexp(1) 231 | ), 232 | data = mtcars, 233 | start = list(a = 4, b = -1, sigma = 1) 234 | ) 235 | 236 | m %>% 237 | tidy_draws() %>% 238 | gather_variables() %>% 239 | median_qi() 240 |
    #> # A tibble: 3 x 7 241 | #> .variable .value .lower .upper .width .point .interval 242 | #> <chr> <dbl> <dbl> <dbl> <dbl> <chr> <chr> 243 | #> 1 a 3.83 3.67 3.99 0.95 median qi 244 | #> 2 b -0.271 -0.319 -0.224 0.95 median qi 245 | #> 3 sigma 0.132 0.0995 0.163 0.95 median qi
    246 |
    247 |
    248 | 253 |
    254 | 255 | 256 |
    257 | 260 | 261 |
    262 |

    Site built with pkgdown 1.6.1.

    263 |
    264 | 265 |
    266 |
    267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | -------------------------------------------------------------------------------- /docs/reference/tidybayes.rethinking-deprecated.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Deprecated functions, arguments, and column names in tidybayes — tidybayes.rethinking-deprecated • tidybayes.rethinking 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 66 | 67 | 68 | 69 | 70 | 77 | 78 | 79 | 80 | 81 | 82 |
    83 |
    84 | 135 | 136 | 137 | 138 |
    139 | 140 |
    141 |
    142 | 147 | 148 |
    149 |

    Deprecated functions, arguments, and column names and their alternatives are listed below.

    150 |
    151 | 152 | 153 | 154 |

    Deprecated Functions

    155 | 156 | 157 | 158 | 159 |

    When tidybayes.rethinking was originally created, tidybayes did not have good 160 | analogs for tidy_link() or tidy_sim(). However, tidybayes now has a mature API 161 | analogous to these functions, so they have been deprecated:

      162 |
    • tidy_link() has been replaced with add_linpred_draws() / linpred_draws(). See 163 | linpred_draws.ulam() for information on rethinking-specific arguments, or 164 | tidybayes::linpred_draws() for information on the general function.

    • 165 |
    • tidy_sim() has been replaced with add_predicted_draws() / predicted_draws(). See 166 | predicted_draws.ulam() for information on rethinking-specific arguments, or 167 | tidybayes::predicted_draws() for information on the general function.

    • 168 |
    169 | 170 |

    Author

    171 | 172 |

    Matthew Kay

    173 | 174 |
    175 | 180 |
    181 | 182 | 183 |
    184 | 187 | 188 |
    189 |

    Site built with pkgdown 1.6.1.

    190 |
    191 | 192 |
    193 |
    194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | http://mjskay.github.io/tidybayes.rethinking/index.html 5 | 6 | 7 | http://mjskay.github.io/tidybayes.rethinking/reference/linpred_draws.ulam.html 8 | 9 | 10 | http://mjskay.github.io/tidybayes.rethinking/reference/predicted_draws.ulam.html 11 | 12 | 13 | http://mjskay.github.io/tidybayes.rethinking/reference/tidybayes.rethinking-deprecated.html 14 | 15 | 16 | http://mjskay.github.io/tidybayes.rethinking/reference/tidy_draws.map.html 17 | 18 | 19 | http://mjskay.github.io/tidybayes.rethinking/articles/tidy-rethinking.html 20 | 21 | 22 | -------------------------------------------------------------------------------- /figures-source/github-preview.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/figures-source/github-preview.pdf -------------------------------------------------------------------------------- /figures-source/github-preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/figures-source/github-preview.png -------------------------------------------------------------------------------- /figures-source/logo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/figures-source/logo.pdf -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citation("tidybayes") 2 | -------------------------------------------------------------------------------- /man/figures/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 47 | 49 | 53 | 55 | 57 | 58 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 71 | 72 | 73 | 74 | 75 | 77 | 79 | 80 | 82 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /man/linpred_draws.ulam.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linpred_draws.R 3 | \name{linpred_draws.ulam} 4 | \alias{linpred_draws.ulam} 5 | \alias{linpred_draws.quap} 6 | \alias{linpred_draws.map} 7 | \alias{linpred_draws.map2stan} 8 | \title{Add draws from the posterior link-level predictor of a rethinking model to a data frame} 9 | \usage{ 10 | \method{linpred_draws}{ulam}( 11 | object, 12 | newdata, 13 | value = ".value", 14 | ..., 15 | post = NULL, 16 | ndraws = NULL, 17 | seed = NULL, 18 | dpar = FALSE, 19 | re_formula = NULL, 20 | category = ".category" 21 | ) 22 | 23 | \method{linpred_draws}{quap}( 24 | object, 25 | newdata, 26 | value = ".value", 27 | ..., 28 | post = NULL, 29 | ndraws = NULL, 30 | seed = NULL, 31 | dpar = FALSE, 32 | re_formula = NULL, 33 | category = ".category" 34 | ) 35 | 36 | \method{linpred_draws}{map}( 37 | object, 38 | newdata, 39 | value = ".value", 40 | ..., 41 | post = NULL, 42 | ndraws = NULL, 43 | seed = NULL, 44 | dpar = FALSE, 45 | re_formula = NULL, 46 | category = ".category" 47 | ) 48 | 49 | \method{linpred_draws}{map2stan}( 50 | object, 51 | newdata, 52 | value = ".value", 53 | ..., 54 | post = NULL, 55 | ndraws = NULL, 56 | seed = NULL, 57 | dpar = FALSE, 58 | re_formula = NULL, 59 | category = ".category" 60 | ) 61 | } 62 | \arguments{ 63 | \item{object}{A model fit using \code{rethinking::quap()}, \code{rethinking::ulam()}, 64 | \code{rethinking::map()}, or \code{rethinking::map2stan()}.} 65 | 66 | \item{newdata}{Data frame to generate predictions from.} 67 | 68 | \item{value}{The name of the output column: 69 | \itemize{ 70 | \item for \verb{[add_]epred_draws()}, defaults to \code{".epred"}. 71 | \item for \verb{[add_]predicted_draws()}, defaults to \code{".prediction"}. 72 | \item for \verb{[add_]linpred_draws()}, defaults to \code{".linpred"}. 73 | \item for \verb{[add_]residual_draws()}, defaults to \code{".residual"} 74 | }} 75 | 76 | \item{...}{Optional parameters passed on to \code{rethinking::link()}. The most pertinent are: 77 | \itemize{ 78 | \item \code{replace}: Optional named list of samples to replace inside posterior samples. See examples in \code{rethinking::link()}. 79 | }} 80 | 81 | \item{post}{Optional samples from posterior. When missing, \code{linpred_draws()} extracts these in advance, 82 | bypassing \code{rethinking::link()}'s normal process (\code{rethinking::link()} uses \code{rstan::extract()}, which 83 | unfortunately permutes samples, breaking the ability of the \code{.draw} column to be meaningfully joined 84 | with output from other methods, like \code{spread_draws()}).} 85 | 86 | \item{ndraws}{The number of draws per fit to return. When \code{NULL} (the default), \code{rethinking::ulam()} and 87 | \code{rethinking::map2stan()} models return all draws; \code{rethinking::quap()} and \code{rethinking::map()} models 88 | return 5000 draws.} 89 | 90 | \item{seed}{A seed to use when subsampling draws (i.e. when \code{ndraws} is not \code{NULL}).} 91 | 92 | \item{dpar}{Should distributional regression 93 | parameters be included in the output? In rethinking models, these correspond to the linear submodels 94 | returned by \code{rethinking::link()}. If \code{TRUE}, distributional regression 95 | parameters are included in the output as additional columns named after each parameter 96 | (alternative names can be provided using a list or named vector, e.g. \code{c(sigma.hat = "sigma")} 97 | would output the \code{"sigma"} parameter from a model as a column named \code{"sigma.hat"}). 98 | If \code{FALSE} (the default), distributional regression parameters are not included; instead, 99 | just the first linear submodel returned by \code{rethinking::link()} is used.} 100 | 101 | \item{re_formula, category}{Not used with this model type.} 102 | } 103 | \description{ 104 | Adds draws from the posterior link-level predictor of a rethinking model to a data frame. 105 | Provides support for \code{\link[tidybayes:add_predicted_draws]{tidybayes::linpred_draws()}} / \code{\link[tidybayes:add_predicted_draws]{tidybayes::add_linpred_draws()}} / 106 | for models from the \code{rethinking} package. 107 | } 108 | -------------------------------------------------------------------------------- /man/predicted_draws.ulam.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/predicted_draws.R 3 | \name{predicted_draws.ulam} 4 | \alias{predicted_draws.ulam} 5 | \alias{predicted_draws.quap} 6 | \alias{predicted_draws.map} 7 | \alias{predicted_draws.map2stan} 8 | \title{Add draws from the posterior predictive of a rethinking model to a data frame} 9 | \usage{ 10 | \method{predicted_draws}{ulam}( 11 | object, 12 | newdata, 13 | value = ".prediction", 14 | ..., 15 | ndraws = NULL, 16 | seed = NULL, 17 | re_formula = NULL, 18 | category = ".category" 19 | ) 20 | 21 | \method{predicted_draws}{quap}( 22 | object, 23 | newdata, 24 | value = ".prediction", 25 | ..., 26 | ndraws = NULL, 27 | seed = NULL, 28 | re_formula = NULL, 29 | category = ".category" 30 | ) 31 | 32 | \method{predicted_draws}{map}( 33 | object, 34 | newdata, 35 | value = ".prediction", 36 | ..., 37 | ndraws = NULL, 38 | seed = NULL, 39 | re_formula = NULL, 40 | category = ".category" 41 | ) 42 | 43 | \method{predicted_draws}{map2stan}( 44 | object, 45 | newdata, 46 | value = ".prediction", 47 | ..., 48 | ndraws = NULL, 49 | seed = NULL, 50 | re_formula = NULL, 51 | category = ".category" 52 | ) 53 | } 54 | \arguments{ 55 | \item{object}{A model fit using \code{rethinking::quap()}, \code{rethinking::ulam()}, 56 | \code{rethinking::map()}, or \code{rethinking::map2stan()}.} 57 | 58 | \item{newdata}{Data frame to generate predictions from.} 59 | 60 | \item{value}{The name of the output column: 61 | \itemize{ 62 | \item for \verb{[add_]epred_draws()}, defaults to \code{".epred"}. 63 | \item for \verb{[add_]predicted_draws()}, defaults to \code{".prediction"}. 64 | \item for \verb{[add_]linpred_draws()}, defaults to \code{".linpred"}. 65 | \item for \verb{[add_]residual_draws()}, defaults to \code{".residual"} 66 | }} 67 | 68 | \item{...}{Optional parameters passed on to \code{rethinking::sim()}. The most pertinent are: 69 | \itemize{ 70 | \item \code{post}: Optional samples from posterior. If missing, simulates samples using \code{ndraws}. 71 | }} 72 | 73 | \item{ndraws}{The number of draws per prediction to return. When \code{NULL} (the default), \code{rethinking::ulam()} and 74 | \code{rethinking::map2stan()} models return all draws; \code{rethinking::quap()} and \code{rethinking::map()} models 75 | return 5000 draws.} 76 | 77 | \item{seed}{A seed to use when subsampling draws (i.e. when \code{ndraws} is not \code{NULL}).} 78 | 79 | \item{re_formula, category}{Not used with this model type.} 80 | } 81 | \description{ 82 | Adds draws from the posterior predictive distribution of a rethinking model to a data frame. 83 | Provides support for \code{\link[tidybayes:add_predicted_draws]{tidybayes::predicted_draws()}} / \code{\link[tidybayes:add_predicted_draws]{tidybayes::add_predicted_draws()}} for 84 | models from the \code{rethinking} package. 85 | } 86 | -------------------------------------------------------------------------------- /man/tidy_draws.map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tidy_draws.R 3 | \name{tidy_draws.map} 4 | \alias{tidy_draws.map} 5 | \alias{tidy_draws.quap} 6 | \alias{tidy_draws.map2stan} 7 | \alias{tidy_draws.ulam} 8 | \title{Get a sample of posterior draws from quap and map models as a tibble} 9 | \usage{ 10 | \method{tidy_draws}{map}(model, n = 5000, ...) 11 | 12 | \method{tidy_draws}{quap}(model, n = 5000, ...) 13 | 14 | \method{tidy_draws}{map2stan}(model, ...) 15 | 16 | \method{tidy_draws}{ulam}(model, ...) 17 | } 18 | \arguments{ 19 | \item{model}{A model fit using \code{rethinking::map()}, \code{rethinking::quap()}, 20 | \code{rethinking::map2stan()}, or \code{rethinking::ulam()}} 21 | 22 | \item{n}{For \code{map} and \code{quap} models, the number of draws to generate (defaults to 5000). 23 | Ignored for \code{map2stan} and \code{ulam} models.} 24 | 25 | \item{...}{Further arguments passed to other methods (mostly unused).} 26 | } 27 | \description{ 28 | Implementation of \code{\link[tidybayes:tidy_draws]{tidybayes::tidy_draws()}} for \code{\link[rethinking:quap]{rethinking::map()}} and \code{\link[rethinking:quap]{rethinking::quap()}} 29 | models. Extract draws from a Bayesian fit into a wide-format data frame with a 30 | \code{.chain}, \code{.iteration}, and \code{.draw} column, as well as all variables as columns. 31 | While this function can be useful for quick glances at models (especially 32 | combined with \code{\link[=gather_variables]{gather_variables()}} and \code{\link[=median_qi]{median_qi()}}), it is 33 | generally speaking not as useful as \code{\link[=spread_draws]{spread_draws()}} or 34 | \code{\link[=gather_draws]{gather_draws()}} for most applications, and is mainly used internally. 35 | } 36 | \details{ 37 | The main additional functionality compared to \code{\link[tidybayes:tidy_draws]{tidybayes::tidy_draws()}} when used on 38 | other models is that since draws must be generated on-the-fly, 39 | an argument (\code{n}) is provided to indicate how many draws to take. The \code{.chain} and 40 | \code{.iteration} columns are also always \code{NA}, since they have no meaning for these model 41 | types (use the \code{.draw} column if you need to index draws). Otherwise, the result of 42 | this function follows the same format as \code{\link[tidybayes:tidy_draws]{tidybayes::tidy_draws()}}; see that 43 | documentation for more information. 44 | } 45 | \examples{ 46 | 47 | library(rethinking) 48 | library(tidybayes) 49 | library(dplyr) 50 | 51 | m = quap(alist( 52 | mpg ~ dlnorm(mu, sigma), 53 | mu <- a + b*wt, 54 | c(a,b) ~ dnorm(0, 10), 55 | sigma ~ dexp(1) 56 | ), 57 | data = mtcars, 58 | start = list(a = 4, b = -1, sigma = 1) 59 | ) 60 | 61 | m \%>\% 62 | tidy_draws() \%>\% 63 | gather_variables() \%>\% 64 | median_qi() 65 | 66 | } 67 | -------------------------------------------------------------------------------- /man/tidybayes.rethinking-deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated.R, R/linpred_draws.R, 3 | % R/predicted_draws.R 4 | \name{tidybayes.rethinking-deprecated} 5 | \alias{tidybayes.rethinking-deprecated} 6 | \alias{tidy_link} 7 | \alias{tidy_sim} 8 | \title{Deprecated functions, arguments, and column names in tidybayes} 9 | \description{ 10 | Deprecated functions, arguments, and column names and their alternatives are listed below. 11 | } 12 | \section{Deprecated Functions}{ 13 | 14 | 15 | When \code{tidybayes.rethinking} was originally created, \code{tidybayes} did not have good 16 | analogs for \code{tidy_link()} or \code{tidy_sim()}. However, \code{tidybayes} now has a mature API 17 | analogous to these functions, so they have been deprecated: 18 | \itemize{ 19 | \item \code{tidy_link()} has been replaced with \code{add_linpred_draws()} / \code{linpred_draws()}. See 20 | \code{linpred_draws.ulam()} for information on rethinking-specific arguments, or 21 | \code{tidybayes::linpred_draws()} for information on the general function. 22 | \item \code{tidy_sim()} has been replaced with \code{add_predicted_draws()} / \code{predicted_draws()}. See 23 | \code{predicted_draws.ulam()} for information on rethinking-specific arguments, or 24 | \code{tidybayes::predicted_draws()} for information on the general function. 25 | } 26 | } 27 | 28 | \author{ 29 | Matthew Kay 30 | } 31 | -------------------------------------------------------------------------------- /pkgdown/extra.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-size: 15.5px; 3 | } 4 | 5 | .navbar-brand { 6 | font-size: 16px; 7 | font-weight: bold; 8 | } 9 | 10 | .navbar-default .navbar-nav>li>a:hover, 11 | .navbar-default .navbar-nav>li>a:focus { 12 | background-color: #eee; 13 | } 14 | 15 | p.caption { 16 | display: none; 17 | } 18 | 19 | h1, .h1 { 20 | font-size: 32px; 21 | font-weight: bold; 22 | } 23 | 24 | h1 small, .h1 small { 25 | font-size: 70%; 26 | text-transform: uppercase; 27 | letter-spacing: 0.5px; 28 | } 29 | 30 | img#tidybayes_logo { 31 | width: 80px; 32 | margin-top: -48px; 33 | margin-right: -60px; 34 | } 35 | 36 | .page-header h1 { 37 | padding-right: 60px; 38 | } 39 | 40 | @media (max-width: 1200px) { 41 | img#tidybayes_logo { 42 | display: none; 43 | } 44 | .page-header h1 { 45 | padding-right: 0; 46 | } 47 | } 48 | 49 | h2, .h2 { 50 | font-size: 28px; 51 | font-weight: bold; 52 | } 53 | 54 | h3, .h3 { 55 | font-size: 20px; 56 | font-weight: bold; 57 | } 58 | 59 | h4, .h4 { 60 | font-size: 20px; 61 | font-weight: normal; 62 | } 63 | 64 | .contents h1, .contents h2, .contents h3, .contents h4 { 65 | margin-bottom: 20px; 66 | } 67 | 68 | .contents .page-header h1 { 69 | margin-top: 25px; 70 | } 71 | 72 | .contents h3, .contents h4 { 73 | margin-top: -55px; 74 | } 75 | 76 | h4.date, h4.author { 77 | font-size: 1em; 78 | color: #bbb; 79 | display: inline; 80 | padding-right: 0.5em; 81 | } 82 | 83 | pre code { 84 | font-size: 13.5px; 85 | white-space: pre; 86 | } 87 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | test_check("tidybayes.rethinking") 3 | -------------------------------------------------------------------------------- /tests/testthat/test.fitted_draws.R: -------------------------------------------------------------------------------- 1 | # Tests for fitted_draws 2 | # 3 | # Author: mjskay 4 | ############################################################################### 5 | 6 | library(testthat) 7 | library(tidybayes) 8 | library(tidybayes.rethinking) 9 | 10 | context("fitted_draws") 11 | -------------------------------------------------------------------------------- /vignettes/slabinterval_family.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mjskay/tidybayes.rethinking/867520fbdb148975ea9cd7fab426205e24f69749/vignettes/slabinterval_family.png --------------------------------------------------------------------------------