-
-
Notifications
You must be signed in to change notification settings - Fork 84
add ppc_intervals_data() and ppc_ribbon_data() #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Awesome. I will take a look at the changes to the code shortly but what you describe sounds good. On another note, for now don't worry about travis-ci errors as long as the tests pass locally for you. I've been having issues with travis lately (as described in #102) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really great. Just one tiny change that I think needs to be made before I merge it:
Currently we have dplyr (>= 0.4.3)
in Imports, but with your changes I think we need to bump that up to something like dplyr (>= 0.7.2)
right?
@@ -1,7 +1,7 @@ | |||
library(bayesplot) | |||
context("PPC: intervals & ribbon") | |||
|
|||
source("data-for-ppc-tests.R") | |||
source(test_path("data-for-ppc-tests.R")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't believe I hadn't seen the testthat::test_path
function before! Much better than having to manually change the path when working locally with the file.
..., | ||
prob = 0.9, | ||
alpha = 0.33, | ||
size = 0.25) { | ||
check_ignored_arguments(...) | ||
y <- validate_y(y) | ||
if (!missing(intervals)) { | ||
if (!is.null(intervals)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on switching from missing
to is.null
here and elsewhere
Now requiring dplyr 7.1. Also ppc_data <- ppc_intervals_data(y, yrep, x = year, prob = 0.5)
ppc_data
#> # A tibble: 50 x 7
#> y_id y_obs x prob lo mid hi
#> <int> <dbl> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 1 0.53805957 2000 0.5 -1.3676763 0.04949865 1.234838
#> 2 2 -0.08530312 2000 0.5 -1.4076316 0.02063800 1.525351
#> 3 3 -2.07159502 2000 0.5 -1.4066701 -0.21142794 1.142865
#> 4 4 0.50558133 2000 0.5 -0.9525499 -0.07389371 1.325387
#> 5 5 -0.53260805 2000 0.5 -1.6223410 -0.12686028 1.460296
#> 6 6 -0.58404397 2001 0.5 -1.3369523 0.24740165 1.662270
#> 7 7 -1.70230154 2001 0.5 -1.0900023 0.24664589 1.483820
#> 8 8 -1.93219789 2001 0.5 -1.1667882 0.12664362 1.487778
#> 9 9 1.13020785 2001 0.5 -1.2858419 0.04993576 1.298840
#> 10 10 -2.06319327 2001 0.5 -1.0138175 0.13137916 1.391382
#> # ... with 40 more rows
ppc_data1 <- ppc_intervals_data(y, yrep, x = year, prob = 0.5)
ppc_data2 <- ppc_intervals_data(y, yrep, x = year, prob = 0.8)
ppc_data3 <- ppc_intervals_data(y, yrep, x = year, prob = 0.9)
library(ggplot2)
theme_set(theme_grey())
ggplot(rbind(ppc_data1, ppc_data2, ppc_data3)) +
aes(x = x, y = mid, ymin = lo, ymax = hi) +
geom_linerange(aes(size = -prob)) +
guides(size = "none") +
theme_grey() |
Good idea on including |
See issue #99.
I added functions
ppc_intervals_data()
andppc_ribbon_data()
. These return the data that would be plotted by theppc_intervals
family of plotters.I refactored the internal
.ppc_intervals_data()
function. Before it stacked replication intervals and observed ys on top of each other and told them apart using a columnis_y
. That is:But now, those observed values are stored in a column called
y_obs
:This format makes creating the plots a little easier.
I also updated the unit tests to match this new output format.
I don't like relying on
is.missing()
when setting default values for missing function arguments. (It's much harder to test during interactive programming.) When I ran into this issue, I instead used the pattern...I also imported rlang and started to use the new system of nonstandard evaluation for the tidyverse.
Visual tests
These are the plots generated by the examples in
?ppc_intervals
:ppc_loo_intervals()
build on top of theppc_intervals()
function, so here are some plots generated in thetest-ppc-loo.R
file. (I would use the example but it takes forever to run.) This check just confirms that everything looks okay.