Skip to content

Commit

Permalink
merge pr #437: fix two-sided p-value shading
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Dec 31, 2021
2 parents 43e97b8 + 950bc64 commit 62d9bb3
Show file tree
Hide file tree
Showing 7 changed files with 1,115 additions and 8 deletions.
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

To be released as v1.0.2.

* Fixes `generate()` errors when columns are named `x` (#431).
* Fixed error from `visualize` when passed `generate()`d `infer_dist` objects that had not been passed to `hypothesize()` (#432).

* Fix p-value shading when the calculated statistic falls exactly on the boundaries of a histogram bin (#424).
* Fix `generate()` errors when columns are named `x` (#431).
* Fix error from `visualize` when passed `generate()`d `infer_dist` objects that had not been passed to `hypothesize()` (#432).
* Update visual checks for `visualize` output to align with the R 4.1.0+ graphics engine (#438).

# infer v1.0.1 (GitHub Only)
Expand Down
10 changes: 9 additions & 1 deletion R/shade_p_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,15 @@ two_tail_area <- function(obs_stat, direction) {
max(obs_stat, second_border), "right", do_warn = FALSE
)(data)

dplyr::bind_rows(left_area, right_area)
ret <- dplyr::bind_rows(left_area, right_area)

# jitter one of the x coords that the right and left area have in common
# so that their heights aren't summed
common_x <- which.max(ret$x[ret$dir == "left"])

ret$x[common_x] <- ret$x[common_x] - 1e-5*ret$x[common_x]

ret
}
}

Expand Down
1,076 changes: 1,076 additions & 0 deletions tests/testthat/_snaps/shade_p_value/pval-stat-match.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/visualize/vis-sim-both-1.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/visualize/vis-sim-both-2.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/visualize/viz-fit-p-val-both.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions tests/testthat/test-shade_p_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ test_that("shade_p_value works", {
"pval-both-corrupt",
expect_warning(gss_viz_both + shade_p_value(1, "aaa"), "direction")
)

# -roper p-value shading when the calculated statistic falls exactly on the
# boundaries of a histogram bin (#424)
r_hat <- gss %>%
observe(college ~ sex, success = "no degree",
stat = "ratio of props", order = c("female", "male"))

set.seed(33)

null_dist <- gss %>%
specify(college ~ sex, success = "no degree") %>%
hypothesize(null = "independence") %>%
generate(reps = 1000) %>%
calculate(stat = "ratio of props", order = c("female", "male"))


expect_doppelganger(
"pval-stat-match",
visualize(null_dist) +
shade_p_value(obs_stat = r_hat, direction = "two-sided")
)
})

test_that("shade_p_value accepts synonyms for 'direction'", {
Expand Down

0 comments on commit 62d9bb3

Please sign in to comment.