Skip to content

Commit d103d42

Browse files
committed
add message if stat="mean"
1 parent 86b8d44 commit d103d42

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

R/ppc-test-statistics.R

+16-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#' @examples
6060
#' y <- example_y_data()
6161
#' yrep <- example_yrep_draws()
62-
#' ppc_stat(y, yrep)
62+
#' ppc_stat(y, yrep, stat = "median")
6363
#' ppc_stat(y, yrep, stat = "sd") + legend_none()
6464
#'
6565
#' # use your own function for the 'stat' argument
@@ -74,8 +74,8 @@
7474
#' # plots by group
7575
#' color_scheme_set("teal")
7676
#' group <- example_group_data()
77-
#' ppc_stat_grouped(y, yrep, group)
78-
#' ppc_stat_grouped(y, yrep, group) + yaxis_text()
77+
#' ppc_stat_grouped(y, yrep, group, stat = "median")
78+
#' ppc_stat_grouped(y, yrep, group, stat = "mad") + yaxis_text()
7979
#'
8080
#' # force y-axes to have same scales, allow x axis to vary
8181
#' ppc_stat_grouped(y, yrep, group, facet_args = list(scales = "free_x")) + yaxis_text()
@@ -111,6 +111,7 @@ ppc_stat <-
111111
breaks = NULL,
112112
freq = TRUE) {
113113
stopifnot(length(stat) == 1)
114+
message_if_using_mean(stat)
114115
dots <- list(...)
115116
if (!from_grouped(dots)) {
116117
check_ignored_arguments(...)
@@ -194,6 +195,7 @@ ppc_stat_freqpoly <-
194195
bins = NULL,
195196
freq = TRUE) {
196197
stopifnot(length(stat) == 1)
198+
message_if_using_mean(stat)
197199
dots <- list(...)
198200
if (!from_grouped(dots)) {
199201
check_ignored_arguments(...)
@@ -275,6 +277,8 @@ ppc_stat_2d <- function(y,
275277
if (length(stat) != 2) {
276278
abort("For ppc_stat_2d the 'stat' argument must have length 2.")
277279
}
280+
message_if_using_mean(stat[1])
281+
message_if_using_mean(stat[2])
278282

279283
if (is.character(stat)) {
280284
lgnd_title <- bquote(italic(T) == (list(.(stat[1]), .(stat[2]))))
@@ -410,3 +414,12 @@ stat_2d_segment_data <- function(data) {
410414
Ty_label <- function() expression(italic(T(italic(y))))
411415
Tyrep_label <- function() expression(italic(T)(italic(y)[rep]))
412416

417+
418+
message_if_using_mean <- function(stat) {
419+
if (is.character(stat) && stat == "mean") {
420+
message(
421+
"Note: in most cases the default test statistic 'mean' is ",
422+
"too weak to detect anything of interest."
423+
)
424+
}
425+
}

tests/testthat/test-ppc-test-statistics.R

+31
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,37 @@ test_that("ppc_stat throws errors if 'stat' wrong length", {
2424
"length(stat) == 1 is not TRUE", fixed = TRUE)
2525
})
2626

27+
test_that("ppc_stat and ppc_stat_freqpoly message if stat='mean'", {
28+
expect_message(
29+
ppc_stat(y, yrep),
30+
"'mean' is too weak to detect anything of interest"
31+
)
32+
expect_silent(
33+
ppc_stat(y, yrep, stat = "mad")
34+
)
35+
expect_message(
36+
ppc_stat_grouped(y, yrep, group),
37+
"'mean' is too weak to detect anything of interest"
38+
)
39+
expect_silent(
40+
ppc_stat_grouped(y, yrep, group, stat = "mad")
41+
)
42+
expect_message(
43+
ppc_stat_freqpoly(y, yrep),
44+
"'mean' is too weak to detect anything of interest"
45+
)
46+
expect_silent(
47+
ppc_stat_freqpoly(y, yrep, group, stat = "mad")
48+
)
49+
expect_message(
50+
ppc_stat_freqpoly_grouped(y, yrep, group),
51+
"'mean' is too weak to detect anything of interest"
52+
)
53+
expect_silent(
54+
ppc_stat_freqpoly_grouped(y, yrep, group, stat = "mad")
55+
)
56+
})
57+
2758
test_that("ppc_stat returns ggplot object", {
2859
expect_gg(ppc_stat(y, yrep, binwidth = 0.05))
2960
expect_gg(ppc_stat(y, yrep, stat = "sd", binwidth = 0.05))

0 commit comments

Comments
 (0)