Skip to content

Commit

Permalink
Update github ci and deps
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Apr 24, 2024
1 parent 4f2eddd commit d777de6
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 84 deletions.
31 changes: 14 additions & 17 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,32 @@ jobs:
matrix:
config:
# running Windows and Mac with --no-examples to avoid spurious Stan crashes in examples
- {os: windows-latest, r: 'release', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes", "--no-examples"'}
- {os: macOS-latest, r: 'release', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes", "--no-examples"'}
- {os: ubuntu-latest, r: 'devel', suffix: '', not_cran: 'true', check_options: 'NULL', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: windows-latest, r: 'release', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes", "--ignore-vignettes", "--no-examples"'}
- {os: macOS-latest, r: 'release', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes", "--ignore-vignettes", "--no-examples"'}
- {os: ubuntu-latest, r: 'devel', suffix: '', not_cran: 'true', check_options: 'NULL', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest", http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release', suffix: '', not_cran: 'true', check_options: 'NULL', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: ubuntu-latest, r: 'release', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes"', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: ubuntu-latest, r: 'oldrel', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes"', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: ubuntu-latest, r: '4.1', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes"', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: ubuntu-latest, r: '4.0', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes"', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: ubuntu-latest, r: '3.6', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes"', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: ubuntu-latest, r: 'release', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes", "--ignore-vignettes"', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: ubuntu-latest, r: 'oldrel', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes", "--ignore-vignettes"', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: ubuntu-latest, r: '4.1', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes", "--ignore-vignettes"', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: ubuntu-latest, r: '4.0', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes", "--ignore-vignettes"', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
- {os: ubuntu-latest, r: '3.6', suffix: 'quick', not_cran: 'false', check_options: '"--no-build-vignettes", "--ignore-vignettes"', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
_R_CHECK_FORCE_SUGGESTS_: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-pandoc@v2

- name: Query dependencies
run: |
install.packages('remotes')
Expand All @@ -64,13 +65,9 @@ jobs:
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
Rscript -e "install.packages('pak')"
sysreqs=$(Rscript -e "cat(tryCatch(pak::pkg_sysreqs('.', dependencies = TRUE), error = function(e) pak::pkg_sysreqs('.'))[['install_scripts']])")
sudo -s eval "$sysreqs"
sudo apt-get install jags cargo libudunits2-dev libgdal-dev
# cargo: for gifski
# libudunits2-dev for units (transformr)
# libgdal-dev for sf (transformr)
- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Suggests:
rstanarm (>= 2.19.2),
emmeans,
broom (>= 0.4.3),
dotwhisker,
MCMCglmm,
bayesplot,
modelr,
Expand All @@ -59,6 +58,7 @@ Suggests:
gganimate,
gifski,
png,
ragg,
pkgdown,
distributional,
transformr
Expand Down
10 changes: 1 addition & 9 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,6 @@ bind_rows(linear_results, bayes_results) %>%

Shrinkage towards the overall mean is visible in the Bayesian results.

Compatibility with `broom::tidy` also gives compatibility with `dotwhisker::dwplot`:

```{r dwplot, warning = FALSE}
bind_rows(linear_results, bayes_results) %>%
rename(term = condition) %>%
dotwhisker::dwplot()
```

### Posterior prediction and complex custom plots

The tidy data format returned by `spread_draws` also facilitates additional computation on variables followed by the construction of more complex custom plots. For example, we can generate posterior predictions easily, and use the `.width` argument (passed internally to `median_qi`) to generate any number of intervals from the posterior predictions, then plot them alongside point summaries and the data:
Expand Down Expand Up @@ -502,7 +494,7 @@ p = mtcars %>%
transition_states(.draw, 0, 1) +
shadow_mark(past = TRUE, future = TRUE, alpha = 1/20, color = "gray50")
animate(p, nframes = ndraws, fps = 2.5, width = 672, height = 480, res = 100, dev = "png", type = "cairo")
animate(p, nframes = ndraws, fps = 2.5, width = 672, height = 480, units = "px", res = 100, dev = "ragg_png")
```

See `vignette("tidybayes")` for a variety of additional examples and more explanation of how it works.
Expand Down
63 changes: 26 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,21 @@ m %>%
## # Groups: condition [1]
## condition condition_mean .chain .iteration .draw response_sd
## <fct> <dbl> <int> <int> <int> <dbl>
## 1 A 0.234 1 1 1 0.640
## 2 A 0.156 1 2 2 0.455
## 3 A 0.0598 1 3 3 0.713
## 4 A 0.426 1 4 4 0.681
## 5 A 0.0164 1 5 5 0.626
## 6 A 0.131 1 6 6 0.501
## 7 A 0.397 1 7 7 0.537
## 8 A 0.325 1 8 8 0.543
## 9 A 0.363 1 9 9 0.504
## 10 A 0.152 1 10 10 0.620
## 11 A 0.263 1 11 11 0.473
## 12 A 0.328 1 12 12 0.463
## 13 A -0.114 1 13 13 0.705
## 14 A 0.486 1 14 14 0.564
## 15 A 0.0881 1 15 15 0.492
## 1 A 0.00544 1 1 1 0.576
## 2 A -0.0836 1 2 2 0.576
## 3 A 0.0324 1 3 3 0.551
## 4 A 0.113 1 4 4 0.576
## 5 A 0.157 1 5 5 0.583
## 6 A 0.218 1 6 6 0.621
## 7 A 0.276 1 7 7 0.641
## 8 A 0.0130 1 8 8 0.637
## 9 A 0.152 1 9 9 0.609
## 10 A 0.192 1 10 10 0.521
## 11 A 0.154 1 11 11 0.558
## 12 A 0.298 1 12 12 0.552
## 13 A 0.349 1 13 13 0.531
## 14 A 0.471 1 14 14 0.566
## 15 A 0.313 1 15 15 0.568

The condition numbers are automatically turned back into text (“A”, “B”,
“C”, …) and split into their own column. A long-format data frame is
Expand Down Expand Up @@ -428,11 +428,11 @@ m %>%
## # A tibble: 5 × 7
## condition condition_mean .lower .upper .width .point .interval
## <fct> <dbl> <dbl> <dbl> <dbl> <chr> <chr>
## 1 A 0.195 -0.141 0.540 0.95 median qi
## 2 B 0.999 0.647 1.34 0.95 median qi
## 1 A 0.199 -0.142 0.549 0.95 median qi
## 2 B 1.01 0.651 1.34 0.95 median qi
## 3 C 1.84 1.48 2.19 0.95 median qi
## 4 D 1.02 0.663 1.35 0.95 median qi
## 5 E -0.886 -1.23 -0.528 0.95 median qi
## 4 D 1.02 0.681 1.37 0.95 median qi
## 5 E -0.890 -1.23 -0.529 0.95 median qi

### Comparison to other models via compatibility with `broom`

Expand Down Expand Up @@ -481,11 +481,11 @@ bayes_results
## # A tibble: 5 × 8
## condition estimate conf.low conf.high .width .point .interval model
## <fct> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr>
## 1 A 0.195 -0.141 0.540 0.95 median qi Bayes
## 2 B 0.999 0.647 1.34 0.95 median qi Bayes
## 1 A 0.199 -0.142 0.549 0.95 median qi Bayes
## 2 B 1.01 0.651 1.34 0.95 median qi Bayes
## 3 C 1.84 1.48 2.19 0.95 median qi Bayes
## 4 D 1.02 0.663 1.35 0.95 median qi Bayes
## 5 E -0.886 -1.23 -0.528 0.95 median qi Bayes
## 4 D 1.02 0.681 1.37 0.95 median qi Bayes
## 5 E -0.890 -1.23 -0.529 0.95 median qi Bayes

This makes it easy to bind the two results together and plot them:

Expand All @@ -499,17 +499,6 @@ bind_rows(linear_results, bayes_results) %>%

Shrinkage towards the overall mean is visible in the Bayesian results.

Compatibility with `broom::tidy` also gives compatibility with
`dotwhisker::dwplot`:

``` r
bind_rows(linear_results, bayes_results) %>%
rename(term = condition) %>%
dotwhisker::dwplot()
```

![](man/figures/README/dwplot-1.png)<!-- -->

### Posterior prediction and complex custom plots

The tidy data format returned by `spread_draws` also facilitates
Expand Down Expand Up @@ -667,7 +656,7 @@ p = mtcars %>%
transition_states(.draw, 0, 1) +
shadow_mark(past = TRUE, future = TRUE, alpha = 1/20, color = "gray50")

animate(p, nframes = ndraws, fps = 2.5, width = 672, height = 480, res = 100, dev = "png", type = "cairo")
animate(p, nframes = ndraws, fps = 2.5, width = 672, height = 480, units = "px", res = 100, dev = "ragg_png")
```

![](man/figures/README/hops-1.gif)<!-- -->
Expand All @@ -689,6 +678,6 @@ have encountered, but I would love to make it cover more!

## Citing `tidybayes`

Matthew Kay (2023). *tidybayes: Tidy Data and Geoms for Bayesian
Models*. R package version 3.0.4, <https://mjskay.github.io/tidybayes/>.
Matthew Kay (2024). *tidybayes: Tidy Data and Geoms for Bayesian
Models*. R package version 3.0.6, <https://mjskay.github.io/tidybayes/>.
DOI: [10.5281/zenodo.1308151](https://doi.org/10.5281/zenodo.1308151).
Binary file modified man/figures/README/broom_bind-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README/hops-1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README/make_data-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README/pp_bands-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README/pp_bands_facet-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README/pp_intervals-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README/quantile_dotplots-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README/spaghetti-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README/stat_eye-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README/stat_halfeye-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/testthat/test.tidy_draws.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ test_that("tidy_draws works with rjags", {
})

test_that("tidy_draws works with jagsUI", {
skip_if_not_installed("rjags")
skip_if_not_installed("jagsUI")

# this test model is kind of dumb because jagsUI doesn't seem to allow you to not input data
Expand Down
4 changes: 2 additions & 2 deletions vignettes/tidy-brms.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ p = mtcars %>%
transition_states(.draw, 0, 1) +
shadow_mark(future = TRUE, color = "gray50", alpha = 1/20)
animate(p, nframes = ndraws, fps = 2.5, width = 432, height = 288, res = 96, dev = "png", type = "cairo")
animate(p, nframes = ndraws, fps = 2.5, width = 432, height = 288, units = "px", res = 96, dev = "ragg_png")
```

```{r echo=FALSE, results='asis'}
Expand Down Expand Up @@ -757,7 +757,7 @@ p = mtcars_clean %>%
scale_fill_brewer(palette = "Dark2") +
transition_manual(.draw)
animate(p, nframes = ndraws, fps = 2.5, width = 576, height = 192, res = 96, dev = "png", type = "cairo")
animate(p, nframes = ndraws, fps = 2.5, width = 576, height = 192, units = "px", res = 96, dev = "ragg_png")
```

```{r echo=FALSE, results='asis'}
Expand Down
4 changes: 2 additions & 2 deletions vignettes/tidybayes-residuals.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ p = cens_df %>%
geom_abline() +
transition_manual(residual_draw)
animate(p, nframes = k, width = 384, height = 384, res = 96, dev = "png", type = "cairo")
animate(p, nframes = k, width = 384, height = 384, units = "px", res = 96, dev = "ragg_png")
```

```{r echo=FALSE, results='asis'}
Expand Down Expand Up @@ -710,7 +710,7 @@ p = bin_df %>%
geom_abline() +
transition_manual(.residual_draw)
animate(p, nframes = k, width = 384, height = 384, res = 96, dev = "png", type = "cairo")
animate(p, nframes = k, width = 384, height = 384, units = "px", res = 96, dev = "ragg_png")
```

```{r echo=FALSE, results='asis'}
Expand Down
32 changes: 16 additions & 16 deletions vignettes/tidybayes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ if (requireNamespace("pkgdown", quietly = TRUE) && pkgdown::in_pkgdown()) {
large_height = 5.25
}
eval_chunks = if (isTRUE(exists("params"))) params$EVAL else FALSE
knitr::opts_chunk$set(
fig.width = small_width,
fig.height = small_height,
eval = if (isTRUE(exists("params"))) params$EVAL else FALSE
eval = eval_chunks
)
if (capabilities("cairo") && Sys.info()[['sysname']] != "Darwin") {
knitr::opts_chunk$set(
Expand Down Expand Up @@ -104,7 +105,6 @@ library(ggdist)
library(tidybayes)
library(ggplot2)
library(cowplot)
library(emmeans)
library(broom)
library(rstan)
library(rstanarm)
Expand Down Expand Up @@ -643,9 +643,9 @@ m_linear = lm(response ~ condition, data = ABC)

Combining `emmeans::emmeans` with `broom::tidy`, we can generate tidy-format summaries of conditional means from the above model:

```{r}
```{r, eval = eval_chunks && requireNamespace("emmeans", quietly = TRUE)}
linear_results = m_linear %>%
emmeans(~ condition) %>%
emmeans::emmeans(~ condition) %>%
tidy(conf.int = TRUE) %>%
mutate(model = "OLS")
Expand Down Expand Up @@ -733,19 +733,19 @@ m_rst = stan_glm(response ~ condition, data = ABC)

We can use `emmeans::emmeans()` to get conditional means with uncertainty:

```{r}
```{r, eval = eval_chunks && requireNamespace("emmeans", quietly = TRUE)}
m_rst %>%
emmeans( ~ condition) %>%
emmeans::emmeans( ~ condition) %>%
gather_emmeans_draws() %>%
median_qi()
```

Or `emmeans::emmeans()` with `emmeans::contrast()` to do all pairwise comparisons:

```{r}
```{r, eval = eval_chunks && requireNamespace("emmeans", quietly = TRUE)}
m_rst %>%
emmeans( ~ condition) %>%
contrast(method = "pairwise") %>%
emmeans::emmeans( ~ condition) %>%
emmeans::contrast(method = "pairwise") %>%
gather_emmeans_draws() %>%
median_qi()
```
Expand All @@ -754,20 +754,20 @@ See the documentation for `emmeans::pairwise.emmc()` for a list of the numerous

As before, we can plot the results instead of using a table:

```{r fig.width = tiny_width, fig.height = tiny_height}
```{r fig.width = tiny_width, fig.height = tiny_height, eval = eval_chunks && requireNamespace("emmeans", quietly = TRUE)}
m_rst %>%
emmeans( ~ condition) %>%
contrast(method = "pairwise") %>%
emmeans::emmeans( ~ condition) %>%
emmeans::contrast(method = "pairwise") %>%
gather_emmeans_draws() %>%
ggplot(aes(x = .value, y = contrast)) +
stat_halfeye()
```

`gather_emmeans_draws()` also supports `emm_list` objects, which contain estimates from different reference grids (see `emmeans::ref_grid()` for more information on reference grids). An additional column with the default name of `.grid` is added to indicate the reference grid for each row in the output:

```{r}
```{r, eval = eval_chunks && requireNamespace("emmeans", quietly = TRUE)}
m_rst %>%
emmeans(pairwise ~ condition) %>%
emmeans::emmeans(pairwise ~ condition) %>%
gather_emmeans_draws() %>%
median_qi()
```
Expand All @@ -789,8 +789,8 @@ Now we can use `emmeans()` and `gather_emmeans_draws()` exactly as we did with `

```r
m_glmm %>%
emmeans( ~ condition, data = ABC) %>%
contrast(method = "pairwise") %>%
emmeans::emmeans( ~ condition, data = ABC) %>%
emmeans::contrast(method = "pairwise") %>%
gather_emmeans_draws() %>%
ggplot(aes(x = .value, y = contrast)) +
stat_halfeye()
Expand Down

0 comments on commit d777de6

Please sign in to comment.