Skip to content
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

fix two-sided p-value shading #437

Merged
merged 6 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

To be released as v1.0.2.

* Fixed p-value shading when the calculated statistic falls exactly on the boundaries of a histogram bin (#424).

# infer v1.0.1 (GitHub Only)

This release reflects the infer version accepted to the Journal of Open Source Software.
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
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